From ab2d3c1ac6e7d242b9c05f3866ffbab4470e337f Mon Sep 17 00:00:00 2001 From: "1447560092@qq.com" <1447560092@qq.com> Date: Thu, 2 Jan 2025 13:13:12 +0800 Subject: [PATCH] fix:add code --- .gitignore | 38 + Dockerfile | 24 + LICENSE | 21 + Makefile | 107 + README.md | 94 + ServerDeployment | 205 + ServerList | 73 + ServiceUpdateLog | 159 + api/matchmaking/v1/README.md | 37 + api/matchmaking/v1/backend/backend.pb.go | 231 + api/matchmaking/v1/backend/backend.proto | 27 + api/matchmaking/v1/backend/backend_grpc.pb.go | 112 + api/matchmaking/v1/backend/backend_http.pb.go | 79 + api/matchmaking/v1/block/blockOrder.pb.go | 1248 ++++ api/matchmaking/v1/block/blockOrder.proto | 134 + .../v1/block/blockOrder_grpc.pb.go | 272 + .../v1/block/blockOrder_http.pb.go | 239 + api/matchmaking/v1/error/error_reason.pb.go | 132 + api/matchmaking/v1/error/error_reason.proto | 10 + api/matchmaking/v1/forex/forex.pb.go | 1383 +++++ api/matchmaking/v1/forex/forex.proto | 151 + api/matchmaking/v1/forex/forex_grpc.pb.go | 312 + api/matchmaking/v1/forex/forex_http.pb.go | 279 + api/matchmaking/v1/money/money.pb.go | 1412 +++++ api/matchmaking/v1/money/money.proto | 160 + api/matchmaking/v1/money/money_grpc.pb.go | 352 ++ api/matchmaking/v1/money/money_http.pb.go | 319 + api/matchmaking/v1/option/optionInr.pb.go | 1508 +++++ api/matchmaking/v1/option/optionInr.proto | 162 + .../v1/option/optionInr_grpc.pb.go | 312 + .../v1/option/optionInr_http.pb.go | 279 + api/matchmaking/v1/order/order.pb.go | 435 ++ api/matchmaking/v1/order/order.proto | 67 + api/matchmaking/v1/order/order_grpc.pb.go | 272 + api/matchmaking/v1/order/order_http.pb.go | 239 + api/matchmaking/v1/share/shareBrl.pb.go | 1327 +++++ api/matchmaking/v1/share/shareBrl.proto | 144 + api/matchmaking/v1/share/shareBrl_grpc.pb.go | 312 + api/matchmaking/v1/share/shareBrl_http.pb.go | 279 + api/matchmaking/v1/share/shareEur.pb.go | 1327 +++++ api/matchmaking/v1/share/shareEur.proto | 144 + api/matchmaking/v1/share/shareEur_grpc.pb.go | 312 + api/matchmaking/v1/share/shareEur_http.pb.go | 279 + api/matchmaking/v1/share/shareFur.pb.go | 1327 +++++ api/matchmaking/v1/share/shareFur.proto | 144 + api/matchmaking/v1/share/shareFur_grpc.pb.go | 312 + api/matchmaking/v1/share/shareFur_http.pb.go | 279 + api/matchmaking/v1/share/shareGbx.pb.go | 1327 +++++ api/matchmaking/v1/share/shareGbx.proto | 145 + api/matchmaking/v1/share/shareGbx_grpc.pb.go | 312 + api/matchmaking/v1/share/shareGbx_http.pb.go | 279 + api/matchmaking/v1/share/shareHkd.pb.go | 1327 +++++ api/matchmaking/v1/share/shareHkd.proto | 145 + api/matchmaking/v1/share/shareHkd_grpc.pb.go | 312 + api/matchmaking/v1/share/shareHkd_http.pb.go | 279 + api/matchmaking/v1/share/shareIdn.pb.go | 1327 +++++ api/matchmaking/v1/share/shareIdn.proto | 144 + api/matchmaking/v1/share/shareIdn_grpc.pb.go | 312 + api/matchmaking/v1/share/shareIdn_http.pb.go | 279 + api/matchmaking/v1/share/shareInr.pb.go | 1327 +++++ api/matchmaking/v1/share/shareInr.proto | 145 + api/matchmaking/v1/share/shareInr_grpc.pb.go | 312 + api/matchmaking/v1/share/shareInr_http.pb.go | 279 + api/matchmaking/v1/share/shareJpy.pb.go | 1327 +++++ api/matchmaking/v1/share/shareJpy.proto | 144 + api/matchmaking/v1/share/shareJpy_grpc.pb.go | 312 + api/matchmaking/v1/share/shareJpy_http.pb.go | 279 + api/matchmaking/v1/share/shareMys.pb.go | 1337 +++++ api/matchmaking/v1/share/shareMys.proto | 146 + api/matchmaking/v1/share/shareMys_grpc.pb.go | 312 + api/matchmaking/v1/share/shareMys_http.pb.go | 279 + api/matchmaking/v1/share/shareSgd.pb.go | 1327 +++++ api/matchmaking/v1/share/shareSgd.proto | 144 + api/matchmaking/v1/share/shareSgd_grpc.pb.go | 312 + api/matchmaking/v1/share/shareSgd_http.pb.go | 279 + api/matchmaking/v1/share/shareTha.pb.go | 1327 +++++ api/matchmaking/v1/share/shareTha.proto | 144 + api/matchmaking/v1/share/shareTha_grpc.pb.go | 312 + api/matchmaking/v1/share/shareTha_http.pb.go | 279 + api/matchmaking/v1/share/shareUs.pb.go | 1323 +++++ api/matchmaking/v1/share/shareUs.proto | 145 + api/matchmaking/v1/share/shareUs_grpc.pb.go | 312 + api/matchmaking/v1/share/shareUs_http.pb.go | 279 + api/matchmaking/v1/virtually/contract.pb.go | 1393 +++++ api/matchmaking/v1/virtually/contract.proto | 151 + .../v1/virtually/contract_grpc.pb.go | 312 + .../v1/virtually/contract_http.pb.go | 279 + api/matchmaking/v1/virtually/second.pb.go | 1078 ++++ api/matchmaking/v1/virtually/second.proto | 104 + .../v1/virtually/second_grpc.pb.go | 152 + .../v1/virtually/second_http.pb.go | 119 + api/matchmaking/v1/virtually/spots.pb.go | 1004 ++++ api/matchmaking/v1/virtually/spots.proto | 106 + api/matchmaking/v1/virtually/spots_grpc.pb.go | 232 + api/matchmaking/v1/virtually/spots_http.pb.go | 199 + cmd/matchmaking-system/main.go | 102 + cmd/matchmaking-system/wire.go | 22 + cmd/matchmaking-system/wire_gen.go | 89 + configs/README.md | 72 + configs/admin.yaml | 26 + configs/adminBlk.yaml | 25 + configs/backend.yaml | 25 + configs/contract.yaml | 25 + configs/forex.yaml | 25 + configs/money.yaml | 25 + configs/optionInr.yaml | 25 + configs/second.yaml | 25 + configs/shareBlk.yaml | 25 + configs/shareBrl.yaml | 25 + configs/shareCache.yaml | 25 + configs/shareEur.yaml | 25 + configs/shareFur.yaml | 25 + configs/shareGbx.yaml | 25 + configs/shareHkd.yaml | 25 + configs/shareIdn.yaml | 25 + configs/shareInit.yaml | 25 + configs/shareInr.yaml | 25 + configs/shareJpy.yaml | 25 + configs/shareMys.yaml | 25 + configs/shareSgd.yaml | 25 + configs/shareTha.yaml | 25 + configs/shareUs.yaml | 25 + configs/spots.yaml | 25 + deploy/environment/docker-compose.yaml | 38 + go.mod | 81 + go.sum | 399 ++ internal/biz/README.md | 16 + internal/biz/backend.go | 70 + internal/biz/biz.go | 33 + internal/biz/forex.go | 188 + internal/biz/money.go | 210 + internal/biz/option_inr.go | 211 + internal/biz/order.go | 1387 +++++ internal/biz/share_blk.go | 466 ++ internal/biz/share_brl.go | 211 + internal/biz/share_eur.go | 211 + internal/biz/share_fur.go | 211 + internal/biz/share_gbx.go | 211 + internal/biz/share_hkd.go | 212 + internal/biz/share_idn.go | 211 + internal/biz/share_inr.go | 211 + internal/biz/share_jpy.go | 211 + internal/biz/share_mys.go | 211 + internal/biz/share_sgd.go | 211 + internal/biz/share_tha.go | 211 + internal/biz/share_us.go | 212 + internal/biz/structure/contract.go | 235 + internal/biz/structure/model.go | 421 ++ internal/biz/structure/order.go | 177 + internal/biz/structure/spots.go | 134 + internal/biz/virtual_contract.go | 190 + internal/biz/virtual_second.go | 103 + internal/biz/virtual_spots.go | 150 + internal/conf/conf.pb.go | 848 +++ internal/conf/conf.proto | 54 + internal/data/README.md | 38 + internal/data/aliyun.go | 272 + internal/data/cache/cache.go | 16 + internal/data/cache/cache_test.go | 28 + internal/data/control.go | 558 ++ internal/data/control_admin.go | 229 + internal/data/control_ainit.go | 70 + internal/data/control_forex.go | 16 + internal/data/control_money.go | 22 + internal/data/control_option.go | 18 + internal/data/control_share.go | 186 + internal/data/control_virtual.go | 36 + internal/data/convert/order.go | 4587 +++++++++++++++ internal/data/convert/order_test.go | 2525 ++++++++ internal/data/convert/share.go | 51 + internal/data/convert/share_test.go | 85 + internal/data/data.go | 97 + internal/data/memory/bigcache.go | 40 + internal/data/memory/bigcache_test.go | 23 + internal/data/memory/forexinit.go | 62 + internal/data/memory/moneyinit.go | 102 + internal/data/memory/optioninit.go | 92 + internal/data/memory/shareinit.go | 512 ++ internal/data/memory/virtualinit.go | 76 + internal/data/mongo/mongo.go | 368 ++ internal/data/mongo/mongo_test.go | 911 +++ internal/data/mq/README.md | 7 + internal/data/mq/consumer/consumer.go | 75 + internal/data/mq/consumer/consumer_test.go | 35 + internal/data/mq/consumer/entrust.go | 130 + internal/data/mq/consumer/position.go | 130 + internal/data/mq/mq.go | 66 + internal/data/mq/mq_test.go | 76 + internal/data/mq/producers/entrust.go | 93 + internal/data/mq/producers/position.go | 93 + internal/data/mq/producers/producers.go | 35 + internal/data/mq/producers/producers_test.go | 35 + internal/data/mysql/mysql.go | 32 + internal/data/mysql/mysql_test.go | 48 + internal/data/order_backend.go | 34 + internal/data/order_forex.go | 1358 +++++ internal/data/order_money.go | 1826 ++++++ internal/data/order_option_inr.go | 1365 +++++ internal/data/order_share_blk.go | 90 + internal/data/order_share_brl.go | 1507 +++++ internal/data/order_share_eur.go | 1507 +++++ internal/data/order_share_fur.go | 1505 +++++ internal/data/order_share_gbx.go | 1486 +++++ internal/data/order_share_hkd.go | 1506 +++++ internal/data/order_share_idn.go | 1498 +++++ internal/data/order_share_inr.go | 1501 +++++ internal/data/order_share_jpy.go | 1505 +++++ internal/data/order_share_mys.go | 1534 +++++ internal/data/order_share_sgd.go | 1507 +++++ internal/data/order_share_tha.go | 1511 +++++ internal/data/order_share_us.go | 1625 ++++++ internal/data/order_virtual_contract.go | 1495 +++++ internal/data/order_virtual_second.go | 647 ++ internal/data/order_virtual_spots.go | 747 +++ internal/data/order_way_ipo.go | 100 + internal/data/order_way_ipo_brl.go | 376 ++ internal/data/order_way_ipo_eur.go | 376 ++ internal/data/order_way_ipo_fur.go | 376 ++ internal/data/order_way_ipo_gbx.go | 376 ++ internal/data/order_way_ipo_hkd.go | 378 ++ internal/data/order_way_ipo_idn.go | 377 ++ internal/data/order_way_ipo_inr.go | 378 ++ internal/data/order_way_ipo_jpy.go | 376 ++ internal/data/order_way_ipo_mys.go | 378 ++ internal/data/order_way_ipo_sgd.go | 379 ++ internal/data/order_way_ipo_tha.go | 375 ++ internal/data/order_way_ipo_us.go | 374 ++ internal/data/redis/redis.go | 112 + internal/data/redis/redis_test.go | 524 ++ internal/data/restore_cached_data.go | 830 +++ internal/data/restore_cached_order_no.go | 86 + internal/data/restore_clear_cache_data.go | 664 +++ internal/data/sms/sms.go | 86 + internal/data/sms/sms_test.go | 204 + internal/data/socket/README.md | 23 + internal/data/socket/block_admin.go | 1172 ++++ internal/data/socket/block_user.go | 74 + internal/data/socket/forexData/forex.go | 42 + internal/data/socket/forex_admin.go | 98 + internal/data/socket/forex_user.go | 185 + internal/data/socket/moneyData/money.go | 42 + internal/data/socket/money_admin.go | 98 + internal/data/socket/money_user.go | 228 + internal/data/socket/optionData/option_inr.go | 48 + internal/data/socket/option_admin.go | 98 + internal/data/socket/option_user.go | 166 + internal/data/socket/order.go | 442 ++ internal/data/socket/order_test.go | 114 + internal/data/socket/order_ws.go | 192 + internal/data/socket/publicData/public.go | 1068 ++++ .../data/socket/publicData/public_test.go | 128 + internal/data/socket/shareData/share_blk.go | 47 + internal/data/socket/shareData/share_brl.go | 37 + internal/data/socket/shareData/share_eur.go | 37 + internal/data/socket/shareData/share_fur.go | 37 + internal/data/socket/shareData/share_gbx.go | 37 + internal/data/socket/shareData/share_hkd.go | 46 + internal/data/socket/shareData/share_idn.go | 37 + internal/data/socket/shareData/share_inr.go | 37 + internal/data/socket/shareData/share_jpy.go | 37 + internal/data/socket/shareData/share_mys.go | 37 + internal/data/socket/shareData/share_sgd.go | 37 + internal/data/socket/shareData/share_tha.go | 37 + internal/data/socket/shareData/share_us.go | 37 + internal/data/socket/share_admin.go | 1022 ++++ internal/data/socket/share_user.go | 2036 +++++++ internal/data/socket/virtualData/contract.go | 42 + internal/data/socket/virtualData/second.go | 42 + internal/data/socket/virtualData/spots.go | 43 + internal/data/socket/virtual_admin.go | 156 + internal/data/socket/virtual_user.go | 505 ++ internal/data/subscribe_forex.go | 853 +++ internal/data/subscribe_money.go | 1143 ++++ internal/data/subscribe_option_inr.go | 1123 ++++ internal/data/subscribe_share_blk.go | 1439 +++++ internal/data/subscribe_share_brl.go | 1250 ++++ internal/data/subscribe_share_eur.go | 1250 ++++ internal/data/subscribe_share_fur.go | 1250 ++++ internal/data/subscribe_share_gbx.go | 1241 ++++ internal/data/subscribe_share_hkd.go | 1241 ++++ internal/data/subscribe_share_idn.go | 1247 ++++ internal/data/subscribe_share_inr.go | 1248 ++++ internal/data/subscribe_share_jpy.go | 1250 ++++ internal/data/subscribe_share_mys.go | 1246 ++++ internal/data/subscribe_share_sgd.go | 1249 ++++ internal/data/subscribe_share_tha.go | 1249 ++++ internal/data/subscribe_share_us.go | 1244 ++++ internal/data/subscribe_virtual_contract.go | 862 +++ internal/data/subscribe_virtual_second.go | 334 ++ internal/data/subscribe_virtual_spots.go | 365 ++ internal/data/tradedeal/forex/forex.go | 126 + internal/data/tradedeal/money/money.go | 149 + internal/data/tradedeal/option/option_inr.go | 302 + internal/data/tradedeal/share/share_blk.go | 46 + internal/data/tradedeal/share/share_brl.go | 330 ++ internal/data/tradedeal/share/share_eur.go | 330 ++ internal/data/tradedeal/share/share_fur.go | 330 ++ internal/data/tradedeal/share/share_gbx.go | 316 + internal/data/tradedeal/share/share_hkd.go | 330 ++ internal/data/tradedeal/share/share_idn.go | 328 ++ internal/data/tradedeal/share/share_inr.go | 328 ++ internal/data/tradedeal/share/share_jpy.go | 330 ++ internal/data/tradedeal/share/share_mys.go | 330 ++ internal/data/tradedeal/share/share_sgd.go | 330 ++ internal/data/tradedeal/share/share_tha.go | 330 ++ internal/data/tradedeal/share/share_us.go | 326 ++ .../tradedeal/virtual/virtual_contract.go | 137 + .../data/tradedeal/virtual/virtual_second.go | 117 + .../data/tradedeal/virtual/virtual_spots.go | 105 + internal/data/utils_check.go | 2249 +++++++ internal/data/utils_check_test.go | 1926 ++++++ internal/data/utils_other.go | 3171 ++++++++++ internal/errors/error_encoder.go | 58 + internal/errors/error_encoder_test.go | 75 + internal/pkg/flags/market_time.go | 99 + internal/pkg/flags/message.go | 108 + internal/pkg/flags/share.go | 132 + internal/pkg/flags/system.go | 275 + internal/pkg/flags/table.go | 113 + internal/pkg/gzip/gzip.go | 61 + internal/pkg/gzip/gzip_test.go | 103 + internal/pkg/logging/applogger/applogger.go | 92 + .../pkg/logging/applogger/applogger_test.go | 256 + internal/pkg/logging/common/common.go | 25 + .../logging/perflogger/performancelogger.go | 104 + .../perflogger/performancelogger_test.go | 259 + internal/pkg/middleware/auth/auth.go | 98 + internal/pkg/middleware/auth/auth_test.go | 97 + internal/pkg/model/bot_account.go | 22 + internal/pkg/model/bot_admin.go | 19 + internal/pkg/model/bot_admin_log.go | 19 + internal/pkg/model/bot_announcement.go | 19 + internal/pkg/model/bot_attachment.go | 22 + internal/pkg/model/bot_auth_group.go | 11 + internal/pkg/model/bot_auth_group_access.go | 6 + internal/pkg/model/bot_auth_menu.go | 20 + internal/pkg/model/bot_auth_role.go | 12 + internal/pkg/model/bot_auth_rule.go | 22 + internal/pkg/model/bot_banner.go | 18 + internal/pkg/model/bot_brokerage_setting.go | 11 + internal/pkg/model/bot_category.go | 18 + internal/pkg/model/bot_config.go | 16 + internal/pkg/model/bot_contract_list.go | 22 + internal/pkg/model/bot_contract_market.go | 17 + internal/pkg/model/bot_contract_sec_trade.go | 40 + internal/pkg/model/bot_contract_setting.go | 13 + internal/pkg/model/bot_contract_trade.go | 38 + internal/pkg/model/bot_country.go | 9 + internal/pkg/model/bot_digital_list.go | 19 + internal/pkg/model/bot_digital_trade.go | 30 + internal/pkg/model/bot_document.go | 19 + internal/pkg/model/bot_drawal_setting.go | 11 + internal/pkg/model/bot_faq.go | 18 + internal/pkg/model/bot_fee_setting.go | 14 + internal/pkg/model/bot_file.go | 12 + internal/pkg/model/bot_forex_list.go | 22 + internal/pkg/model/bot_forex_trade.go | 38 + internal/pkg/model/bot_history_fund_stock.go | 15 + internal/pkg/model/bot_language_setting.go | 8 + internal/pkg/model/bot_money_trade.go | 37 + internal/pkg/model/bot_payment_list.go | 24 + internal/pkg/model/bot_pre_brl_stock.go | 38 + internal/pkg/model/bot_pre_eur_stock.go | 38 + internal/pkg/model/bot_pre_fund_stock.go | 38 + .../pkg/model/bot_pre_fund_stock_refer.go | 8 + internal/pkg/model/bot_pre_fur_stock.go | 38 + internal/pkg/model/bot_pre_hkd_stock.go | 38 + internal/pkg/model/bot_pre_idn_stock.go | 38 + internal/pkg/model/bot_pre_in_stock.go | 38 + internal/pkg/model/bot_pre_jp_stock.go | 38 + internal/pkg/model/bot_pre_mys_stock.go | 38 + internal/pkg/model/bot_pre_sgd_stock.go | 38 + internal/pkg/model/bot_pre_tha_stock.go | 38 + internal/pkg/model/bot_pre_us_stock.go | 38 + internal/pkg/model/bot_recharge_apply.go | 29 + internal/pkg/model/bot_service_setting.go | 9 + internal/pkg/model/bot_stock_block_list.go | 27 + internal/pkg/model/bot_stock_block_trade.go | 37 + internal/pkg/model/bot_stock_brl_list.go | 21 + internal/pkg/model/bot_stock_brl_trade.go | 36 + internal/pkg/model/bot_stock_eur_list.go | 21 + internal/pkg/model/bot_stock_eur_trade.go | 36 + internal/pkg/model/bot_stock_fur_list.go | 21 + internal/pkg/model/bot_stock_fur_trade.go | 36 + internal/pkg/model/bot_stock_gbx_list.go | 22 + internal/pkg/model/bot_stock_gbx_trade.go | 36 + internal/pkg/model/bot_stock_hkd_list.go | 21 + internal/pkg/model/bot_stock_hkd_trade.go | 36 + internal/pkg/model/bot_stock_idn_list.go | 20 + internal/pkg/model/bot_stock_idn_trade.go | 36 + internal/pkg/model/bot_stock_in_list.go | 22 + internal/pkg/model/bot_stock_in_trade.go | 36 + internal/pkg/model/bot_stock_index.go | 18 + internal/pkg/model/bot_stock_jp_list.go | 21 + internal/pkg/model/bot_stock_jp_trade.go | 36 + internal/pkg/model/bot_stock_list.go | 20 + internal/pkg/model/bot_stock_market.go | 25 + internal/pkg/model/bot_stock_mys_list.go | 21 + .../pkg/model/bot_stock_mys_list_p_two.go | 22 + internal/pkg/model/bot_stock_mys_trade.go | 37 + .../pkg/model/bot_stock_option_inr_list.go | 21 + .../pkg/model/bot_stock_option_inr_trade.go | 45 + .../pkg/model/bot_stock_prices_setting.go | 15 + internal/pkg/model/bot_stock_sgd_list.go | 21 + internal/pkg/model/bot_stock_sgd_trade.go | 36 + internal/pkg/model/bot_stock_tha_list.go | 20 + internal/pkg/model/bot_stock_tha_trade.go | 36 + internal/pkg/model/bot_stock_trade.go | 36 + internal/pkg/model/bot_trade_fee.go | 15 + internal/pkg/model/bot_user_arrears.go | 16 + .../pkg/model/bot_user_balance_change_log.go | 16 + internal/pkg/model/bot_user_bank.go | 24 + .../model/bot_user_brl_give_stock_order.go | 20 + .../pkg/model/bot_user_brl_pre_stock_order.go | 26 + internal/pkg/model/bot_user_brokerage.go | 16 + internal/pkg/model/bot_user_contract.go | 15 + internal/pkg/model/bot_user_contract_log.go | 17 + internal/pkg/model/bot_user_contract_sec.go | 15 + .../pkg/model/bot_user_contract_sec_log.go | 17 + internal/pkg/model/bot_user_digital.go | 15 + internal/pkg/model/bot_user_digital_log.go | 17 + .../model/bot_user_eur_give_stock_order.go | 20 + .../pkg/model/bot_user_eur_pre_stock_order.go | 26 + internal/pkg/model/bot_user_forex.go | 15 + internal/pkg/model/bot_user_forex_log.go | 17 + .../model/bot_user_fund_pre_stock_order.go | 23 + .../model/bot_user_fur_give_stock_order.go | 20 + .../pkg/model/bot_user_fur_pre_stock_order.go | 26 + .../model/bot_user_gbx_give_stock_order.go | 20 + .../pkg/model/bot_user_gbx_pre_stock_order.go | 26 + .../model/bot_user_hkd_give_stock_order.go | 20 + .../pkg/model/bot_user_hkd_pre_stock_order.go | 26 + .../model/bot_user_idn_give_stock_order.go | 20 + .../pkg/model/bot_user_idn_pre_stock_order.go | 26 + .../pkg/model/bot_user_in_give_stock_order.go | 20 + .../pkg/model/bot_user_in_pre_stock_order.go | 26 + .../pkg/model/bot_user_jp_give_stock_order.go | 20 + .../pkg/model/bot_user_jp_pre_stock_order.go | 26 + internal/pkg/model/bot_user_level.go | 8 + internal/pkg/model/bot_user_login_log.go | 15 + internal/pkg/model/bot_user_market.go | 14 + internal/pkg/model/bot_user_money.go | 15 + internal/pkg/model/bot_user_money_log.go | 17 + .../model/bot_user_mys_give_stock_order.go | 20 + .../pkg/model/bot_user_mys_pre_stock_order.go | 26 + .../model/bot_user_sgd_give_stock_order.go | 20 + .../pkg/model/bot_user_sgd_pre_stock_order.go | 26 + internal/pkg/model/bot_user_stock.go | 15 + .../pkg/model/bot_user_stock_block_log.go | 18 + internal/pkg/model/bot_user_stock_brl.go | 15 + internal/pkg/model/bot_user_stock_brl_log.go | 17 + internal/pkg/model/bot_user_stock_eur.go | 15 + internal/pkg/model/bot_user_stock_eur_log.go | 17 + internal/pkg/model/bot_user_stock_fund.go | 15 + .../bot_user_stock_fund_interest_receipt.go | 21 + internal/pkg/model/bot_user_stock_fund_log.go | 17 + internal/pkg/model/bot_user_stock_fur.go | 15 + internal/pkg/model/bot_user_stock_fur_log.go | 17 + internal/pkg/model/bot_user_stock_gbx.go | 15 + internal/pkg/model/bot_user_stock_gbx_log.go | 17 + internal/pkg/model/bot_user_stock_hkd.go | 15 + internal/pkg/model/bot_user_stock_hkd_log.go | 17 + internal/pkg/model/bot_user_stock_idn.go | 15 + internal/pkg/model/bot_user_stock_idn_log.go | 17 + internal/pkg/model/bot_user_stock_in.go | 15 + internal/pkg/model/bot_user_stock_in_log.go | 17 + internal/pkg/model/bot_user_stock_jp.go | 15 + internal/pkg/model/bot_user_stock_jp_log.go | 17 + internal/pkg/model/bot_user_stock_log.go | 17 + internal/pkg/model/bot_user_stock_mys.go | 15 + internal/pkg/model/bot_user_stock_mys_log.go | 17 + .../pkg/model/bot_user_stock_option_inr.go | 15 + .../model/bot_user_stock_option_inr_log.go | 17 + internal/pkg/model/bot_user_stock_sgd.go | 15 + internal/pkg/model/bot_user_stock_sgd_log.go | 17 + internal/pkg/model/bot_user_stock_tha.go | 15 + internal/pkg/model/bot_user_stock_tha_log.go | 17 + .../model/bot_user_tha_give_stock_order.go | 20 + .../pkg/model/bot_user_tha_pre_stock_order.go | 26 + internal/pkg/model/bot_user_transfer.go | 20 + .../pkg/model/bot_user_us_give_stock_order.go | 20 + .../pkg/model/bot_user_us_pre_stock_order.go | 26 + internal/pkg/model/bot_user_verify_log.go | 19 + internal/pkg/model/bot_user_walletaddress.go | 16 + internal/pkg/model/bot_user_withdrawal.go | 29 + internal/pkg/model/bot_users.go | 36 + internal/pkg/pprof/cpu.prof | Bin 0 -> 4487 bytes internal/pkg/pprof/pprof_test.go | 31 + internal/pkg/setting/block.go | 28 + internal/pkg/setting/forex.go | 11 + internal/pkg/setting/hongkong.go | 16 + internal/pkg/setting/money.go | 11 + internal/pkg/setting/option.go | 16 + internal/pkg/setting/share.go | 91 + internal/pkg/setting/virtual.go | 21 + internal/pkg/utils/utils.go | 694 +++ internal/pkg/utils/utils_test.go | 741 +++ internal/server/grpc.go | 64 + internal/server/http.go | 132 + internal/server/server.go | 8 + internal/service/README.md | 17 + internal/service/backend.go | 30 + internal/service/backend/backend.go | 73 + internal/service/block/share_blk.go | 305 + internal/service/forex.go | 129 + internal/service/forex/forex.go | 325 ++ internal/service/money.go | 150 + internal/service/money/money.go | 346 ++ internal/service/option/option_inr.go | 358 ++ internal/service/option_inr.go | 131 + internal/service/order.go | 110 + internal/service/order/order.go | 134 + internal/service/order/order_test.go | 119 + internal/service/service.go | 127 + internal/service/share/share_brl.go | 314 + internal/service/share/share_eur.go | 314 + internal/service/share/share_fur.go | 314 + internal/service/share/share_gbx.go | 316 + internal/service/share/share_hkd.go | 317 + internal/service/share/share_idn.go | 317 + internal/service/share/share_inr.go | 317 + internal/service/share/share_jpy.go | 314 + internal/service/share/share_mys.go | 318 + internal/service/share/share_sgd.go | 317 + internal/service/share/share_tha.go | 317 + internal/service/share/share_us.go | 317 + internal/service/share_blk.go | 114 + internal/service/share_brl.go | 131 + internal/service/share_eur.go | 131 + internal/service/share_fur.go | 131 + internal/service/share_gbx.go | 131 + internal/service/share_hkd.go | 131 + internal/service/share_idn.go | 131 + internal/service/share_inr.go | 131 + internal/service/share_jpy.go | 131 + internal/service/share_mys.go | 131 + internal/service/share_sgd.go | 131 + internal/service/share_tha.go | 131 + internal/service/share_us.go | 131 + internal/service/virtual/contract.go | 326 ++ internal/service/virtual/second.go | 194 + internal/service/virtual/spots.go | 216 + internal/service/virtual_contract.go | 130 + internal/service/virtual_second.go | 51 + internal/service/virtual_spots.go | 93 + openapi.yaml | 5187 +++++++++++++++++ third_party/README.md | 1 + third_party/errors/errors.proto | 18 + third_party/google/api/annotations.proto | 31 + third_party/google/api/client.proto | 101 + third_party/google/api/field_behavior.proto | 80 + third_party/google/api/http.proto | 375 ++ third_party/google/api/httpbody.proto | 77 + third_party/google/protobuf/any.proto | 158 + third_party/google/protobuf/api.proto | 208 + .../google/protobuf/compiler/plugin.proto | 183 + third_party/google/protobuf/descriptor.proto | 921 +++ third_party/google/protobuf/duration.proto | 116 + third_party/google/protobuf/empty.proto | 52 + third_party/google/protobuf/field_mask.proto | 245 + .../google/protobuf/source_context.proto | 48 + third_party/google/protobuf/struct.proto | 95 + third_party/google/protobuf/timestamp.proto | 147 + third_party/google/protobuf/type.proto | 187 + third_party/google/protobuf/wrappers.proto | 123 + third_party/openapi/v3/annotations.proto | 60 + third_party/openapi/v3/openapi.proto | 672 +++ third_party/validate/README.md | 3 + third_party/validate/validate.proto | 863 +++ 569 files changed, 162383 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 ServerDeployment create mode 100644 ServerList create mode 100644 ServiceUpdateLog create mode 100644 api/matchmaking/v1/README.md create mode 100644 api/matchmaking/v1/backend/backend.pb.go create mode 100644 api/matchmaking/v1/backend/backend.proto create mode 100644 api/matchmaking/v1/backend/backend_grpc.pb.go create mode 100644 api/matchmaking/v1/backend/backend_http.pb.go create mode 100644 api/matchmaking/v1/block/blockOrder.pb.go create mode 100644 api/matchmaking/v1/block/blockOrder.proto create mode 100644 api/matchmaking/v1/block/blockOrder_grpc.pb.go create mode 100644 api/matchmaking/v1/block/blockOrder_http.pb.go create mode 100644 api/matchmaking/v1/error/error_reason.pb.go create mode 100644 api/matchmaking/v1/error/error_reason.proto create mode 100644 api/matchmaking/v1/forex/forex.pb.go create mode 100644 api/matchmaking/v1/forex/forex.proto create mode 100644 api/matchmaking/v1/forex/forex_grpc.pb.go create mode 100644 api/matchmaking/v1/forex/forex_http.pb.go create mode 100644 api/matchmaking/v1/money/money.pb.go create mode 100644 api/matchmaking/v1/money/money.proto create mode 100644 api/matchmaking/v1/money/money_grpc.pb.go create mode 100644 api/matchmaking/v1/money/money_http.pb.go create mode 100644 api/matchmaking/v1/option/optionInr.pb.go create mode 100644 api/matchmaking/v1/option/optionInr.proto create mode 100644 api/matchmaking/v1/option/optionInr_grpc.pb.go create mode 100644 api/matchmaking/v1/option/optionInr_http.pb.go create mode 100644 api/matchmaking/v1/order/order.pb.go create mode 100644 api/matchmaking/v1/order/order.proto create mode 100644 api/matchmaking/v1/order/order_grpc.pb.go create mode 100644 api/matchmaking/v1/order/order_http.pb.go create mode 100644 api/matchmaking/v1/share/shareBrl.pb.go create mode 100644 api/matchmaking/v1/share/shareBrl.proto create mode 100644 api/matchmaking/v1/share/shareBrl_grpc.pb.go create mode 100644 api/matchmaking/v1/share/shareBrl_http.pb.go create mode 100644 api/matchmaking/v1/share/shareEur.pb.go create mode 100644 api/matchmaking/v1/share/shareEur.proto create mode 100644 api/matchmaking/v1/share/shareEur_grpc.pb.go create mode 100644 api/matchmaking/v1/share/shareEur_http.pb.go create mode 100644 api/matchmaking/v1/share/shareFur.pb.go create mode 100644 api/matchmaking/v1/share/shareFur.proto create mode 100644 api/matchmaking/v1/share/shareFur_grpc.pb.go create mode 100644 api/matchmaking/v1/share/shareFur_http.pb.go create mode 100644 api/matchmaking/v1/share/shareGbx.pb.go create mode 100644 api/matchmaking/v1/share/shareGbx.proto create mode 100644 api/matchmaking/v1/share/shareGbx_grpc.pb.go create mode 100644 api/matchmaking/v1/share/shareGbx_http.pb.go create mode 100644 api/matchmaking/v1/share/shareHkd.pb.go create mode 100644 api/matchmaking/v1/share/shareHkd.proto create mode 100644 api/matchmaking/v1/share/shareHkd_grpc.pb.go create mode 100644 api/matchmaking/v1/share/shareHkd_http.pb.go create mode 100644 api/matchmaking/v1/share/shareIdn.pb.go create mode 100644 api/matchmaking/v1/share/shareIdn.proto create mode 100644 api/matchmaking/v1/share/shareIdn_grpc.pb.go create mode 100644 api/matchmaking/v1/share/shareIdn_http.pb.go create mode 100644 api/matchmaking/v1/share/shareInr.pb.go create mode 100644 api/matchmaking/v1/share/shareInr.proto create mode 100644 api/matchmaking/v1/share/shareInr_grpc.pb.go create mode 100644 api/matchmaking/v1/share/shareInr_http.pb.go create mode 100644 api/matchmaking/v1/share/shareJpy.pb.go create mode 100644 api/matchmaking/v1/share/shareJpy.proto create mode 100644 api/matchmaking/v1/share/shareJpy_grpc.pb.go create mode 100644 api/matchmaking/v1/share/shareJpy_http.pb.go create mode 100644 api/matchmaking/v1/share/shareMys.pb.go create mode 100644 api/matchmaking/v1/share/shareMys.proto create mode 100644 api/matchmaking/v1/share/shareMys_grpc.pb.go create mode 100644 api/matchmaking/v1/share/shareMys_http.pb.go create mode 100644 api/matchmaking/v1/share/shareSgd.pb.go create mode 100644 api/matchmaking/v1/share/shareSgd.proto create mode 100644 api/matchmaking/v1/share/shareSgd_grpc.pb.go create mode 100644 api/matchmaking/v1/share/shareSgd_http.pb.go create mode 100644 api/matchmaking/v1/share/shareTha.pb.go create mode 100644 api/matchmaking/v1/share/shareTha.proto create mode 100644 api/matchmaking/v1/share/shareTha_grpc.pb.go create mode 100644 api/matchmaking/v1/share/shareTha_http.pb.go create mode 100644 api/matchmaking/v1/share/shareUs.pb.go create mode 100644 api/matchmaking/v1/share/shareUs.proto create mode 100644 api/matchmaking/v1/share/shareUs_grpc.pb.go create mode 100644 api/matchmaking/v1/share/shareUs_http.pb.go create mode 100644 api/matchmaking/v1/virtually/contract.pb.go create mode 100644 api/matchmaking/v1/virtually/contract.proto create mode 100644 api/matchmaking/v1/virtually/contract_grpc.pb.go create mode 100644 api/matchmaking/v1/virtually/contract_http.pb.go create mode 100644 api/matchmaking/v1/virtually/second.pb.go create mode 100644 api/matchmaking/v1/virtually/second.proto create mode 100644 api/matchmaking/v1/virtually/second_grpc.pb.go create mode 100644 api/matchmaking/v1/virtually/second_http.pb.go create mode 100644 api/matchmaking/v1/virtually/spots.pb.go create mode 100644 api/matchmaking/v1/virtually/spots.proto create mode 100644 api/matchmaking/v1/virtually/spots_grpc.pb.go create mode 100644 api/matchmaking/v1/virtually/spots_http.pb.go create mode 100644 cmd/matchmaking-system/main.go create mode 100644 cmd/matchmaking-system/wire.go create mode 100644 cmd/matchmaking-system/wire_gen.go create mode 100644 configs/README.md create mode 100644 configs/admin.yaml create mode 100644 configs/adminBlk.yaml create mode 100644 configs/backend.yaml create mode 100644 configs/contract.yaml create mode 100644 configs/forex.yaml create mode 100644 configs/money.yaml create mode 100644 configs/optionInr.yaml create mode 100644 configs/second.yaml create mode 100644 configs/shareBlk.yaml create mode 100644 configs/shareBrl.yaml create mode 100644 configs/shareCache.yaml create mode 100644 configs/shareEur.yaml create mode 100644 configs/shareFur.yaml create mode 100644 configs/shareGbx.yaml create mode 100644 configs/shareHkd.yaml create mode 100644 configs/shareIdn.yaml create mode 100644 configs/shareInit.yaml create mode 100644 configs/shareInr.yaml create mode 100644 configs/shareJpy.yaml create mode 100644 configs/shareMys.yaml create mode 100644 configs/shareSgd.yaml create mode 100644 configs/shareTha.yaml create mode 100644 configs/shareUs.yaml create mode 100644 configs/spots.yaml create mode 100644 deploy/environment/docker-compose.yaml create mode 100644 go.mod create mode 100644 go.sum create mode 100644 internal/biz/README.md create mode 100644 internal/biz/backend.go create mode 100644 internal/biz/biz.go create mode 100644 internal/biz/forex.go create mode 100644 internal/biz/money.go create mode 100644 internal/biz/option_inr.go create mode 100644 internal/biz/order.go create mode 100644 internal/biz/share_blk.go create mode 100644 internal/biz/share_brl.go create mode 100644 internal/biz/share_eur.go create mode 100644 internal/biz/share_fur.go create mode 100644 internal/biz/share_gbx.go create mode 100644 internal/biz/share_hkd.go create mode 100644 internal/biz/share_idn.go create mode 100644 internal/biz/share_inr.go create mode 100644 internal/biz/share_jpy.go create mode 100644 internal/biz/share_mys.go create mode 100644 internal/biz/share_sgd.go create mode 100644 internal/biz/share_tha.go create mode 100644 internal/biz/share_us.go create mode 100644 internal/biz/structure/contract.go create mode 100644 internal/biz/structure/model.go create mode 100644 internal/biz/structure/order.go create mode 100644 internal/biz/structure/spots.go create mode 100644 internal/biz/virtual_contract.go create mode 100644 internal/biz/virtual_second.go create mode 100644 internal/biz/virtual_spots.go create mode 100644 internal/conf/conf.pb.go create mode 100644 internal/conf/conf.proto create mode 100644 internal/data/README.md create mode 100644 internal/data/aliyun.go create mode 100644 internal/data/cache/cache.go create mode 100644 internal/data/cache/cache_test.go create mode 100644 internal/data/control.go create mode 100644 internal/data/control_admin.go create mode 100644 internal/data/control_ainit.go create mode 100644 internal/data/control_forex.go create mode 100644 internal/data/control_money.go create mode 100644 internal/data/control_option.go create mode 100644 internal/data/control_share.go create mode 100644 internal/data/control_virtual.go create mode 100644 internal/data/convert/order.go create mode 100644 internal/data/convert/order_test.go create mode 100644 internal/data/convert/share.go create mode 100644 internal/data/convert/share_test.go create mode 100644 internal/data/data.go create mode 100644 internal/data/memory/bigcache.go create mode 100644 internal/data/memory/bigcache_test.go create mode 100644 internal/data/memory/forexinit.go create mode 100644 internal/data/memory/moneyinit.go create mode 100644 internal/data/memory/optioninit.go create mode 100644 internal/data/memory/shareinit.go create mode 100644 internal/data/memory/virtualinit.go create mode 100644 internal/data/mongo/mongo.go create mode 100644 internal/data/mongo/mongo_test.go create mode 100644 internal/data/mq/README.md create mode 100644 internal/data/mq/consumer/consumer.go create mode 100644 internal/data/mq/consumer/consumer_test.go create mode 100644 internal/data/mq/consumer/entrust.go create mode 100644 internal/data/mq/consumer/position.go create mode 100644 internal/data/mq/mq.go create mode 100644 internal/data/mq/mq_test.go create mode 100644 internal/data/mq/producers/entrust.go create mode 100644 internal/data/mq/producers/position.go create mode 100644 internal/data/mq/producers/producers.go create mode 100644 internal/data/mq/producers/producers_test.go create mode 100644 internal/data/mysql/mysql.go create mode 100644 internal/data/mysql/mysql_test.go create mode 100644 internal/data/order_backend.go create mode 100644 internal/data/order_forex.go create mode 100644 internal/data/order_money.go create mode 100644 internal/data/order_option_inr.go create mode 100644 internal/data/order_share_blk.go create mode 100644 internal/data/order_share_brl.go create mode 100644 internal/data/order_share_eur.go create mode 100644 internal/data/order_share_fur.go create mode 100644 internal/data/order_share_gbx.go create mode 100644 internal/data/order_share_hkd.go create mode 100644 internal/data/order_share_idn.go create mode 100644 internal/data/order_share_inr.go create mode 100644 internal/data/order_share_jpy.go create mode 100644 internal/data/order_share_mys.go create mode 100644 internal/data/order_share_sgd.go create mode 100644 internal/data/order_share_tha.go create mode 100644 internal/data/order_share_us.go create mode 100644 internal/data/order_virtual_contract.go create mode 100644 internal/data/order_virtual_second.go create mode 100644 internal/data/order_virtual_spots.go create mode 100644 internal/data/order_way_ipo.go create mode 100644 internal/data/order_way_ipo_brl.go create mode 100644 internal/data/order_way_ipo_eur.go create mode 100644 internal/data/order_way_ipo_fur.go create mode 100644 internal/data/order_way_ipo_gbx.go create mode 100644 internal/data/order_way_ipo_hkd.go create mode 100644 internal/data/order_way_ipo_idn.go create mode 100644 internal/data/order_way_ipo_inr.go create mode 100644 internal/data/order_way_ipo_jpy.go create mode 100644 internal/data/order_way_ipo_mys.go create mode 100644 internal/data/order_way_ipo_sgd.go create mode 100644 internal/data/order_way_ipo_tha.go create mode 100644 internal/data/order_way_ipo_us.go create mode 100644 internal/data/redis/redis.go create mode 100644 internal/data/redis/redis_test.go create mode 100644 internal/data/restore_cached_data.go create mode 100644 internal/data/restore_cached_order_no.go create mode 100644 internal/data/restore_clear_cache_data.go create mode 100644 internal/data/sms/sms.go create mode 100644 internal/data/sms/sms_test.go create mode 100644 internal/data/socket/README.md create mode 100644 internal/data/socket/block_admin.go create mode 100644 internal/data/socket/block_user.go create mode 100644 internal/data/socket/forexData/forex.go create mode 100644 internal/data/socket/forex_admin.go create mode 100644 internal/data/socket/forex_user.go create mode 100644 internal/data/socket/moneyData/money.go create mode 100644 internal/data/socket/money_admin.go create mode 100644 internal/data/socket/money_user.go create mode 100644 internal/data/socket/optionData/option_inr.go create mode 100644 internal/data/socket/option_admin.go create mode 100644 internal/data/socket/option_user.go create mode 100644 internal/data/socket/order.go create mode 100644 internal/data/socket/order_test.go create mode 100644 internal/data/socket/order_ws.go create mode 100644 internal/data/socket/publicData/public.go create mode 100644 internal/data/socket/publicData/public_test.go create mode 100644 internal/data/socket/shareData/share_blk.go create mode 100644 internal/data/socket/shareData/share_brl.go create mode 100644 internal/data/socket/shareData/share_eur.go create mode 100644 internal/data/socket/shareData/share_fur.go create mode 100644 internal/data/socket/shareData/share_gbx.go create mode 100644 internal/data/socket/shareData/share_hkd.go create mode 100644 internal/data/socket/shareData/share_idn.go create mode 100644 internal/data/socket/shareData/share_inr.go create mode 100644 internal/data/socket/shareData/share_jpy.go create mode 100644 internal/data/socket/shareData/share_mys.go create mode 100644 internal/data/socket/shareData/share_sgd.go create mode 100644 internal/data/socket/shareData/share_tha.go create mode 100644 internal/data/socket/shareData/share_us.go create mode 100644 internal/data/socket/share_admin.go create mode 100644 internal/data/socket/share_user.go create mode 100644 internal/data/socket/virtualData/contract.go create mode 100644 internal/data/socket/virtualData/second.go create mode 100644 internal/data/socket/virtualData/spots.go create mode 100644 internal/data/socket/virtual_admin.go create mode 100644 internal/data/socket/virtual_user.go create mode 100644 internal/data/subscribe_forex.go create mode 100644 internal/data/subscribe_money.go create mode 100644 internal/data/subscribe_option_inr.go create mode 100644 internal/data/subscribe_share_blk.go create mode 100644 internal/data/subscribe_share_brl.go create mode 100644 internal/data/subscribe_share_eur.go create mode 100644 internal/data/subscribe_share_fur.go create mode 100644 internal/data/subscribe_share_gbx.go create mode 100644 internal/data/subscribe_share_hkd.go create mode 100644 internal/data/subscribe_share_idn.go create mode 100644 internal/data/subscribe_share_inr.go create mode 100644 internal/data/subscribe_share_jpy.go create mode 100644 internal/data/subscribe_share_mys.go create mode 100644 internal/data/subscribe_share_sgd.go create mode 100644 internal/data/subscribe_share_tha.go create mode 100644 internal/data/subscribe_share_us.go create mode 100644 internal/data/subscribe_virtual_contract.go create mode 100644 internal/data/subscribe_virtual_second.go create mode 100644 internal/data/subscribe_virtual_spots.go create mode 100644 internal/data/tradedeal/forex/forex.go create mode 100644 internal/data/tradedeal/money/money.go create mode 100644 internal/data/tradedeal/option/option_inr.go create mode 100644 internal/data/tradedeal/share/share_blk.go create mode 100644 internal/data/tradedeal/share/share_brl.go create mode 100644 internal/data/tradedeal/share/share_eur.go create mode 100644 internal/data/tradedeal/share/share_fur.go create mode 100644 internal/data/tradedeal/share/share_gbx.go create mode 100644 internal/data/tradedeal/share/share_hkd.go create mode 100644 internal/data/tradedeal/share/share_idn.go create mode 100644 internal/data/tradedeal/share/share_inr.go create mode 100644 internal/data/tradedeal/share/share_jpy.go create mode 100644 internal/data/tradedeal/share/share_mys.go create mode 100644 internal/data/tradedeal/share/share_sgd.go create mode 100644 internal/data/tradedeal/share/share_tha.go create mode 100644 internal/data/tradedeal/share/share_us.go create mode 100644 internal/data/tradedeal/virtual/virtual_contract.go create mode 100644 internal/data/tradedeal/virtual/virtual_second.go create mode 100644 internal/data/tradedeal/virtual/virtual_spots.go create mode 100644 internal/data/utils_check.go create mode 100644 internal/data/utils_check_test.go create mode 100644 internal/data/utils_other.go create mode 100644 internal/errors/error_encoder.go create mode 100644 internal/errors/error_encoder_test.go create mode 100644 internal/pkg/flags/market_time.go create mode 100644 internal/pkg/flags/message.go create mode 100644 internal/pkg/flags/share.go create mode 100644 internal/pkg/flags/system.go create mode 100644 internal/pkg/flags/table.go create mode 100644 internal/pkg/gzip/gzip.go create mode 100644 internal/pkg/gzip/gzip_test.go create mode 100644 internal/pkg/logging/applogger/applogger.go create mode 100644 internal/pkg/logging/applogger/applogger_test.go create mode 100644 internal/pkg/logging/common/common.go create mode 100644 internal/pkg/logging/perflogger/performancelogger.go create mode 100644 internal/pkg/logging/perflogger/performancelogger_test.go create mode 100644 internal/pkg/middleware/auth/auth.go create mode 100644 internal/pkg/middleware/auth/auth_test.go create mode 100644 internal/pkg/model/bot_account.go create mode 100644 internal/pkg/model/bot_admin.go create mode 100644 internal/pkg/model/bot_admin_log.go create mode 100644 internal/pkg/model/bot_announcement.go create mode 100644 internal/pkg/model/bot_attachment.go create mode 100644 internal/pkg/model/bot_auth_group.go create mode 100644 internal/pkg/model/bot_auth_group_access.go create mode 100644 internal/pkg/model/bot_auth_menu.go create mode 100644 internal/pkg/model/bot_auth_role.go create mode 100644 internal/pkg/model/bot_auth_rule.go create mode 100644 internal/pkg/model/bot_banner.go create mode 100644 internal/pkg/model/bot_brokerage_setting.go create mode 100644 internal/pkg/model/bot_category.go create mode 100644 internal/pkg/model/bot_config.go create mode 100644 internal/pkg/model/bot_contract_list.go create mode 100644 internal/pkg/model/bot_contract_market.go create mode 100644 internal/pkg/model/bot_contract_sec_trade.go create mode 100644 internal/pkg/model/bot_contract_setting.go create mode 100644 internal/pkg/model/bot_contract_trade.go create mode 100644 internal/pkg/model/bot_country.go create mode 100644 internal/pkg/model/bot_digital_list.go create mode 100644 internal/pkg/model/bot_digital_trade.go create mode 100644 internal/pkg/model/bot_document.go create mode 100644 internal/pkg/model/bot_drawal_setting.go create mode 100644 internal/pkg/model/bot_faq.go create mode 100644 internal/pkg/model/bot_fee_setting.go create mode 100644 internal/pkg/model/bot_file.go create mode 100644 internal/pkg/model/bot_forex_list.go create mode 100644 internal/pkg/model/bot_forex_trade.go create mode 100644 internal/pkg/model/bot_history_fund_stock.go create mode 100644 internal/pkg/model/bot_language_setting.go create mode 100644 internal/pkg/model/bot_money_trade.go create mode 100644 internal/pkg/model/bot_payment_list.go create mode 100644 internal/pkg/model/bot_pre_brl_stock.go create mode 100644 internal/pkg/model/bot_pre_eur_stock.go create mode 100644 internal/pkg/model/bot_pre_fund_stock.go create mode 100644 internal/pkg/model/bot_pre_fund_stock_refer.go create mode 100644 internal/pkg/model/bot_pre_fur_stock.go create mode 100644 internal/pkg/model/bot_pre_hkd_stock.go create mode 100644 internal/pkg/model/bot_pre_idn_stock.go create mode 100644 internal/pkg/model/bot_pre_in_stock.go create mode 100644 internal/pkg/model/bot_pre_jp_stock.go create mode 100644 internal/pkg/model/bot_pre_mys_stock.go create mode 100644 internal/pkg/model/bot_pre_sgd_stock.go create mode 100644 internal/pkg/model/bot_pre_tha_stock.go create mode 100644 internal/pkg/model/bot_pre_us_stock.go create mode 100644 internal/pkg/model/bot_recharge_apply.go create mode 100644 internal/pkg/model/bot_service_setting.go create mode 100644 internal/pkg/model/bot_stock_block_list.go create mode 100644 internal/pkg/model/bot_stock_block_trade.go create mode 100644 internal/pkg/model/bot_stock_brl_list.go create mode 100644 internal/pkg/model/bot_stock_brl_trade.go create mode 100644 internal/pkg/model/bot_stock_eur_list.go create mode 100644 internal/pkg/model/bot_stock_eur_trade.go create mode 100644 internal/pkg/model/bot_stock_fur_list.go create mode 100644 internal/pkg/model/bot_stock_fur_trade.go create mode 100644 internal/pkg/model/bot_stock_gbx_list.go create mode 100644 internal/pkg/model/bot_stock_gbx_trade.go create mode 100644 internal/pkg/model/bot_stock_hkd_list.go create mode 100644 internal/pkg/model/bot_stock_hkd_trade.go create mode 100644 internal/pkg/model/bot_stock_idn_list.go create mode 100644 internal/pkg/model/bot_stock_idn_trade.go create mode 100644 internal/pkg/model/bot_stock_in_list.go create mode 100644 internal/pkg/model/bot_stock_in_trade.go create mode 100644 internal/pkg/model/bot_stock_index.go create mode 100644 internal/pkg/model/bot_stock_jp_list.go create mode 100644 internal/pkg/model/bot_stock_jp_trade.go create mode 100644 internal/pkg/model/bot_stock_list.go create mode 100644 internal/pkg/model/bot_stock_market.go create mode 100644 internal/pkg/model/bot_stock_mys_list.go create mode 100644 internal/pkg/model/bot_stock_mys_list_p_two.go create mode 100644 internal/pkg/model/bot_stock_mys_trade.go create mode 100644 internal/pkg/model/bot_stock_option_inr_list.go create mode 100644 internal/pkg/model/bot_stock_option_inr_trade.go create mode 100644 internal/pkg/model/bot_stock_prices_setting.go create mode 100644 internal/pkg/model/bot_stock_sgd_list.go create mode 100644 internal/pkg/model/bot_stock_sgd_trade.go create mode 100644 internal/pkg/model/bot_stock_tha_list.go create mode 100644 internal/pkg/model/bot_stock_tha_trade.go create mode 100644 internal/pkg/model/bot_stock_trade.go create mode 100644 internal/pkg/model/bot_trade_fee.go create mode 100644 internal/pkg/model/bot_user_arrears.go create mode 100644 internal/pkg/model/bot_user_balance_change_log.go create mode 100644 internal/pkg/model/bot_user_bank.go create mode 100644 internal/pkg/model/bot_user_brl_give_stock_order.go create mode 100644 internal/pkg/model/bot_user_brl_pre_stock_order.go create mode 100644 internal/pkg/model/bot_user_brokerage.go create mode 100644 internal/pkg/model/bot_user_contract.go create mode 100644 internal/pkg/model/bot_user_contract_log.go create mode 100644 internal/pkg/model/bot_user_contract_sec.go create mode 100644 internal/pkg/model/bot_user_contract_sec_log.go create mode 100644 internal/pkg/model/bot_user_digital.go create mode 100644 internal/pkg/model/bot_user_digital_log.go create mode 100644 internal/pkg/model/bot_user_eur_give_stock_order.go create mode 100644 internal/pkg/model/bot_user_eur_pre_stock_order.go create mode 100644 internal/pkg/model/bot_user_forex.go create mode 100644 internal/pkg/model/bot_user_forex_log.go create mode 100644 internal/pkg/model/bot_user_fund_pre_stock_order.go create mode 100644 internal/pkg/model/bot_user_fur_give_stock_order.go create mode 100644 internal/pkg/model/bot_user_fur_pre_stock_order.go create mode 100644 internal/pkg/model/bot_user_gbx_give_stock_order.go create mode 100644 internal/pkg/model/bot_user_gbx_pre_stock_order.go create mode 100644 internal/pkg/model/bot_user_hkd_give_stock_order.go create mode 100644 internal/pkg/model/bot_user_hkd_pre_stock_order.go create mode 100644 internal/pkg/model/bot_user_idn_give_stock_order.go create mode 100644 internal/pkg/model/bot_user_idn_pre_stock_order.go create mode 100644 internal/pkg/model/bot_user_in_give_stock_order.go create mode 100644 internal/pkg/model/bot_user_in_pre_stock_order.go create mode 100644 internal/pkg/model/bot_user_jp_give_stock_order.go create mode 100644 internal/pkg/model/bot_user_jp_pre_stock_order.go create mode 100644 internal/pkg/model/bot_user_level.go create mode 100644 internal/pkg/model/bot_user_login_log.go create mode 100644 internal/pkg/model/bot_user_market.go create mode 100644 internal/pkg/model/bot_user_money.go create mode 100644 internal/pkg/model/bot_user_money_log.go create mode 100644 internal/pkg/model/bot_user_mys_give_stock_order.go create mode 100644 internal/pkg/model/bot_user_mys_pre_stock_order.go create mode 100644 internal/pkg/model/bot_user_sgd_give_stock_order.go create mode 100644 internal/pkg/model/bot_user_sgd_pre_stock_order.go create mode 100644 internal/pkg/model/bot_user_stock.go create mode 100644 internal/pkg/model/bot_user_stock_block_log.go create mode 100644 internal/pkg/model/bot_user_stock_brl.go create mode 100644 internal/pkg/model/bot_user_stock_brl_log.go create mode 100644 internal/pkg/model/bot_user_stock_eur.go create mode 100644 internal/pkg/model/bot_user_stock_eur_log.go create mode 100644 internal/pkg/model/bot_user_stock_fund.go create mode 100644 internal/pkg/model/bot_user_stock_fund_interest_receipt.go create mode 100644 internal/pkg/model/bot_user_stock_fund_log.go create mode 100644 internal/pkg/model/bot_user_stock_fur.go create mode 100644 internal/pkg/model/bot_user_stock_fur_log.go create mode 100644 internal/pkg/model/bot_user_stock_gbx.go create mode 100644 internal/pkg/model/bot_user_stock_gbx_log.go create mode 100644 internal/pkg/model/bot_user_stock_hkd.go create mode 100644 internal/pkg/model/bot_user_stock_hkd_log.go create mode 100644 internal/pkg/model/bot_user_stock_idn.go create mode 100644 internal/pkg/model/bot_user_stock_idn_log.go create mode 100644 internal/pkg/model/bot_user_stock_in.go create mode 100644 internal/pkg/model/bot_user_stock_in_log.go create mode 100644 internal/pkg/model/bot_user_stock_jp.go create mode 100644 internal/pkg/model/bot_user_stock_jp_log.go create mode 100644 internal/pkg/model/bot_user_stock_log.go create mode 100644 internal/pkg/model/bot_user_stock_mys.go create mode 100644 internal/pkg/model/bot_user_stock_mys_log.go create mode 100644 internal/pkg/model/bot_user_stock_option_inr.go create mode 100644 internal/pkg/model/bot_user_stock_option_inr_log.go create mode 100644 internal/pkg/model/bot_user_stock_sgd.go create mode 100644 internal/pkg/model/bot_user_stock_sgd_log.go create mode 100644 internal/pkg/model/bot_user_stock_tha.go create mode 100644 internal/pkg/model/bot_user_stock_tha_log.go create mode 100644 internal/pkg/model/bot_user_tha_give_stock_order.go create mode 100644 internal/pkg/model/bot_user_tha_pre_stock_order.go create mode 100644 internal/pkg/model/bot_user_transfer.go create mode 100644 internal/pkg/model/bot_user_us_give_stock_order.go create mode 100644 internal/pkg/model/bot_user_us_pre_stock_order.go create mode 100644 internal/pkg/model/bot_user_verify_log.go create mode 100644 internal/pkg/model/bot_user_walletaddress.go create mode 100644 internal/pkg/model/bot_user_withdrawal.go create mode 100644 internal/pkg/model/bot_users.go create mode 100644 internal/pkg/pprof/cpu.prof create mode 100644 internal/pkg/pprof/pprof_test.go create mode 100644 internal/pkg/setting/block.go create mode 100644 internal/pkg/setting/forex.go create mode 100644 internal/pkg/setting/hongkong.go create mode 100644 internal/pkg/setting/money.go create mode 100644 internal/pkg/setting/option.go create mode 100644 internal/pkg/setting/share.go create mode 100644 internal/pkg/setting/virtual.go create mode 100644 internal/pkg/utils/utils.go create mode 100644 internal/pkg/utils/utils_test.go create mode 100644 internal/server/grpc.go create mode 100644 internal/server/http.go create mode 100644 internal/server/server.go create mode 100644 internal/service/README.md create mode 100644 internal/service/backend.go create mode 100644 internal/service/backend/backend.go create mode 100644 internal/service/block/share_blk.go create mode 100644 internal/service/forex.go create mode 100644 internal/service/forex/forex.go create mode 100644 internal/service/money.go create mode 100644 internal/service/money/money.go create mode 100644 internal/service/option/option_inr.go create mode 100644 internal/service/option_inr.go create mode 100644 internal/service/order.go create mode 100644 internal/service/order/order.go create mode 100644 internal/service/order/order_test.go create mode 100644 internal/service/service.go create mode 100644 internal/service/share/share_brl.go create mode 100644 internal/service/share/share_eur.go create mode 100644 internal/service/share/share_fur.go create mode 100644 internal/service/share/share_gbx.go create mode 100644 internal/service/share/share_hkd.go create mode 100644 internal/service/share/share_idn.go create mode 100644 internal/service/share/share_inr.go create mode 100644 internal/service/share/share_jpy.go create mode 100644 internal/service/share/share_mys.go create mode 100644 internal/service/share/share_sgd.go create mode 100644 internal/service/share/share_tha.go create mode 100644 internal/service/share/share_us.go create mode 100644 internal/service/share_blk.go create mode 100644 internal/service/share_brl.go create mode 100644 internal/service/share_eur.go create mode 100644 internal/service/share_fur.go create mode 100644 internal/service/share_gbx.go create mode 100644 internal/service/share_hkd.go create mode 100644 internal/service/share_idn.go create mode 100644 internal/service/share_inr.go create mode 100644 internal/service/share_jpy.go create mode 100644 internal/service/share_mys.go create mode 100644 internal/service/share_sgd.go create mode 100644 internal/service/share_tha.go create mode 100644 internal/service/share_us.go create mode 100644 internal/service/virtual/contract.go create mode 100644 internal/service/virtual/second.go create mode 100644 internal/service/virtual/spots.go create mode 100644 internal/service/virtual_contract.go create mode 100644 internal/service/virtual_second.go create mode 100644 internal/service/virtual_spots.go create mode 100644 openapi.yaml create mode 100644 third_party/README.md create mode 100644 third_party/errors/errors.proto create mode 100644 third_party/google/api/annotations.proto create mode 100644 third_party/google/api/client.proto create mode 100644 third_party/google/api/field_behavior.proto create mode 100644 third_party/google/api/http.proto create mode 100644 third_party/google/api/httpbody.proto create mode 100644 third_party/google/protobuf/any.proto create mode 100644 third_party/google/protobuf/api.proto create mode 100644 third_party/google/protobuf/compiler/plugin.proto create mode 100644 third_party/google/protobuf/descriptor.proto create mode 100644 third_party/google/protobuf/duration.proto create mode 100644 third_party/google/protobuf/empty.proto create mode 100644 third_party/google/protobuf/field_mask.proto create mode 100644 third_party/google/protobuf/source_context.proto create mode 100644 third_party/google/protobuf/struct.proto create mode 100644 third_party/google/protobuf/timestamp.proto create mode 100644 third_party/google/protobuf/type.proto create mode 100644 third_party/google/protobuf/wrappers.proto create mode 100644 third_party/openapi/v3/annotations.proto create mode 100644 third_party/openapi/v3/openapi.proto create mode 100644 third_party/validate/README.md create mode 100644 third_party/validate/validate.proto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3de7fa2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +# Reference https://github.com/github/gitignore/blob/master/Go.gitignore +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +vendor/ + +# Go workspace file +go.work + +# Compiled Object files, Static and Dynamic libs (Shared Objects) +*.o +*.a +*.so + +# OS General +Thumbs.db +.DS_Store + +# project +*.cert +*.key +*.log +bin/ + +# Develop tools +.vscode/ +.idea/ +*.swp diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8539353 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM golang:1.21 AS builder + +COPY . /src +WORKDIR /src + +RUN GOPROXY=https://goproxy.cn make build + +FROM debian:stable-slim + +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates \ + netbase \ + && rm -rf /var/lib/apt/lists/ \ + && apt-get autoremove -y && apt-get autoclean -y + +COPY --from=builder /src/bin /app + +WORKDIR /app + +EXPOSE 8000 +EXPOSE 9000 +VOLUME /data/conf + +CMD ["./server", "-conf", "/data/conf"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..684318c --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 go-kratos + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..db70465 --- /dev/null +++ b/Makefile @@ -0,0 +1,107 @@ +GOHOSTOS:=$(shell go env GOHOSTOS) +GOPATH:=$(shell go env GOPATH) +VERSION=$(shell git describe --tags --always) + +ifeq ($(GOHOSTOS), windows) + #the `find.exe` is different from `find` in bash/shell. + #to see https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/find. + #changed to use git-bash.exe to run find cli or other cli friendly, caused of every developer has a Git. + Git_Bash=$(subst \,/,$(subst cmd\,bin\bash.exe,$(dir $(shell where git)))) + INTERNAL_PROTO_FILES=$(shell $(Git_Bash) -c "find internal -name *.proto") + API_PROTO_FILES=$(shell $(Git_Bash) -c "find api -name *.proto") +else + INTERNAL_PROTO_FILES=$(shell find internal -name *.proto) + API_PROTO_FILES=$(shell find api -name *.proto) +endif + +.PHONY: init +# init env +init: + go install google.golang.org/protobuf/cmd/protoc-gen-go@latest + go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest + go install github.com/go-kratos/kratos/cmd/kratos/v2@latest + go install github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest + go install github.com/google/gnostic/cmd/protoc-gen-openapi@latest + go install github.com/google/wire/cmd/wire@latest + +.PHONY: errors +# generate errors code +errors: + protoc --proto_path=. \ + --proto_path=./third_party \ + --go_out=paths=source_relative:. \ + --go-errors_out=paths=source_relative:. \ + $(API_PROTO_FILES) + +.PHONY: config +# generate internal proto +config: + protoc --proto_path=./internal \ + --proto_path=./third_party \ + --go_out=paths=source_relative:./internal \ + $(INTERNAL_PROTO_FILES) + +.PHONY: api +# generate api proto +api: + protoc --proto_path=./api \ + --proto_path=./third_party \ + --go_out=paths=source_relative:./api \ + --go-http_out=paths=source_relative:./api \ + --go-grpc_out=paths=source_relative:./api \ + --openapi_out=fq_schema_naming=true,default_response=false:. \ + $(API_PROTO_FILES) + +.PHONY: build +# generate build +build: + mkdir -p bin/ && go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/ ./... + +.PHONY: win_build +# generate win_build +win_build: + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/ ./... + +.PHONY: generate +# generate +generate: + go mod tidy + go get github.com/google/wire/cmd/wire@latest + go generate ./... + +.PHONY: wire +# generate wire +wire: + cd cmd/matchmaking-system/ && wire + +.PHONY: run +# generate run +run: + kratos run + +.PHONY: all +# generate all +all: + make api; + make errors; + make config; + make generate; + +# show help +help: + @echo '' + @echo 'Usage:' + @echo ' make [target]' + @echo '' + @echo 'Targets:' + @awk '/^[a-zA-Z\-\_0-9]+:/ { \ + helpMessage = match(lastLine, /^# (.*)/); \ + if (helpMessage) { \ + helpCommand = substr($$1, 0, index($$1, ":")); \ + helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \ + printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \ + } \ + } \ + { lastLine = $$0 }' $(MAKEFILE_LIST) + +.DEFAULT_GOAL := help diff --git a/README.md b/README.md new file mode 100644 index 0000000..8b2cad3 --- /dev/null +++ b/README.md @@ -0,0 +1,94 @@ +# kratos-matchmaking system +kratos Framework creation transaction service project +> Note: In this project, if Kratos provides packages, they will not package third-party packages themselves. + +# kratos-matchmaking remarks +``` +Branch: +1、main +2、other_main (P1 and P2 project apply) +3、latest_main (other project apply) +``` + +The specific directory structure design of the project is as follows: + +``` +|-- kratos-matchmakingSystem + |-- wss service + |-- AdminWss // Administrator subscription + |-- AdminBlkWss // Administrator block subscription + |-- SpotsWss // Spot subscription + |-- ContractWss // Contract subscription + |-- SecondWss // Second contract subscription + |-- ShareUsWss // US stock subscription + |-- ShareMysWss // Horse stock subscription + |-- ShareThaWss // Thai stock subscription + |-- ShareIdnWss // Indonesian stock subscription + |-- ShareInrWss // Indian stock subscription + |-- ShareSgdWss // Singapore Stock Subscription + |-- ShareHkdWss // Hong Kong Stock Subscription + |-- ShareGbxWss // Hong Uk Subscription + |-- ShareBlkWss // Block Stock Subscription + |-- OptionInrWss // Options (India) Stock Subscription + + |-- api service // Transaction API service (TODO: can be changed to microservices, currently also compiled for multi-service deployment) + ├── api + │ ├── v1 + │ │ └── option + │ │ └── optionInr // Options (Indian stock) + │ │ └── order + │ │ └── order // New stock subscription (US, Malaysian, Thai, Indonesian, Indian, Singapore, Hong Kong) + │ │ └── share + │ │ └── shareUs // US stock + │ │ └── shareMys // Malaysian stock + │ │ └── shareTha // Thai stock + │ │ └── shareIdn // Indonesian stock + │ │ └── shareInr // Indian stock + │ │ └── shareSgd // Singapore stock + │ │ └── shareHkd // Hong Kong stock + │ │ └── shareGbx // Uk stock + │ │ └── virtually + │ │ └── spots // Spots + │ │ └── contract // Contract + │ │ └── second // Second contract + │ │ └── block + │ │ └── shareBlock // Block stock + + |-- monitor service // Initialize | Entrust | Position + ├── start + │ ├── user + │ │ └── init + │ │ └── virtually // Digital currency (spot | contract | second contract) + │ │ └── option // Options (India) + │ │ └── share // Stocks (US, Malaysian, Thai, Indonesian, Indian, Singapore, Hong Kong, options, new stock subscription) + │ │ └── option + │ │ └── optionInr // Options (Indian stock) + │ │ └── order + │ │ └── order // New stock subscription (US, Malaysian, Thai, Indonesian, Indian, Singapore, Hong Kong) + │ │ └── share + │ │ └── shareUs // US stock + │ │ └── shareMys // Malaysian stock + │ │ └── shareTha // Thai stock + │ │ └── shareIdn // Indonesian stock + │ │ └── shareInr // Indian stock + │ │ └── shareSgd // Singapore stock + │ │ └── shareHkd // Hong Kong stock + │ │ └── shareGbx // Uk stock + │ │ └── virtually + │ │ └── contract // Spots + │ │ └── second // Contract + │ │ └── block + │ │ └── shareBlock // Block stock + │ ├── admin + │ │ └── contract // Contract + │ │ └── second // Second contract + │ │ └── shareUs // US stock + │ │ └── shareMys // Malaysian stock + │ │ └── shareTha // Thai stock + │ │ └── shareIdn // Indonesian stock + │ │ └── shareInr // Indian stock + │ │ └── shareSgd // Singapore stock + │ │ └── shareHkd // Hong Kong stock + │ │ └── shareGbx // Uk stock + │ │ └── shareBlk // Block stock +``` \ No newline at end of file diff --git a/ServerDeployment b/ServerDeployment new file mode 100644 index 0000000..e6f73e2 --- /dev/null +++ b/ServerDeployment @@ -0,0 +1,205 @@ +公司无线密码: + 账号1:H3C_2202-5G-1 + 密码:A13b142202) + 账号2:ssid + 密码:Meetingyou0) +------------------------------------------------------------------------------------------------------------------------------------------------- + +1、美股数据接入账号: + https://polygon.io/dashboard/api-keys + 账号:rnldburn@gmail.com + 密码: Meetingyou0 + key: CDGMfPJmyiEX5dbjagLSEipf5Y4XbXVb + +2、亚马逊oss接入: + myaccesspoint + 桶名称:log-aws-bucket-2023 + S3: s3://arn:aws:s3:ap-southeast-1:297182325232:accesspoint/myaccesspoint + ARN: arn:aws:s3:ap-southeast-1:297182325232:accesspoint/myaccesspoint + 别名:myaccesspoint-9kcrj5icrgdejw1fydhda6n6rfcjkaps1a-s3alias + +3、区域:ap-southeast-1 + aws_access_key_id:AKIAUKMLSNHYAP7EOBDE + aws_secret_access_key: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 + endpoint:s3.ap-southeast-1.amazonaws.com + +4、阿里云(测试服务器) + 网址:https://account.alibabacloud.com/login/login.htm + 账户:ouanczqrouoydxc@outlook.com + 密码:Meetingyou0)) +------------------------------------------------------------------------------------------------------------------------------------------------ + +1、域名解析: + cotelaiamelia@gmail.com + Meetingyou0)(*& + +2、GCP-谷歌云-测试环境: + 项目名称:SC Project 47850 + LoginAccount:zajdelvipondespq9931@gmail.com + 邮箱密码:7ae8b5w0u0z + 访问地址:https://cloud.google.com/?hl=zh-CN + +3、GCP-谷歌云-正式环境: + 项目名称:SC Project 51416 + 登录邮箱:cloudrun40@gmail.com + 邮箱密码:Meetingyou0 + 辅助邮箱:rnldburn@gmail.com + 访问地址:https://cloud.google.com/?hl=zh-CN + +4、跳板机 + ec2-13-212-72-30.ap-southeast-1.compute.amazonaws.com + 用户名:Administrator + 密码:J.RUhgy8hHf?QsaK50cckzv3ynl7X.W= + +5、YAPI + 管理员账号:admin@admin.com + 管理员密码:Meetingyou0)) +------------------------------------------------------------------------------------------------------------------------------------------------ + +1、测试服务接口是否正常 + curl -X POST -H 'Content-Type: application/json' -d '{ "status": "0","pageSize": "10","pageCount": "1"}' http://10.160.0.2:8003/order_shareus/share_list + curl -X POST -H 'Content-Type: application/json' -d '{ "status": "0","pageSize": "10","pageCount": "1"}' http://trade.lazardinvestgroup.net/order_shareus/share_list + curl -X POST -H 'Content-Type: application/json' -d '{ "status": "0","pageSize": "10","pageCount": "1"}' http://10.160.0.2:8002/order_contract/contract_list + curl -X POST -H 'Content-Type: application/json' -d '{ "status": "0","pageSize": "10","pageCount": "1"}' http://trade.chdh.me/order_contract/contract_list + curl -X POST -H 'Content-Type: application/json' -d '{ "status": "0","pageSize": "10","pageCount": "1"}' https://172.23.48.59:8004/order_sharemys/share_list + curl -X POST -H 'Content-Type: application/json' -d '{ }' http://172.26.45.215:8022/order_backend/update_is_real + curl -X POST -H 'Content-Type: application/json' -d '{ "code": "BSE:IXIGO","id": "80","stock": "7"}' http://10.160.0.17:8000/order_sharepre/share_pre_trade + +2、初始化股票数据 34.100.189.47 + ./shareUs -conf /home/ubuntu/service/config/shareUs.yaml -check shareUs -network onLine + ./digitalInit -conf /home/ubuntu/service/config/digitalInit.yaml -check digitalInit -network onLine + ./optionInr -conf /home/ubuntu/service/config/optionInr.yaml -check optionInr -network onLine + ./shareClearCache -conf /home/ubuntu/service/config/shareInit.yaml -check shareClearCache -network onLine + ./contract -conf /home/ubuntu/service/config/contract.yaml -check contract -network onLine + ./second -conf /home/ubuntu/service/config/second.yaml -check second -network onLine + ./shareCache -conf /home/ubuntu/service/config/shareCache.yaml -check shareCache -network onLine + ./wssPool --check tickDB --hostS 0.0.0.0 --addrS :1000 --model allUs --config /home/ubuntu/wss-server/config/config06.yaml + ./wssPool --check tickDB --hostS 0.0.0.0 --addrS :1000 --model Us --config /home/ubuntu/wss-server/config/config06.yaml + ./wssPool --check tickDB --hostS 0.0.0.0 --addrS :1000 --model allUs --config /home/ubuntu/wss-server/config/config06.yaml + ./wssPool --check stockDataUs --hostS 0.0.0.0 --addrS :1000 --project US --config /home/ubuntu/wss-server/config/config.yaml + ./wssPool --check tickDB --hostS 0.0.0.0 --addrS :1000 --model updateStockUsCode --config /home/ubuntu/wss-server/config/config06.yaml + ./wssPool --check stockCode --hostS 0.0.0.0 --addrS :7777 --project US --config /home/ubuntu/wss-server/config/config06.yaml + +3、mysql-生成model + ./xorm.exe reverse mysql admin:Meetingyou0@\(dbtest.crsocbk1nt38.ap-southeast-1.rds.amazonaws.com:3306\)/bourse?charset=utf8 templates/goxorm + ./xorm.exe reverse mysql admin:Meetingyou0@\(ubsfim.c59brkvf12hq.ap-southeast-3.rds.amazonaws.com:3306\)/bourse?charset=utf8 templates/goxorm + ./xorm.exe reverse mysql root:'q7%B/$o>ck5r]{x<'@\(35.186.154.125:3306\)/bourse?charset=utf8 templates/goxorm + ./xorm.exe reverse mysql root:123456789@\(127.0.0.1:13306\)/bourse?charset=utf8 templates/goxorm + +4、本地环境-docker启动服务 + docker run --name mysql -p 13306:3306 -e MYSQL_ROOT_PASSWORD=12345678 mysql:8.0.28 + docker run --name f2ad9f23df82a3e5efabd1574b862a94c0657c73a6179efec07d5cf9ae5a307f -p 13306:3306 -e MYSQL_ROOT_PASSWORD=123456789 -d mysql:8.0.28 + docker run --name my-redis -p 6379:6379 -d redis --requirepass "123456" +----------------------------------------------------------------------------------------------------------------------------------------------------------------- + +服务器环境部署: +1、redis部署 + sudo apt update + sudo apt-get install redis-server + +2、mongod部署 + sudo apt update + wget -qO- https://get.docker.com/ | sh + apt install docker-compose + docker-compose up -d + docker-compose down + +3、安装supervisor + sudo apt update + apt install supervisor + +4、安装nginxs + sudo apt update + sudo apt install nginx + sudo systemctl start nginx + sudo service nginx reload {start|stop|restart|reload|force-reload|status|configtest|rotate|upgrade) + +5、设置最大链接数 + vim /etc/profile + ulimit -n 1000000 + source /etc/profile + +6、初始化服务器 + 切换用户:sudo -i + 修改登录权限:vim /etc/ssh/sshd_config + 修改配置:PasswordAuthentication yes + 修改配置: ChallengeResponseAuthentication yes + 重启ssh服务:service ssh restart + 修改密码:passwd + +7、修改服务器时区 + sudo timedatectl set-timezone Asia/Shanghai + +8、查看redis链接数 + netstat -an | grep :26379 | wc -l + netstat -tuln | grep :80 + +9、corn 定时器 + sudo systemctl status cron + sudo systemctl stop cron + sudo systemctl enable cron + sudo service cron restart +----------------------------------------------------------------------------------------------------------------------------------------------------------------- + +1、市场总资产: 冻结 + 可用 + 持仓市值 +2、市场可用资产: 可用 +3、市场累计盈亏(订单表-->平仓状态): + 1、买涨:订单量 * (平仓价 - 开仓价) + 2、买跌:订单量 * (开仓价 - 平仓价) +4、市场冻结资产: 冻结 +5、市场总手续费(统计订单表-->【持仓和平仓】状态): + 1、交易手续费:bot_stock_fur_trade ------ sum(service_cost + closing_cost) + 2、申购手续费:bot_user_fur_pre_stock_order ----- sum(get_fee) +----------------------------------------------------------------------------------------------------------------------------------------------------------------- + +目前杠杆设置注解: + 1、全市场杠杆倍数设置——》针对所有市场股票给的默认杠杆倍数(目前设置的是1,可修改),且不需要关闭,当然也不影响用户单独设置其他杠杆倍数; + 2、用户杠杆倍数设置——》如果用户通过了申请且满足了后台设置触发杠杆的条件(例如:1、是否开启杠杆,2、是否达到最小面值,3、是否满足设置杠杆的范围(最大和最小)),就会使用这个用户单独设置的杠杆倍数; +----------------------------------------------------------------------------------------------------------------------------------------------------------------- + +docker save liuqingzheng/yapi:latest > yapi_latest.tar +docker save mongo:latest > mongo_latest.tar + +docker save gitea/gitea:latest > gitea_latest.tar +docker save mysql:5.7 > mysql.tar + +scp -P 31544 mongo_latest.tar mysql.tar gitea_latest.tar yapi_latest.tar root@154.86.0.30:/root +docker load < mongo_latest.tar mysql.tar gitea_latest.tar yapi_latest.tar + +docker run -d --name yapi-mongo -e MONGO_INITDB_ROOT_USERNAME=admin@admin.com -e MONGO_INITDB_ROOT_PASSWORD=admin mongo:latest +docker run -d --name yapi-mongo mongo:latest +docker run -d --name yapi-web -p 3001:3000 liuqingzheng/yapi:latest + +find / -name config.json 2>/dev/null + +docker run -d --name gitea_server_1 -p 3000:3000 -p 222:31544 gitea/gitea:latest +docker run -d --name gitea_db_1 -p 3306:3306 -p 33060:33060 mysql/mysql:5.7 + +文档|git +yapi:http://154.86.0.30:3001/ +git:http://103.71.254.42:3000/ +----------------------------------------------------------------------------------------------------------------------------------------------------------------- + +cron 执行定时任务; cat /etc/crontab +// 行情报警、指数、泰股、马股、港股、印度股、印尼股、新加坡股、英股、德股、法股 +*/20 * * * 1-5 root /home/ubuntu/wss-server/checkStock --check tickDB --model checkStock --config /home/ubuntu/wss-server/config/config06.yaml>>/var/log/checkStock.log 2>&1 & +*/5 * * * 1-6 root /home/ubuntu/wss-server/stockIndex --check tickDB --model stockIndex --config /home/ubuntu/wss-server/config/config06.yaml>>/var/log/stockIndex.log 2>&1 & +*/5 * * * 1-5 root /home/ubuntu/wss-server/thailandStock --check tickDB --model southAsiaStock --contract Thailand --hostS 0.0.0.0.0 --addrS :289 --config /home/ubuntu/wss-server/config/config06.yaml>>/var/log/thailandStock.log 2>&1 & +*/5 * * * 1-5 root /home/ubuntu/wss-server/malaysiaStock --check tickDB --model southAsiaStock --contract Malaysia --hostS 0.0.0.0.0 --addrS :299 --config /home/ubuntu/wss-server/config/config06.yaml>>/var/log/malaysiaStock.log 2>&1 +*/5 * * * 1-5 root /home/ubuntu/wss-server/hongkongStock --check tickDB --model southAsiaStock --contract HongKong --config /home/ubuntu/wss-server/config/config06.yaml>>/var/log/hongkongStock.log 2>&1 & +*/5 * * * 1-5 root /home/ubuntu/wss-server/indiaStock --check tickDB --model southAsiaStock --contract India --config /home/ubuntu/wss-server/config/config06.yaml>>/var/log/indiaStock.log 2>&1 & +*/5 * * * 1-5 root /home/ubuntu/wss-server/indonesiaStock --check tickDB --model southAsiaStock --contract Indonesia --config /home/ubuntu/wss-server/config/config06.yaml>>/var/log/indonesiaStock.log 2>&1 & +*/5 * * * 1-5 root /home/ubuntu/wss-server/singaporeStock --check tickDB --model southAsiaStock --contract Singapore --config /home/ubuntu/wss-server/config/config06.yaml>>/var/log/singaporeStock.log 2>&1 & +*/5 * * * 1-5 root /home/ubuntu/wss-server/ukStock --check tickDB --model southAsiaStock --contract UK --config=/home/ubuntu/wss-server/config/config06.yaml>>/var/log/ukStock.log 2>&1 & +*/5 * * * 1-5 root /home/ubuntu/wss-server/germanyStock --check tickDB --model southAsiaStock --contract Germany --config=/home/ubuntu/wss-server/config/config06.yaml>>/var/log/germanyStock.log 2>&1 & +*/5 * * * 1-5 root /home/ubuntu/wss-server/franceStock --check tickDB --model southAsiaStock --contract France --config=/home/ubuntu/wss-server/config/config06.yaml>>/var/log/franceStock.log 2>&1 & + +// 更新上一次行情价格 +8 9 * * * root /home/ubuntu/wss-server/preClose --check=tickDB --model=previousClose --config=/home/ubuntu/wss-server/config/config06.yaml>>/var/log/preClose.log 2>&1 & + +// 数据清理 +12 22 * * 2-5 root /home/ubuntu/wss-server/deleteSpot --check=tickDB --model=deleteSpot --contract=false --config /home/ubuntu/wss-server/config/config06.yaml>>/var/log/deleteSpot.log 2>&1 & + +// 插针数据推送 +*/1 * * * * root /home/ubuntu/wss-server/stockCloseData --check=tickDB --model=stockCloseData --config=/home/ubuntu/wss-server/config/config06.yaml>>/var/log/stockCloseData.log 2>&1 & +----------------------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/ServerList b/ServerList new file mode 100644 index 0000000..7f34324 --- /dev/null +++ b/ServerList @@ -0,0 +1,73 @@ +------------------------------------------------------------------------------------------------------------------------------------------------ + +test(谷歌云)服务器(域名:jdtest88.com) +web-mysql 47.237.29.68(公) 172.26.45.216(私有) +trade-quotes 47.237.64.60(公) 172.26.45.215(私有) +mongo 8.222.169.172(公) 172.26.45.217(私有) + +msyql +host:47.237.29.68(公) 172.26.45.216(私有) +user:root +密码:Meetingyou0)) + +redis +host:47.237.29.68(公) 172.26.45.216(私有) +密码:MRrfvtyujnb&hg56 +端口:6379 + +mongodb数据库 +host:8.222.169.172(公) 172.26.45.217(私有) +账号:pqRRVamndJ +密码:35LlW3pXF76&WD!OOlnI +------------------------------------------------------------------------------------------------------------------------------------------------ + +project01-新服务器(域名:macquariegig.com) +p1-web 10.148.0.8 (nic0) 34.87.157.112 (nic0) +p1-mongo 10.148.0.11 (nic0) 35.186.148.111 (nic0) +p1-quotes 10.148.0.10 (nic0) 35.240.154.77 (nic0) +p1-trade 10.148.0.9 (nic0) 34.87.42.105 (nic0) + +mysql +host: 10.148.0.8 (nic0) 34.87.157.112 (nic0) +user:root +pwd: Meetingyou0))2024$ +port:23306 + +redis +host: 10.148.0.8 (nic0) 34.87.157.112 (nic0) +port:26379 +pwd:7d00cb62-1d1c-4c86-b50a-ebf9f00cc9fd + +mongodb +host: 10.148.0.11 (nic0) 35.186.148.111 (nic0) +port:28075 +user:pqRRVamndJ +pwd:35LlW3pXF76&WD!OOlnI +------------------------------------------------------------------------------------------------------------------------------------------------ + +project06-新服务器(域名:yrsig.com) +p6-mongo 10.154.0.10 (nic0) 35.189.116.242 (nic0) +p6-quotes 10.154.0.8 (nic0) 35.246.61.201 (nic0) +p6-trade 10.154.0.7 (nic0) 35.246.63.137 (nic0) +p6-web 10.154.0.9 (nic0) 34.105.182.222 (nic0) + +用户名:root +密码:Meetingyou0)) + +mysql +IP: 10.154.0.9(nic0) 34.105.182.222(nic0) +port: 23306 +USER: root +PWD: Meetingyou0))2024$ + +redis +IP: 10.154.0.9(nic0) 34.105.182.222(nic0) +port :26379 +PWD: 7d00cb62-1d1c-4c86-b50a-ebf9f00cc9fd + +mongodb +host:10.154.0.10(nic0) 35.189.116.242 (nic0) +port:28075 +user:pqRRVamndJ +pwd:35LlW3pXF76&WD!OOlnI +------------------------------------------------------------------------------------------------------------------------------------------------ \ No newline at end of file diff --git a/ServiceUpdateLog b/ServiceUpdateLog new file mode 100644 index 0000000..52c03fa --- /dev/null +++ b/ServiceUpdateLog @@ -0,0 +1,159 @@ + +------------------------------------------------------------------------------------------------------------------------------------------------ +p7正式环境,美股|泰股|马股|港股|IPO交易服务更新 +服务部署完毕(2024-06-21) +此次更新功能包含: +1、部署美股、泰股、马股、港股、IPO交易服务 +2、访问地址 + 1>交易订单域名: https://trade.tdcowengroup.com + 2>交易订单Wss: wss://trade.tdcowengroup.com +3、相关API文档参见 + 1>http://103.71.254.42:3001/project/56/interface/api + 2>http://103.71.254.42:3001/project/56/interface/api/cat_88 +------------------------------------------------------------------------------------------------------------------------------------------------ + +测试|正式环境,德股|法股交易服务更新 +服务部署完毕(2024-06-24) +此次更新功能包含: +1、部署德股、法股交易服务 +2、测试访问地址 + 1>交易订单域名: https://trade.jdtest88.com + 2>交易订单Wss: wss://trade.jdtest88.com +3、线上访问地址 + 1>交易订单域名: https://trade.twinim.com + 2>交易订单Wss: wss://trade.twinim.com +4、相关API文档参见 + 1>http://103.71.254.42:3001/project/56/interface/api/cat_807 + 2>http://103.71.254.42:3001/project/56/interface/api/cat_799 + 3>http://103.71.254.42:3001/project/56/interface/api/cat_88 +------------------------------------------------------------------------------------------------------------------------------------------------ + +测试|p6正式环境,股票交易服务更新 +服务部署完毕(2024-06-27) +此次更新功能包含: +1、统一股票订单列表时间格式 +------------------------------------------------------------------------------------------------------------------------------------------------ + +p2|p7正式环境,股票交易服务更新 +服务部署完毕(2024-07-01) +此次更新功能包含: +1、更新通过配置股票插针进行后台交易 +------------------------------------------------------------------------------------------------------------------------------------------------ + +p8正式环境,数字币交易服务更新 +服务部署完毕(2024-07-02) +此次更新功能包含: +1、部署合约、现货、秒合约交易服务 +2、线上访问地址 + 1>交易订单域名: https://trade.chdh.me + 2>交易订单Wss: wss://trade.chdh.me +3、相关API文档参见 + 1>http://103.71.254.42:3001/project/56/interface/api/cat_519 + 2>http://103.71.254.42:3001/project/56/interface/api/cat_74 + 3>http://103.71.254.42:3001/project/56/interface/api/cat_81 +------------------------------------------------------------------------------------------------------------------------------------------------ + +关于插针改动(p2\p6\p7): +1、前端/后端-(订单wss订阅|浮动盈亏wss订阅|市场总金额浮动盈亏wss订阅)取值为:实时价、闭盘价(优先级:实时价 > 闭盘价) +2、盘中插针(优先级:插针价 > 实时价) + 1>设置时:交易开仓取值为:插针价 + 2>未设置时:交易开仓取值为:实时价 +3、盘前|盘后插针 (在设置容许下单的前提下:例如调整开盘时间等) + 1>设置时:交易开仓取值为:插针价 +------------------------------------------------------------------------------------------------------------------------------------------------ + +测试环境,股票交易统计服务更新 +服务部署完毕(2024-07-10) +此次更新功能包含: +1、新增股票各个市场订阅统计服务(包含:用户市场总资产、用户市场总可用余额、用户市场冻结、用户市场累计盈亏、用户市场总手续费、用户市场总浮动盈亏) +2、相关API文档参见 + 1>http://103.71.254.42:3001/project/56/interface/api/cat_88 +------------------------------------------------------------------------------------------------------------------------------------------------ + +FB +应用编号:489884953731337 +应用密钥:77fcf7fe8f8b1ba26ad622b537e321c9 +gg +客户端ID: 220504529176-bl8cfsr1dktbebl1qo1km6mu02lfdjaa.apps.googleusercontent.com +客户端密钥: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 +------------------------------------------------------------------------------------------------------------------------------------------------ + +p6正式环境,股票交易服务更新 +服务部署完毕(2024-08-02) +此次更新功能包含: +1、新增股票市场IPO欠款功能 +------------------------------------------------------------------------------------------------------------------------------------------------ + +正式环境,p9股票交易服务更新 +服务部署完毕(2024-08-13) +此次更新功能包含: +1、部署美股、泰股、巴西股交易服务 +2、线上访问地址 + 1>交易订单域名: https://trade.wedbushig.com + 2>交易订单Wss: wss://trade.wedbushig.com +3、相关API文档参见 + 1>订单api:http://103.71.254.42:3001/project/56/interface/api/cat_808 + 2>订单订阅:http://103.71.254.42:3001/project/56/interface/api/4543 + 3>管理员|浮动盈亏订阅:http://103.71.254.42:3001/project/56/interface/api/519 +------------------------------------------------------------------------------------------------------------------------------------------------ + +正式|测试(美股\德股\法股\英股)环境,p6股票交易服务更新 +服务部署完毕(2024-08-14) +此次更新功能包含: +1、修改股票交易杠杆取值逻辑 +------------------------------------------------------------------------------------------------------------------------------------------------ + +目前杠杆开启的条件: +1、申请杠杆(开启杠杆) +2、是否满足设置杠杆的最小购买量 +3、设置杠杆倍数是否满足区间范围(最小~最大) + +杠杆优先级: +1、设置默认杠杆 +2、设置单个用户杠杆 +3、优先级:设置单个用户杠杆 > 默认值 +------------------------------------------------------------------------------------------------------------------------------------------------ + +p9测试环境,数字币交易服务更新 +服务部署完毕(2024-09-19) +此次更新功能包含: +1、部署合约、现货、秒合约交易服务 +2、交易访问地址 + 1>交易订单域名: https://trade.jdtest88.com + 2>交易订单Wss: wss://trade.jdtest88.com +3、行情访问地址 + 1>行情订单域名: https://quotes.jdtest88.com + 2>行情订单Wss: wss://quotes.jdtest88.com + +------------------------------------------------------------------------------------------------------------------------------------------------ + +外汇交易服务更新 +服务部署完毕(2024-10-27) +此次更新功能包含: +1、部署外汇交易、行情服务 +2、交易访问地址 + 1>交易订单域名: https://trade.jdtest88.com + 2>交易订单Wss: wss://trade.jdtest88.com +3、行情访问地址 + 1>行情订单域名: https://quotes.jdtest88.com + 2>行情订单Wss: wss://quotes.jdtest88.com +3、相关API文档参见 + 1>行情API:http://154.86.0.30:3001/project/65/interface/api/cat_812 + 2>行情订阅:http://154.86.0.30:3001/project/65/interface/api/cat_158 + 3>交易API:http://154.86.0.30:3001/project/56/interface/api/cat_814 + 4>交易订单订阅:http://154.86.0.30:3001/project/56/interface/api/4621 + 5>管理员|浮动盈亏订阅:http://154.86.0.30:3001/project/56/interface/api/cat_88 +------------------------------------------------------------------------------------------------------------------------------------------------ + +p1外汇交易服务更新 +服务部署完毕(2024-12-14) +此次更新功能包含: +1、部署p1外汇交易 +2、交易访问地址 + 1>交易订单域名: https://trade.jdtest88.com + 2>交易订单Wss: wss://trade.jdtest88.com +3、相关API文档参见 + 1>交易API:http://154.86.0.30:3001/project/56/interface/api/cat_818 + 2>交易订单订阅:http://154.86.0.30:3001/project/56/interface/api/4657 + 3>管理员|浮动盈亏订阅:http://154.86.0.30:3001/project/56/interface/api/519 +------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/api/matchmaking/v1/README.md b/api/matchmaking/v1/README.md new file mode 100644 index 0000000..55f65b4 --- /dev/null +++ b/api/matchmaking/v1/README.md @@ -0,0 +1,37 @@ +# 项目api管理 + +## 金融市场-数字币(virtually) +``` + 1、现货 spots + 2、合约 cntract + 3、秒合约 second +``` + +## 金融市场-股票(share) +``` + 1、美股 shareUs + 2、泰股 shareTha + 3、马股 shareMys + 4、印度股 shareInr + 5、印尼股 shareIdn + 6、新加坡股 shareSgd + 7、港股 shareHkd + 8、英股 shareGbx +``` + +## 金融市场-大宗交易(block) +``` + 1、美股 shareBlk + 2、泰股 shareBlk + 3、马股 shareBlk + 4、印尼股 shareBlk + 5、印度股 shareBlk + 6、新加坡股 shareBlk + 7、港股 shareBlk + 8、英股 shareGbx +``` + +## 金融市场-期权(option) +``` + 1、印度股 optionInr +``` diff --git a/api/matchmaking/v1/backend/backend.pb.go b/api/matchmaking/v1/backend/backend.pb.go new file mode 100644 index 0000000..ebf8bc4 --- /dev/null +++ b/api/matchmaking/v1/backend/backend.pb.go @@ -0,0 +1,231 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/backend/backend.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type BotUsersReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *BotUsersReply) Reset() { + *x = BotUsersReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_backend_backend_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotUsersReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotUsersReply) ProtoMessage() {} + +func (x *BotUsersReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_backend_backend_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotUsersReply.ProtoReflect.Descriptor instead. +func (*BotUsersReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_backend_backend_proto_rawDescGZIP(), []int{0} +} + +func (x *BotUsersReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *BotUsersReply) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +func (x *BotUsersReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type BotUsersNullRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *BotUsersNullRequest) Reset() { + *x = BotUsersNullRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_backend_backend_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotUsersNullRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotUsersNullRequest) ProtoMessage() {} + +func (x *BotUsersNullRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_backend_backend_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotUsersNullRequest.ProtoReflect.Descriptor instead. +func (*BotUsersNullRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_backend_backend_proto_rawDescGZIP(), []int{1} +} + +var File_matchmaking_v1_backend_backend_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_backend_backend_proto_rawDesc = []byte{ + 0x0a, 0x24, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x2f, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, + 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, + 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x51, 0x0a, 0x0d, 0x42, 0x6f, 0x74, 0x55, 0x73, 0x65, 0x72, 0x73, + 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, + 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, + 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x15, 0x0a, 0x13, 0x42, 0x6f, 0x74, 0x55, 0x73, + 0x65, 0x72, 0x73, 0x4e, 0x75, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x32, 0x92, + 0x01, 0x0a, 0x07, 0x42, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x12, 0x86, 0x01, 0x0a, 0x16, 0x55, + 0x70, 0x64, 0x61, 0x74, 0x65, 0x42, 0x6f, 0x74, 0x55, 0x73, 0x65, 0x72, 0x73, 0x42, 0x79, 0x49, + 0x73, 0x52, 0x65, 0x61, 0x6c, 0x12, 0x23, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, + 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x55, 0x73, 0x65, 0x72, 0x73, 0x4e, + 0x75, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x55, + 0x73, 0x65, 0x72, 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x28, 0x82, 0xd3, 0xe4, 0x93, 0x02, + 0x22, 0x3a, 0x01, 0x2a, 0x22, 0x1d, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x62, 0x61, 0x63, + 0x6b, 0x65, 0x6e, 0x64, 0x2f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x69, 0x73, 0x5f, 0x72, + 0x65, 0x61, 0x6c, 0x42, 0x2a, 0x5a, 0x28, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2d, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_backend_backend_proto_rawDescOnce sync.Once + file_matchmaking_v1_backend_backend_proto_rawDescData = file_matchmaking_v1_backend_backend_proto_rawDesc +) + +func file_matchmaking_v1_backend_backend_proto_rawDescGZIP() []byte { + file_matchmaking_v1_backend_backend_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_backend_backend_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_backend_backend_proto_rawDescData) + }) + return file_matchmaking_v1_backend_backend_proto_rawDescData +} + +var file_matchmaking_v1_backend_backend_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_matchmaking_v1_backend_backend_proto_goTypes = []any{ + (*BotUsersReply)(nil), // 0: matchmaking.v1.BotUsersReply + (*BotUsersNullRequest)(nil), // 1: matchmaking.v1.BotUsersNullRequest +} +var file_matchmaking_v1_backend_backend_proto_depIdxs = []int32{ + 1, // 0: matchmaking.v1.Backend.UpdateBotUsersByIsReal:input_type -> matchmaking.v1.BotUsersNullRequest + 0, // 1: matchmaking.v1.Backend.UpdateBotUsersByIsReal:output_type -> matchmaking.v1.BotUsersReply + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_backend_backend_proto_init() } +func file_matchmaking_v1_backend_backend_proto_init() { + if File_matchmaking_v1_backend_backend_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_matchmaking_v1_backend_backend_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*BotUsersReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_backend_backend_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*BotUsersNullRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_backend_backend_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_matchmaking_v1_backend_backend_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_backend_backend_proto_depIdxs, + MessageInfos: file_matchmaking_v1_backend_backend_proto_msgTypes, + }.Build() + File_matchmaking_v1_backend_backend_proto = out.File + file_matchmaking_v1_backend_backend_proto_rawDesc = nil + file_matchmaking_v1_backend_backend_proto_goTypes = nil + file_matchmaking_v1_backend_backend_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/backend/backend.proto b/api/matchmaking/v1/backend/backend.proto new file mode 100644 index 0000000..658ad15 --- /dev/null +++ b/api/matchmaking/v1/backend/backend.proto @@ -0,0 +1,27 @@ +syntax = "proto3"; + +package matchmaking.v1; + +import "google/api/annotations.proto"; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +service Backend { + // UpdateBotUsersByIsReal 更新用户KYC认证 + rpc UpdateBotUsersByIsReal(BotUsersNullRequest)returns(BotUsersReply){ + option (google.api.http) = { + post:"/order_backend/update_is_real", + body:"*", + }; + } +} + +message BotUsersReply{ + int64 code =1;// 状态码 + string data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message BotUsersNullRequest{ + +} \ No newline at end of file diff --git a/api/matchmaking/v1/backend/backend_grpc.pb.go b/api/matchmaking/v1/backend/backend_grpc.pb.go new file mode 100644 index 0000000..a58c1a0 --- /dev/null +++ b/api/matchmaking/v1/backend/backend_grpc.pb.go @@ -0,0 +1,112 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.1 +// source: matchmaking/v1/backend/backend.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + Backend_UpdateBotUsersByIsReal_FullMethodName = "/matchmaking.v1.Backend/UpdateBotUsersByIsReal" +) + +// BackendClient is the client API for Backend service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type BackendClient interface { + // UpdateBotUsersByIsReal 更新用户KYC认证 + UpdateBotUsersByIsReal(ctx context.Context, in *BotUsersNullRequest, opts ...grpc.CallOption) (*BotUsersReply, error) +} + +type backendClient struct { + cc grpc.ClientConnInterface +} + +func NewBackendClient(cc grpc.ClientConnInterface) BackendClient { + return &backendClient{cc} +} + +func (c *backendClient) UpdateBotUsersByIsReal(ctx context.Context, in *BotUsersNullRequest, opts ...grpc.CallOption) (*BotUsersReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(BotUsersReply) + err := c.cc.Invoke(ctx, Backend_UpdateBotUsersByIsReal_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// BackendServer is the server API for Backend service. +// All implementations must embed UnimplementedBackendServer +// for forward compatibility +type BackendServer interface { + // UpdateBotUsersByIsReal 更新用户KYC认证 + UpdateBotUsersByIsReal(context.Context, *BotUsersNullRequest) (*BotUsersReply, error) + mustEmbedUnimplementedBackendServer() +} + +// UnimplementedBackendServer must be embedded to have forward compatible implementations. +type UnimplementedBackendServer struct { +} + +func (UnimplementedBackendServer) UpdateBotUsersByIsReal(context.Context, *BotUsersNullRequest) (*BotUsersReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateBotUsersByIsReal not implemented") +} +func (UnimplementedBackendServer) mustEmbedUnimplementedBackendServer() {} + +// UnsafeBackendServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to BackendServer will +// result in compilation errors. +type UnsafeBackendServer interface { + mustEmbedUnimplementedBackendServer() +} + +func RegisterBackendServer(s grpc.ServiceRegistrar, srv BackendServer) { + s.RegisterService(&Backend_ServiceDesc, srv) +} + +func _Backend_UpdateBotUsersByIsReal_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BotUsersNullRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BackendServer).UpdateBotUsersByIsReal(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Backend_UpdateBotUsersByIsReal_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BackendServer).UpdateBotUsersByIsReal(ctx, req.(*BotUsersNullRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Backend_ServiceDesc is the grpc.ServiceDesc for Backend service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Backend_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "matchmaking.v1.Backend", + HandlerType: (*BackendServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "UpdateBotUsersByIsReal", + Handler: _Backend_UpdateBotUsersByIsReal_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "matchmaking/v1/backend/backend.proto", +} diff --git a/api/matchmaking/v1/backend/backend_http.pb.go b/api/matchmaking/v1/backend/backend_http.pb.go new file mode 100644 index 0000000..30fe7bd --- /dev/null +++ b/api/matchmaking/v1/backend/backend_http.pb.go @@ -0,0 +1,79 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.3 +// - protoc v5.27.1 +// source: matchmaking/v1/backend/backend.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationBackendUpdateBotUsersByIsReal = "/matchmaking.v1.Backend/UpdateBotUsersByIsReal" + +type BackendHTTPServer interface { + // UpdateBotUsersByIsReal UpdateBotUsersByIsReal 更新用户KYC认证 + UpdateBotUsersByIsReal(context.Context, *BotUsersNullRequest) (*BotUsersReply, error) +} + +func RegisterBackendHTTPServer(s *http.Server, srv BackendHTTPServer) { + r := s.Route("/") + r.POST("/order_backend/update_is_real", _Backend_UpdateBotUsersByIsReal0_HTTP_Handler(srv)) +} + +func _Backend_UpdateBotUsersByIsReal0_HTTP_Handler(srv BackendHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in BotUsersNullRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationBackendUpdateBotUsersByIsReal) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.UpdateBotUsersByIsReal(ctx, req.(*BotUsersNullRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*BotUsersReply) + return ctx.Result(200, reply) + } +} + +type BackendHTTPClient interface { + UpdateBotUsersByIsReal(ctx context.Context, req *BotUsersNullRequest, opts ...http.CallOption) (rsp *BotUsersReply, err error) +} + +type BackendHTTPClientImpl struct { + cc *http.Client +} + +func NewBackendHTTPClient(client *http.Client) BackendHTTPClient { + return &BackendHTTPClientImpl{client} +} + +func (c *BackendHTTPClientImpl) UpdateBotUsersByIsReal(ctx context.Context, in *BotUsersNullRequest, opts ...http.CallOption) (*BotUsersReply, error) { + var out BotUsersReply + pattern := "/order_backend/update_is_real" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationBackendUpdateBotUsersByIsReal)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/api/matchmaking/v1/block/blockOrder.pb.go b/api/matchmaking/v1/block/blockOrder.pb.go new file mode 100644 index 0000000..c51c517 --- /dev/null +++ b/api/matchmaking/v1/block/blockOrder.pb.go @@ -0,0 +1,1248 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/block/blockOrder.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GetBotStockBlockTradeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status int64 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` // 状态码 + PageSize int64 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,3,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + Type int64 `protobuf:"varint,4,opt,name=type,proto3" json:"type,omitempty"` // 市场类型 +} + +func (x *GetBotStockBlockTradeRequest) Reset() { + *x = GetBotStockBlockTradeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_block_blockOrder_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotStockBlockTradeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotStockBlockTradeRequest) ProtoMessage() {} + +func (x *GetBotStockBlockTradeRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_block_blockOrder_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotStockBlockTradeRequest.ProtoReflect.Descriptor instead. +func (*GetBotStockBlockTradeRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_block_blockOrder_proto_rawDescGZIP(), []int{0} +} + +func (x *GetBotStockBlockTradeRequest) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *GetBotStockBlockTradeRequest) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *GetBotStockBlockTradeRequest) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *GetBotStockBlockTradeRequest) GetType() int64 { + if x != nil { + return x.Type + } + return 0 +} + +type GetBotStockBlockTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *BotStockBlockTradeData `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *GetBotStockBlockTradeReply) Reset() { + *x = GetBotStockBlockTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_block_blockOrder_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotStockBlockTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotStockBlockTradeReply) ProtoMessage() {} + +func (x *GetBotStockBlockTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_block_blockOrder_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotStockBlockTradeReply.ProtoReflect.Descriptor instead. +func (*GetBotStockBlockTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_block_blockOrder_proto_rawDescGZIP(), []int{1} +} + +func (x *GetBotStockBlockTradeReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *GetBotStockBlockTradeReply) GetData() *BotStockBlockTradeData { + if x != nil { + return x.Data + } + return nil +} + +func (x *GetBotStockBlockTradeReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type BotStockBlockTradeData struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PageSize int64 `protobuf:"varint,1,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,2,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + Data []*BotOrderBlockTrade `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty"` // 返回结果 + TotalCount int64 `protobuf:"varint,4,opt,name=totalCount,proto3" json:"totalCount,omitempty"` // 总数据 +} + +func (x *BotStockBlockTradeData) Reset() { + *x = BotStockBlockTradeData{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_block_blockOrder_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockBlockTradeData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockBlockTradeData) ProtoMessage() {} + +func (x *BotStockBlockTradeData) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_block_blockOrder_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockBlockTradeData.ProtoReflect.Descriptor instead. +func (*BotStockBlockTradeData) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_block_blockOrder_proto_rawDescGZIP(), []int{2} +} + +func (x *BotStockBlockTradeData) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *BotStockBlockTradeData) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *BotStockBlockTradeData) GetData() []*BotOrderBlockTrade { + if x != nil { + return x.Data + } + return nil +} + +func (x *BotStockBlockTradeData) GetTotalCount() int64 { + if x != nil { + return x.TotalCount + } + return 0 +} + +type BotOrderBlockTrade struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID + StockId string `protobuf:"bytes,2,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票代码 + TradeType int64 `protobuf:"varint,3,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型 + DealType int64 `protobuf:"varint,4,opt,name=dealType,proto3" json:"dealType,omitempty"` // 交易方式 + LimitPrice string `protobuf:"bytes,5,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,6,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + DealPrice string `protobuf:"bytes,7,opt,name=dealPrice,proto3" json:"dealPrice,omitempty"` // 开仓价 + ClosingPrice string `protobuf:"bytes,8,opt,name=closingPrice,proto3" json:"closingPrice,omitempty"` // 平仓价 + OrderNumber string `protobuf:"bytes,9,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损状态 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + ServiceCost string `protobuf:"bytes,13,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 开仓手续费 + MarketMoney string `protobuf:"bytes,14,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderMoney string `protobuf:"bytes,15,opt,name=orderMoney,proto3" json:"orderMoney,omitempty"` // 订单总金额 + Status int64 `protobuf:"varint,16,opt,name=status,proto3" json:"status,omitempty"` // 订单状态 + CreateTime *timestamppb.Timestamp `protobuf:"bytes,17,opt,name=createTime,proto3" json:"createTime,omitempty"` // 订单创建时间 + UpdateTime *timestamppb.Timestamp `protobuf:"bytes,18,opt,name=updateTime,proto3" json:"updateTime,omitempty"` // 订单更新时间 + OpenTime *timestamppb.Timestamp `protobuf:"bytes,19,opt,name=openTime,proto3" json:"openTime,omitempty"` // 订单开仓时间 + ClosingTime *timestamppb.Timestamp `protobuf:"bytes,20,opt,name=closingTime,proto3" json:"closingTime,omitempty"` // 订单平仓时间 + ClosingCost string `protobuf:"bytes,21,opt,name=closingCost,proto3" json:"closingCost,omitempty"` // 平仓手续费 + FaceValue string `protobuf:"bytes,22,opt,name=faceValue,proto3" json:"faceValue,omitempty"` // 面值 + PryNum string `protobuf:"bytes,23,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 + KeepDecimal string `protobuf:"bytes,24,opt,name=keepDecimal,proto3" json:"keepDecimal,omitempty"` // 保留小数位 + StockName string `protobuf:"bytes,25,opt,name=stockName,proto3" json:"stockName,omitempty"` // 股票名称 + Type int64 `protobuf:"varint,26,opt,name=type,proto3" json:"type,omitempty"` // 市场类型 +} + +func (x *BotOrderBlockTrade) Reset() { + *x = BotOrderBlockTrade{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_block_blockOrder_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotOrderBlockTrade) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotOrderBlockTrade) ProtoMessage() {} + +func (x *BotOrderBlockTrade) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_block_blockOrder_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotOrderBlockTrade.ProtoReflect.Descriptor instead. +func (*BotOrderBlockTrade) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_block_blockOrder_proto_rawDescGZIP(), []int{3} +} + +func (x *BotOrderBlockTrade) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *BotOrderBlockTrade) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *BotOrderBlockTrade) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *BotOrderBlockTrade) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *BotOrderBlockTrade) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *BotOrderBlockTrade) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *BotOrderBlockTrade) GetDealPrice() string { + if x != nil { + return x.DealPrice + } + return "" +} + +func (x *BotOrderBlockTrade) GetClosingPrice() string { + if x != nil { + return x.ClosingPrice + } + return "" +} + +func (x *BotOrderBlockTrade) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *BotOrderBlockTrade) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *BotOrderBlockTrade) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *BotOrderBlockTrade) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *BotOrderBlockTrade) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *BotOrderBlockTrade) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *BotOrderBlockTrade) GetOrderMoney() string { + if x != nil { + return x.OrderMoney + } + return "" +} + +func (x *BotOrderBlockTrade) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *BotOrderBlockTrade) GetCreateTime() *timestamppb.Timestamp { + if x != nil { + return x.CreateTime + } + return nil +} + +func (x *BotOrderBlockTrade) GetUpdateTime() *timestamppb.Timestamp { + if x != nil { + return x.UpdateTime + } + return nil +} + +func (x *BotOrderBlockTrade) GetOpenTime() *timestamppb.Timestamp { + if x != nil { + return x.OpenTime + } + return nil +} + +func (x *BotOrderBlockTrade) GetClosingTime() *timestamppb.Timestamp { + if x != nil { + return x.ClosingTime + } + return nil +} + +func (x *BotOrderBlockTrade) GetClosingCost() string { + if x != nil { + return x.ClosingCost + } + return "" +} + +func (x *BotOrderBlockTrade) GetFaceValue() string { + if x != nil { + return x.FaceValue + } + return "" +} + +func (x *BotOrderBlockTrade) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *BotOrderBlockTrade) GetKeepDecimal() string { + if x != nil { + return x.KeepDecimal + } + return "" +} + +func (x *BotOrderBlockTrade) GetStockName() string { + if x != nil { + return x.StockName + } + return "" +} + +func (x *BotOrderBlockTrade) GetType() int64 { + if x != nil { + return x.Type + } + return 0 +} + +type OrderBlockRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + StockId string `protobuf:"bytes,1,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票Code + TradeType int64 `protobuf:"varint,2,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型:1买入,2卖出 + DealType int64 `protobuf:"varint,3,opt,name=dealType,proto3" json:"dealType,omitempty"` // 委托方式:1限价,2市价 + LimitPrice string `protobuf:"bytes,4,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,5,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + MarketMoney string `protobuf:"bytes,6,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderNumber string `protobuf:"bytes,7,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + ServiceCost string `protobuf:"bytes,8,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 手续费 + StopType int64 `protobuf:"varint,9,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止损止盈设置:1无设置,2止损止盈 + StopLossPrice string `protobuf:"bytes,10,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,11,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止损 + PryNum string `protobuf:"bytes,12,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 + Type int64 `protobuf:"varint,13,opt,name=type,proto3" json:"type,omitempty"` // 市场类型 +} + +func (x *OrderBlockRequest) Reset() { + *x = OrderBlockRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_block_blockOrder_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OrderBlockRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OrderBlockRequest) ProtoMessage() {} + +func (x *OrderBlockRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_block_blockOrder_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OrderBlockRequest.ProtoReflect.Descriptor instead. +func (*OrderBlockRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_block_blockOrder_proto_rawDescGZIP(), []int{4} +} + +func (x *OrderBlockRequest) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *OrderBlockRequest) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *OrderBlockRequest) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *OrderBlockRequest) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *OrderBlockRequest) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *OrderBlockRequest) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *OrderBlockRequest) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *OrderBlockRequest) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *OrderBlockRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *OrderBlockRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *OrderBlockRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *OrderBlockRequest) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *OrderBlockRequest) GetType() int64 { + if x != nil { + return x.Type + } + return 0 +} + +type UpdateBlockOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id + StopType int64 `protobuf:"varint,2,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,3,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,4,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + Type int64 `protobuf:"varint,5,opt,name=type,proto3" json:"type,omitempty"` // 市场类型 +} + +func (x *UpdateBlockOrderRequest) Reset() { + *x = UpdateBlockOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_block_blockOrder_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateBlockOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateBlockOrderRequest) ProtoMessage() {} + +func (x *UpdateBlockOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_block_blockOrder_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateBlockOrderRequest.ProtoReflect.Descriptor instead. +func (*UpdateBlockOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_block_blockOrder_proto_rawDescGZIP(), []int{5} +} + +func (x *UpdateBlockOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *UpdateBlockOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *UpdateBlockOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *UpdateBlockOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *UpdateBlockOrderRequest) GetType() int64 { + if x != nil { + return x.Type + } + return 0 +} + +type OrderBlockReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *OrderBlockResult `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *OrderBlockReply) Reset() { + *x = OrderBlockReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_block_blockOrder_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OrderBlockReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OrderBlockReply) ProtoMessage() {} + +func (x *OrderBlockReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_block_blockOrder_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OrderBlockReply.ProtoReflect.Descriptor instead. +func (*OrderBlockReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_block_blockOrder_proto_rawDescGZIP(), []int{6} +} + +func (x *OrderBlockReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *OrderBlockReply) GetData() *OrderBlockResult { + if x != nil { + return x.Data + } + return nil +} + +func (x *OrderBlockReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type CancelBlockOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID + Type int64 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"` // 市场类型 +} + +func (x *CancelBlockOrderRequest) Reset() { + *x = CancelBlockOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_block_blockOrder_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CancelBlockOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CancelBlockOrderRequest) ProtoMessage() {} + +func (x *CancelBlockOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_block_blockOrder_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CancelBlockOrderRequest.ProtoReflect.Descriptor instead. +func (*CancelBlockOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_block_blockOrder_proto_rawDescGZIP(), []int{7} +} + +func (x *CancelBlockOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *CancelBlockOrderRequest) GetType() int64 { + if x != nil { + return x.Type + } + return 0 +} + +type OrderBlockResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id +} + +func (x *OrderBlockResult) Reset() { + *x = OrderBlockResult{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_block_blockOrder_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OrderBlockResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OrderBlockResult) ProtoMessage() {} + +func (x *OrderBlockResult) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_block_blockOrder_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OrderBlockResult.ProtoReflect.Descriptor instead. +func (*OrderBlockResult) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_block_blockOrder_proto_rawDescGZIP(), []int{8} +} + +func (x *OrderBlockResult) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +var File_matchmaking_v1_block_blockOrder_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_block_blockOrder_proto_rawDesc = []byte{ + 0x0a, 0x25, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, + 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, + 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x84, 0x01, 0x0a, 0x1c, 0x47, 0x65, 0x74, 0x42, 0x6f, + 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, + 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, + 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, + 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, + 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x86, 0x01, + 0x0a, 0x1a, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x42, 0x6c, 0x6f, + 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, + 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, + 0x12, 0x3a, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, + 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, + 0x64, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, + 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xaa, 0x01, 0x0a, 0x16, 0x42, 0x6f, 0x74, 0x53, 0x74, + 0x6f, 0x63, 0x6b, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, + 0x61, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, + 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x36, 0x0a, 0x04, 0x64, + 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x6d, 0x61, 0x74, 0x63, + 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x04, 0x64, + 0x61, 0x74, 0x61, 0x12, 0x1e, 0x0a, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, + 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x22, 0xa4, 0x07, 0x0a, 0x12, 0x42, 0x6f, 0x74, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x1c, + 0x0a, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, + 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, + 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, + 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, + 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, + 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, + 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x65, + 0x61, 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x64, + 0x65, 0x61, 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6c, 0x6f, 0x73, + 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, + 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, + 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x1a, + 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, + 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, + 0x6f, 0x73, 0x74, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, + 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, + 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, + 0x75, 0x73, 0x18, 0x10, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x12, 0x3a, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x11, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, + 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x3a, 0x0a, 0x0a, + 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x12, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x75, 0x70, + 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x36, 0x0a, 0x08, 0x6f, 0x70, 0x65, 0x6e, + 0x54, 0x69, 0x6d, 0x65, 0x18, 0x13, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, + 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, + 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x08, 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, + 0x12, 0x3c, 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x18, + 0x14, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, + 0x70, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, + 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x15, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, + 0x12, 0x1c, 0x0a, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x16, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x16, + 0x0a, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x17, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, + 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x12, 0x20, 0x0a, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, + 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x18, 0x18, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6b, 0x65, 0x65, + 0x70, 0x44, 0x65, 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x74, 0x6f, 0x63, + 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x19, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x6f, + 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x1a, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0xa1, 0x03, 0x0a, 0x11, 0x4f, + 0x72, 0x64, 0x65, 0x72, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, + 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, + 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, + 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, + 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, + 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, + 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, + 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, + 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, + 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, + 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, + 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x0c, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, + 0x70, 0x65, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0xad, + 0x01, 0x0a, 0x17, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, + 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, + 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, + 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, + 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, + 0x70, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x75, + 0x0a, 0x0f, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x34, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, + 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, + 0x65, 0x73, 0x75, 0x6c, 0x74, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x47, 0x0a, 0x17, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x42, + 0x6c, 0x6f, 0x63, 0x6b, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, + 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x2c, + 0x0a, 0x10, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x75, + 0x6c, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x32, 0xe3, 0x05, 0x0a, + 0x0a, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x9a, 0x01, 0x0a, 0x15, + 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x42, 0x6c, 0x6f, 0x63, 0x6b, + 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x2c, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, + 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, + 0x63, 0x6b, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, + 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, + 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, + 0x27, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x21, 0x3a, 0x01, 0x2a, 0x22, 0x1c, 0x2f, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2f, 0x73, 0x68, + 0x61, 0x72, 0x65, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x12, 0x8a, 0x01, 0x0a, 0x14, 0x53, 0x68, 0x61, + 0x72, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x50, 0x6c, 0x61, 0x63, 0x65, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x12, 0x21, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x42, 0x6c, 0x6f, 0x63, 0x6b, + 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2e, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x28, 0x3a, 0x01, 0x2a, + 0x22, 0x23, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x62, 0x6c, + 0x6f, 0x63, 0x6b, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x5f, + 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x92, 0x01, 0x0a, 0x15, 0x53, 0x68, 0x61, 0x72, 0x65, 0x42, + 0x6c, 0x6f, 0x63, 0x6b, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, + 0x27, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, + 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x42, + 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2f, 0x82, 0xd3, 0xe4, 0x93, 0x02, + 0x29, 0x3a, 0x01, 0x2a, 0x22, 0x24, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, + 0x72, 0x65, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x75, 0x70, + 0x64, 0x61, 0x74, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x8b, 0x01, 0x0a, 0x12, 0x53, + 0x68, 0x61, 0x72, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, + 0x6e, 0x12, 0x27, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x2e, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2b, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x25, 0x3a, 0x01, 0x2a, 0x22, 0x20, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, + 0x68, 0x61, 0x72, 0x65, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, + 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x87, 0x01, 0x0a, 0x10, 0x53, 0x68, 0x61, + 0x72, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x12, 0x27, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, + 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, + 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x42, 0x6c, 0x6f, + 0x63, 0x6b, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x29, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x23, 0x3a, + 0x01, 0x2a, 0x22, 0x1e, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, + 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6e, 0x63, + 0x65, 0x6c, 0x42, 0x2a, 0x5a, 0x28, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, + 0x67, 0x2d, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_block_blockOrder_proto_rawDescOnce sync.Once + file_matchmaking_v1_block_blockOrder_proto_rawDescData = file_matchmaking_v1_block_blockOrder_proto_rawDesc +) + +func file_matchmaking_v1_block_blockOrder_proto_rawDescGZIP() []byte { + file_matchmaking_v1_block_blockOrder_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_block_blockOrder_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_block_blockOrder_proto_rawDescData) + }) + return file_matchmaking_v1_block_blockOrder_proto_rawDescData +} + +var file_matchmaking_v1_block_blockOrder_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_matchmaking_v1_block_blockOrder_proto_goTypes = []any{ + (*GetBotStockBlockTradeRequest)(nil), // 0: matchmaking.v1.GetBotStockBlockTradeRequest + (*GetBotStockBlockTradeReply)(nil), // 1: matchmaking.v1.GetBotStockBlockTradeReply + (*BotStockBlockTradeData)(nil), // 2: matchmaking.v1.BotStockBlockTradeData + (*BotOrderBlockTrade)(nil), // 3: matchmaking.v1.BotOrderBlockTrade + (*OrderBlockRequest)(nil), // 4: matchmaking.v1.OrderBlockRequest + (*UpdateBlockOrderRequest)(nil), // 5: matchmaking.v1.UpdateBlockOrderRequest + (*OrderBlockReply)(nil), // 6: matchmaking.v1.OrderBlockReply + (*CancelBlockOrderRequest)(nil), // 7: matchmaking.v1.CancelBlockOrderRequest + (*OrderBlockResult)(nil), // 8: matchmaking.v1.OrderBlockResult + (*timestamppb.Timestamp)(nil), // 9: google.protobuf.Timestamp +} +var file_matchmaking_v1_block_blockOrder_proto_depIdxs = []int32{ + 2, // 0: matchmaking.v1.GetBotStockBlockTradeReply.data:type_name -> matchmaking.v1.BotStockBlockTradeData + 3, // 1: matchmaking.v1.BotStockBlockTradeData.data:type_name -> matchmaking.v1.BotOrderBlockTrade + 9, // 2: matchmaking.v1.BotOrderBlockTrade.createTime:type_name -> google.protobuf.Timestamp + 9, // 3: matchmaking.v1.BotOrderBlockTrade.updateTime:type_name -> google.protobuf.Timestamp + 9, // 4: matchmaking.v1.BotOrderBlockTrade.openTime:type_name -> google.protobuf.Timestamp + 9, // 5: matchmaking.v1.BotOrderBlockTrade.closingTime:type_name -> google.protobuf.Timestamp + 8, // 6: matchmaking.v1.OrderBlockReply.data:type_name -> matchmaking.v1.OrderBlockResult + 0, // 7: matchmaking.v1.BlockTrade.GetBotStockBlockTrade:input_type -> matchmaking.v1.GetBotStockBlockTradeRequest + 4, // 8: matchmaking.v1.BlockTrade.ShareBlockPlaceOrder:input_type -> matchmaking.v1.OrderBlockRequest + 5, // 9: matchmaking.v1.BlockTrade.ShareBlockUpdateOrder:input_type -> matchmaking.v1.UpdateBlockOrderRequest + 7, // 10: matchmaking.v1.BlockTrade.ShareBlockPosition:input_type -> matchmaking.v1.CancelBlockOrderRequest + 7, // 11: matchmaking.v1.BlockTrade.ShareBlockCancel:input_type -> matchmaking.v1.CancelBlockOrderRequest + 1, // 12: matchmaking.v1.BlockTrade.GetBotStockBlockTrade:output_type -> matchmaking.v1.GetBotStockBlockTradeReply + 6, // 13: matchmaking.v1.BlockTrade.ShareBlockPlaceOrder:output_type -> matchmaking.v1.OrderBlockReply + 6, // 14: matchmaking.v1.BlockTrade.ShareBlockUpdateOrder:output_type -> matchmaking.v1.OrderBlockReply + 6, // 15: matchmaking.v1.BlockTrade.ShareBlockPosition:output_type -> matchmaking.v1.OrderBlockReply + 6, // 16: matchmaking.v1.BlockTrade.ShareBlockCancel:output_type -> matchmaking.v1.OrderBlockReply + 12, // [12:17] is the sub-list for method output_type + 7, // [7:12] is the sub-list for method input_type + 7, // [7:7] is the sub-list for extension type_name + 7, // [7:7] is the sub-list for extension extendee + 0, // [0:7] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_block_blockOrder_proto_init() } +func file_matchmaking_v1_block_blockOrder_proto_init() { + if File_matchmaking_v1_block_blockOrder_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_matchmaking_v1_block_blockOrder_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*GetBotStockBlockTradeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_block_blockOrder_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*GetBotStockBlockTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_block_blockOrder_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*BotStockBlockTradeData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_block_blockOrder_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*BotOrderBlockTrade); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_block_blockOrder_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*OrderBlockRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_block_blockOrder_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*UpdateBlockOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_block_blockOrder_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*OrderBlockReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_block_blockOrder_proto_msgTypes[7].Exporter = func(v any, i int) any { + switch v := v.(*CancelBlockOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_block_blockOrder_proto_msgTypes[8].Exporter = func(v any, i int) any { + switch v := v.(*OrderBlockResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_block_blockOrder_proto_rawDesc, + NumEnums: 0, + NumMessages: 9, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_matchmaking_v1_block_blockOrder_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_block_blockOrder_proto_depIdxs, + MessageInfos: file_matchmaking_v1_block_blockOrder_proto_msgTypes, + }.Build() + File_matchmaking_v1_block_blockOrder_proto = out.File + file_matchmaking_v1_block_blockOrder_proto_rawDesc = nil + file_matchmaking_v1_block_blockOrder_proto_goTypes = nil + file_matchmaking_v1_block_blockOrder_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/block/blockOrder.proto b/api/matchmaking/v1/block/blockOrder.proto new file mode 100644 index 0000000..c3705ac --- /dev/null +++ b/api/matchmaking/v1/block/blockOrder.proto @@ -0,0 +1,134 @@ +syntax = "proto3"; + +package matchmaking.v1; + +import "google/api/annotations.proto"; +import "google/protobuf/timestamp.proto"; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +service BlockTrade { + // GetBotStockBlockTrade 大宗交易股列表查询 + rpc GetBotStockBlockTrade(GetBotStockBlockTradeRequest)returns(GetBotStockBlockTradeReply){ + option (google.api.http) = { + post:"/order_shareblock/share_list", + body:"*", + }; + } + // ShareBlockPlaceOrder 大宗交易股下单 + rpc ShareBlockPlaceOrder(OrderBlockRequest)returns(OrderBlockReply) { + option (google.api.http) = { + post: "/order_shareblock/share_place_order", + body: "*", + }; + } + // ShareBlockUpdateOrder 大宗交易股设置止盈止损 + rpc ShareBlockUpdateOrder(UpdateBlockOrderRequest)returns(OrderBlockReply){ + option (google.api.http) = { + post:"/order_shareblock/share_update_order", + body:"*", + }; + } + // ShareBlockPosition 大宗交易股平仓 + rpc ShareBlockPosition(CancelBlockOrderRequest)returns(OrderBlockReply){ + option (google.api.http) = { + post:"/order_shareblock/share_position", + body:"*", + }; + } + // ShareBlockCancel 大宗交易股撤单 + rpc ShareBlockCancel(CancelBlockOrderRequest)returns(OrderBlockReply){ + option (google.api.http) = { + post:"/order_shareblock/share_cancel", + body:"*", + }; + } +} + +message GetBotStockBlockTradeRequest{ + int64 status =1;// 状态码 + int64 pageSize =2; // 每页显示条数 + int64 pageCount =3;// 开始的位置 + int64 type =4;// 市场类型 +} + +message GetBotStockBlockTradeReply{ + int64 code =1;// 状态码 + BotStockBlockTradeData data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message BotStockBlockTradeData{ + int64 pageSize =1; // 每页显示条数 + int64 pageCount =2;// 开始的位置 + repeated BotOrderBlockTrade data =3;// 返回结果 + int64 totalCount =4;// 总数据 +} + +message BotOrderBlockTrade{ + string orderId =1;// 订单ID + string stockId =2;// 股票代码 + int64 tradeType =3;// 交易类型 + int64 dealType =4;// 交易方式 + string limitPrice =5;// 限价 + string marketPrice =6;// 市价 + string dealPrice =7;// 开仓价 + string closingPrice =8;// 平仓价 + string orderNumber =9;// 订单数量 + int64 stopType =10;// 止盈止损状态 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string serviceCost =13;// 开仓手续费 + string marketMoney =14;// 订单金额 + string orderMoney =15;// 订单总金额 + int64 status =16;// 订单状态 + google.protobuf.Timestamp createTime =17;// 订单创建时间 + google.protobuf.Timestamp updateTime =18;// 订单更新时间 + google.protobuf.Timestamp openTime =19;// 订单开仓时间 + google.protobuf.Timestamp closingTime =20;// 订单平仓时间 + string closingCost =21;// 平仓手续费 + string faceValue =22;// 面值 + string pryNum =23;// 杠杆 + string keepDecimal =24;// 保留小数位 + string stockName =25;// 股票名称 + int64 type =26;// 市场类型 +} + +message OrderBlockRequest{ + string stockId =1;// 股票Code + int64 tradeType =2;// 交易类型:1买入,2卖出 + int64 dealType =3;// 委托方式:1限价,2市价 + string limitPrice =4;// 限价 + string marketPrice =5;// 市价 + string marketMoney =6;// 订单金额 + string orderNumber =7;// 订单数量 + string serviceCost =8;// 手续费 + int64 stopType =9;// 止损止盈设置:1无设置,2止损止盈 + string stopLossPrice =10;// 止损 + string stopWinPrice =11;// 止损 + string pryNum =12;// 杠杆 + int64 type =13;// 市场类型 +} + +message UpdateBlockOrderRequest{ + string orderId =1;// 订单Id + int64 stopType =2;// 止盈止损 + string stopLossPrice =3;// 止损 + string stopWinPrice =4;// 止盈 + int64 type =5;// 市场类型 +} + +message OrderBlockReply{ + int64 code =1;// 状态码 + OrderBlockResult data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message CancelBlockOrderRequest{ + string orderId =1;// 订单ID + int64 type =2;// 市场类型 +} + +message OrderBlockResult { + string orderId =1;// 订单Id +} \ No newline at end of file diff --git a/api/matchmaking/v1/block/blockOrder_grpc.pb.go b/api/matchmaking/v1/block/blockOrder_grpc.pb.go new file mode 100644 index 0000000..bc45d2c --- /dev/null +++ b/api/matchmaking/v1/block/blockOrder_grpc.pb.go @@ -0,0 +1,272 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.1 +// source: matchmaking/v1/block/blockOrder.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + BlockTrade_GetBotStockBlockTrade_FullMethodName = "/matchmaking.v1.BlockTrade/GetBotStockBlockTrade" + BlockTrade_ShareBlockPlaceOrder_FullMethodName = "/matchmaking.v1.BlockTrade/ShareBlockPlaceOrder" + BlockTrade_ShareBlockUpdateOrder_FullMethodName = "/matchmaking.v1.BlockTrade/ShareBlockUpdateOrder" + BlockTrade_ShareBlockPosition_FullMethodName = "/matchmaking.v1.BlockTrade/ShareBlockPosition" + BlockTrade_ShareBlockCancel_FullMethodName = "/matchmaking.v1.BlockTrade/ShareBlockCancel" +) + +// BlockTradeClient is the client API for BlockTrade service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type BlockTradeClient interface { + // GetBotStockBlockTrade 大宗交易股列表查询 + GetBotStockBlockTrade(ctx context.Context, in *GetBotStockBlockTradeRequest, opts ...grpc.CallOption) (*GetBotStockBlockTradeReply, error) + // ShareBlockPlaceOrder 大宗交易股下单 + ShareBlockPlaceOrder(ctx context.Context, in *OrderBlockRequest, opts ...grpc.CallOption) (*OrderBlockReply, error) + // ShareBlockUpdateOrder 大宗交易股设置止盈止损 + ShareBlockUpdateOrder(ctx context.Context, in *UpdateBlockOrderRequest, opts ...grpc.CallOption) (*OrderBlockReply, error) + // ShareBlockPosition 大宗交易股平仓 + ShareBlockPosition(ctx context.Context, in *CancelBlockOrderRequest, opts ...grpc.CallOption) (*OrderBlockReply, error) + // ShareBlockCancel 大宗交易股撤单 + ShareBlockCancel(ctx context.Context, in *CancelBlockOrderRequest, opts ...grpc.CallOption) (*OrderBlockReply, error) +} + +type blockTradeClient struct { + cc grpc.ClientConnInterface +} + +func NewBlockTradeClient(cc grpc.ClientConnInterface) BlockTradeClient { + return &blockTradeClient{cc} +} + +func (c *blockTradeClient) GetBotStockBlockTrade(ctx context.Context, in *GetBotStockBlockTradeRequest, opts ...grpc.CallOption) (*GetBotStockBlockTradeReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetBotStockBlockTradeReply) + err := c.cc.Invoke(ctx, BlockTrade_GetBotStockBlockTrade_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *blockTradeClient) ShareBlockPlaceOrder(ctx context.Context, in *OrderBlockRequest, opts ...grpc.CallOption) (*OrderBlockReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(OrderBlockReply) + err := c.cc.Invoke(ctx, BlockTrade_ShareBlockPlaceOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *blockTradeClient) ShareBlockUpdateOrder(ctx context.Context, in *UpdateBlockOrderRequest, opts ...grpc.CallOption) (*OrderBlockReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(OrderBlockReply) + err := c.cc.Invoke(ctx, BlockTrade_ShareBlockUpdateOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *blockTradeClient) ShareBlockPosition(ctx context.Context, in *CancelBlockOrderRequest, opts ...grpc.CallOption) (*OrderBlockReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(OrderBlockReply) + err := c.cc.Invoke(ctx, BlockTrade_ShareBlockPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *blockTradeClient) ShareBlockCancel(ctx context.Context, in *CancelBlockOrderRequest, opts ...grpc.CallOption) (*OrderBlockReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(OrderBlockReply) + err := c.cc.Invoke(ctx, BlockTrade_ShareBlockCancel_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// BlockTradeServer is the server API for BlockTrade service. +// All implementations must embed UnimplementedBlockTradeServer +// for forward compatibility +type BlockTradeServer interface { + // GetBotStockBlockTrade 大宗交易股列表查询 + GetBotStockBlockTrade(context.Context, *GetBotStockBlockTradeRequest) (*GetBotStockBlockTradeReply, error) + // ShareBlockPlaceOrder 大宗交易股下单 + ShareBlockPlaceOrder(context.Context, *OrderBlockRequest) (*OrderBlockReply, error) + // ShareBlockUpdateOrder 大宗交易股设置止盈止损 + ShareBlockUpdateOrder(context.Context, *UpdateBlockOrderRequest) (*OrderBlockReply, error) + // ShareBlockPosition 大宗交易股平仓 + ShareBlockPosition(context.Context, *CancelBlockOrderRequest) (*OrderBlockReply, error) + // ShareBlockCancel 大宗交易股撤单 + ShareBlockCancel(context.Context, *CancelBlockOrderRequest) (*OrderBlockReply, error) + mustEmbedUnimplementedBlockTradeServer() +} + +// UnimplementedBlockTradeServer must be embedded to have forward compatible implementations. +type UnimplementedBlockTradeServer struct { +} + +func (UnimplementedBlockTradeServer) GetBotStockBlockTrade(context.Context, *GetBotStockBlockTradeRequest) (*GetBotStockBlockTradeReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBotStockBlockTrade not implemented") +} +func (UnimplementedBlockTradeServer) ShareBlockPlaceOrder(context.Context, *OrderBlockRequest) (*OrderBlockReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareBlockPlaceOrder not implemented") +} +func (UnimplementedBlockTradeServer) ShareBlockUpdateOrder(context.Context, *UpdateBlockOrderRequest) (*OrderBlockReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareBlockUpdateOrder not implemented") +} +func (UnimplementedBlockTradeServer) ShareBlockPosition(context.Context, *CancelBlockOrderRequest) (*OrderBlockReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareBlockPosition not implemented") +} +func (UnimplementedBlockTradeServer) ShareBlockCancel(context.Context, *CancelBlockOrderRequest) (*OrderBlockReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareBlockCancel not implemented") +} +func (UnimplementedBlockTradeServer) mustEmbedUnimplementedBlockTradeServer() {} + +// UnsafeBlockTradeServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to BlockTradeServer will +// result in compilation errors. +type UnsafeBlockTradeServer interface { + mustEmbedUnimplementedBlockTradeServer() +} + +func RegisterBlockTradeServer(s grpc.ServiceRegistrar, srv BlockTradeServer) { + s.RegisterService(&BlockTrade_ServiceDesc, srv) +} + +func _BlockTrade_GetBotStockBlockTrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetBotStockBlockTradeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BlockTradeServer).GetBotStockBlockTrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: BlockTrade_GetBotStockBlockTrade_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BlockTradeServer).GetBotStockBlockTrade(ctx, req.(*GetBotStockBlockTradeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _BlockTrade_ShareBlockPlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(OrderBlockRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BlockTradeServer).ShareBlockPlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: BlockTrade_ShareBlockPlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BlockTradeServer).ShareBlockPlaceOrder(ctx, req.(*OrderBlockRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _BlockTrade_ShareBlockUpdateOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateBlockOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BlockTradeServer).ShareBlockUpdateOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: BlockTrade_ShareBlockUpdateOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BlockTradeServer).ShareBlockUpdateOrder(ctx, req.(*UpdateBlockOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _BlockTrade_ShareBlockPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelBlockOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BlockTradeServer).ShareBlockPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: BlockTrade_ShareBlockPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BlockTradeServer).ShareBlockPosition(ctx, req.(*CancelBlockOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _BlockTrade_ShareBlockCancel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelBlockOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BlockTradeServer).ShareBlockCancel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: BlockTrade_ShareBlockCancel_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BlockTradeServer).ShareBlockCancel(ctx, req.(*CancelBlockOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// BlockTrade_ServiceDesc is the grpc.ServiceDesc for BlockTrade service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var BlockTrade_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "matchmaking.v1.BlockTrade", + HandlerType: (*BlockTradeServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetBotStockBlockTrade", + Handler: _BlockTrade_GetBotStockBlockTrade_Handler, + }, + { + MethodName: "ShareBlockPlaceOrder", + Handler: _BlockTrade_ShareBlockPlaceOrder_Handler, + }, + { + MethodName: "ShareBlockUpdateOrder", + Handler: _BlockTrade_ShareBlockUpdateOrder_Handler, + }, + { + MethodName: "ShareBlockPosition", + Handler: _BlockTrade_ShareBlockPosition_Handler, + }, + { + MethodName: "ShareBlockCancel", + Handler: _BlockTrade_ShareBlockCancel_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "matchmaking/v1/block/blockOrder.proto", +} diff --git a/api/matchmaking/v1/block/blockOrder_http.pb.go b/api/matchmaking/v1/block/blockOrder_http.pb.go new file mode 100644 index 0000000..dabb42b --- /dev/null +++ b/api/matchmaking/v1/block/blockOrder_http.pb.go @@ -0,0 +1,239 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.3 +// - protoc v5.27.1 +// source: matchmaking/v1/block/blockOrder.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationBlockTradeGetBotStockBlockTrade = "/matchmaking.v1.BlockTrade/GetBotStockBlockTrade" +const OperationBlockTradeShareBlockCancel = "/matchmaking.v1.BlockTrade/ShareBlockCancel" +const OperationBlockTradeShareBlockPlaceOrder = "/matchmaking.v1.BlockTrade/ShareBlockPlaceOrder" +const OperationBlockTradeShareBlockPosition = "/matchmaking.v1.BlockTrade/ShareBlockPosition" +const OperationBlockTradeShareBlockUpdateOrder = "/matchmaking.v1.BlockTrade/ShareBlockUpdateOrder" + +type BlockTradeHTTPServer interface { + // GetBotStockBlockTrade GetBotStockBlockTrade 大宗交易股列表查询 + GetBotStockBlockTrade(context.Context, *GetBotStockBlockTradeRequest) (*GetBotStockBlockTradeReply, error) + // ShareBlockCancel ShareBlockCancel 大宗交易股撤单 + ShareBlockCancel(context.Context, *CancelBlockOrderRequest) (*OrderBlockReply, error) + // ShareBlockPlaceOrder ShareBlockPlaceOrder 大宗交易股下单 + ShareBlockPlaceOrder(context.Context, *OrderBlockRequest) (*OrderBlockReply, error) + // ShareBlockPosition ShareBlockPosition 大宗交易股平仓 + ShareBlockPosition(context.Context, *CancelBlockOrderRequest) (*OrderBlockReply, error) + // ShareBlockUpdateOrder ShareBlockUpdateOrder 大宗交易股设置止盈止损 + ShareBlockUpdateOrder(context.Context, *UpdateBlockOrderRequest) (*OrderBlockReply, error) +} + +func RegisterBlockTradeHTTPServer(s *http.Server, srv BlockTradeHTTPServer) { + r := s.Route("/") + r.POST("/order_shareblock/share_list", _BlockTrade_GetBotStockBlockTrade0_HTTP_Handler(srv)) + r.POST("/order_shareblock/share_place_order", _BlockTrade_ShareBlockPlaceOrder0_HTTP_Handler(srv)) + r.POST("/order_shareblock/share_update_order", _BlockTrade_ShareBlockUpdateOrder0_HTTP_Handler(srv)) + r.POST("/order_shareblock/share_position", _BlockTrade_ShareBlockPosition0_HTTP_Handler(srv)) + r.POST("/order_shareblock/share_cancel", _BlockTrade_ShareBlockCancel0_HTTP_Handler(srv)) +} + +func _BlockTrade_GetBotStockBlockTrade0_HTTP_Handler(srv BlockTradeHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetBotStockBlockTradeRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationBlockTradeGetBotStockBlockTrade) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.GetBotStockBlockTrade(ctx, req.(*GetBotStockBlockTradeRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetBotStockBlockTradeReply) + return ctx.Result(200, reply) + } +} + +func _BlockTrade_ShareBlockPlaceOrder0_HTTP_Handler(srv BlockTradeHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in OrderBlockRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationBlockTradeShareBlockPlaceOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareBlockPlaceOrder(ctx, req.(*OrderBlockRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*OrderBlockReply) + return ctx.Result(200, reply) + } +} + +func _BlockTrade_ShareBlockUpdateOrder0_HTTP_Handler(srv BlockTradeHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in UpdateBlockOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationBlockTradeShareBlockUpdateOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareBlockUpdateOrder(ctx, req.(*UpdateBlockOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*OrderBlockReply) + return ctx.Result(200, reply) + } +} + +func _BlockTrade_ShareBlockPosition0_HTTP_Handler(srv BlockTradeHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelBlockOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationBlockTradeShareBlockPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareBlockPosition(ctx, req.(*CancelBlockOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*OrderBlockReply) + return ctx.Result(200, reply) + } +} + +func _BlockTrade_ShareBlockCancel0_HTTP_Handler(srv BlockTradeHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelBlockOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationBlockTradeShareBlockCancel) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareBlockCancel(ctx, req.(*CancelBlockOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*OrderBlockReply) + return ctx.Result(200, reply) + } +} + +type BlockTradeHTTPClient interface { + GetBotStockBlockTrade(ctx context.Context, req *GetBotStockBlockTradeRequest, opts ...http.CallOption) (rsp *GetBotStockBlockTradeReply, err error) + ShareBlockCancel(ctx context.Context, req *CancelBlockOrderRequest, opts ...http.CallOption) (rsp *OrderBlockReply, err error) + ShareBlockPlaceOrder(ctx context.Context, req *OrderBlockRequest, opts ...http.CallOption) (rsp *OrderBlockReply, err error) + ShareBlockPosition(ctx context.Context, req *CancelBlockOrderRequest, opts ...http.CallOption) (rsp *OrderBlockReply, err error) + ShareBlockUpdateOrder(ctx context.Context, req *UpdateBlockOrderRequest, opts ...http.CallOption) (rsp *OrderBlockReply, err error) +} + +type BlockTradeHTTPClientImpl struct { + cc *http.Client +} + +func NewBlockTradeHTTPClient(client *http.Client) BlockTradeHTTPClient { + return &BlockTradeHTTPClientImpl{client} +} + +func (c *BlockTradeHTTPClientImpl) GetBotStockBlockTrade(ctx context.Context, in *GetBotStockBlockTradeRequest, opts ...http.CallOption) (*GetBotStockBlockTradeReply, error) { + var out GetBotStockBlockTradeReply + pattern := "/order_shareblock/share_list" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationBlockTradeGetBotStockBlockTrade)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *BlockTradeHTTPClientImpl) ShareBlockCancel(ctx context.Context, in *CancelBlockOrderRequest, opts ...http.CallOption) (*OrderBlockReply, error) { + var out OrderBlockReply + pattern := "/order_shareblock/share_cancel" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationBlockTradeShareBlockCancel)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *BlockTradeHTTPClientImpl) ShareBlockPlaceOrder(ctx context.Context, in *OrderBlockRequest, opts ...http.CallOption) (*OrderBlockReply, error) { + var out OrderBlockReply + pattern := "/order_shareblock/share_place_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationBlockTradeShareBlockPlaceOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *BlockTradeHTTPClientImpl) ShareBlockPosition(ctx context.Context, in *CancelBlockOrderRequest, opts ...http.CallOption) (*OrderBlockReply, error) { + var out OrderBlockReply + pattern := "/order_shareblock/share_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationBlockTradeShareBlockPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *BlockTradeHTTPClientImpl) ShareBlockUpdateOrder(ctx context.Context, in *UpdateBlockOrderRequest, opts ...http.CallOption) (*OrderBlockReply, error) { + var out OrderBlockReply + pattern := "/order_shareblock/share_update_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationBlockTradeShareBlockUpdateOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/api/matchmaking/v1/error/error_reason.pb.go b/api/matchmaking/v1/error/error_reason.pb.go new file mode 100644 index 0000000..2f905d9 --- /dev/null +++ b/api/matchmaking/v1/error/error_reason.pb.go @@ -0,0 +1,132 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/error/error_reason.proto + +package v1 + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type ErrorReason int32 + +const ( + ErrorReason_GREETER_UNSPECIFIED ErrorReason = 0 + ErrorReason_USER_NOT_FOUND ErrorReason = 1 +) + +// Enum value maps for ErrorReason. +var ( + ErrorReason_name = map[int32]string{ + 0: "GREETER_UNSPECIFIED", + 1: "USER_NOT_FOUND", + } + ErrorReason_value = map[string]int32{ + "GREETER_UNSPECIFIED": 0, + "USER_NOT_FOUND": 1, + } +) + +func (x ErrorReason) Enum() *ErrorReason { + p := new(ErrorReason) + *p = x + return p +} + +func (x ErrorReason) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (ErrorReason) Descriptor() protoreflect.EnumDescriptor { + return file_matchmaking_v1_error_error_reason_proto_enumTypes[0].Descriptor() +} + +func (ErrorReason) Type() protoreflect.EnumType { + return &file_matchmaking_v1_error_error_reason_proto_enumTypes[0] +} + +func (x ErrorReason) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use ErrorReason.Descriptor instead. +func (ErrorReason) EnumDescriptor() ([]byte, []int) { + return file_matchmaking_v1_error_error_reason_proto_rawDescGZIP(), []int{0} +} + +var File_matchmaking_v1_error_error_reason_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_error_error_reason_proto_rawDesc = []byte{ + 0x0a, 0x27, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x2f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x72, 0x65, 0x61, + 0x73, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2a, 0x3a, 0x0a, 0x0b, 0x45, 0x72, 0x72, + 0x6f, 0x72, 0x52, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x17, 0x0a, 0x13, 0x47, 0x52, 0x45, 0x45, + 0x54, 0x45, 0x52, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, + 0x00, 0x12, 0x12, 0x0a, 0x0e, 0x55, 0x53, 0x45, 0x52, 0x5f, 0x4e, 0x4f, 0x54, 0x5f, 0x46, 0x4f, + 0x55, 0x4e, 0x44, 0x10, 0x01, 0x42, 0x2a, 0x5a, 0x28, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, + 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2f, 0x61, 0x70, 0x69, 0x2f, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x76, + 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_error_error_reason_proto_rawDescOnce sync.Once + file_matchmaking_v1_error_error_reason_proto_rawDescData = file_matchmaking_v1_error_error_reason_proto_rawDesc +) + +func file_matchmaking_v1_error_error_reason_proto_rawDescGZIP() []byte { + file_matchmaking_v1_error_error_reason_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_error_error_reason_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_error_error_reason_proto_rawDescData) + }) + return file_matchmaking_v1_error_error_reason_proto_rawDescData +} + +var file_matchmaking_v1_error_error_reason_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_matchmaking_v1_error_error_reason_proto_goTypes = []any{ + (ErrorReason)(0), // 0: matchmaking.v1.ErrorReason +} +var file_matchmaking_v1_error_error_reason_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_error_error_reason_proto_init() } +func file_matchmaking_v1_error_error_reason_proto_init() { + if File_matchmaking_v1_error_error_reason_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_error_error_reason_proto_rawDesc, + NumEnums: 1, + NumMessages: 0, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_matchmaking_v1_error_error_reason_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_error_error_reason_proto_depIdxs, + EnumInfos: file_matchmaking_v1_error_error_reason_proto_enumTypes, + }.Build() + File_matchmaking_v1_error_error_reason_proto = out.File + file_matchmaking_v1_error_error_reason_proto_rawDesc = nil + file_matchmaking_v1_error_error_reason_proto_goTypes = nil + file_matchmaking_v1_error_error_reason_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/error/error_reason.proto b/api/matchmaking/v1/error/error_reason.proto new file mode 100644 index 0000000..1cb960a --- /dev/null +++ b/api/matchmaking/v1/error/error_reason.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package matchmaking.v1; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +enum ErrorReason { + GREETER_UNSPECIFIED = 0; + USER_NOT_FOUND = 1; +} diff --git a/api/matchmaking/v1/forex/forex.pb.go b/api/matchmaking/v1/forex/forex.pb.go new file mode 100644 index 0000000..288e0fd --- /dev/null +++ b/api/matchmaking/v1/forex/forex.pb.go @@ -0,0 +1,1383 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/forex/forex.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GetBotForexTradeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status int64 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` // 状态码 + PageSize int64 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,3,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + State int64 `protobuf:"varint,4,opt,name=state,proto3" json:"state,omitempty"` // 订单类型 +} + +func (x *GetBotForexTradeRequest) Reset() { + *x = GetBotForexTradeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotForexTradeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotForexTradeRequest) ProtoMessage() {} + +func (x *GetBotForexTradeRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotForexTradeRequest.ProtoReflect.Descriptor instead. +func (*GetBotForexTradeRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_forex_forex_proto_rawDescGZIP(), []int{0} +} + +func (x *GetBotForexTradeRequest) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *GetBotForexTradeRequest) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *GetBotForexTradeRequest) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *GetBotForexTradeRequest) GetState() int64 { + if x != nil { + return x.State + } + return 0 +} + +type GetBotForexTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *BotForexTradeData `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *GetBotForexTradeReply) Reset() { + *x = GetBotForexTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotForexTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotForexTradeReply) ProtoMessage() {} + +func (x *GetBotForexTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotForexTradeReply.ProtoReflect.Descriptor instead. +func (*GetBotForexTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_forex_forex_proto_rawDescGZIP(), []int{1} +} + +func (x *GetBotForexTradeReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *GetBotForexTradeReply) GetData() *BotForexTradeData { + if x != nil { + return x.Data + } + return nil +} + +func (x *GetBotForexTradeReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type BotForexTradeData struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PageSize int64 `protobuf:"varint,1,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,2,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + Data []*BotForexTrade `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty"` // 返回结果 + TotalCount int64 `protobuf:"varint,4,opt,name=totalCount,proto3" json:"totalCount,omitempty"` // 总数据 +} + +func (x *BotForexTradeData) Reset() { + *x = BotForexTradeData{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotForexTradeData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotForexTradeData) ProtoMessage() {} + +func (x *BotForexTradeData) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotForexTradeData.ProtoReflect.Descriptor instead. +func (*BotForexTradeData) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_forex_forex_proto_rawDescGZIP(), []int{2} +} + +func (x *BotForexTradeData) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *BotForexTradeData) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *BotForexTradeData) GetData() []*BotForexTrade { + if x != nil { + return x.Data + } + return nil +} + +func (x *BotForexTradeData) GetTotalCount() int64 { + if x != nil { + return x.TotalCount + } + return 0 +} + +type BotForexTrade struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID + ForexId string `protobuf:"bytes,2,opt,name=forexId,proto3" json:"forexId,omitempty"` // 外汇ID + TradeType int64 `protobuf:"varint,3,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型 + DealType int64 `protobuf:"varint,4,opt,name=dealType,proto3" json:"dealType,omitempty"` // 交易方式 + LimitPrice string `protobuf:"bytes,5,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,6,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + DealPrice string `protobuf:"bytes,7,opt,name=dealPrice,proto3" json:"dealPrice,omitempty"` // 开仓价 + ClosingPrice string `protobuf:"bytes,8,opt,name=closingPrice,proto3" json:"closingPrice,omitempty"` // 平仓价 + OrderNumber string `protobuf:"bytes,9,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损状态 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + ServiceCost string `protobuf:"bytes,13,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 开仓手续费 + EarnestMoney string `protobuf:"bytes,14,opt,name=earnestMoney,proto3" json:"earnestMoney,omitempty"` // 保证金 + OrderMoney string `protobuf:"bytes,15,opt,name=orderMoney,proto3" json:"orderMoney,omitempty"` // 订单总额 + Status int64 `protobuf:"varint,16,opt,name=status,proto3" json:"status,omitempty"` // 订单状态 + CreateTime *timestamppb.Timestamp `protobuf:"bytes,17,opt,name=createTime,proto3" json:"createTime,omitempty"` // 订单创建时间 + UpdateTime *timestamppb.Timestamp `protobuf:"bytes,18,opt,name=updateTime,proto3" json:"updateTime,omitempty"` // 订单更新时间 + OpenTime *timestamppb.Timestamp `protobuf:"bytes,19,opt,name=openTime,proto3" json:"openTime,omitempty"` // 订单开仓时间 + ClosingTime *timestamppb.Timestamp `protobuf:"bytes,20,opt,name=closingTime,proto3" json:"closingTime,omitempty"` // 订单平仓时间 + ClosingCost string `protobuf:"bytes,21,opt,name=closingCost,proto3" json:"closingCost,omitempty"` // 平仓手续费 + FaceValue string `protobuf:"bytes,22,opt,name=faceValue,proto3" json:"faceValue,omitempty"` // 面值 + OvernightCost string `protobuf:"bytes,23,opt,name=overnightCost,proto3" json:"overnightCost,omitempty"` // 过夜手续费 + PryNum string `protobuf:"bytes,24,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆值 + KeepDecimal string `protobuf:"bytes,25,opt,name=keepDecimal,proto3" json:"keepDecimal,omitempty"` // 保留小数位 + SecondTime string `protobuf:"bytes,26,opt,name=secondTime,proto3" json:"secondTime,omitempty"` // 秒外汇时间 + State int64 `protobuf:"varint,27,opt,name=state,proto3" json:"state,omitempty"` // 订单类型 +} + +func (x *BotForexTrade) Reset() { + *x = BotForexTrade{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotForexTrade) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotForexTrade) ProtoMessage() {} + +func (x *BotForexTrade) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotForexTrade.ProtoReflect.Descriptor instead. +func (*BotForexTrade) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_forex_forex_proto_rawDescGZIP(), []int{3} +} + +func (x *BotForexTrade) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *BotForexTrade) GetForexId() string { + if x != nil { + return x.ForexId + } + return "" +} + +func (x *BotForexTrade) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *BotForexTrade) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *BotForexTrade) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *BotForexTrade) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *BotForexTrade) GetDealPrice() string { + if x != nil { + return x.DealPrice + } + return "" +} + +func (x *BotForexTrade) GetClosingPrice() string { + if x != nil { + return x.ClosingPrice + } + return "" +} + +func (x *BotForexTrade) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *BotForexTrade) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *BotForexTrade) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *BotForexTrade) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *BotForexTrade) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *BotForexTrade) GetEarnestMoney() string { + if x != nil { + return x.EarnestMoney + } + return "" +} + +func (x *BotForexTrade) GetOrderMoney() string { + if x != nil { + return x.OrderMoney + } + return "" +} + +func (x *BotForexTrade) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *BotForexTrade) GetCreateTime() *timestamppb.Timestamp { + if x != nil { + return x.CreateTime + } + return nil +} + +func (x *BotForexTrade) GetUpdateTime() *timestamppb.Timestamp { + if x != nil { + return x.UpdateTime + } + return nil +} + +func (x *BotForexTrade) GetOpenTime() *timestamppb.Timestamp { + if x != nil { + return x.OpenTime + } + return nil +} + +func (x *BotForexTrade) GetClosingTime() *timestamppb.Timestamp { + if x != nil { + return x.ClosingTime + } + return nil +} + +func (x *BotForexTrade) GetClosingCost() string { + if x != nil { + return x.ClosingCost + } + return "" +} + +func (x *BotForexTrade) GetFaceValue() string { + if x != nil { + return x.FaceValue + } + return "" +} + +func (x *BotForexTrade) GetOvernightCost() string { + if x != nil { + return x.OvernightCost + } + return "" +} + +func (x *BotForexTrade) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *BotForexTrade) GetKeepDecimal() string { + if x != nil { + return x.KeepDecimal + } + return "" +} + +func (x *BotForexTrade) GetSecondTime() string { + if x != nil { + return x.SecondTime + } + return "" +} + +func (x *BotForexTrade) GetState() int64 { + if x != nil { + return x.State + } + return 0 +} + +type ForexRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ForexId string `protobuf:"bytes,1,opt,name=forexId,proto3" json:"forexId,omitempty"` // 交易对 + TradeType int64 `protobuf:"varint,2,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型:1买入,2卖出 + DealType int64 `protobuf:"varint,3,opt,name=dealType,proto3" json:"dealType,omitempty"` // 委托方式:1限价,2市价 + LimitPrice string `protobuf:"bytes,4,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,5,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + OrderAmount string `protobuf:"bytes,6,opt,name=orderAmount,proto3" json:"orderAmount,omitempty"` // 订单金额 + OrderNumber string `protobuf:"bytes,7,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + EarnestMoney string `protobuf:"bytes,8,opt,name=earnestMoney,proto3" json:"earnestMoney,omitempty"` // 保证金 + ServiceCost string `protobuf:"bytes,9,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 手续费 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止损止盈设置:0无设置,1止损止盈 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + PryNum string `protobuf:"bytes,13,opt,name=pryNum,proto3" json:"pryNum,omitempty"` //杠杆 + Time int64 `protobuf:"varint,14,opt,name=time,proto3" json:"time,omitempty"` // 秒外汇时间 +} + +func (x *ForexRequest) Reset() { + *x = ForexRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ForexRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ForexRequest) ProtoMessage() {} + +func (x *ForexRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ForexRequest.ProtoReflect.Descriptor instead. +func (*ForexRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_forex_forex_proto_rawDescGZIP(), []int{4} +} + +func (x *ForexRequest) GetForexId() string { + if x != nil { + return x.ForexId + } + return "" +} + +func (x *ForexRequest) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *ForexRequest) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *ForexRequest) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *ForexRequest) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *ForexRequest) GetOrderAmount() string { + if x != nil { + return x.OrderAmount + } + return "" +} + +func (x *ForexRequest) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *ForexRequest) GetEarnestMoney() string { + if x != nil { + return x.EarnestMoney + } + return "" +} + +func (x *ForexRequest) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *ForexRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *ForexRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *ForexRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *ForexRequest) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *ForexRequest) GetTime() int64 { + if x != nil { + return x.Time + } + return 0 +} + +type ForexReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *ForexResult `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *ForexReply) Reset() { + *x = ForexReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ForexReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ForexReply) ProtoMessage() {} + +func (x *ForexReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ForexReply.ProtoReflect.Descriptor instead. +func (*ForexReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_forex_forex_proto_rawDescGZIP(), []int{5} +} + +func (x *ForexReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *ForexReply) GetData() *ForexResult { + if x != nil { + return x.Data + } + return nil +} + +func (x *ForexReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type ForexResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id +} + +func (x *ForexResult) Reset() { + *x = ForexResult{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ForexResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ForexResult) ProtoMessage() {} + +func (x *ForexResult) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ForexResult.ProtoReflect.Descriptor instead. +func (*ForexResult) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_forex_forex_proto_rawDescGZIP(), []int{6} +} + +func (x *ForexResult) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type UpdateForexRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id + StopType int64 `protobuf:"varint,2,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,3,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,4,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 +} + +func (x *UpdateForexRequest) Reset() { + *x = UpdateForexRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateForexRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateForexRequest) ProtoMessage() {} + +func (x *UpdateForexRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateForexRequest.ProtoReflect.Descriptor instead. +func (*UpdateForexRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_forex_forex_proto_rawDescGZIP(), []int{7} +} + +func (x *UpdateForexRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *UpdateForexRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *UpdateForexRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *UpdateForexRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +type CancelForexRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID +} + +func (x *CancelForexRequest) Reset() { + *x = CancelForexRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CancelForexRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CancelForexRequest) ProtoMessage() {} + +func (x *CancelForexRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CancelForexRequest.ProtoReflect.Descriptor instead. +func (*CancelForexRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_forex_forex_proto_rawDescGZIP(), []int{8} +} + +func (x *CancelForexRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type AllForexRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *AllForexRequest) Reset() { + *x = AllForexRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllForexRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllForexRequest) ProtoMessage() {} + +func (x *AllForexRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllForexRequest.ProtoReflect.Descriptor instead. +func (*AllForexRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_forex_forex_proto_rawDescGZIP(), []int{9} +} + +type AllForexReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *AllForexReply) Reset() { + *x = AllForexReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllForexReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllForexReply) ProtoMessage() {} + +func (x *AllForexReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_forex_forex_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllForexReply.ProtoReflect.Descriptor instead. +func (*AllForexReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_forex_forex_proto_rawDescGZIP(), []int{10} +} + +func (x *AllForexReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *AllForexReply) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +func (x *AllForexReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_matchmaking_v1_forex_forex_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_forex_forex_proto_rawDesc = []byte{ + 0x0a, 0x20, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x66, 0x6f, 0x72, 0x65, 0x78, 0x2f, 0x66, 0x6f, 0x72, 0x65, 0x78, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, + 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x22, 0x81, 0x01, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x46, 0x6f, 0x72, 0x65, + 0x78, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, + 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, + 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, + 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, + 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0x7c, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x46, + 0x6f, 0x72, 0x65, 0x78, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, + 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, + 0x64, 0x65, 0x12, 0x35, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x21, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, + 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x46, 0x6f, 0x72, 0x65, 0x78, 0x54, 0x72, 0x61, 0x64, 0x65, 0x44, + 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x22, 0xa0, 0x01, 0x0a, 0x11, 0x42, 0x6f, 0x74, 0x46, 0x6f, 0x72, 0x65, 0x78, + 0x54, 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, 0x61, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, + 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x12, 0x31, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x03, 0x28, + 0x0b, 0x32, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x46, 0x6f, 0x72, 0x65, 0x78, 0x54, 0x72, 0x61, 0x64, 0x65, + 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x1e, 0x0a, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, + 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, + 0x6c, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0xcb, 0x07, 0x0a, 0x0d, 0x42, 0x6f, 0x74, 0x46, 0x6f, + 0x72, 0x65, 0x78, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x66, 0x6f, 0x72, 0x65, 0x78, 0x49, 0x64, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x66, 0x6f, 0x72, 0x65, 0x78, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, + 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, + 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, + 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, + 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, + 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x65, 0x61, 0x6c, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x64, 0x65, 0x61, + 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, + 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6c, + 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, + 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, + 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, + 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, + 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0c, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, + 0x74, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x43, 0x6f, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x0c, 0x65, 0x61, 0x72, 0x6e, 0x65, 0x73, 0x74, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x61, 0x72, 0x6e, + 0x65, 0x73, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, + 0x75, 0x73, 0x18, 0x10, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x12, 0x3a, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x11, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, + 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x3a, 0x0a, 0x0a, + 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x12, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x75, 0x70, + 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x36, 0x0a, 0x08, 0x6f, 0x70, 0x65, 0x6e, + 0x54, 0x69, 0x6d, 0x65, 0x18, 0x13, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, + 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, + 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x08, 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, + 0x12, 0x3c, 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x18, + 0x14, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, + 0x70, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, + 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x15, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, + 0x12, 0x1c, 0x0a, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x16, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x24, + 0x0a, 0x0d, 0x6f, 0x76, 0x65, 0x72, 0x6e, 0x69, 0x67, 0x68, 0x74, 0x43, 0x6f, 0x73, 0x74, 0x18, + 0x17, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x6f, 0x76, 0x65, 0x72, 0x6e, 0x69, 0x67, 0x68, 0x74, + 0x43, 0x6f, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x18, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x12, 0x20, 0x0a, 0x0b, + 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x18, 0x19, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x12, 0x1e, + 0x0a, 0x0a, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x1a, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x14, + 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x1b, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x73, + 0x74, 0x61, 0x74, 0x65, 0x22, 0xc0, 0x03, 0x0a, 0x0c, 0x46, 0x6f, 0x72, 0x65, 0x78, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x66, 0x6f, 0x72, 0x65, 0x78, 0x49, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x66, 0x6f, 0x72, 0x65, 0x78, 0x49, 0x64, 0x12, + 0x1c, 0x0a, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, + 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, + 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, + 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, + 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, + 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x20, 0x0a, + 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x07, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, + 0x22, 0x0a, 0x0c, 0x65, 0x61, 0x72, 0x6e, 0x65, 0x73, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, + 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x61, 0x72, 0x6e, 0x65, 0x73, 0x74, 0x4d, 0x6f, + 0x6e, 0x65, 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, + 0x73, 0x74, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, + 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, + 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, + 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, + 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, + 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x70, + 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, 0x79, + 0x4e, 0x75, 0x6d, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x0e, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x22, 0x6b, 0x0a, 0x0a, 0x46, 0x6f, 0x72, 0x65, 0x78, + 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x2f, 0x0a, 0x04, 0x64, 0x61, 0x74, + 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, + 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x6f, 0x72, 0x65, 0x78, 0x52, 0x65, + 0x73, 0x75, 0x6c, 0x74, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x22, 0x27, 0x0a, 0x0b, 0x46, 0x6f, 0x72, 0x65, 0x78, 0x52, 0x65, 0x73, + 0x75, 0x6c, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x22, 0x94, 0x01, + 0x0a, 0x12, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x46, 0x6f, 0x72, 0x65, 0x78, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, + 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, + 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x22, 0x2e, 0x0a, 0x12, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x46, 0x6f, + 0x72, 0x65, 0x78, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x49, 0x64, 0x22, 0x11, 0x0a, 0x0f, 0x41, 0x6c, 0x6c, 0x46, 0x6f, 0x72, 0x65, 0x78, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x51, 0x0a, 0x0d, 0x41, 0x6c, 0x6c, 0x46, 0x6f, + 0x72, 0x65, 0x78, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x12, 0x0a, 0x04, + 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, + 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0xfc, 0x05, 0x0a, 0x05, 0x46, + 0x6f, 0x72, 0x65, 0x78, 0x12, 0x86, 0x01, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x46, + 0x6f, 0x72, 0x65, 0x78, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x27, 0x2e, 0x6d, 0x61, 0x74, 0x63, + 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6f, + 0x74, 0x46, 0x6f, 0x72, 0x65, 0x78, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x46, 0x6f, 0x72, 0x65, 0x78, 0x54, + 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x22, 0x82, 0xd3, 0xe4, 0x93, 0x02, + 0x1c, 0x3a, 0x01, 0x2a, 0x22, 0x17, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x66, 0x6f, 0x72, + 0x65, 0x78, 0x2f, 0x66, 0x6f, 0x72, 0x65, 0x78, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x12, 0x76, 0x0a, + 0x0f, 0x46, 0x6f, 0x72, 0x65, 0x78, 0x50, 0x6c, 0x61, 0x63, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x12, 0x1c, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, + 0x31, 0x2e, 0x46, 0x6f, 0x72, 0x65, 0x78, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, + 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x46, 0x6f, 0x72, 0x65, 0x78, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x29, 0x82, 0xd3, 0xe4, 0x93, + 0x02, 0x23, 0x3a, 0x01, 0x2a, 0x22, 0x1e, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x66, 0x6f, + 0x72, 0x65, 0x78, 0x2f, 0x66, 0x6f, 0x72, 0x65, 0x78, 0x5f, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x5f, + 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x83, 0x01, 0x0a, 0x15, 0x46, 0x6f, 0x72, 0x65, 0x78, 0x55, + 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x6c, 0x61, 0x63, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, + 0x22, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, + 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x46, 0x6f, 0x72, 0x65, 0x78, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, + 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x6f, 0x72, 0x65, 0x78, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, + 0x2a, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x24, 0x3a, 0x01, 0x2a, 0x22, 0x1f, 0x2f, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x5f, 0x66, 0x6f, 0x72, 0x65, 0x78, 0x2f, 0x66, 0x6f, 0x72, 0x65, 0x78, 0x5f, 0x75, + 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x77, 0x0a, 0x0d, 0x46, + 0x6f, 0x72, 0x65, 0x78, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x22, 0x2e, 0x6d, + 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x61, + 0x6e, 0x63, 0x65, 0x6c, 0x46, 0x6f, 0x72, 0x65, 0x78, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x1a, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, + 0x31, 0x2e, 0x46, 0x6f, 0x72, 0x65, 0x78, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x26, 0x82, 0xd3, + 0xe4, 0x93, 0x02, 0x20, 0x3a, 0x01, 0x2a, 0x22, 0x1b, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, + 0x66, 0x6f, 0x72, 0x65, 0x78, 0x2f, 0x66, 0x6f, 0x72, 0x65, 0x78, 0x5f, 0x70, 0x6f, 0x73, 0x69, + 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x7e, 0x0a, 0x10, 0x46, 0x6f, 0x72, 0x65, 0x78, 0x41, 0x6c, 0x6c, + 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1f, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x46, 0x6f, 0x72, + 0x65, 0x78, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, + 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x46, 0x6f, + 0x72, 0x65, 0x78, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2a, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x24, + 0x3a, 0x01, 0x2a, 0x22, 0x1f, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x66, 0x6f, 0x72, 0x65, + 0x78, 0x2f, 0x66, 0x6f, 0x72, 0x65, 0x78, 0x5f, 0x61, 0x6c, 0x6c, 0x5f, 0x70, 0x6f, 0x73, 0x69, + 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x73, 0x0a, 0x0b, 0x46, 0x6f, 0x72, 0x65, 0x78, 0x43, 0x61, 0x6e, + 0x63, 0x65, 0x6c, 0x12, 0x22, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, + 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x46, 0x6f, 0x72, 0x65, 0x78, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, + 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x6f, 0x72, 0x65, 0x78, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x24, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1e, 0x3a, 0x01, 0x2a, 0x22, 0x19, + 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x66, 0x6f, 0x72, 0x65, 0x78, 0x2f, 0x66, 0x6f, 0x72, + 0x65, 0x78, 0x5f, 0x63, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x42, 0x2a, 0x5a, 0x28, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2f, + 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, + 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_forex_forex_proto_rawDescOnce sync.Once + file_matchmaking_v1_forex_forex_proto_rawDescData = file_matchmaking_v1_forex_forex_proto_rawDesc +) + +func file_matchmaking_v1_forex_forex_proto_rawDescGZIP() []byte { + file_matchmaking_v1_forex_forex_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_forex_forex_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_forex_forex_proto_rawDescData) + }) + return file_matchmaking_v1_forex_forex_proto_rawDescData +} + +var file_matchmaking_v1_forex_forex_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_matchmaking_v1_forex_forex_proto_goTypes = []any{ + (*GetBotForexTradeRequest)(nil), // 0: matchmaking.v1.GetBotForexTradeRequest + (*GetBotForexTradeReply)(nil), // 1: matchmaking.v1.GetBotForexTradeReply + (*BotForexTradeData)(nil), // 2: matchmaking.v1.BotForexTradeData + (*BotForexTrade)(nil), // 3: matchmaking.v1.BotForexTrade + (*ForexRequest)(nil), // 4: matchmaking.v1.ForexRequest + (*ForexReply)(nil), // 5: matchmaking.v1.ForexReply + (*ForexResult)(nil), // 6: matchmaking.v1.ForexResult + (*UpdateForexRequest)(nil), // 7: matchmaking.v1.UpdateForexRequest + (*CancelForexRequest)(nil), // 8: matchmaking.v1.CancelForexRequest + (*AllForexRequest)(nil), // 9: matchmaking.v1.AllForexRequest + (*AllForexReply)(nil), // 10: matchmaking.v1.AllForexReply + (*timestamppb.Timestamp)(nil), // 11: google.protobuf.Timestamp +} +var file_matchmaking_v1_forex_forex_proto_depIdxs = []int32{ + 2, // 0: matchmaking.v1.GetBotForexTradeReply.data:type_name -> matchmaking.v1.BotForexTradeData + 3, // 1: matchmaking.v1.BotForexTradeData.data:type_name -> matchmaking.v1.BotForexTrade + 11, // 2: matchmaking.v1.BotForexTrade.createTime:type_name -> google.protobuf.Timestamp + 11, // 3: matchmaking.v1.BotForexTrade.updateTime:type_name -> google.protobuf.Timestamp + 11, // 4: matchmaking.v1.BotForexTrade.openTime:type_name -> google.protobuf.Timestamp + 11, // 5: matchmaking.v1.BotForexTrade.closingTime:type_name -> google.protobuf.Timestamp + 6, // 6: matchmaking.v1.ForexReply.data:type_name -> matchmaking.v1.ForexResult + 0, // 7: matchmaking.v1.Forex.GetBotForexTrade:input_type -> matchmaking.v1.GetBotForexTradeRequest + 4, // 8: matchmaking.v1.Forex.ForexPlaceOrder:input_type -> matchmaking.v1.ForexRequest + 7, // 9: matchmaking.v1.Forex.ForexUpdatePlaceOrder:input_type -> matchmaking.v1.UpdateForexRequest + 8, // 10: matchmaking.v1.Forex.ForexPosition:input_type -> matchmaking.v1.CancelForexRequest + 9, // 11: matchmaking.v1.Forex.ForexAllPosition:input_type -> matchmaking.v1.AllForexRequest + 8, // 12: matchmaking.v1.Forex.ForexCancel:input_type -> matchmaking.v1.CancelForexRequest + 1, // 13: matchmaking.v1.Forex.GetBotForexTrade:output_type -> matchmaking.v1.GetBotForexTradeReply + 5, // 14: matchmaking.v1.Forex.ForexPlaceOrder:output_type -> matchmaking.v1.ForexReply + 5, // 15: matchmaking.v1.Forex.ForexUpdatePlaceOrder:output_type -> matchmaking.v1.ForexReply + 5, // 16: matchmaking.v1.Forex.ForexPosition:output_type -> matchmaking.v1.ForexReply + 10, // 17: matchmaking.v1.Forex.ForexAllPosition:output_type -> matchmaking.v1.AllForexReply + 5, // 18: matchmaking.v1.Forex.ForexCancel:output_type -> matchmaking.v1.ForexReply + 13, // [13:19] is the sub-list for method output_type + 7, // [7:13] is the sub-list for method input_type + 7, // [7:7] is the sub-list for extension type_name + 7, // [7:7] is the sub-list for extension extendee + 0, // [0:7] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_forex_forex_proto_init() } +func file_matchmaking_v1_forex_forex_proto_init() { + if File_matchmaking_v1_forex_forex_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_matchmaking_v1_forex_forex_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*GetBotForexTradeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_forex_forex_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*GetBotForexTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_forex_forex_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*BotForexTradeData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_forex_forex_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*BotForexTrade); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_forex_forex_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*ForexRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_forex_forex_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*ForexReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_forex_forex_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*ForexResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_forex_forex_proto_msgTypes[7].Exporter = func(v any, i int) any { + switch v := v.(*UpdateForexRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_forex_forex_proto_msgTypes[8].Exporter = func(v any, i int) any { + switch v := v.(*CancelForexRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_forex_forex_proto_msgTypes[9].Exporter = func(v any, i int) any { + switch v := v.(*AllForexRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_forex_forex_proto_msgTypes[10].Exporter = func(v any, i int) any { + switch v := v.(*AllForexReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_forex_forex_proto_rawDesc, + NumEnums: 0, + NumMessages: 11, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_matchmaking_v1_forex_forex_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_forex_forex_proto_depIdxs, + MessageInfos: file_matchmaking_v1_forex_forex_proto_msgTypes, + }.Build() + File_matchmaking_v1_forex_forex_proto = out.File + file_matchmaking_v1_forex_forex_proto_rawDesc = nil + file_matchmaking_v1_forex_forex_proto_goTypes = nil + file_matchmaking_v1_forex_forex_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/forex/forex.proto b/api/matchmaking/v1/forex/forex.proto new file mode 100644 index 0000000..3a201eb --- /dev/null +++ b/api/matchmaking/v1/forex/forex.proto @@ -0,0 +1,151 @@ +syntax = "proto3"; + +package matchmaking.v1; + +import "google/api/annotations.proto"; +import "google/protobuf/timestamp.proto"; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +service Forex { + // GetBotForexTrade 外汇列表查询 + rpc GetBotForexTrade(GetBotForexTradeRequest)returns(GetBotForexTradeReply){ + option (google.api.http) = { + post:"/order_forex/forex_list", + body:"*", + }; + } + // ForexPlaceOrder 外汇下单 + rpc ForexPlaceOrder(ForexRequest)returns(ForexReply){ + option (google.api.http) = { + post: "/order_forex/forex_place_order", + body: "*", + }; + } + // ForexUpdatePlaceOrder 外汇设置止盈止损 + rpc ForexUpdatePlaceOrder(UpdateForexRequest)returns(ForexReply){ + option (google.api.http) = { + post: "/order_forex/forex_update_order", + body: "*", + }; + } + // ForexPosition 外汇平仓 + rpc ForexPosition(CancelForexRequest)returns(ForexReply){ + option (google.api.http) = { + post:"/order_forex/forex_position", + body:"*", + }; + } + // ForexAllPosition 外汇一键平仓 + rpc ForexAllPosition(AllForexRequest)returns(AllForexReply){ + option (google.api.http) = { + post:"/order_forex/forex_all_position", + body:"*", + }; + } + // ForexCancel 外汇撤单 + rpc ForexCancel(CancelForexRequest)returns(ForexReply){ + option (google.api.http) = { + post:"/order_forex/forex_cancel", + body:"*", + }; + } +} + +message GetBotForexTradeRequest{ + int64 status =1;// 状态码 + int64 pageSize =2; // 每页显示条数 + int64 pageCount =3;// 开始的位置 + int64 state = 4;// 订单类型 +} + +message GetBotForexTradeReply{ + int64 code =1;// 状态码 + BotForexTradeData data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message BotForexTradeData{ + int64 pageSize =1; // 每页显示条数 + int64 pageCount =2;// 开始的位置 + repeated BotForexTrade data =3;// 返回结果 + int64 totalCount =4;// 总数据 +} + +message BotForexTrade{ + string orderId =1;// 订单ID + string forexId =2;// 外汇ID + int64 tradeType =3;// 交易类型 + int64 dealType =4;// 交易方式 + string limitPrice =5;// 限价 + string marketPrice =6;// 市价 + string dealPrice =7;// 开仓价 + string closingPrice =8;// 平仓价 + string orderNumber =9;// 订单数量 + int64 stopType =10;// 止盈止损状态 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string serviceCost =13;// 开仓手续费 + string earnestMoney =14;// 保证金 + string orderMoney =15;// 订单总额 + int64 status =16;// 订单状态 + google.protobuf.Timestamp createTime =17;// 订单创建时间 + google.protobuf.Timestamp updateTime =18;// 订单更新时间 + google.protobuf.Timestamp openTime =19;// 订单开仓时间 + google.protobuf.Timestamp closingTime =20;// 订单平仓时间 + string closingCost =21;// 平仓手续费 + string faceValue =22;// 面值 + string overnightCost =23;// 过夜手续费 + string pryNum =24;// 杠杆值 + string keepDecimal =25;// 保留小数位 + string secondTime = 26;// 秒外汇时间 + int64 state = 27;// 订单类型 +} + +message ForexRequest{ + string forexId =1;// 交易对 + int64 tradeType =2;// 交易类型:1买入,2卖出 + int64 dealType =3;// 委托方式:1限价,2市价 + string limitPrice =4;// 限价 + string marketPrice =5;// 市价 + string orderAmount =6;// 订单金额 + string orderNumber =7;// 订单数量 + string earnestMoney =8;// 保证金 + string serviceCost =9;// 手续费 + int64 stopType =10;// 止损止盈设置:0无设置,1止损止盈 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string pryNum =13;//杠杆 + int64 time = 14;// 秒外汇时间 +} + +message ForexReply{ + int64 code =1;// 状态码 + ForexResult data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message ForexResult { + string orderId =1;// 订单Id +} + +message UpdateForexRequest{ + string orderId =1;// 订单Id + int64 stopType =2;// 止盈止损 + string stopLossPrice =3;// 止损 + string stopWinPrice =4;// 止盈 +} + +message CancelForexRequest{ + string orderId =1;// 订单ID +} + +message AllForexRequest{ + +} + +message AllForexReply{ + int64 code =1;// 状态码 + string data =2;// 返回结果 + string message =3;// 返回消息提示 +} \ No newline at end of file diff --git a/api/matchmaking/v1/forex/forex_grpc.pb.go b/api/matchmaking/v1/forex/forex_grpc.pb.go new file mode 100644 index 0000000..7d38bd8 --- /dev/null +++ b/api/matchmaking/v1/forex/forex_grpc.pb.go @@ -0,0 +1,312 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.1 +// source: matchmaking/v1/forex/forex.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + Forex_GetBotForexTrade_FullMethodName = "/matchmaking.v1.Forex/GetBotForexTrade" + Forex_ForexPlaceOrder_FullMethodName = "/matchmaking.v1.Forex/ForexPlaceOrder" + Forex_ForexUpdatePlaceOrder_FullMethodName = "/matchmaking.v1.Forex/ForexUpdatePlaceOrder" + Forex_ForexPosition_FullMethodName = "/matchmaking.v1.Forex/ForexPosition" + Forex_ForexAllPosition_FullMethodName = "/matchmaking.v1.Forex/ForexAllPosition" + Forex_ForexCancel_FullMethodName = "/matchmaking.v1.Forex/ForexCancel" +) + +// ForexClient is the client API for Forex service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ForexClient interface { + // GetBotForexTrade 外汇列表查询 + GetBotForexTrade(ctx context.Context, in *GetBotForexTradeRequest, opts ...grpc.CallOption) (*GetBotForexTradeReply, error) + // ForexPlaceOrder 外汇下单 + ForexPlaceOrder(ctx context.Context, in *ForexRequest, opts ...grpc.CallOption) (*ForexReply, error) + // ForexUpdatePlaceOrder 外汇设置止盈止损 + ForexUpdatePlaceOrder(ctx context.Context, in *UpdateForexRequest, opts ...grpc.CallOption) (*ForexReply, error) + // ForexPosition 外汇平仓 + ForexPosition(ctx context.Context, in *CancelForexRequest, opts ...grpc.CallOption) (*ForexReply, error) + // ForexAllPosition 外汇一键平仓 + ForexAllPosition(ctx context.Context, in *AllForexRequest, opts ...grpc.CallOption) (*AllForexReply, error) + // ForexCancel 外汇撤单 + ForexCancel(ctx context.Context, in *CancelForexRequest, opts ...grpc.CallOption) (*ForexReply, error) +} + +type forexClient struct { + cc grpc.ClientConnInterface +} + +func NewForexClient(cc grpc.ClientConnInterface) ForexClient { + return &forexClient{cc} +} + +func (c *forexClient) GetBotForexTrade(ctx context.Context, in *GetBotForexTradeRequest, opts ...grpc.CallOption) (*GetBotForexTradeReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetBotForexTradeReply) + err := c.cc.Invoke(ctx, Forex_GetBotForexTrade_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *forexClient) ForexPlaceOrder(ctx context.Context, in *ForexRequest, opts ...grpc.CallOption) (*ForexReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(ForexReply) + err := c.cc.Invoke(ctx, Forex_ForexPlaceOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *forexClient) ForexUpdatePlaceOrder(ctx context.Context, in *UpdateForexRequest, opts ...grpc.CallOption) (*ForexReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(ForexReply) + err := c.cc.Invoke(ctx, Forex_ForexUpdatePlaceOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *forexClient) ForexPosition(ctx context.Context, in *CancelForexRequest, opts ...grpc.CallOption) (*ForexReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(ForexReply) + err := c.cc.Invoke(ctx, Forex_ForexPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *forexClient) ForexAllPosition(ctx context.Context, in *AllForexRequest, opts ...grpc.CallOption) (*AllForexReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AllForexReply) + err := c.cc.Invoke(ctx, Forex_ForexAllPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *forexClient) ForexCancel(ctx context.Context, in *CancelForexRequest, opts ...grpc.CallOption) (*ForexReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(ForexReply) + err := c.cc.Invoke(ctx, Forex_ForexCancel_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ForexServer is the server API for Forex service. +// All implementations must embed UnimplementedForexServer +// for forward compatibility +type ForexServer interface { + // GetBotForexTrade 外汇列表查询 + GetBotForexTrade(context.Context, *GetBotForexTradeRequest) (*GetBotForexTradeReply, error) + // ForexPlaceOrder 外汇下单 + ForexPlaceOrder(context.Context, *ForexRequest) (*ForexReply, error) + // ForexUpdatePlaceOrder 外汇设置止盈止损 + ForexUpdatePlaceOrder(context.Context, *UpdateForexRequest) (*ForexReply, error) + // ForexPosition 外汇平仓 + ForexPosition(context.Context, *CancelForexRequest) (*ForexReply, error) + // ForexAllPosition 外汇一键平仓 + ForexAllPosition(context.Context, *AllForexRequest) (*AllForexReply, error) + // ForexCancel 外汇撤单 + ForexCancel(context.Context, *CancelForexRequest) (*ForexReply, error) + mustEmbedUnimplementedForexServer() +} + +// UnimplementedForexServer must be embedded to have forward compatible implementations. +type UnimplementedForexServer struct { +} + +func (UnimplementedForexServer) GetBotForexTrade(context.Context, *GetBotForexTradeRequest) (*GetBotForexTradeReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBotForexTrade not implemented") +} +func (UnimplementedForexServer) ForexPlaceOrder(context.Context, *ForexRequest) (*ForexReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ForexPlaceOrder not implemented") +} +func (UnimplementedForexServer) ForexUpdatePlaceOrder(context.Context, *UpdateForexRequest) (*ForexReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ForexUpdatePlaceOrder not implemented") +} +func (UnimplementedForexServer) ForexPosition(context.Context, *CancelForexRequest) (*ForexReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ForexPosition not implemented") +} +func (UnimplementedForexServer) ForexAllPosition(context.Context, *AllForexRequest) (*AllForexReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ForexAllPosition not implemented") +} +func (UnimplementedForexServer) ForexCancel(context.Context, *CancelForexRequest) (*ForexReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ForexCancel not implemented") +} +func (UnimplementedForexServer) mustEmbedUnimplementedForexServer() {} + +// UnsafeForexServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ForexServer will +// result in compilation errors. +type UnsafeForexServer interface { + mustEmbedUnimplementedForexServer() +} + +func RegisterForexServer(s grpc.ServiceRegistrar, srv ForexServer) { + s.RegisterService(&Forex_ServiceDesc, srv) +} + +func _Forex_GetBotForexTrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetBotForexTradeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ForexServer).GetBotForexTrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Forex_GetBotForexTrade_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ForexServer).GetBotForexTrade(ctx, req.(*GetBotForexTradeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Forex_ForexPlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ForexRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ForexServer).ForexPlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Forex_ForexPlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ForexServer).ForexPlaceOrder(ctx, req.(*ForexRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Forex_ForexUpdatePlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateForexRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ForexServer).ForexUpdatePlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Forex_ForexUpdatePlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ForexServer).ForexUpdatePlaceOrder(ctx, req.(*UpdateForexRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Forex_ForexPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelForexRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ForexServer).ForexPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Forex_ForexPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ForexServer).ForexPosition(ctx, req.(*CancelForexRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Forex_ForexAllPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AllForexRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ForexServer).ForexAllPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Forex_ForexAllPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ForexServer).ForexAllPosition(ctx, req.(*AllForexRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Forex_ForexCancel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelForexRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ForexServer).ForexCancel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Forex_ForexCancel_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ForexServer).ForexCancel(ctx, req.(*CancelForexRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Forex_ServiceDesc is the grpc.ServiceDesc for Forex service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Forex_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "matchmaking.v1.Forex", + HandlerType: (*ForexServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetBotForexTrade", + Handler: _Forex_GetBotForexTrade_Handler, + }, + { + MethodName: "ForexPlaceOrder", + Handler: _Forex_ForexPlaceOrder_Handler, + }, + { + MethodName: "ForexUpdatePlaceOrder", + Handler: _Forex_ForexUpdatePlaceOrder_Handler, + }, + { + MethodName: "ForexPosition", + Handler: _Forex_ForexPosition_Handler, + }, + { + MethodName: "ForexAllPosition", + Handler: _Forex_ForexAllPosition_Handler, + }, + { + MethodName: "ForexCancel", + Handler: _Forex_ForexCancel_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "matchmaking/v1/forex/forex.proto", +} diff --git a/api/matchmaking/v1/forex/forex_http.pb.go b/api/matchmaking/v1/forex/forex_http.pb.go new file mode 100644 index 0000000..a315993 --- /dev/null +++ b/api/matchmaking/v1/forex/forex_http.pb.go @@ -0,0 +1,279 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.3 +// - protoc v5.27.1 +// source: matchmaking/v1/forex/forex.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationForexForexAllPosition = "/matchmaking.v1.Forex/ForexAllPosition" +const OperationForexForexCancel = "/matchmaking.v1.Forex/ForexCancel" +const OperationForexForexPlaceOrder = "/matchmaking.v1.Forex/ForexPlaceOrder" +const OperationForexForexPosition = "/matchmaking.v1.Forex/ForexPosition" +const OperationForexForexUpdatePlaceOrder = "/matchmaking.v1.Forex/ForexUpdatePlaceOrder" +const OperationForexGetBotForexTrade = "/matchmaking.v1.Forex/GetBotForexTrade" + +type ForexHTTPServer interface { + // ForexAllPosition ForexAllPosition 外汇一键平仓 + ForexAllPosition(context.Context, *AllForexRequest) (*AllForexReply, error) + // ForexCancel ForexCancel 外汇撤单 + ForexCancel(context.Context, *CancelForexRequest) (*ForexReply, error) + // ForexPlaceOrder ForexPlaceOrder 外汇下单 + ForexPlaceOrder(context.Context, *ForexRequest) (*ForexReply, error) + // ForexPosition ForexPosition 外汇平仓 + ForexPosition(context.Context, *CancelForexRequest) (*ForexReply, error) + // ForexUpdatePlaceOrder ForexUpdatePlaceOrder 外汇设置止盈止损 + ForexUpdatePlaceOrder(context.Context, *UpdateForexRequest) (*ForexReply, error) + // GetBotForexTrade GetBotForexTrade 外汇列表查询 + GetBotForexTrade(context.Context, *GetBotForexTradeRequest) (*GetBotForexTradeReply, error) +} + +func RegisterForexHTTPServer(s *http.Server, srv ForexHTTPServer) { + r := s.Route("/") + r.POST("/order_forex/forex_list", _Forex_GetBotForexTrade0_HTTP_Handler(srv)) + r.POST("/order_forex/forex_place_order", _Forex_ForexPlaceOrder0_HTTP_Handler(srv)) + r.POST("/order_forex/forex_update_order", _Forex_ForexUpdatePlaceOrder0_HTTP_Handler(srv)) + r.POST("/order_forex/forex_position", _Forex_ForexPosition0_HTTP_Handler(srv)) + r.POST("/order_forex/forex_all_position", _Forex_ForexAllPosition0_HTTP_Handler(srv)) + r.POST("/order_forex/forex_cancel", _Forex_ForexCancel0_HTTP_Handler(srv)) +} + +func _Forex_GetBotForexTrade0_HTTP_Handler(srv ForexHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetBotForexTradeRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationForexGetBotForexTrade) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.GetBotForexTrade(ctx, req.(*GetBotForexTradeRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetBotForexTradeReply) + return ctx.Result(200, reply) + } +} + +func _Forex_ForexPlaceOrder0_HTTP_Handler(srv ForexHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in ForexRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationForexForexPlaceOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ForexPlaceOrder(ctx, req.(*ForexRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*ForexReply) + return ctx.Result(200, reply) + } +} + +func _Forex_ForexUpdatePlaceOrder0_HTTP_Handler(srv ForexHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in UpdateForexRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationForexForexUpdatePlaceOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ForexUpdatePlaceOrder(ctx, req.(*UpdateForexRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*ForexReply) + return ctx.Result(200, reply) + } +} + +func _Forex_ForexPosition0_HTTP_Handler(srv ForexHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelForexRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationForexForexPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ForexPosition(ctx, req.(*CancelForexRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*ForexReply) + return ctx.Result(200, reply) + } +} + +func _Forex_ForexAllPosition0_HTTP_Handler(srv ForexHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in AllForexRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationForexForexAllPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ForexAllPosition(ctx, req.(*AllForexRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*AllForexReply) + return ctx.Result(200, reply) + } +} + +func _Forex_ForexCancel0_HTTP_Handler(srv ForexHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelForexRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationForexForexCancel) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ForexCancel(ctx, req.(*CancelForexRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*ForexReply) + return ctx.Result(200, reply) + } +} + +type ForexHTTPClient interface { + ForexAllPosition(ctx context.Context, req *AllForexRequest, opts ...http.CallOption) (rsp *AllForexReply, err error) + ForexCancel(ctx context.Context, req *CancelForexRequest, opts ...http.CallOption) (rsp *ForexReply, err error) + ForexPlaceOrder(ctx context.Context, req *ForexRequest, opts ...http.CallOption) (rsp *ForexReply, err error) + ForexPosition(ctx context.Context, req *CancelForexRequest, opts ...http.CallOption) (rsp *ForexReply, err error) + ForexUpdatePlaceOrder(ctx context.Context, req *UpdateForexRequest, opts ...http.CallOption) (rsp *ForexReply, err error) + GetBotForexTrade(ctx context.Context, req *GetBotForexTradeRequest, opts ...http.CallOption) (rsp *GetBotForexTradeReply, err error) +} + +type ForexHTTPClientImpl struct { + cc *http.Client +} + +func NewForexHTTPClient(client *http.Client) ForexHTTPClient { + return &ForexHTTPClientImpl{client} +} + +func (c *ForexHTTPClientImpl) ForexAllPosition(ctx context.Context, in *AllForexRequest, opts ...http.CallOption) (*AllForexReply, error) { + var out AllForexReply + pattern := "/order_forex/forex_all_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationForexForexAllPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ForexHTTPClientImpl) ForexCancel(ctx context.Context, in *CancelForexRequest, opts ...http.CallOption) (*ForexReply, error) { + var out ForexReply + pattern := "/order_forex/forex_cancel" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationForexForexCancel)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ForexHTTPClientImpl) ForexPlaceOrder(ctx context.Context, in *ForexRequest, opts ...http.CallOption) (*ForexReply, error) { + var out ForexReply + pattern := "/order_forex/forex_place_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationForexForexPlaceOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ForexHTTPClientImpl) ForexPosition(ctx context.Context, in *CancelForexRequest, opts ...http.CallOption) (*ForexReply, error) { + var out ForexReply + pattern := "/order_forex/forex_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationForexForexPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ForexHTTPClientImpl) ForexUpdatePlaceOrder(ctx context.Context, in *UpdateForexRequest, opts ...http.CallOption) (*ForexReply, error) { + var out ForexReply + pattern := "/order_forex/forex_update_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationForexForexUpdatePlaceOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ForexHTTPClientImpl) GetBotForexTrade(ctx context.Context, in *GetBotForexTradeRequest, opts ...http.CallOption) (*GetBotForexTradeReply, error) { + var out GetBotForexTradeReply + pattern := "/order_forex/forex_list" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationForexGetBotForexTrade)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/api/matchmaking/v1/money/money.pb.go b/api/matchmaking/v1/money/money.pb.go new file mode 100644 index 0000000..dffc011 --- /dev/null +++ b/api/matchmaking/v1/money/money.pb.go @@ -0,0 +1,1412 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/money/money.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GetBotMoneyTradeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status int64 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` // 状态码 + PageSize int64 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,3,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + State int64 `protobuf:"varint,4,opt,name=state,proto3" json:"state,omitempty"` // 订单类型 + Type int64 `protobuf:"varint,5,opt,name=type,proto3" json:"type,omitempty"` // 订单市场 +} + +func (x *GetBotMoneyTradeRequest) Reset() { + *x = GetBotMoneyTradeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotMoneyTradeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotMoneyTradeRequest) ProtoMessage() {} + +func (x *GetBotMoneyTradeRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotMoneyTradeRequest.ProtoReflect.Descriptor instead. +func (*GetBotMoneyTradeRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_money_money_proto_rawDescGZIP(), []int{0} +} + +func (x *GetBotMoneyTradeRequest) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *GetBotMoneyTradeRequest) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *GetBotMoneyTradeRequest) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *GetBotMoneyTradeRequest) GetState() int64 { + if x != nil { + return x.State + } + return 0 +} + +func (x *GetBotMoneyTradeRequest) GetType() int64 { + if x != nil { + return x.Type + } + return 0 +} + +type GetBotMoneyTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *BotMoneyTradeData `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *GetBotMoneyTradeReply) Reset() { + *x = GetBotMoneyTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotMoneyTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotMoneyTradeReply) ProtoMessage() {} + +func (x *GetBotMoneyTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotMoneyTradeReply.ProtoReflect.Descriptor instead. +func (*GetBotMoneyTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_money_money_proto_rawDescGZIP(), []int{1} +} + +func (x *GetBotMoneyTradeReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *GetBotMoneyTradeReply) GetData() *BotMoneyTradeData { + if x != nil { + return x.Data + } + return nil +} + +func (x *GetBotMoneyTradeReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type BotMoneyTradeData struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PageSize int64 `protobuf:"varint,1,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,2,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + Data []*BotMoneyTrade `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty"` // 返回结果 + TotalCount int64 `protobuf:"varint,4,opt,name=totalCount,proto3" json:"totalCount,omitempty"` // 总数据 +} + +func (x *BotMoneyTradeData) Reset() { + *x = BotMoneyTradeData{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotMoneyTradeData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotMoneyTradeData) ProtoMessage() {} + +func (x *BotMoneyTradeData) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotMoneyTradeData.ProtoReflect.Descriptor instead. +func (*BotMoneyTradeData) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_money_money_proto_rawDescGZIP(), []int{2} +} + +func (x *BotMoneyTradeData) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *BotMoneyTradeData) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *BotMoneyTradeData) GetData() []*BotMoneyTrade { + if x != nil { + return x.Data + } + return nil +} + +func (x *BotMoneyTradeData) GetTotalCount() int64 { + if x != nil { + return x.TotalCount + } + return 0 +} + +type BotMoneyTrade struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID + StockId string `protobuf:"bytes,2,opt,name=StockId,proto3" json:"StockId,omitempty"` // 综合ID + TradeType int64 `protobuf:"varint,3,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型 + DealType int64 `protobuf:"varint,4,opt,name=dealType,proto3" json:"dealType,omitempty"` // 交易方式 + LimitPrice string `protobuf:"bytes,5,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,6,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + DealPrice string `protobuf:"bytes,7,opt,name=dealPrice,proto3" json:"dealPrice,omitempty"` // 开仓价 + ClosingPrice string `protobuf:"bytes,8,opt,name=closingPrice,proto3" json:"closingPrice,omitempty"` // 平仓价 + OrderNumber string `protobuf:"bytes,9,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损状态 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + ServiceCost string `protobuf:"bytes,13,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 开仓手续费 + EarnestMoney string `protobuf:"bytes,14,opt,name=earnestMoney,proto3" json:"earnestMoney,omitempty"` // 保证金 + OrderMoney string `protobuf:"bytes,15,opt,name=orderMoney,proto3" json:"orderMoney,omitempty"` // 订单总额 + Status int64 `protobuf:"varint,16,opt,name=status,proto3" json:"status,omitempty"` // 订单状态 + CreateTime *timestamppb.Timestamp `protobuf:"bytes,17,opt,name=createTime,proto3" json:"createTime,omitempty"` // 订单创建时间 + UpdateTime *timestamppb.Timestamp `protobuf:"bytes,18,opt,name=updateTime,proto3" json:"updateTime,omitempty"` // 订单更新时间 + OpenTime *timestamppb.Timestamp `protobuf:"bytes,19,opt,name=openTime,proto3" json:"openTime,omitempty"` // 订单开仓时间 + ClosingTime *timestamppb.Timestamp `protobuf:"bytes,20,opt,name=closingTime,proto3" json:"closingTime,omitempty"` // 订单平仓时间 + ClosingCost string `protobuf:"bytes,21,opt,name=closingCost,proto3" json:"closingCost,omitempty"` // 平仓手续费 + FaceValue string `protobuf:"bytes,22,opt,name=faceValue,proto3" json:"faceValue,omitempty"` // 面值 + OvernightCost string `protobuf:"bytes,23,opt,name=overnightCost,proto3" json:"overnightCost,omitempty"` // 过夜手续费 + PryNum string `protobuf:"bytes,24,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆值 + KeepDecimal string `protobuf:"bytes,25,opt,name=keepDecimal,proto3" json:"keepDecimal,omitempty"` // 保留小数位 + SecondTime string `protobuf:"bytes,26,opt,name=secondTime,proto3" json:"secondTime,omitempty"` // 秒综合时间 + State int64 `protobuf:"varint,27,opt,name=state,proto3" json:"state,omitempty"` // 订单类型 +} + +func (x *BotMoneyTrade) Reset() { + *x = BotMoneyTrade{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotMoneyTrade) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotMoneyTrade) ProtoMessage() {} + +func (x *BotMoneyTrade) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotMoneyTrade.ProtoReflect.Descriptor instead. +func (*BotMoneyTrade) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_money_money_proto_rawDescGZIP(), []int{3} +} + +func (x *BotMoneyTrade) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *BotMoneyTrade) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *BotMoneyTrade) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *BotMoneyTrade) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *BotMoneyTrade) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *BotMoneyTrade) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *BotMoneyTrade) GetDealPrice() string { + if x != nil { + return x.DealPrice + } + return "" +} + +func (x *BotMoneyTrade) GetClosingPrice() string { + if x != nil { + return x.ClosingPrice + } + return "" +} + +func (x *BotMoneyTrade) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *BotMoneyTrade) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *BotMoneyTrade) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *BotMoneyTrade) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *BotMoneyTrade) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *BotMoneyTrade) GetEarnestMoney() string { + if x != nil { + return x.EarnestMoney + } + return "" +} + +func (x *BotMoneyTrade) GetOrderMoney() string { + if x != nil { + return x.OrderMoney + } + return "" +} + +func (x *BotMoneyTrade) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *BotMoneyTrade) GetCreateTime() *timestamppb.Timestamp { + if x != nil { + return x.CreateTime + } + return nil +} + +func (x *BotMoneyTrade) GetUpdateTime() *timestamppb.Timestamp { + if x != nil { + return x.UpdateTime + } + return nil +} + +func (x *BotMoneyTrade) GetOpenTime() *timestamppb.Timestamp { + if x != nil { + return x.OpenTime + } + return nil +} + +func (x *BotMoneyTrade) GetClosingTime() *timestamppb.Timestamp { + if x != nil { + return x.ClosingTime + } + return nil +} + +func (x *BotMoneyTrade) GetClosingCost() string { + if x != nil { + return x.ClosingCost + } + return "" +} + +func (x *BotMoneyTrade) GetFaceValue() string { + if x != nil { + return x.FaceValue + } + return "" +} + +func (x *BotMoneyTrade) GetOvernightCost() string { + if x != nil { + return x.OvernightCost + } + return "" +} + +func (x *BotMoneyTrade) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *BotMoneyTrade) GetKeepDecimal() string { + if x != nil { + return x.KeepDecimal + } + return "" +} + +func (x *BotMoneyTrade) GetSecondTime() string { + if x != nil { + return x.SecondTime + } + return "" +} + +func (x *BotMoneyTrade) GetState() int64 { + if x != nil { + return x.State + } + return 0 +} + +type MoneyRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + StockId string `protobuf:"bytes,1,opt,name=stockId,proto3" json:"stockId,omitempty"` // 交易对 + TradeType int64 `protobuf:"varint,2,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型:1买入,2卖出 + DealType int64 `protobuf:"varint,3,opt,name=dealType,proto3" json:"dealType,omitempty"` // 委托方式:1限价,2市价 + LimitPrice string `protobuf:"bytes,4,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,5,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + OrderAmount string `protobuf:"bytes,6,opt,name=orderAmount,proto3" json:"orderAmount,omitempty"` // 订单金额 + OrderNumber string `protobuf:"bytes,7,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + EarnestMoney string `protobuf:"bytes,8,opt,name=earnestMoney,proto3" json:"earnestMoney,omitempty"` // 保证金 + ServiceCost string `protobuf:"bytes,9,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 手续费 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止损止盈设置:0无设置,1止损止盈 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + PryNum string `protobuf:"bytes,13,opt,name=pryNum,proto3" json:"pryNum,omitempty"` //杠杆 + Time int64 `protobuf:"varint,14,opt,name=time,proto3" json:"time,omitempty"` // 秒综合时间 + Type int64 `protobuf:"varint,15,opt,name=type,proto3" json:"type,omitempty"` // 交易市场 +} + +func (x *MoneyRequest) Reset() { + *x = MoneyRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MoneyRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MoneyRequest) ProtoMessage() {} + +func (x *MoneyRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MoneyRequest.ProtoReflect.Descriptor instead. +func (*MoneyRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_money_money_proto_rawDescGZIP(), []int{4} +} + +func (x *MoneyRequest) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *MoneyRequest) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *MoneyRequest) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *MoneyRequest) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *MoneyRequest) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *MoneyRequest) GetOrderAmount() string { + if x != nil { + return x.OrderAmount + } + return "" +} + +func (x *MoneyRequest) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *MoneyRequest) GetEarnestMoney() string { + if x != nil { + return x.EarnestMoney + } + return "" +} + +func (x *MoneyRequest) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *MoneyRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *MoneyRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *MoneyRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *MoneyRequest) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *MoneyRequest) GetTime() int64 { + if x != nil { + return x.Time + } + return 0 +} + +func (x *MoneyRequest) GetType() int64 { + if x != nil { + return x.Type + } + return 0 +} + +type MoneyReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *MoneyResult `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *MoneyReply) Reset() { + *x = MoneyReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MoneyReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MoneyReply) ProtoMessage() {} + +func (x *MoneyReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MoneyReply.ProtoReflect.Descriptor instead. +func (*MoneyReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_money_money_proto_rawDescGZIP(), []int{5} +} + +func (x *MoneyReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *MoneyReply) GetData() *MoneyResult { + if x != nil { + return x.Data + } + return nil +} + +func (x *MoneyReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type MoneyResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id +} + +func (x *MoneyResult) Reset() { + *x = MoneyResult{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MoneyResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MoneyResult) ProtoMessage() {} + +func (x *MoneyResult) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MoneyResult.ProtoReflect.Descriptor instead. +func (*MoneyResult) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_money_money_proto_rawDescGZIP(), []int{6} +} + +func (x *MoneyResult) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type UpdateMoneyRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id + StopType int64 `protobuf:"varint,2,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,3,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,4,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 +} + +func (x *UpdateMoneyRequest) Reset() { + *x = UpdateMoneyRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateMoneyRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateMoneyRequest) ProtoMessage() {} + +func (x *UpdateMoneyRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateMoneyRequest.ProtoReflect.Descriptor instead. +func (*UpdateMoneyRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_money_money_proto_rawDescGZIP(), []int{7} +} + +func (x *UpdateMoneyRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *UpdateMoneyRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *UpdateMoneyRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *UpdateMoneyRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +type CancelMoneyRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID +} + +func (x *CancelMoneyRequest) Reset() { + *x = CancelMoneyRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CancelMoneyRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CancelMoneyRequest) ProtoMessage() {} + +func (x *CancelMoneyRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CancelMoneyRequest.ProtoReflect.Descriptor instead. +func (*CancelMoneyRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_money_money_proto_rawDescGZIP(), []int{8} +} + +func (x *CancelMoneyRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type AllMoneyRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *AllMoneyRequest) Reset() { + *x = AllMoneyRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllMoneyRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllMoneyRequest) ProtoMessage() {} + +func (x *AllMoneyRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllMoneyRequest.ProtoReflect.Descriptor instead. +func (*AllMoneyRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_money_money_proto_rawDescGZIP(), []int{9} +} + +type AllMoneyReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *AllMoneyReply) Reset() { + *x = AllMoneyReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllMoneyReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllMoneyReply) ProtoMessage() {} + +func (x *AllMoneyReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_money_money_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllMoneyReply.ProtoReflect.Descriptor instead. +func (*AllMoneyReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_money_money_proto_rawDescGZIP(), []int{10} +} + +func (x *AllMoneyReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *AllMoneyReply) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +func (x *AllMoneyReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_matchmaking_v1_money_money_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_money_money_proto_rawDesc = []byte{ + 0x0a, 0x20, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x2f, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, + 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x22, 0x95, 0x01, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x4d, 0x6f, 0x6e, 0x65, + 0x79, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, + 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, + 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, + 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, + 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x05, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x7c, 0x0a, 0x15, 0x47, 0x65, 0x74, + 0x42, 0x6f, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, + 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x35, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x54, 0x72, + 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, + 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xa0, 0x01, 0x0a, 0x11, 0x42, 0x6f, 0x74, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x54, 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, 0x61, 0x12, 0x1a, 0x0a, + 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, + 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, + 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x31, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, + 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, + 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x54, + 0x72, 0x61, 0x64, 0x65, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x1e, 0x0a, 0x0a, 0x74, 0x6f, + 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, + 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0xcb, 0x07, 0x0a, 0x0d, 0x42, + 0x6f, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, + 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x49, + 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, + 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, + 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, + 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, + 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, + 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1c, 0x0a, 0x09, + 0x64, 0x65, 0x61, 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x09, 0x64, 0x65, 0x61, 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6c, + 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0c, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, + 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x09, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, + 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0a, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, + 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, + 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x0c, 0x65, 0x61, 0x72, 0x6e, + 0x65, 0x73, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, + 0x65, 0x61, 0x72, 0x6e, 0x65, 0x73, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, + 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, + 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x10, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x12, 0x3a, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, + 0x6d, 0x65, 0x18, 0x11, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, + 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, + 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, + 0x12, 0x3a, 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x12, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, + 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x36, 0x0a, 0x08, + 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x13, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, + 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x08, 0x6f, 0x70, 0x65, 0x6e, + 0x54, 0x69, 0x6d, 0x65, 0x12, 0x3c, 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, + 0x69, 0x6d, 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, + 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, + 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, + 0x74, 0x18, 0x15, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, + 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, + 0x65, 0x18, 0x16, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, + 0x75, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x6f, 0x76, 0x65, 0x72, 0x6e, 0x69, 0x67, 0x68, 0x74, 0x43, + 0x6f, 0x73, 0x74, 0x18, 0x17, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x6f, 0x76, 0x65, 0x72, 0x6e, + 0x69, 0x67, 0x68, 0x74, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x72, 0x79, 0x4e, + 0x75, 0x6d, 0x18, 0x18, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, + 0x12, 0x20, 0x0a, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x18, + 0x19, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, 0x6d, + 0x61, 0x6c, 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, + 0x18, 0x1a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x54, 0x69, + 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x1b, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0xd4, 0x03, 0x0a, 0x0c, 0x4d, 0x6f, 0x6e, + 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, + 0x63, 0x6b, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x63, + 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, + 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, + 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, + 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, + 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x06, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x41, 0x6d, 0x6f, 0x75, 0x6e, + 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, + 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, + 0x62, 0x65, 0x72, 0x12, 0x22, 0x0a, 0x0c, 0x65, 0x61, 0x72, 0x6e, 0x65, 0x73, 0x74, 0x4d, 0x6f, + 0x6e, 0x65, 0x79, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x61, 0x72, 0x6e, 0x65, + 0x73, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, + 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, + 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, + 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, + 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, + 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0c, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, + 0x16, 0x0a, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x18, + 0x0e, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, + 0x79, 0x70, 0x65, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, + 0x6b, 0x0a, 0x0a, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, + 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, + 0x65, 0x12, 0x2f, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x1b, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, + 0x2e, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x52, 0x04, 0x64, 0x61, + 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x27, 0x0a, 0x0b, + 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x49, 0x64, 0x22, 0x94, 0x01, 0x0a, 0x12, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, + 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, + 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, + 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, + 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, + 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, + 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x22, 0x2e, 0x0a, 0x12, + 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x22, 0x11, 0x0a, 0x0f, + 0x41, 0x6c, 0x6c, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, + 0x51, 0x0a, 0x0d, 0x41, 0x6c, 0x6c, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, + 0x63, 0x6f, 0x64, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x32, 0x86, 0x07, 0x0a, 0x05, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x86, 0x01, 0x0a, + 0x10, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x54, 0x72, 0x61, 0x64, + 0x65, 0x12, 0x27, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x54, 0x72, + 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, + 0x6f, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x22, 0x22, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1c, 0x3a, 0x01, 0x2a, 0x22, 0x17, 0x2f, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x5f, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x2f, 0x6d, 0x6f, 0x6e, 0x65, 0x79, + 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x12, 0x76, 0x0a, 0x0f, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x50, 0x6c, + 0x61, 0x63, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x1c, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, + 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x70, + 0x6c, 0x79, 0x22, 0x29, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x23, 0x3a, 0x01, 0x2a, 0x22, 0x1e, 0x2f, + 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x2f, 0x6d, 0x6f, 0x6e, 0x65, + 0x79, 0x5f, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x83, 0x01, + 0x0a, 0x15, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x6c, 0x61, + 0x63, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x22, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, + 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x6f, 0x6e, + 0x65, 0x79, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2a, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x24, 0x3a, + 0x01, 0x2a, 0x22, 0x1f, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x6d, 0x6f, 0x6e, 0x65, 0x79, + 0x2f, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x12, 0x77, 0x0a, 0x0d, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x50, 0x6f, 0x73, 0x69, + 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x22, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x4d, 0x6f, 0x6e, 0x65, + 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, + 0x65, 0x70, 0x6c, 0x79, 0x22, 0x26, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x20, 0x3a, 0x01, 0x2a, 0x22, + 0x1b, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x2f, 0x6d, 0x6f, + 0x6e, 0x65, 0x79, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x7e, 0x0a, 0x10, + 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x41, 0x6c, 0x6c, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, + 0x12, 0x1f, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, + 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x22, 0x2a, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x24, 0x3a, 0x01, 0x2a, 0x22, 0x1f, 0x2f, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x5f, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x2f, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x5f, + 0x61, 0x6c, 0x6c, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x73, 0x0a, 0x0b, + 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x12, 0x22, 0x2e, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x61, 0x6e, + 0x63, 0x65, 0x6c, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x1a, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, + 0x2e, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x24, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x1e, 0x3a, 0x01, 0x2a, 0x22, 0x19, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x6d, + 0x6f, 0x6e, 0x65, 0x79, 0x2f, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x5f, 0x63, 0x61, 0x6e, 0x63, 0x65, + 0x6c, 0x12, 0x87, 0x01, 0x0a, 0x17, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x4f, 0x6e, 0x65, 0x43, 0x6c, + 0x69, 0x63, 0x6b, 0x52, 0x65, 0x64, 0x65, 0x6d, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1c, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x6f, 0x6e, + 0x65, 0x79, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x32, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x2c, 0x3a, + 0x01, 0x2a, 0x22, 0x27, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x6d, 0x6f, 0x6e, 0x65, 0x79, + 0x2f, 0x6d, 0x6f, 0x6e, 0x65, 0x79, 0x5f, 0x6f, 0x6e, 0x65, 0x5f, 0x63, 0x6c, 0x69, 0x63, 0x6b, + 0x5f, 0x72, 0x65, 0x64, 0x65, 0x6d, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x2a, 0x5a, 0x28, 0x6d, + 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x73, 0x79, 0x73, 0x74, 0x65, + 0x6d, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, + 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_money_money_proto_rawDescOnce sync.Once + file_matchmaking_v1_money_money_proto_rawDescData = file_matchmaking_v1_money_money_proto_rawDesc +) + +func file_matchmaking_v1_money_money_proto_rawDescGZIP() []byte { + file_matchmaking_v1_money_money_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_money_money_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_money_money_proto_rawDescData) + }) + return file_matchmaking_v1_money_money_proto_rawDescData +} + +var file_matchmaking_v1_money_money_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_matchmaking_v1_money_money_proto_goTypes = []any{ + (*GetBotMoneyTradeRequest)(nil), // 0: matchmaking.v1.GetBotMoneyTradeRequest + (*GetBotMoneyTradeReply)(nil), // 1: matchmaking.v1.GetBotMoneyTradeReply + (*BotMoneyTradeData)(nil), // 2: matchmaking.v1.BotMoneyTradeData + (*BotMoneyTrade)(nil), // 3: matchmaking.v1.BotMoneyTrade + (*MoneyRequest)(nil), // 4: matchmaking.v1.MoneyRequest + (*MoneyReply)(nil), // 5: matchmaking.v1.MoneyReply + (*MoneyResult)(nil), // 6: matchmaking.v1.MoneyResult + (*UpdateMoneyRequest)(nil), // 7: matchmaking.v1.UpdateMoneyRequest + (*CancelMoneyRequest)(nil), // 8: matchmaking.v1.CancelMoneyRequest + (*AllMoneyRequest)(nil), // 9: matchmaking.v1.AllMoneyRequest + (*AllMoneyReply)(nil), // 10: matchmaking.v1.AllMoneyReply + (*timestamppb.Timestamp)(nil), // 11: google.protobuf.Timestamp +} +var file_matchmaking_v1_money_money_proto_depIdxs = []int32{ + 2, // 0: matchmaking.v1.GetBotMoneyTradeReply.data:type_name -> matchmaking.v1.BotMoneyTradeData + 3, // 1: matchmaking.v1.BotMoneyTradeData.data:type_name -> matchmaking.v1.BotMoneyTrade + 11, // 2: matchmaking.v1.BotMoneyTrade.createTime:type_name -> google.protobuf.Timestamp + 11, // 3: matchmaking.v1.BotMoneyTrade.updateTime:type_name -> google.protobuf.Timestamp + 11, // 4: matchmaking.v1.BotMoneyTrade.openTime:type_name -> google.protobuf.Timestamp + 11, // 5: matchmaking.v1.BotMoneyTrade.closingTime:type_name -> google.protobuf.Timestamp + 6, // 6: matchmaking.v1.MoneyReply.data:type_name -> matchmaking.v1.MoneyResult + 0, // 7: matchmaking.v1.Money.GetBotMoneyTrade:input_type -> matchmaking.v1.GetBotMoneyTradeRequest + 4, // 8: matchmaking.v1.Money.MoneyPlaceOrder:input_type -> matchmaking.v1.MoneyRequest + 7, // 9: matchmaking.v1.Money.MoneyUpdatePlaceOrder:input_type -> matchmaking.v1.UpdateMoneyRequest + 8, // 10: matchmaking.v1.Money.MoneyPosition:input_type -> matchmaking.v1.CancelMoneyRequest + 9, // 11: matchmaking.v1.Money.MoneyAllPosition:input_type -> matchmaking.v1.AllMoneyRequest + 8, // 12: matchmaking.v1.Money.MoneyCancel:input_type -> matchmaking.v1.CancelMoneyRequest + 4, // 13: matchmaking.v1.Money.MoneyOneClickRedemption:input_type -> matchmaking.v1.MoneyRequest + 1, // 14: matchmaking.v1.Money.GetBotMoneyTrade:output_type -> matchmaking.v1.GetBotMoneyTradeReply + 5, // 15: matchmaking.v1.Money.MoneyPlaceOrder:output_type -> matchmaking.v1.MoneyReply + 5, // 16: matchmaking.v1.Money.MoneyUpdatePlaceOrder:output_type -> matchmaking.v1.MoneyReply + 5, // 17: matchmaking.v1.Money.MoneyPosition:output_type -> matchmaking.v1.MoneyReply + 10, // 18: matchmaking.v1.Money.MoneyAllPosition:output_type -> matchmaking.v1.AllMoneyReply + 5, // 19: matchmaking.v1.Money.MoneyCancel:output_type -> matchmaking.v1.MoneyReply + 5, // 20: matchmaking.v1.Money.MoneyOneClickRedemption:output_type -> matchmaking.v1.MoneyReply + 14, // [14:21] is the sub-list for method output_type + 7, // [7:14] is the sub-list for method input_type + 7, // [7:7] is the sub-list for extension type_name + 7, // [7:7] is the sub-list for extension extendee + 0, // [0:7] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_money_money_proto_init() } +func file_matchmaking_v1_money_money_proto_init() { + if File_matchmaking_v1_money_money_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_matchmaking_v1_money_money_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*GetBotMoneyTradeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_money_money_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*GetBotMoneyTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_money_money_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*BotMoneyTradeData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_money_money_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*BotMoneyTrade); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_money_money_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*MoneyRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_money_money_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*MoneyReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_money_money_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*MoneyResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_money_money_proto_msgTypes[7].Exporter = func(v any, i int) any { + switch v := v.(*UpdateMoneyRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_money_money_proto_msgTypes[8].Exporter = func(v any, i int) any { + switch v := v.(*CancelMoneyRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_money_money_proto_msgTypes[9].Exporter = func(v any, i int) any { + switch v := v.(*AllMoneyRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_money_money_proto_msgTypes[10].Exporter = func(v any, i int) any { + switch v := v.(*AllMoneyReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_money_money_proto_rawDesc, + NumEnums: 0, + NumMessages: 11, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_matchmaking_v1_money_money_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_money_money_proto_depIdxs, + MessageInfos: file_matchmaking_v1_money_money_proto_msgTypes, + }.Build() + File_matchmaking_v1_money_money_proto = out.File + file_matchmaking_v1_money_money_proto_rawDesc = nil + file_matchmaking_v1_money_money_proto_goTypes = nil + file_matchmaking_v1_money_money_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/money/money.proto b/api/matchmaking/v1/money/money.proto new file mode 100644 index 0000000..b2559c7 --- /dev/null +++ b/api/matchmaking/v1/money/money.proto @@ -0,0 +1,160 @@ +syntax = "proto3"; + +package matchmaking.v1; + +import "google/api/annotations.proto"; +import "google/protobuf/timestamp.proto"; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +service Money { + // GetBotMoneyTrade 综合列表查询 + rpc GetBotMoneyTrade(GetBotMoneyTradeRequest)returns(GetBotMoneyTradeReply){ + option (google.api.http) = { + post:"/order_money/money_list", + body:"*", + }; + } + // MoneyPlaceOrder 综合下单 + rpc MoneyPlaceOrder(MoneyRequest)returns(MoneyReply){ + option (google.api.http) = { + post: "/order_money/money_place_order", + body: "*", + }; + } + // MoneyUpdatePlaceOrder 综合设置止盈止损 + rpc MoneyUpdatePlaceOrder(UpdateMoneyRequest)returns(MoneyReply){ + option (google.api.http) = { + post: "/order_money/money_update_order", + body: "*", + }; + } + // MoneyPosition 综合平仓 + rpc MoneyPosition(CancelMoneyRequest)returns(MoneyReply){ + option (google.api.http) = { + post:"/order_money/money_position", + body:"*", + }; + } + // MoneyAllPosition 综合一键平仓 + rpc MoneyAllPosition(AllMoneyRequest)returns(AllMoneyReply){ + option (google.api.http) = { + post:"/order_money/money_all_position", + body:"*", + }; + } + // MoneyCancel 综合撤单 + rpc MoneyCancel(CancelMoneyRequest)returns(MoneyReply){ + option (google.api.http) = { + post:"/order_money/money_cancel", + body:"*", + }; + } + // MoneyOneClickRedemption 现货一键兑换 + rpc MoneyOneClickRedemption(MoneyRequest)returns(MoneyReply){ + option (google.api.http) = { + post: "/order_money/money_one_click_redemption", + body: "*", + }; + } +} + +message GetBotMoneyTradeRequest{ + int64 status =1;// 状态码 + int64 pageSize =2; // 每页显示条数 + int64 pageCount =3;// 开始的位置 + int64 state = 4;// 订单类型 + int64 type = 5;// 订单市场 +} + +message GetBotMoneyTradeReply{ + int64 code =1;// 状态码 + BotMoneyTradeData data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message BotMoneyTradeData{ + int64 pageSize =1; // 每页显示条数 + int64 pageCount =2;// 开始的位置 + repeated BotMoneyTrade data =3;// 返回结果 + int64 totalCount =4;// 总数据 +} + +message BotMoneyTrade{ + string orderId =1;// 订单ID + string StockId =2;// 综合ID + int64 tradeType =3;// 交易类型 + int64 dealType =4;// 交易方式 + string limitPrice =5;// 限价 + string marketPrice =6;// 市价 + string dealPrice =7;// 开仓价 + string closingPrice =8;// 平仓价 + string orderNumber =9;// 订单数量 + int64 stopType =10;// 止盈止损状态 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string serviceCost =13;// 开仓手续费 + string earnestMoney =14;// 保证金 + string orderMoney =15;// 订单总额 + int64 status =16;// 订单状态 + google.protobuf.Timestamp createTime =17;// 订单创建时间 + google.protobuf.Timestamp updateTime =18;// 订单更新时间 + google.protobuf.Timestamp openTime =19;// 订单开仓时间 + google.protobuf.Timestamp closingTime =20;// 订单平仓时间 + string closingCost =21;// 平仓手续费 + string faceValue =22;// 面值 + string overnightCost =23;// 过夜手续费 + string pryNum =24;// 杠杆值 + string keepDecimal =25;// 保留小数位 + string secondTime = 26;// 秒综合时间 + int64 state = 27;// 订单类型 +} + +message MoneyRequest{ + string stockId =1;// 交易对 + int64 tradeType =2;// 交易类型:1买入,2卖出 + int64 dealType =3;// 委托方式:1限价,2市价 + string limitPrice =4;// 限价 + string marketPrice =5;// 市价 + string orderAmount =6;// 订单金额 + string orderNumber =7;// 订单数量 + string earnestMoney =8;// 保证金 + string serviceCost =9;// 手续费 + int64 stopType =10;// 止损止盈设置:0无设置,1止损止盈 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string pryNum =13;//杠杆 + int64 time = 14;// 秒综合时间 + int64 type = 15;// 交易市场 +} + +message MoneyReply{ + int64 code =1;// 状态码 + MoneyResult data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message MoneyResult { + string orderId =1;// 订单Id +} + +message UpdateMoneyRequest{ + string orderId =1;// 订单Id + int64 stopType =2;// 止盈止损 + string stopLossPrice =3;// 止损 + string stopWinPrice =4;// 止盈 +} + +message CancelMoneyRequest{ + string orderId =1;// 订单ID +} + +message AllMoneyRequest{ + +} + +message AllMoneyReply{ + int64 code =1;// 状态码 + string data =2;// 返回结果 + string message =3;// 返回消息提示 +} \ No newline at end of file diff --git a/api/matchmaking/v1/money/money_grpc.pb.go b/api/matchmaking/v1/money/money_grpc.pb.go new file mode 100644 index 0000000..78858ba --- /dev/null +++ b/api/matchmaking/v1/money/money_grpc.pb.go @@ -0,0 +1,352 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.1 +// source: matchmaking/v1/money/money.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + Money_GetBotMoneyTrade_FullMethodName = "/matchmaking.v1.Money/GetBotMoneyTrade" + Money_MoneyPlaceOrder_FullMethodName = "/matchmaking.v1.Money/MoneyPlaceOrder" + Money_MoneyUpdatePlaceOrder_FullMethodName = "/matchmaking.v1.Money/MoneyUpdatePlaceOrder" + Money_MoneyPosition_FullMethodName = "/matchmaking.v1.Money/MoneyPosition" + Money_MoneyAllPosition_FullMethodName = "/matchmaking.v1.Money/MoneyAllPosition" + Money_MoneyCancel_FullMethodName = "/matchmaking.v1.Money/MoneyCancel" + Money_MoneyOneClickRedemption_FullMethodName = "/matchmaking.v1.Money/MoneyOneClickRedemption" +) + +// MoneyClient is the client API for Money service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type MoneyClient interface { + // GetBotMoneyTrade 综合列表查询 + GetBotMoneyTrade(ctx context.Context, in *GetBotMoneyTradeRequest, opts ...grpc.CallOption) (*GetBotMoneyTradeReply, error) + // MoneyPlaceOrder 综合下单 + MoneyPlaceOrder(ctx context.Context, in *MoneyRequest, opts ...grpc.CallOption) (*MoneyReply, error) + // MoneyUpdatePlaceOrder 综合设置止盈止损 + MoneyUpdatePlaceOrder(ctx context.Context, in *UpdateMoneyRequest, opts ...grpc.CallOption) (*MoneyReply, error) + // MoneyPosition 综合平仓 + MoneyPosition(ctx context.Context, in *CancelMoneyRequest, opts ...grpc.CallOption) (*MoneyReply, error) + // MoneyAllPosition 综合一键平仓 + MoneyAllPosition(ctx context.Context, in *AllMoneyRequest, opts ...grpc.CallOption) (*AllMoneyReply, error) + // MoneyCancel 综合撤单 + MoneyCancel(ctx context.Context, in *CancelMoneyRequest, opts ...grpc.CallOption) (*MoneyReply, error) + // MoneyOneClickRedemption 现货一键兑换 + MoneyOneClickRedemption(ctx context.Context, in *MoneyRequest, opts ...grpc.CallOption) (*MoneyReply, error) +} + +type moneyClient struct { + cc grpc.ClientConnInterface +} + +func NewMoneyClient(cc grpc.ClientConnInterface) MoneyClient { + return &moneyClient{cc} +} + +func (c *moneyClient) GetBotMoneyTrade(ctx context.Context, in *GetBotMoneyTradeRequest, opts ...grpc.CallOption) (*GetBotMoneyTradeReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetBotMoneyTradeReply) + err := c.cc.Invoke(ctx, Money_GetBotMoneyTrade_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *moneyClient) MoneyPlaceOrder(ctx context.Context, in *MoneyRequest, opts ...grpc.CallOption) (*MoneyReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(MoneyReply) + err := c.cc.Invoke(ctx, Money_MoneyPlaceOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *moneyClient) MoneyUpdatePlaceOrder(ctx context.Context, in *UpdateMoneyRequest, opts ...grpc.CallOption) (*MoneyReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(MoneyReply) + err := c.cc.Invoke(ctx, Money_MoneyUpdatePlaceOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *moneyClient) MoneyPosition(ctx context.Context, in *CancelMoneyRequest, opts ...grpc.CallOption) (*MoneyReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(MoneyReply) + err := c.cc.Invoke(ctx, Money_MoneyPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *moneyClient) MoneyAllPosition(ctx context.Context, in *AllMoneyRequest, opts ...grpc.CallOption) (*AllMoneyReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AllMoneyReply) + err := c.cc.Invoke(ctx, Money_MoneyAllPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *moneyClient) MoneyCancel(ctx context.Context, in *CancelMoneyRequest, opts ...grpc.CallOption) (*MoneyReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(MoneyReply) + err := c.cc.Invoke(ctx, Money_MoneyCancel_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *moneyClient) MoneyOneClickRedemption(ctx context.Context, in *MoneyRequest, opts ...grpc.CallOption) (*MoneyReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(MoneyReply) + err := c.cc.Invoke(ctx, Money_MoneyOneClickRedemption_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MoneyServer is the server API for Money service. +// All implementations must embed UnimplementedMoneyServer +// for forward compatibility +type MoneyServer interface { + // GetBotMoneyTrade 综合列表查询 + GetBotMoneyTrade(context.Context, *GetBotMoneyTradeRequest) (*GetBotMoneyTradeReply, error) + // MoneyPlaceOrder 综合下单 + MoneyPlaceOrder(context.Context, *MoneyRequest) (*MoneyReply, error) + // MoneyUpdatePlaceOrder 综合设置止盈止损 + MoneyUpdatePlaceOrder(context.Context, *UpdateMoneyRequest) (*MoneyReply, error) + // MoneyPosition 综合平仓 + MoneyPosition(context.Context, *CancelMoneyRequest) (*MoneyReply, error) + // MoneyAllPosition 综合一键平仓 + MoneyAllPosition(context.Context, *AllMoneyRequest) (*AllMoneyReply, error) + // MoneyCancel 综合撤单 + MoneyCancel(context.Context, *CancelMoneyRequest) (*MoneyReply, error) + // MoneyOneClickRedemption 现货一键兑换 + MoneyOneClickRedemption(context.Context, *MoneyRequest) (*MoneyReply, error) + mustEmbedUnimplementedMoneyServer() +} + +// UnimplementedMoneyServer must be embedded to have forward compatible implementations. +type UnimplementedMoneyServer struct { +} + +func (UnimplementedMoneyServer) GetBotMoneyTrade(context.Context, *GetBotMoneyTradeRequest) (*GetBotMoneyTradeReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBotMoneyTrade not implemented") +} +func (UnimplementedMoneyServer) MoneyPlaceOrder(context.Context, *MoneyRequest) (*MoneyReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method MoneyPlaceOrder not implemented") +} +func (UnimplementedMoneyServer) MoneyUpdatePlaceOrder(context.Context, *UpdateMoneyRequest) (*MoneyReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method MoneyUpdatePlaceOrder not implemented") +} +func (UnimplementedMoneyServer) MoneyPosition(context.Context, *CancelMoneyRequest) (*MoneyReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method MoneyPosition not implemented") +} +func (UnimplementedMoneyServer) MoneyAllPosition(context.Context, *AllMoneyRequest) (*AllMoneyReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method MoneyAllPosition not implemented") +} +func (UnimplementedMoneyServer) MoneyCancel(context.Context, *CancelMoneyRequest) (*MoneyReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method MoneyCancel not implemented") +} +func (UnimplementedMoneyServer) MoneyOneClickRedemption(context.Context, *MoneyRequest) (*MoneyReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method MoneyOneClickRedemption not implemented") +} +func (UnimplementedMoneyServer) mustEmbedUnimplementedMoneyServer() {} + +// UnsafeMoneyServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to MoneyServer will +// result in compilation errors. +type UnsafeMoneyServer interface { + mustEmbedUnimplementedMoneyServer() +} + +func RegisterMoneyServer(s grpc.ServiceRegistrar, srv MoneyServer) { + s.RegisterService(&Money_ServiceDesc, srv) +} + +func _Money_GetBotMoneyTrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetBotMoneyTradeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MoneyServer).GetBotMoneyTrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Money_GetBotMoneyTrade_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MoneyServer).GetBotMoneyTrade(ctx, req.(*GetBotMoneyTradeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Money_MoneyPlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MoneyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MoneyServer).MoneyPlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Money_MoneyPlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MoneyServer).MoneyPlaceOrder(ctx, req.(*MoneyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Money_MoneyUpdatePlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateMoneyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MoneyServer).MoneyUpdatePlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Money_MoneyUpdatePlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MoneyServer).MoneyUpdatePlaceOrder(ctx, req.(*UpdateMoneyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Money_MoneyPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelMoneyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MoneyServer).MoneyPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Money_MoneyPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MoneyServer).MoneyPosition(ctx, req.(*CancelMoneyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Money_MoneyAllPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AllMoneyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MoneyServer).MoneyAllPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Money_MoneyAllPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MoneyServer).MoneyAllPosition(ctx, req.(*AllMoneyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Money_MoneyCancel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelMoneyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MoneyServer).MoneyCancel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Money_MoneyCancel_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MoneyServer).MoneyCancel(ctx, req.(*CancelMoneyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Money_MoneyOneClickRedemption_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MoneyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MoneyServer).MoneyOneClickRedemption(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Money_MoneyOneClickRedemption_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MoneyServer).MoneyOneClickRedemption(ctx, req.(*MoneyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Money_ServiceDesc is the grpc.ServiceDesc for Money service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Money_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "matchmaking.v1.Money", + HandlerType: (*MoneyServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetBotMoneyTrade", + Handler: _Money_GetBotMoneyTrade_Handler, + }, + { + MethodName: "MoneyPlaceOrder", + Handler: _Money_MoneyPlaceOrder_Handler, + }, + { + MethodName: "MoneyUpdatePlaceOrder", + Handler: _Money_MoneyUpdatePlaceOrder_Handler, + }, + { + MethodName: "MoneyPosition", + Handler: _Money_MoneyPosition_Handler, + }, + { + MethodName: "MoneyAllPosition", + Handler: _Money_MoneyAllPosition_Handler, + }, + { + MethodName: "MoneyCancel", + Handler: _Money_MoneyCancel_Handler, + }, + { + MethodName: "MoneyOneClickRedemption", + Handler: _Money_MoneyOneClickRedemption_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "matchmaking/v1/money/money.proto", +} diff --git a/api/matchmaking/v1/money/money_http.pb.go b/api/matchmaking/v1/money/money_http.pb.go new file mode 100644 index 0000000..d0b3443 --- /dev/null +++ b/api/matchmaking/v1/money/money_http.pb.go @@ -0,0 +1,319 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.3 +// - protoc v5.27.1 +// source: matchmaking/v1/money/money.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationMoneyGetBotMoneyTrade = "/matchmaking.v1.Money/GetBotMoneyTrade" +const OperationMoneyMoneyAllPosition = "/matchmaking.v1.Money/MoneyAllPosition" +const OperationMoneyMoneyCancel = "/matchmaking.v1.Money/MoneyCancel" +const OperationMoneyMoneyOneClickRedemption = "/matchmaking.v1.Money/MoneyOneClickRedemption" +const OperationMoneyMoneyPlaceOrder = "/matchmaking.v1.Money/MoneyPlaceOrder" +const OperationMoneyMoneyPosition = "/matchmaking.v1.Money/MoneyPosition" +const OperationMoneyMoneyUpdatePlaceOrder = "/matchmaking.v1.Money/MoneyUpdatePlaceOrder" + +type MoneyHTTPServer interface { + // GetBotMoneyTrade GetBotMoneyTrade 综合列表查询 + GetBotMoneyTrade(context.Context, *GetBotMoneyTradeRequest) (*GetBotMoneyTradeReply, error) + // MoneyAllPosition MoneyAllPosition 综合一键平仓 + MoneyAllPosition(context.Context, *AllMoneyRequest) (*AllMoneyReply, error) + // MoneyCancel MoneyCancel 综合撤单 + MoneyCancel(context.Context, *CancelMoneyRequest) (*MoneyReply, error) + // MoneyOneClickRedemption MoneyOneClickRedemption 现货一键兑换 + MoneyOneClickRedemption(context.Context, *MoneyRequest) (*MoneyReply, error) + // MoneyPlaceOrder MoneyPlaceOrder 综合下单 + MoneyPlaceOrder(context.Context, *MoneyRequest) (*MoneyReply, error) + // MoneyPosition MoneyPosition 综合平仓 + MoneyPosition(context.Context, *CancelMoneyRequest) (*MoneyReply, error) + // MoneyUpdatePlaceOrder MoneyUpdatePlaceOrder 综合设置止盈止损 + MoneyUpdatePlaceOrder(context.Context, *UpdateMoneyRequest) (*MoneyReply, error) +} + +func RegisterMoneyHTTPServer(s *http.Server, srv MoneyHTTPServer) { + r := s.Route("/") + r.POST("/order_money/money_list", _Money_GetBotMoneyTrade0_HTTP_Handler(srv)) + r.POST("/order_money/money_place_order", _Money_MoneyPlaceOrder0_HTTP_Handler(srv)) + r.POST("/order_money/money_update_order", _Money_MoneyUpdatePlaceOrder0_HTTP_Handler(srv)) + r.POST("/order_money/money_position", _Money_MoneyPosition0_HTTP_Handler(srv)) + r.POST("/order_money/money_all_position", _Money_MoneyAllPosition0_HTTP_Handler(srv)) + r.POST("/order_money/money_cancel", _Money_MoneyCancel0_HTTP_Handler(srv)) + r.POST("/order_money/money_one_click_redemption", _Money_MoneyOneClickRedemption0_HTTP_Handler(srv)) +} + +func _Money_GetBotMoneyTrade0_HTTP_Handler(srv MoneyHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetBotMoneyTradeRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationMoneyGetBotMoneyTrade) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.GetBotMoneyTrade(ctx, req.(*GetBotMoneyTradeRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetBotMoneyTradeReply) + return ctx.Result(200, reply) + } +} + +func _Money_MoneyPlaceOrder0_HTTP_Handler(srv MoneyHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in MoneyRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationMoneyMoneyPlaceOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.MoneyPlaceOrder(ctx, req.(*MoneyRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*MoneyReply) + return ctx.Result(200, reply) + } +} + +func _Money_MoneyUpdatePlaceOrder0_HTTP_Handler(srv MoneyHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in UpdateMoneyRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationMoneyMoneyUpdatePlaceOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.MoneyUpdatePlaceOrder(ctx, req.(*UpdateMoneyRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*MoneyReply) + return ctx.Result(200, reply) + } +} + +func _Money_MoneyPosition0_HTTP_Handler(srv MoneyHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelMoneyRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationMoneyMoneyPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.MoneyPosition(ctx, req.(*CancelMoneyRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*MoneyReply) + return ctx.Result(200, reply) + } +} + +func _Money_MoneyAllPosition0_HTTP_Handler(srv MoneyHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in AllMoneyRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationMoneyMoneyAllPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.MoneyAllPosition(ctx, req.(*AllMoneyRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*AllMoneyReply) + return ctx.Result(200, reply) + } +} + +func _Money_MoneyCancel0_HTTP_Handler(srv MoneyHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelMoneyRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationMoneyMoneyCancel) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.MoneyCancel(ctx, req.(*CancelMoneyRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*MoneyReply) + return ctx.Result(200, reply) + } +} + +func _Money_MoneyOneClickRedemption0_HTTP_Handler(srv MoneyHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in MoneyRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationMoneyMoneyOneClickRedemption) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.MoneyOneClickRedemption(ctx, req.(*MoneyRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*MoneyReply) + return ctx.Result(200, reply) + } +} + +type MoneyHTTPClient interface { + GetBotMoneyTrade(ctx context.Context, req *GetBotMoneyTradeRequest, opts ...http.CallOption) (rsp *GetBotMoneyTradeReply, err error) + MoneyAllPosition(ctx context.Context, req *AllMoneyRequest, opts ...http.CallOption) (rsp *AllMoneyReply, err error) + MoneyCancel(ctx context.Context, req *CancelMoneyRequest, opts ...http.CallOption) (rsp *MoneyReply, err error) + MoneyOneClickRedemption(ctx context.Context, req *MoneyRequest, opts ...http.CallOption) (rsp *MoneyReply, err error) + MoneyPlaceOrder(ctx context.Context, req *MoneyRequest, opts ...http.CallOption) (rsp *MoneyReply, err error) + MoneyPosition(ctx context.Context, req *CancelMoneyRequest, opts ...http.CallOption) (rsp *MoneyReply, err error) + MoneyUpdatePlaceOrder(ctx context.Context, req *UpdateMoneyRequest, opts ...http.CallOption) (rsp *MoneyReply, err error) +} + +type MoneyHTTPClientImpl struct { + cc *http.Client +} + +func NewMoneyHTTPClient(client *http.Client) MoneyHTTPClient { + return &MoneyHTTPClientImpl{client} +} + +func (c *MoneyHTTPClientImpl) GetBotMoneyTrade(ctx context.Context, in *GetBotMoneyTradeRequest, opts ...http.CallOption) (*GetBotMoneyTradeReply, error) { + var out GetBotMoneyTradeReply + pattern := "/order_money/money_list" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationMoneyGetBotMoneyTrade)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *MoneyHTTPClientImpl) MoneyAllPosition(ctx context.Context, in *AllMoneyRequest, opts ...http.CallOption) (*AllMoneyReply, error) { + var out AllMoneyReply + pattern := "/order_money/money_all_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationMoneyMoneyAllPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *MoneyHTTPClientImpl) MoneyCancel(ctx context.Context, in *CancelMoneyRequest, opts ...http.CallOption) (*MoneyReply, error) { + var out MoneyReply + pattern := "/order_money/money_cancel" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationMoneyMoneyCancel)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *MoneyHTTPClientImpl) MoneyOneClickRedemption(ctx context.Context, in *MoneyRequest, opts ...http.CallOption) (*MoneyReply, error) { + var out MoneyReply + pattern := "/order_money/money_one_click_redemption" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationMoneyMoneyOneClickRedemption)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *MoneyHTTPClientImpl) MoneyPlaceOrder(ctx context.Context, in *MoneyRequest, opts ...http.CallOption) (*MoneyReply, error) { + var out MoneyReply + pattern := "/order_money/money_place_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationMoneyMoneyPlaceOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *MoneyHTTPClientImpl) MoneyPosition(ctx context.Context, in *CancelMoneyRequest, opts ...http.CallOption) (*MoneyReply, error) { + var out MoneyReply + pattern := "/order_money/money_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationMoneyMoneyPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *MoneyHTTPClientImpl) MoneyUpdatePlaceOrder(ctx context.Context, in *UpdateMoneyRequest, opts ...http.CallOption) (*MoneyReply, error) { + var out MoneyReply + pattern := "/order_money/money_update_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationMoneyMoneyUpdatePlaceOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/api/matchmaking/v1/option/optionInr.pb.go b/api/matchmaking/v1/option/optionInr.pb.go new file mode 100644 index 0000000..631beee --- /dev/null +++ b/api/matchmaking/v1/option/optionInr.pb.go @@ -0,0 +1,1508 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/option/optionInr.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type CancelOptionInrOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID +} + +func (x *CancelOptionInrOrderRequest) Reset() { + *x = CancelOptionInrOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CancelOptionInrOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CancelOptionInrOrderRequest) ProtoMessage() {} + +func (x *CancelOptionInrOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CancelOptionInrOrderRequest.ProtoReflect.Descriptor instead. +func (*CancelOptionInrOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_option_optionInr_proto_rawDescGZIP(), []int{0} +} + +func (x *CancelOptionInrOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type UpdateOptionInrOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id + StopType int64 `protobuf:"varint,2,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,3,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,4,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 +} + +func (x *UpdateOptionInrOrderRequest) Reset() { + *x = UpdateOptionInrOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateOptionInrOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateOptionInrOrderRequest) ProtoMessage() {} + +func (x *UpdateOptionInrOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateOptionInrOrderRequest.ProtoReflect.Descriptor instead. +func (*UpdateOptionInrOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_option_optionInr_proto_rawDescGZIP(), []int{1} +} + +func (x *UpdateOptionInrOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *UpdateOptionInrOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *UpdateOptionInrOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *UpdateOptionInrOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +type OptionInrOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + StockId string `protobuf:"bytes,1,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票类型 + TradeType int64 `protobuf:"varint,2,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型:1看涨(calls-CE),2看跌(puts-PE) + DealType int64 `protobuf:"varint,3,opt,name=dealType,proto3" json:"dealType,omitempty"` // 委托方式:1限价,2市价 + LimitPrice string `protobuf:"bytes,4,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,5,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + MarketMoney string `protobuf:"bytes,6,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderNumber string `protobuf:"bytes,7,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + ServiceCost string `protobuf:"bytes,8,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 手续费 + StopType int64 `protobuf:"varint,9,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止损止盈设置:1无设置,2止损止盈 + StopLossPrice string `protobuf:"bytes,10,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,11,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止损 + PryNum string `protobuf:"bytes,12,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 + StopTime string `protobuf:"bytes,13,opt,name=stopTime,proto3" json:"stopTime,omitempty"` // 到期时间 + StrikePrice string `protobuf:"bytes,14,opt,name=strikePrice,proto3" json:"strikePrice,omitempty"` // 行权价 + TradingType int64 `protobuf:"varint,15,opt,name=tradingType,proto3" json:"tradingType,omitempty"` // 交易方式:1买入(buy),2卖出(sell) + StockCode string `protobuf:"bytes,16,opt,name=stockCode,proto3" json:"stockCode,omitempty"` // 期权订单标识(stockId+到期时间+行权价+(CE|PE)) + Multiplier string `protobuf:"bytes,17,opt,name=multiplier,proto3" json:"multiplier,omitempty"` // 期权乘数 + Ask string `protobuf:"bytes,18,opt,name=ask,proto3" json:"ask,omitempty"` // 卖一价(ask) + Bid string `protobuf:"bytes,19,opt,name=bid,proto3" json:"bid,omitempty"` // 买一价(bid) +} + +func (x *OptionInrOrderRequest) Reset() { + *x = OptionInrOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OptionInrOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OptionInrOrderRequest) ProtoMessage() {} + +func (x *OptionInrOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OptionInrOrderRequest.ProtoReflect.Descriptor instead. +func (*OptionInrOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_option_optionInr_proto_rawDescGZIP(), []int{2} +} + +func (x *OptionInrOrderRequest) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *OptionInrOrderRequest) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *OptionInrOrderRequest) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *OptionInrOrderRequest) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *OptionInrOrderRequest) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *OptionInrOrderRequest) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *OptionInrOrderRequest) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *OptionInrOrderRequest) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *OptionInrOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *OptionInrOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *OptionInrOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *OptionInrOrderRequest) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *OptionInrOrderRequest) GetStopTime() string { + if x != nil { + return x.StopTime + } + return "" +} + +func (x *OptionInrOrderRequest) GetStrikePrice() string { + if x != nil { + return x.StrikePrice + } + return "" +} + +func (x *OptionInrOrderRequest) GetTradingType() int64 { + if x != nil { + return x.TradingType + } + return 0 +} + +func (x *OptionInrOrderRequest) GetStockCode() string { + if x != nil { + return x.StockCode + } + return "" +} + +func (x *OptionInrOrderRequest) GetMultiplier() string { + if x != nil { + return x.Multiplier + } + return "" +} + +func (x *OptionInrOrderRequest) GetAsk() string { + if x != nil { + return x.Ask + } + return "" +} + +func (x *OptionInrOrderRequest) GetBid() string { + if x != nil { + return x.Bid + } + return "" +} + +type GetBotStockOptionInrTradeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status int64 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` // 状态码 + PageSize int64 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,3,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 +} + +func (x *GetBotStockOptionInrTradeRequest) Reset() { + *x = GetBotStockOptionInrTradeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotStockOptionInrTradeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotStockOptionInrTradeRequest) ProtoMessage() {} + +func (x *GetBotStockOptionInrTradeRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotStockOptionInrTradeRequest.ProtoReflect.Descriptor instead. +func (*GetBotStockOptionInrTradeRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_option_optionInr_proto_rawDescGZIP(), []int{3} +} + +func (x *GetBotStockOptionInrTradeRequest) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *GetBotStockOptionInrTradeRequest) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *GetBotStockOptionInrTradeRequest) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +type GetBotStockOptionInrTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *BotStockOptionInrTradeData `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *GetBotStockOptionInrTradeReply) Reset() { + *x = GetBotStockOptionInrTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotStockOptionInrTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotStockOptionInrTradeReply) ProtoMessage() {} + +func (x *GetBotStockOptionInrTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotStockOptionInrTradeReply.ProtoReflect.Descriptor instead. +func (*GetBotStockOptionInrTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_option_optionInr_proto_rawDescGZIP(), []int{4} +} + +func (x *GetBotStockOptionInrTradeReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *GetBotStockOptionInrTradeReply) GetData() *BotStockOptionInrTradeData { + if x != nil { + return x.Data + } + return nil +} + +func (x *GetBotStockOptionInrTradeReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type BotStockOptionInrTradeData struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PageSize int64 `protobuf:"varint,1,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,2,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + Data []*BotStockOptionInrTrade `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty"` // 返回结果 + TotalCount int64 `protobuf:"varint,4,opt,name=totalCount,proto3" json:"totalCount,omitempty"` // 总数据 +} + +func (x *BotStockOptionInrTradeData) Reset() { + *x = BotStockOptionInrTradeData{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockOptionInrTradeData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockOptionInrTradeData) ProtoMessage() {} + +func (x *BotStockOptionInrTradeData) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockOptionInrTradeData.ProtoReflect.Descriptor instead. +func (*BotStockOptionInrTradeData) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_option_optionInr_proto_rawDescGZIP(), []int{5} +} + +func (x *BotStockOptionInrTradeData) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *BotStockOptionInrTradeData) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *BotStockOptionInrTradeData) GetData() []*BotStockOptionInrTrade { + if x != nil { + return x.Data + } + return nil +} + +func (x *BotStockOptionInrTradeData) GetTotalCount() int64 { + if x != nil { + return x.TotalCount + } + return 0 +} + +type BotStockOptionInrTrade struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID + StockId string `protobuf:"bytes,2,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票代码 + TradeType int64 `protobuf:"varint,3,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型 + DealType int64 `protobuf:"varint,4,opt,name=dealType,proto3" json:"dealType,omitempty"` // 交易方式 + LimitPrice string `protobuf:"bytes,5,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,6,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + DealPrice string `protobuf:"bytes,7,opt,name=dealPrice,proto3" json:"dealPrice,omitempty"` // 开仓价 + ClosingPrice string `protobuf:"bytes,8,opt,name=closingPrice,proto3" json:"closingPrice,omitempty"` // 平仓价 + OrderNumber string `protobuf:"bytes,9,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + ServiceCost string `protobuf:"bytes,13,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 开仓手续费 + MarketMoney string `protobuf:"bytes,14,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderMoney string `protobuf:"bytes,15,opt,name=orderMoney,proto3" json:"orderMoney,omitempty"` // 订单总金额 + Status int64 `protobuf:"varint,16,opt,name=status,proto3" json:"status,omitempty"` // 订单状态 + CreateTime *timestamppb.Timestamp `protobuf:"bytes,17,opt,name=createTime,proto3" json:"createTime,omitempty"` // 订单创建时间 + UpdateTime *timestamppb.Timestamp `protobuf:"bytes,18,opt,name=updateTime,proto3" json:"updateTime,omitempty"` // 订单更新时间 + OpenTime *timestamppb.Timestamp `protobuf:"bytes,19,opt,name=openTime,proto3" json:"openTime,omitempty"` // 订单开仓时间 + ClosingTime *timestamppb.Timestamp `protobuf:"bytes,20,opt,name=closingTime,proto3" json:"closingTime,omitempty"` // 订单平仓时间 + ClosingCost string `protobuf:"bytes,21,opt,name=closingCost,proto3" json:"closingCost,omitempty"` // 平仓手续费 + FaceValue string `protobuf:"bytes,22,opt,name=faceValue,proto3" json:"faceValue,omitempty"` // 面值 + PryNum string `protobuf:"bytes,23,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 + KeepDecimal string `protobuf:"bytes,24,opt,name=keepDecimal,proto3" json:"keepDecimal,omitempty"` // 保留小数位 + StockName string `protobuf:"bytes,25,opt,name=stockName,proto3" json:"stockName,omitempty"` // 股票名称 + StopTime string `protobuf:"bytes,26,opt,name=stopTime,proto3" json:"stopTime,omitempty"` // 期权时间 + StrikePrice string `protobuf:"bytes,27,opt,name=strikePrice,proto3" json:"strikePrice,omitempty"` // 权利金 + TradingType int64 `protobuf:"varint,28,opt,name=tradingType,proto3" json:"tradingType,omitempty"` // 交易方式 + StockCode string `protobuf:"bytes,29,opt,name=stockCode,proto3" json:"stockCode,omitempty"` // 期权订单标识(stockId+到期时间+行权价+(CE|PE)) + Multiplier int64 `protobuf:"varint,30,opt,name=multiplier,proto3" json:"multiplier,omitempty"` // 期权乘数 + CostPrice string `protobuf:"bytes,31,opt,name=costPrice,proto3" json:"costPrice,omitempty"` // 成本价格 + Ratio int64 `protobuf:"varint,32,opt,name=ratio,proto3" json:"ratio,omitempty"` // 保证金比例 + Bid string `protobuf:"bytes,33,opt,name=bid,proto3" json:"bid,omitempty"` // 买一价 + Ask string `protobuf:"bytes,34,opt,name=ask,proto3" json:"ask,omitempty"` // 卖一价 +} + +func (x *BotStockOptionInrTrade) Reset() { + *x = BotStockOptionInrTrade{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockOptionInrTrade) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockOptionInrTrade) ProtoMessage() {} + +func (x *BotStockOptionInrTrade) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockOptionInrTrade.ProtoReflect.Descriptor instead. +func (*BotStockOptionInrTrade) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_option_optionInr_proto_rawDescGZIP(), []int{6} +} + +func (x *BotStockOptionInrTrade) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *BotStockOptionInrTrade) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *BotStockOptionInrTrade) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *BotStockOptionInrTrade) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *BotStockOptionInrTrade) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *BotStockOptionInrTrade) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *BotStockOptionInrTrade) GetDealPrice() string { + if x != nil { + return x.DealPrice + } + return "" +} + +func (x *BotStockOptionInrTrade) GetClosingPrice() string { + if x != nil { + return x.ClosingPrice + } + return "" +} + +func (x *BotStockOptionInrTrade) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *BotStockOptionInrTrade) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *BotStockOptionInrTrade) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *BotStockOptionInrTrade) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *BotStockOptionInrTrade) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *BotStockOptionInrTrade) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *BotStockOptionInrTrade) GetOrderMoney() string { + if x != nil { + return x.OrderMoney + } + return "" +} + +func (x *BotStockOptionInrTrade) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *BotStockOptionInrTrade) GetCreateTime() *timestamppb.Timestamp { + if x != nil { + return x.CreateTime + } + return nil +} + +func (x *BotStockOptionInrTrade) GetUpdateTime() *timestamppb.Timestamp { + if x != nil { + return x.UpdateTime + } + return nil +} + +func (x *BotStockOptionInrTrade) GetOpenTime() *timestamppb.Timestamp { + if x != nil { + return x.OpenTime + } + return nil +} + +func (x *BotStockOptionInrTrade) GetClosingTime() *timestamppb.Timestamp { + if x != nil { + return x.ClosingTime + } + return nil +} + +func (x *BotStockOptionInrTrade) GetClosingCost() string { + if x != nil { + return x.ClosingCost + } + return "" +} + +func (x *BotStockOptionInrTrade) GetFaceValue() string { + if x != nil { + return x.FaceValue + } + return "" +} + +func (x *BotStockOptionInrTrade) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *BotStockOptionInrTrade) GetKeepDecimal() string { + if x != nil { + return x.KeepDecimal + } + return "" +} + +func (x *BotStockOptionInrTrade) GetStockName() string { + if x != nil { + return x.StockName + } + return "" +} + +func (x *BotStockOptionInrTrade) GetStopTime() string { + if x != nil { + return x.StopTime + } + return "" +} + +func (x *BotStockOptionInrTrade) GetStrikePrice() string { + if x != nil { + return x.StrikePrice + } + return "" +} + +func (x *BotStockOptionInrTrade) GetTradingType() int64 { + if x != nil { + return x.TradingType + } + return 0 +} + +func (x *BotStockOptionInrTrade) GetStockCode() string { + if x != nil { + return x.StockCode + } + return "" +} + +func (x *BotStockOptionInrTrade) GetMultiplier() int64 { + if x != nil { + return x.Multiplier + } + return 0 +} + +func (x *BotStockOptionInrTrade) GetCostPrice() string { + if x != nil { + return x.CostPrice + } + return "" +} + +func (x *BotStockOptionInrTrade) GetRatio() int64 { + if x != nil { + return x.Ratio + } + return 0 +} + +func (x *BotStockOptionInrTrade) GetBid() string { + if x != nil { + return x.Bid + } + return "" +} + +func (x *BotStockOptionInrTrade) GetAsk() string { + if x != nil { + return x.Ask + } + return "" +} + +type OptionInrOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *OptionInrOrderResult `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *OptionInrOrderReply) Reset() { + *x = OptionInrOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OptionInrOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OptionInrOrderReply) ProtoMessage() {} + +func (x *OptionInrOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OptionInrOrderReply.ProtoReflect.Descriptor instead. +func (*OptionInrOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_option_optionInr_proto_rawDescGZIP(), []int{7} +} + +func (x *OptionInrOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *OptionInrOrderReply) GetData() *OptionInrOrderResult { + if x != nil { + return x.Data + } + return nil +} + +func (x *OptionInrOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type OptionInrOrderResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id +} + +func (x *OptionInrOrderResult) Reset() { + *x = OptionInrOrderResult{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OptionInrOrderResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OptionInrOrderResult) ProtoMessage() {} + +func (x *OptionInrOrderResult) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OptionInrOrderResult.ProtoReflect.Descriptor instead. +func (*OptionInrOrderResult) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_option_optionInr_proto_rawDescGZIP(), []int{8} +} + +func (x *OptionInrOrderResult) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type AllOptionInrOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *AllOptionInrOrderRequest) Reset() { + *x = AllOptionInrOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllOptionInrOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllOptionInrOrderRequest) ProtoMessage() {} + +func (x *AllOptionInrOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllOptionInrOrderRequest.ProtoReflect.Descriptor instead. +func (*AllOptionInrOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_option_optionInr_proto_rawDescGZIP(), []int{9} +} + +type AllOptionInrOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *AllOptionInrOrderReply) Reset() { + *x = AllOptionInrOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllOptionInrOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllOptionInrOrderReply) ProtoMessage() {} + +func (x *AllOptionInrOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_option_optionInr_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllOptionInrOrderReply.ProtoReflect.Descriptor instead. +func (*AllOptionInrOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_option_optionInr_proto_rawDescGZIP(), []int{10} +} + +func (x *AllOptionInrOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *AllOptionInrOrderReply) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +func (x *AllOptionInrOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_matchmaking_v1_option_optionInr_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_option_optionInr_proto_rawDesc = []byte{ + 0x0a, 0x25, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, + 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, + 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, + 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x37, 0x0a, 0x1b, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, + 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x22, + 0x9d, 0x01, 0x0a, 0x1b, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, + 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, + 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, + 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, + 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, + 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, + 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x22, + 0xd3, 0x04, 0x0a, 0x15, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, + 0x63, 0x6b, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x63, + 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, + 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, + 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, + 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, + 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x06, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, + 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, + 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, + 0x62, 0x65, 0x72, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, + 0x73, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, + 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, + 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, + 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, + 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, + 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x70, + 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, 0x79, + 0x4e, 0x75, 0x6d, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x69, 0x6d, 0x65, 0x18, + 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x69, 0x6d, 0x65, 0x12, + 0x20, 0x0a, 0x0b, 0x73, 0x74, 0x72, 0x69, 0x6b, 0x65, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0e, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x74, 0x72, 0x69, 0x6b, 0x65, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x74, 0x72, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x54, 0x79, 0x70, 0x65, + 0x18, 0x0f, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x74, 0x72, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x54, + 0x79, 0x70, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x43, 0x6f, 0x64, 0x65, + 0x18, 0x10, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x43, 0x6f, 0x64, + 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x18, + 0x11, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x6c, 0x69, 0x65, + 0x72, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x73, 0x6b, 0x18, 0x12, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, + 0x61, 0x73, 0x6b, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x69, 0x64, 0x18, 0x13, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x03, 0x62, 0x69, 0x64, 0x22, 0x74, 0x0a, 0x20, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, + 0x74, 0x6f, 0x63, 0x6b, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x54, 0x72, 0x61, + 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, + 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, + 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x8e, 0x01, 0x0a, 0x1e, + 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x4f, 0x70, 0x74, 0x69, 0x6f, + 0x6e, 0x49, 0x6e, 0x72, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, + 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, + 0x64, 0x65, 0x12, 0x3e, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x2a, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, + 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, + 0x49, 0x6e, 0x72, 0x54, 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, + 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xb2, 0x01, 0x0a, + 0x1a, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, + 0x6e, 0x72, 0x54, 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, 0x61, 0x12, 0x1a, 0x0a, 0x08, 0x70, + 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, + 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, + 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, + 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x3a, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, + 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x4f, 0x70, 0x74, + 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x04, 0x64, 0x61, 0x74, + 0x61, 0x12, 0x1e, 0x0a, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, + 0x74, 0x22, 0x8a, 0x09, 0x0a, 0x16, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x4f, 0x70, + 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, + 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, + 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, + 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, + 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, + 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, + 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, + 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1c, 0x0a, 0x09, + 0x64, 0x65, 0x61, 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x09, 0x64, 0x65, 0x61, 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6c, + 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0c, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, + 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x09, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, + 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0a, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, + 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, + 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, + 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, + 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, + 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x18, 0x10, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, + 0x75, 0x73, 0x12, 0x3a, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, + 0x18, 0x11, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, + 0x6d, 0x70, 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x3a, + 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x12, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, + 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x36, 0x0a, 0x08, 0x6f, 0x70, + 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x13, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, + 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x08, 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, + 0x6d, 0x65, 0x12, 0x3c, 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, + 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, + 0x61, 0x6d, 0x70, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, + 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x18, + 0x15, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, + 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x18, + 0x16, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, + 0x12, 0x16, 0x0a, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x17, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x12, 0x20, 0x0a, 0x0b, 0x6b, 0x65, 0x65, 0x70, + 0x44, 0x65, 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x18, 0x18, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6b, + 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x74, + 0x6f, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x19, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, + 0x74, 0x6f, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, + 0x54, 0x69, 0x6d, 0x65, 0x18, 0x1a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, + 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x74, 0x72, 0x69, 0x6b, 0x65, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x18, 0x1b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x74, 0x72, 0x69, 0x6b, + 0x65, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x74, 0x72, 0x61, 0x64, 0x69, 0x6e, + 0x67, 0x54, 0x79, 0x70, 0x65, 0x18, 0x1c, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x74, 0x72, 0x61, + 0x64, 0x69, 0x6e, 0x67, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x74, 0x6f, 0x63, + 0x6b, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x1d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x6f, + 0x63, 0x6b, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x70, + 0x6c, 0x69, 0x65, 0x72, 0x18, 0x1e, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x6d, 0x75, 0x6c, 0x74, + 0x69, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6f, 0x73, 0x74, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x18, 0x1f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x6f, 0x73, 0x74, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x18, 0x20, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x05, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x69, + 0x64, 0x18, 0x21, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x62, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, + 0x61, 0x73, 0x6b, 0x18, 0x22, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x61, 0x73, 0x6b, 0x22, 0x7d, + 0x0a, 0x13, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x38, 0x0a, 0x04, 0x64, 0x61, 0x74, + 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, + 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, + 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x52, 0x04, 0x64, + 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x30, 0x0a, + 0x14, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, + 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x22, + 0x1a, 0x0a, 0x18, 0x41, 0x6c, 0x6c, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x4f, + 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x5a, 0x0a, 0x16, 0x41, + 0x6c, 0x6c, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, + 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, + 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0xa0, 0x07, 0x0a, 0x09, 0x4f, 0x70, 0x74, 0x69, + 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x12, 0xa5, 0x01, 0x0a, 0x19, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x54, 0x72, + 0x61, 0x64, 0x65, 0x12, 0x30, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, + 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, + 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2e, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, + 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, + 0x63, 0x6b, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x54, 0x72, 0x61, 0x64, 0x65, + 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x26, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x20, 0x3a, 0x01, 0x2a, + 0x22, 0x1b, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x69, + 0x6e, 0x72, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x12, 0x90, 0x01, + 0x0a, 0x13, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x50, 0x6c, 0x61, 0x63, 0x65, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, + 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x6d, + 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x70, + 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x5f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x69, 0x6e, 0x72, 0x2f, 0x73, + 0x68, 0x61, 0x72, 0x65, 0x5f, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x12, 0x98, 0x01, 0x0a, 0x14, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x55, 0x70, + 0x64, 0x61, 0x74, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x2b, 0x2e, 0x6d, 0x61, 0x74, 0x63, + 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, + 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, + 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, + 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2e, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x28, 0x3a, 0x01, 0x2a, 0x22, 0x23, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x6f, + 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x69, 0x6e, 0x72, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x75, + 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x8d, 0x01, 0x0a, 0x0f, + 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x12, + 0x2b, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, + 0x2e, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x6d, + 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x70, + 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x22, 0x28, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x22, 0x3a, 0x01, 0x2a, 0x22, 0x1d, 0x2f, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x5f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x69, 0x6e, 0x72, 0x2f, 0x73, + 0x68, 0x61, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x12, 0x91, 0x01, 0x0a, 0x11, + 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, + 0x6e, 0x12, 0x2b, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x2e, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, + 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, + 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x2a, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x24, 0x3a, 0x01, 0x2a, 0x22, 0x1f, + 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x69, 0x6e, 0x72, + 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, + 0x98, 0x01, 0x0a, 0x14, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x41, 0x6c, 0x6c, + 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x28, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x4f, 0x70, 0x74, + 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x26, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x72, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2e, 0x82, 0xd3, 0xe4, 0x93, + 0x02, 0x28, 0x3a, 0x01, 0x2a, 0x22, 0x23, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x6f, 0x70, + 0x74, 0x69, 0x6f, 0x6e, 0x69, 0x6e, 0x72, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x61, 0x6c, + 0x6c, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x2a, 0x5a, 0x28, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, + 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_option_optionInr_proto_rawDescOnce sync.Once + file_matchmaking_v1_option_optionInr_proto_rawDescData = file_matchmaking_v1_option_optionInr_proto_rawDesc +) + +func file_matchmaking_v1_option_optionInr_proto_rawDescGZIP() []byte { + file_matchmaking_v1_option_optionInr_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_option_optionInr_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_option_optionInr_proto_rawDescData) + }) + return file_matchmaking_v1_option_optionInr_proto_rawDescData +} + +var file_matchmaking_v1_option_optionInr_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_matchmaking_v1_option_optionInr_proto_goTypes = []any{ + (*CancelOptionInrOrderRequest)(nil), // 0: matchmaking.v1.CancelOptionInrOrderRequest + (*UpdateOptionInrOrderRequest)(nil), // 1: matchmaking.v1.UpdateOptionInrOrderRequest + (*OptionInrOrderRequest)(nil), // 2: matchmaking.v1.OptionInrOrderRequest + (*GetBotStockOptionInrTradeRequest)(nil), // 3: matchmaking.v1.GetBotStockOptionInrTradeRequest + (*GetBotStockOptionInrTradeReply)(nil), // 4: matchmaking.v1.GetBotStockOptionInrTradeReply + (*BotStockOptionInrTradeData)(nil), // 5: matchmaking.v1.BotStockOptionInrTradeData + (*BotStockOptionInrTrade)(nil), // 6: matchmaking.v1.BotStockOptionInrTrade + (*OptionInrOrderReply)(nil), // 7: matchmaking.v1.OptionInrOrderReply + (*OptionInrOrderResult)(nil), // 8: matchmaking.v1.OptionInrOrderResult + (*AllOptionInrOrderRequest)(nil), // 9: matchmaking.v1.AllOptionInrOrderRequest + (*AllOptionInrOrderReply)(nil), // 10: matchmaking.v1.AllOptionInrOrderReply + (*timestamppb.Timestamp)(nil), // 11: google.protobuf.Timestamp +} +var file_matchmaking_v1_option_optionInr_proto_depIdxs = []int32{ + 5, // 0: matchmaking.v1.GetBotStockOptionInrTradeReply.data:type_name -> matchmaking.v1.BotStockOptionInrTradeData + 6, // 1: matchmaking.v1.BotStockOptionInrTradeData.data:type_name -> matchmaking.v1.BotStockOptionInrTrade + 11, // 2: matchmaking.v1.BotStockOptionInrTrade.createTime:type_name -> google.protobuf.Timestamp + 11, // 3: matchmaking.v1.BotStockOptionInrTrade.updateTime:type_name -> google.protobuf.Timestamp + 11, // 4: matchmaking.v1.BotStockOptionInrTrade.openTime:type_name -> google.protobuf.Timestamp + 11, // 5: matchmaking.v1.BotStockOptionInrTrade.closingTime:type_name -> google.protobuf.Timestamp + 8, // 6: matchmaking.v1.OptionInrOrderReply.data:type_name -> matchmaking.v1.OptionInrOrderResult + 3, // 7: matchmaking.v1.OptionInr.GetBotStockOptionInrTrade:input_type -> matchmaking.v1.GetBotStockOptionInrTradeRequest + 2, // 8: matchmaking.v1.OptionInr.OptionInrPlaceOrder:input_type -> matchmaking.v1.OptionInrOrderRequest + 1, // 9: matchmaking.v1.OptionInr.OptionInrUpdateOrder:input_type -> matchmaking.v1.UpdateOptionInrOrderRequest + 0, // 10: matchmaking.v1.OptionInr.OptionInrCancel:input_type -> matchmaking.v1.CancelOptionInrOrderRequest + 0, // 11: matchmaking.v1.OptionInr.OptionInrPosition:input_type -> matchmaking.v1.CancelOptionInrOrderRequest + 9, // 12: matchmaking.v1.OptionInr.OptionInrAllPosition:input_type -> matchmaking.v1.AllOptionInrOrderRequest + 4, // 13: matchmaking.v1.OptionInr.GetBotStockOptionInrTrade:output_type -> matchmaking.v1.GetBotStockOptionInrTradeReply + 7, // 14: matchmaking.v1.OptionInr.OptionInrPlaceOrder:output_type -> matchmaking.v1.OptionInrOrderReply + 7, // 15: matchmaking.v1.OptionInr.OptionInrUpdateOrder:output_type -> matchmaking.v1.OptionInrOrderReply + 7, // 16: matchmaking.v1.OptionInr.OptionInrCancel:output_type -> matchmaking.v1.OptionInrOrderReply + 7, // 17: matchmaking.v1.OptionInr.OptionInrPosition:output_type -> matchmaking.v1.OptionInrOrderReply + 10, // 18: matchmaking.v1.OptionInr.OptionInrAllPosition:output_type -> matchmaking.v1.AllOptionInrOrderReply + 13, // [13:19] is the sub-list for method output_type + 7, // [7:13] is the sub-list for method input_type + 7, // [7:7] is the sub-list for extension type_name + 7, // [7:7] is the sub-list for extension extendee + 0, // [0:7] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_option_optionInr_proto_init() } +func file_matchmaking_v1_option_optionInr_proto_init() { + if File_matchmaking_v1_option_optionInr_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_matchmaking_v1_option_optionInr_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*CancelOptionInrOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_option_optionInr_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*UpdateOptionInrOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_option_optionInr_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*OptionInrOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_option_optionInr_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*GetBotStockOptionInrTradeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_option_optionInr_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*GetBotStockOptionInrTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_option_optionInr_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*BotStockOptionInrTradeData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_option_optionInr_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*BotStockOptionInrTrade); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_option_optionInr_proto_msgTypes[7].Exporter = func(v any, i int) any { + switch v := v.(*OptionInrOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_option_optionInr_proto_msgTypes[8].Exporter = func(v any, i int) any { + switch v := v.(*OptionInrOrderResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_option_optionInr_proto_msgTypes[9].Exporter = func(v any, i int) any { + switch v := v.(*AllOptionInrOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_option_optionInr_proto_msgTypes[10].Exporter = func(v any, i int) any { + switch v := v.(*AllOptionInrOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_option_optionInr_proto_rawDesc, + NumEnums: 0, + NumMessages: 11, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_matchmaking_v1_option_optionInr_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_option_optionInr_proto_depIdxs, + MessageInfos: file_matchmaking_v1_option_optionInr_proto_msgTypes, + }.Build() + File_matchmaking_v1_option_optionInr_proto = out.File + file_matchmaking_v1_option_optionInr_proto_rawDesc = nil + file_matchmaking_v1_option_optionInr_proto_goTypes = nil + file_matchmaking_v1_option_optionInr_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/option/optionInr.proto b/api/matchmaking/v1/option/optionInr.proto new file mode 100644 index 0000000..024cdc7 --- /dev/null +++ b/api/matchmaking/v1/option/optionInr.proto @@ -0,0 +1,162 @@ +syntax = "proto3"; + +package matchmaking.v1; + +import "google/api/annotations.proto"; +import "google/protobuf/timestamp.proto"; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +service OptionInr { + // GetBotStockOptionInrTrade 期权-印度股列表查询 + rpc GetBotStockOptionInrTrade(GetBotStockOptionInrTradeRequest)returns(GetBotStockOptionInrTradeReply){ + option (google.api.http) = { + post:"/order_optioninr/share_list", + body:"*", + }; + } + // OptionInrPlaceOrder 期权-印度股下单 + rpc OptionInrPlaceOrder(OptionInrOrderRequest)returns(OptionInrOrderReply) { + option (google.api.http) = { + post: "/order_optioninr/share_place_order", + body: "*", + }; + } + // OptionInrUpdateOrder 期权-印度股设置止盈止损 + rpc OptionInrUpdateOrder(UpdateOptionInrOrderRequest)returns(OptionInrOrderReply){ + option (google.api.http) = { + post:"/order_optioninr/share_update_order", + body:"*", + }; + } + // OptionInrCancel 期权-印度股撤单 + rpc OptionInrCancel(CancelOptionInrOrderRequest)returns(OptionInrOrderReply){ + option (google.api.http) = { + post:"/order_optioninr/share_cancel", + body:"*", + }; + } + // OptionInrPosition 期权-印度股平仓 + rpc OptionInrPosition(CancelOptionInrOrderRequest)returns(OptionInrOrderReply){ + option (google.api.http) = { + post:"/order_optioninr/share_position", + body:"*", + }; + } + // OptionInrAllPosition 期权-印度股一键平仓 + rpc OptionInrAllPosition(AllOptionInrOrderRequest)returns(AllOptionInrOrderReply){ + option (google.api.http) = { + post:"/order_optioninr/share_all_position", + body:"*", + }; + } +} + +message CancelOptionInrOrderRequest{ + string orderId =1;// 订单ID +} + +message UpdateOptionInrOrderRequest{ + string orderId =1;// 订单Id + int64 stopType =2;// 止盈止损 + string stopLossPrice =3;// 止损 + string stopWinPrice =4;// 止盈 +} + +message OptionInrOrderRequest{ + string stockId =1;// 股票类型 + int64 tradeType =2;// 交易类型:1看涨(calls-CE),2看跌(puts-PE) + int64 dealType =3;// 委托方式:1限价,2市价 + string limitPrice =4;// 限价 + string marketPrice =5;// 市价 + string marketMoney =6;// 订单金额 + string orderNumber =7;// 订单数量 + string serviceCost =8;// 手续费 + int64 stopType =9;// 止损止盈设置:1无设置,2止损止盈 + string stopLossPrice =10;// 止损 + string stopWinPrice =11;// 止损 + string pryNum =12;// 杠杆 + string stopTime =13;// 到期时间 + string strikePrice =14;// 行权价 + int64 tradingType =15;// 交易方式:1买入(buy),2卖出(sell) + string stockCode =16;// 期权订单标识(stockId+到期时间+行权价+(CE|PE)) + string multiplier =17;// 期权乘数 + string ask =18;// 卖一价(ask) + string bid =19;// 买一价(bid) +} + +message GetBotStockOptionInrTradeRequest{ + int64 status =1;// 状态码 + int64 pageSize =2; // 每页显示条数 + int64 pageCount =3;// 开始的位置 +} + +message GetBotStockOptionInrTradeReply{ + int64 code =1;// 状态码 + BotStockOptionInrTradeData data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message BotStockOptionInrTradeData{ + int64 pageSize =1; // 每页显示条数 + int64 pageCount =2;// 开始的位置 + repeated BotStockOptionInrTrade data =3;// 返回结果 + int64 totalCount =4;// 总数据 +} + +message BotStockOptionInrTrade{ + string orderId =1;// 订单ID + string stockId =2;// 股票代码 + int64 tradeType =3;// 交易类型 + int64 dealType =4;// 交易方式 + string limitPrice =5;// 限价 + string marketPrice =6;// 市价 + string dealPrice =7;// 开仓价 + string closingPrice =8;// 平仓价 + string orderNumber =9;// 订单数量 + int64 stopType =10;// 止盈止损 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string serviceCost =13;// 开仓手续费 + string marketMoney =14;// 订单金额 + string orderMoney =15;// 订单总金额 + int64 status =16;// 订单状态 + google.protobuf.Timestamp createTime =17;// 订单创建时间 + google.protobuf.Timestamp updateTime =18;// 订单更新时间 + google.protobuf.Timestamp openTime =19;// 订单开仓时间 + google.protobuf.Timestamp closingTime =20;// 订单平仓时间 + string closingCost =21;// 平仓手续费 + string faceValue =22;// 面值 + string pryNum =23;// 杠杆 + string keepDecimal =24;// 保留小数位 + string stockName =25;// 股票名称 + string stopTime = 26;// 期权时间 + string strikePrice =27;// 权利金 + int64 tradingType =28;// 交易方式 + string stockCode =29;// 期权订单标识(stockId+到期时间+行权价+(CE|PE)) + int64 multiplier =30;// 期权乘数 + string costPrice = 31;// 成本价格 + int64 ratio =32;// 保证金比例 + string bid =33;// 买一价 + string ask =34;// 卖一价 +} + +message OptionInrOrderReply{ + int64 code =1;// 状态码 + OptionInrOrderResult data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message OptionInrOrderResult { + string orderId =1;// 订单Id +} + +message AllOptionInrOrderRequest{ + +} + +message AllOptionInrOrderReply{ + int64 code =1;// 状态码 + string data =2;// 返回结果 + string message =3;// 返回消息提示 +} \ No newline at end of file diff --git a/api/matchmaking/v1/option/optionInr_grpc.pb.go b/api/matchmaking/v1/option/optionInr_grpc.pb.go new file mode 100644 index 0000000..89e9554 --- /dev/null +++ b/api/matchmaking/v1/option/optionInr_grpc.pb.go @@ -0,0 +1,312 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.1 +// source: matchmaking/v1/option/optionInr.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + OptionInr_GetBotStockOptionInrTrade_FullMethodName = "/matchmaking.v1.OptionInr/GetBotStockOptionInrTrade" + OptionInr_OptionInrPlaceOrder_FullMethodName = "/matchmaking.v1.OptionInr/OptionInrPlaceOrder" + OptionInr_OptionInrUpdateOrder_FullMethodName = "/matchmaking.v1.OptionInr/OptionInrUpdateOrder" + OptionInr_OptionInrCancel_FullMethodName = "/matchmaking.v1.OptionInr/OptionInrCancel" + OptionInr_OptionInrPosition_FullMethodName = "/matchmaking.v1.OptionInr/OptionInrPosition" + OptionInr_OptionInrAllPosition_FullMethodName = "/matchmaking.v1.OptionInr/OptionInrAllPosition" +) + +// OptionInrClient is the client API for OptionInr service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type OptionInrClient interface { + // GetBotStockOptionInrTrade 期权-印度股列表查询 + GetBotStockOptionInrTrade(ctx context.Context, in *GetBotStockOptionInrTradeRequest, opts ...grpc.CallOption) (*GetBotStockOptionInrTradeReply, error) + // OptionInrPlaceOrder 期权-印度股下单 + OptionInrPlaceOrder(ctx context.Context, in *OptionInrOrderRequest, opts ...grpc.CallOption) (*OptionInrOrderReply, error) + // OptionInrUpdateOrder 期权-印度股设置止盈止损 + OptionInrUpdateOrder(ctx context.Context, in *UpdateOptionInrOrderRequest, opts ...grpc.CallOption) (*OptionInrOrderReply, error) + // OptionInrCancel 期权-印度股撤单 + OptionInrCancel(ctx context.Context, in *CancelOptionInrOrderRequest, opts ...grpc.CallOption) (*OptionInrOrderReply, error) + // OptionInrPosition 期权-印度股平仓 + OptionInrPosition(ctx context.Context, in *CancelOptionInrOrderRequest, opts ...grpc.CallOption) (*OptionInrOrderReply, error) + // OptionInrAllPosition 期权-印度股一键平仓 + OptionInrAllPosition(ctx context.Context, in *AllOptionInrOrderRequest, opts ...grpc.CallOption) (*AllOptionInrOrderReply, error) +} + +type optionInrClient struct { + cc grpc.ClientConnInterface +} + +func NewOptionInrClient(cc grpc.ClientConnInterface) OptionInrClient { + return &optionInrClient{cc} +} + +func (c *optionInrClient) GetBotStockOptionInrTrade(ctx context.Context, in *GetBotStockOptionInrTradeRequest, opts ...grpc.CallOption) (*GetBotStockOptionInrTradeReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetBotStockOptionInrTradeReply) + err := c.cc.Invoke(ctx, OptionInr_GetBotStockOptionInrTrade_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *optionInrClient) OptionInrPlaceOrder(ctx context.Context, in *OptionInrOrderRequest, opts ...grpc.CallOption) (*OptionInrOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(OptionInrOrderReply) + err := c.cc.Invoke(ctx, OptionInr_OptionInrPlaceOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *optionInrClient) OptionInrUpdateOrder(ctx context.Context, in *UpdateOptionInrOrderRequest, opts ...grpc.CallOption) (*OptionInrOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(OptionInrOrderReply) + err := c.cc.Invoke(ctx, OptionInr_OptionInrUpdateOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *optionInrClient) OptionInrCancel(ctx context.Context, in *CancelOptionInrOrderRequest, opts ...grpc.CallOption) (*OptionInrOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(OptionInrOrderReply) + err := c.cc.Invoke(ctx, OptionInr_OptionInrCancel_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *optionInrClient) OptionInrPosition(ctx context.Context, in *CancelOptionInrOrderRequest, opts ...grpc.CallOption) (*OptionInrOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(OptionInrOrderReply) + err := c.cc.Invoke(ctx, OptionInr_OptionInrPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *optionInrClient) OptionInrAllPosition(ctx context.Context, in *AllOptionInrOrderRequest, opts ...grpc.CallOption) (*AllOptionInrOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AllOptionInrOrderReply) + err := c.cc.Invoke(ctx, OptionInr_OptionInrAllPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// OptionInrServer is the server API for OptionInr service. +// All implementations must embed UnimplementedOptionInrServer +// for forward compatibility +type OptionInrServer interface { + // GetBotStockOptionInrTrade 期权-印度股列表查询 + GetBotStockOptionInrTrade(context.Context, *GetBotStockOptionInrTradeRequest) (*GetBotStockOptionInrTradeReply, error) + // OptionInrPlaceOrder 期权-印度股下单 + OptionInrPlaceOrder(context.Context, *OptionInrOrderRequest) (*OptionInrOrderReply, error) + // OptionInrUpdateOrder 期权-印度股设置止盈止损 + OptionInrUpdateOrder(context.Context, *UpdateOptionInrOrderRequest) (*OptionInrOrderReply, error) + // OptionInrCancel 期权-印度股撤单 + OptionInrCancel(context.Context, *CancelOptionInrOrderRequest) (*OptionInrOrderReply, error) + // OptionInrPosition 期权-印度股平仓 + OptionInrPosition(context.Context, *CancelOptionInrOrderRequest) (*OptionInrOrderReply, error) + // OptionInrAllPosition 期权-印度股一键平仓 + OptionInrAllPosition(context.Context, *AllOptionInrOrderRequest) (*AllOptionInrOrderReply, error) + mustEmbedUnimplementedOptionInrServer() +} + +// UnimplementedOptionInrServer must be embedded to have forward compatible implementations. +type UnimplementedOptionInrServer struct { +} + +func (UnimplementedOptionInrServer) GetBotStockOptionInrTrade(context.Context, *GetBotStockOptionInrTradeRequest) (*GetBotStockOptionInrTradeReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBotStockOptionInrTrade not implemented") +} +func (UnimplementedOptionInrServer) OptionInrPlaceOrder(context.Context, *OptionInrOrderRequest) (*OptionInrOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method OptionInrPlaceOrder not implemented") +} +func (UnimplementedOptionInrServer) OptionInrUpdateOrder(context.Context, *UpdateOptionInrOrderRequest) (*OptionInrOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method OptionInrUpdateOrder not implemented") +} +func (UnimplementedOptionInrServer) OptionInrCancel(context.Context, *CancelOptionInrOrderRequest) (*OptionInrOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method OptionInrCancel not implemented") +} +func (UnimplementedOptionInrServer) OptionInrPosition(context.Context, *CancelOptionInrOrderRequest) (*OptionInrOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method OptionInrPosition not implemented") +} +func (UnimplementedOptionInrServer) OptionInrAllPosition(context.Context, *AllOptionInrOrderRequest) (*AllOptionInrOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method OptionInrAllPosition not implemented") +} +func (UnimplementedOptionInrServer) mustEmbedUnimplementedOptionInrServer() {} + +// UnsafeOptionInrServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to OptionInrServer will +// result in compilation errors. +type UnsafeOptionInrServer interface { + mustEmbedUnimplementedOptionInrServer() +} + +func RegisterOptionInrServer(s grpc.ServiceRegistrar, srv OptionInrServer) { + s.RegisterService(&OptionInr_ServiceDesc, srv) +} + +func _OptionInr_GetBotStockOptionInrTrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetBotStockOptionInrTradeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OptionInrServer).GetBotStockOptionInrTrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: OptionInr_GetBotStockOptionInrTrade_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OptionInrServer).GetBotStockOptionInrTrade(ctx, req.(*GetBotStockOptionInrTradeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _OptionInr_OptionInrPlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(OptionInrOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OptionInrServer).OptionInrPlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: OptionInr_OptionInrPlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OptionInrServer).OptionInrPlaceOrder(ctx, req.(*OptionInrOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _OptionInr_OptionInrUpdateOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateOptionInrOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OptionInrServer).OptionInrUpdateOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: OptionInr_OptionInrUpdateOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OptionInrServer).OptionInrUpdateOrder(ctx, req.(*UpdateOptionInrOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _OptionInr_OptionInrCancel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelOptionInrOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OptionInrServer).OptionInrCancel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: OptionInr_OptionInrCancel_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OptionInrServer).OptionInrCancel(ctx, req.(*CancelOptionInrOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _OptionInr_OptionInrPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelOptionInrOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OptionInrServer).OptionInrPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: OptionInr_OptionInrPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OptionInrServer).OptionInrPosition(ctx, req.(*CancelOptionInrOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _OptionInr_OptionInrAllPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AllOptionInrOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OptionInrServer).OptionInrAllPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: OptionInr_OptionInrAllPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OptionInrServer).OptionInrAllPosition(ctx, req.(*AllOptionInrOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// OptionInr_ServiceDesc is the grpc.ServiceDesc for OptionInr service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var OptionInr_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "matchmaking.v1.OptionInr", + HandlerType: (*OptionInrServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetBotStockOptionInrTrade", + Handler: _OptionInr_GetBotStockOptionInrTrade_Handler, + }, + { + MethodName: "OptionInrPlaceOrder", + Handler: _OptionInr_OptionInrPlaceOrder_Handler, + }, + { + MethodName: "OptionInrUpdateOrder", + Handler: _OptionInr_OptionInrUpdateOrder_Handler, + }, + { + MethodName: "OptionInrCancel", + Handler: _OptionInr_OptionInrCancel_Handler, + }, + { + MethodName: "OptionInrPosition", + Handler: _OptionInr_OptionInrPosition_Handler, + }, + { + MethodName: "OptionInrAllPosition", + Handler: _OptionInr_OptionInrAllPosition_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "matchmaking/v1/option/optionInr.proto", +} diff --git a/api/matchmaking/v1/option/optionInr_http.pb.go b/api/matchmaking/v1/option/optionInr_http.pb.go new file mode 100644 index 0000000..d0285a8 --- /dev/null +++ b/api/matchmaking/v1/option/optionInr_http.pb.go @@ -0,0 +1,279 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.3 +// - protoc v5.27.1 +// source: matchmaking/v1/option/optionInr.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationOptionInrGetBotStockOptionInrTrade = "/matchmaking.v1.OptionInr/GetBotStockOptionInrTrade" +const OperationOptionInrOptionInrAllPosition = "/matchmaking.v1.OptionInr/OptionInrAllPosition" +const OperationOptionInrOptionInrCancel = "/matchmaking.v1.OptionInr/OptionInrCancel" +const OperationOptionInrOptionInrPlaceOrder = "/matchmaking.v1.OptionInr/OptionInrPlaceOrder" +const OperationOptionInrOptionInrPosition = "/matchmaking.v1.OptionInr/OptionInrPosition" +const OperationOptionInrOptionInrUpdateOrder = "/matchmaking.v1.OptionInr/OptionInrUpdateOrder" + +type OptionInrHTTPServer interface { + // GetBotStockOptionInrTrade GetBotStockOptionInrTrade 期权-印度股列表查询 + GetBotStockOptionInrTrade(context.Context, *GetBotStockOptionInrTradeRequest) (*GetBotStockOptionInrTradeReply, error) + // OptionInrAllPosition OptionInrAllPosition 期权-印度股一键平仓 + OptionInrAllPosition(context.Context, *AllOptionInrOrderRequest) (*AllOptionInrOrderReply, error) + // OptionInrCancel OptionInrCancel 期权-印度股撤单 + OptionInrCancel(context.Context, *CancelOptionInrOrderRequest) (*OptionInrOrderReply, error) + // OptionInrPlaceOrder OptionInrPlaceOrder 期权-印度股下单 + OptionInrPlaceOrder(context.Context, *OptionInrOrderRequest) (*OptionInrOrderReply, error) + // OptionInrPosition OptionInrPosition 期权-印度股平仓 + OptionInrPosition(context.Context, *CancelOptionInrOrderRequest) (*OptionInrOrderReply, error) + // OptionInrUpdateOrder OptionInrUpdateOrder 期权-印度股设置止盈止损 + OptionInrUpdateOrder(context.Context, *UpdateOptionInrOrderRequest) (*OptionInrOrderReply, error) +} + +func RegisterOptionInrHTTPServer(s *http.Server, srv OptionInrHTTPServer) { + r := s.Route("/") + r.POST("/order_optioninr/share_list", _OptionInr_GetBotStockOptionInrTrade0_HTTP_Handler(srv)) + r.POST("/order_optioninr/share_place_order", _OptionInr_OptionInrPlaceOrder0_HTTP_Handler(srv)) + r.POST("/order_optioninr/share_update_order", _OptionInr_OptionInrUpdateOrder0_HTTP_Handler(srv)) + r.POST("/order_optioninr/share_cancel", _OptionInr_OptionInrCancel0_HTTP_Handler(srv)) + r.POST("/order_optioninr/share_position", _OptionInr_OptionInrPosition0_HTTP_Handler(srv)) + r.POST("/order_optioninr/share_all_position", _OptionInr_OptionInrAllPosition0_HTTP_Handler(srv)) +} + +func _OptionInr_GetBotStockOptionInrTrade0_HTTP_Handler(srv OptionInrHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetBotStockOptionInrTradeRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationOptionInrGetBotStockOptionInrTrade) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.GetBotStockOptionInrTrade(ctx, req.(*GetBotStockOptionInrTradeRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetBotStockOptionInrTradeReply) + return ctx.Result(200, reply) + } +} + +func _OptionInr_OptionInrPlaceOrder0_HTTP_Handler(srv OptionInrHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in OptionInrOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationOptionInrOptionInrPlaceOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.OptionInrPlaceOrder(ctx, req.(*OptionInrOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*OptionInrOrderReply) + return ctx.Result(200, reply) + } +} + +func _OptionInr_OptionInrUpdateOrder0_HTTP_Handler(srv OptionInrHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in UpdateOptionInrOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationOptionInrOptionInrUpdateOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.OptionInrUpdateOrder(ctx, req.(*UpdateOptionInrOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*OptionInrOrderReply) + return ctx.Result(200, reply) + } +} + +func _OptionInr_OptionInrCancel0_HTTP_Handler(srv OptionInrHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelOptionInrOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationOptionInrOptionInrCancel) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.OptionInrCancel(ctx, req.(*CancelOptionInrOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*OptionInrOrderReply) + return ctx.Result(200, reply) + } +} + +func _OptionInr_OptionInrPosition0_HTTP_Handler(srv OptionInrHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelOptionInrOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationOptionInrOptionInrPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.OptionInrPosition(ctx, req.(*CancelOptionInrOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*OptionInrOrderReply) + return ctx.Result(200, reply) + } +} + +func _OptionInr_OptionInrAllPosition0_HTTP_Handler(srv OptionInrHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in AllOptionInrOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationOptionInrOptionInrAllPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.OptionInrAllPosition(ctx, req.(*AllOptionInrOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*AllOptionInrOrderReply) + return ctx.Result(200, reply) + } +} + +type OptionInrHTTPClient interface { + GetBotStockOptionInrTrade(ctx context.Context, req *GetBotStockOptionInrTradeRequest, opts ...http.CallOption) (rsp *GetBotStockOptionInrTradeReply, err error) + OptionInrAllPosition(ctx context.Context, req *AllOptionInrOrderRequest, opts ...http.CallOption) (rsp *AllOptionInrOrderReply, err error) + OptionInrCancel(ctx context.Context, req *CancelOptionInrOrderRequest, opts ...http.CallOption) (rsp *OptionInrOrderReply, err error) + OptionInrPlaceOrder(ctx context.Context, req *OptionInrOrderRequest, opts ...http.CallOption) (rsp *OptionInrOrderReply, err error) + OptionInrPosition(ctx context.Context, req *CancelOptionInrOrderRequest, opts ...http.CallOption) (rsp *OptionInrOrderReply, err error) + OptionInrUpdateOrder(ctx context.Context, req *UpdateOptionInrOrderRequest, opts ...http.CallOption) (rsp *OptionInrOrderReply, err error) +} + +type OptionInrHTTPClientImpl struct { + cc *http.Client +} + +func NewOptionInrHTTPClient(client *http.Client) OptionInrHTTPClient { + return &OptionInrHTTPClientImpl{client} +} + +func (c *OptionInrHTTPClientImpl) GetBotStockOptionInrTrade(ctx context.Context, in *GetBotStockOptionInrTradeRequest, opts ...http.CallOption) (*GetBotStockOptionInrTradeReply, error) { + var out GetBotStockOptionInrTradeReply + pattern := "/order_optioninr/share_list" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationOptionInrGetBotStockOptionInrTrade)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *OptionInrHTTPClientImpl) OptionInrAllPosition(ctx context.Context, in *AllOptionInrOrderRequest, opts ...http.CallOption) (*AllOptionInrOrderReply, error) { + var out AllOptionInrOrderReply + pattern := "/order_optioninr/share_all_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationOptionInrOptionInrAllPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *OptionInrHTTPClientImpl) OptionInrCancel(ctx context.Context, in *CancelOptionInrOrderRequest, opts ...http.CallOption) (*OptionInrOrderReply, error) { + var out OptionInrOrderReply + pattern := "/order_optioninr/share_cancel" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationOptionInrOptionInrCancel)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *OptionInrHTTPClientImpl) OptionInrPlaceOrder(ctx context.Context, in *OptionInrOrderRequest, opts ...http.CallOption) (*OptionInrOrderReply, error) { + var out OptionInrOrderReply + pattern := "/order_optioninr/share_place_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationOptionInrOptionInrPlaceOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *OptionInrHTTPClientImpl) OptionInrPosition(ctx context.Context, in *CancelOptionInrOrderRequest, opts ...http.CallOption) (*OptionInrOrderReply, error) { + var out OptionInrOrderReply + pattern := "/order_optioninr/share_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationOptionInrOptionInrPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *OptionInrHTTPClientImpl) OptionInrUpdateOrder(ctx context.Context, in *UpdateOptionInrOrderRequest, opts ...http.CallOption) (*OptionInrOrderReply, error) { + var out OptionInrOrderReply + pattern := "/order_optioninr/share_update_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationOptionInrOptionInrUpdateOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/api/matchmaking/v1/order/order.pb.go b/api/matchmaking/v1/order/order.pb.go new file mode 100644 index 0000000..d1a2eca --- /dev/null +++ b/api/matchmaking/v1/order/order.pb.go @@ -0,0 +1,435 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/order/order.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type ShareTradeStockIdRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"` // 股票代码 + CodeOld string `protobuf:"bytes,2,opt,name=codeOld,proto3" json:"codeOld,omitempty"` // 旧股票代码 + Stock int64 `protobuf:"varint,3,opt,name=stock,proto3" json:"stock,omitempty"` // 股票市场 +} + +func (x *ShareTradeStockIdRequest) Reset() { + *x = ShareTradeStockIdRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_order_order_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ShareTradeStockIdRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ShareTradeStockIdRequest) ProtoMessage() {} + +func (x *ShareTradeStockIdRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_order_order_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ShareTradeStockIdRequest.ProtoReflect.Descriptor instead. +func (*ShareTradeStockIdRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_order_order_proto_rawDescGZIP(), []int{0} +} + +func (x *ShareTradeStockIdRequest) GetCode() string { + if x != nil { + return x.Code + } + return "" +} + +func (x *ShareTradeStockIdRequest) GetCodeOld() string { + if x != nil { + return x.CodeOld + } + return "" +} + +func (x *ShareTradeStockIdRequest) GetStock() int64 { + if x != nil { + return x.Stock + } + return 0 +} + +type SharePreRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"` // 股票代码 + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` // 新股申购-订单Id + Stock int32 `protobuf:"varint,3,opt,name=stock,proto3" json:"stock,omitempty"` // 股票市场 +} + +func (x *SharePreRequest) Reset() { + *x = SharePreRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_order_order_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SharePreRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SharePreRequest) ProtoMessage() {} + +func (x *SharePreRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_order_order_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SharePreRequest.ProtoReflect.Descriptor instead. +func (*SharePreRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_order_order_proto_rawDescGZIP(), []int{1} +} + +func (x *SharePreRequest) GetCode() string { + if x != nil { + return x.Code + } + return "" +} + +func (x *SharePreRequest) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *SharePreRequest) GetStock() int32 { + if x != nil { + return x.Stock + } + return 0 +} + +type SharePreReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *SharePreReply) Reset() { + *x = SharePreReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_order_order_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SharePreReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SharePreReply) ProtoMessage() {} + +func (x *SharePreReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_order_order_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SharePreReply.ProtoReflect.Descriptor instead. +func (*SharePreReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_order_order_proto_rawDescGZIP(), []int{2} +} + +func (x *SharePreReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *SharePreReply) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +func (x *SharePreReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type ShareNullRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *ShareNullRequest) Reset() { + *x = ShareNullRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_order_order_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ShareNullRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ShareNullRequest) ProtoMessage() {} + +func (x *ShareNullRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_order_order_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ShareNullRequest.ProtoReflect.Descriptor instead. +func (*ShareNullRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_order_order_proto_rawDescGZIP(), []int{3} +} + +var File_matchmaking_v1_order_order_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_order_order_proto_rawDesc = []byte{ + 0x0a, 0x20, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, + 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x22, 0x5e, 0x0a, 0x18, 0x53, 0x68, 0x61, 0x72, 0x65, 0x54, 0x72, 0x61, 0x64, 0x65, 0x53, 0x74, + 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, + 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, + 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x64, 0x65, 0x4f, 0x6c, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x07, 0x63, 0x6f, 0x64, 0x65, 0x4f, 0x6c, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, + 0x6f, 0x63, 0x6b, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x22, 0x4b, 0x0a, 0x0f, 0x53, 0x68, 0x61, 0x72, 0x65, 0x50, 0x72, 0x65, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x22, 0x51, 0x0a, + 0x0d, 0x53, 0x68, 0x61, 0x72, 0x65, 0x50, 0x72, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, + 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, + 0x64, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, + 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x22, 0x12, 0x0a, 0x10, 0x53, 0x68, 0x61, 0x72, 0x65, 0x4e, 0x75, 0x6c, 0x6c, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x32, 0xb1, 0x05, 0x0a, 0x05, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x7b, + 0x0a, 0x0d, 0x53, 0x68, 0x61, 0x72, 0x65, 0x50, 0x72, 0x65, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, + 0x1f, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, + 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x50, 0x72, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, + 0x31, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x50, 0x72, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, + 0x2a, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x24, 0x3a, 0x01, 0x2a, 0x22, 0x1f, 0x2f, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x70, 0x72, 0x65, 0x2f, 0x73, 0x68, 0x61, 0x72, + 0x65, 0x5f, 0x70, 0x72, 0x65, 0x5f, 0x74, 0x72, 0x61, 0x64, 0x65, 0x12, 0x90, 0x01, 0x0a, 0x16, + 0x53, 0x68, 0x61, 0x72, 0x65, 0x50, 0x72, 0x65, 0x54, 0x72, 0x61, 0x64, 0x65, 0x42, 0x79, 0x4f, + 0x72, 0x64, 0x65, 0x72, 0x4e, 0x6f, 0x12, 0x1f, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, + 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x50, 0x72, 0x65, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, + 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x50, 0x72, + 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x36, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x30, 0x3a, 0x01, + 0x2a, 0x22, 0x2b, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x70, + 0x72, 0x65, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x70, 0x72, 0x65, 0x5f, 0x74, 0x72, 0x61, + 0x64, 0x65, 0x5f, 0x62, 0x79, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x6e, 0x6f, 0x12, 0x8e, + 0x01, 0x0a, 0x17, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x68, 0x61, 0x72, 0x65, 0x54, 0x72, + 0x61, 0x64, 0x65, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x28, 0x2e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x61, 0x72, + 0x65, 0x54, 0x72, 0x61, 0x64, 0x65, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x50, 0x72, 0x65, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x2a, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x24, 0x3a, 0x01, 0x2a, 0x22, 0x1f, + 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x70, 0x72, 0x65, 0x2f, + 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x5f, 0x69, 0x64, 0x12, + 0x7c, 0x0a, 0x0e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x47, 0x69, 0x76, 0x65, 0x61, 0x77, 0x61, 0x79, + 0x73, 0x12, 0x1f, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x50, 0x72, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x50, 0x72, 0x65, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x22, 0x2a, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x24, 0x3a, 0x01, 0x2a, 0x22, 0x1f, 0x2f, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x70, 0x72, 0x65, 0x2f, 0x73, 0x68, + 0x61, 0x72, 0x65, 0x5f, 0x67, 0x69, 0x76, 0x65, 0x61, 0x77, 0x61, 0x79, 0x73, 0x12, 0x88, 0x01, + 0x0a, 0x15, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x68, 0x61, 0x72, 0x65, 0x41, 0x6c, 0x6c, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x20, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, + 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x4e, 0x75, + 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, + 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, + 0x50, 0x72, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2e, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x28, + 0x3a, 0x01, 0x2a, 0x22, 0x23, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, + 0x65, 0x70, 0x72, 0x65, 0x2f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x61, 0x6c, 0x6c, 0x5f, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x5f, 0x69, 0x64, 0x42, 0x2a, 0x5a, 0x28, 0x6d, 0x61, 0x74, 0x63, + 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2f, 0x61, + 0x70, 0x69, 0x2f, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, + 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_order_order_proto_rawDescOnce sync.Once + file_matchmaking_v1_order_order_proto_rawDescData = file_matchmaking_v1_order_order_proto_rawDesc +) + +func file_matchmaking_v1_order_order_proto_rawDescGZIP() []byte { + file_matchmaking_v1_order_order_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_order_order_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_order_order_proto_rawDescData) + }) + return file_matchmaking_v1_order_order_proto_rawDescData +} + +var file_matchmaking_v1_order_order_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_matchmaking_v1_order_order_proto_goTypes = []any{ + (*ShareTradeStockIdRequest)(nil), // 0: matchmaking.v1.ShareTradeStockIdRequest + (*SharePreRequest)(nil), // 1: matchmaking.v1.SharePreRequest + (*SharePreReply)(nil), // 2: matchmaking.v1.SharePreReply + (*ShareNullRequest)(nil), // 3: matchmaking.v1.ShareNullRequest +} +var file_matchmaking_v1_order_order_proto_depIdxs = []int32{ + 1, // 0: matchmaking.v1.Order.SharePreTrade:input_type -> matchmaking.v1.SharePreRequest + 1, // 1: matchmaking.v1.Order.SharePreTradeByOrderNo:input_type -> matchmaking.v1.SharePreRequest + 0, // 2: matchmaking.v1.Order.UpdateShareTradeStockId:input_type -> matchmaking.v1.ShareTradeStockIdRequest + 1, // 3: matchmaking.v1.Order.ShareGiveaways:input_type -> matchmaking.v1.SharePreRequest + 3, // 4: matchmaking.v1.Order.UpdateShareAllStockId:input_type -> matchmaking.v1.ShareNullRequest + 2, // 5: matchmaking.v1.Order.SharePreTrade:output_type -> matchmaking.v1.SharePreReply + 2, // 6: matchmaking.v1.Order.SharePreTradeByOrderNo:output_type -> matchmaking.v1.SharePreReply + 2, // 7: matchmaking.v1.Order.UpdateShareTradeStockId:output_type -> matchmaking.v1.SharePreReply + 2, // 8: matchmaking.v1.Order.ShareGiveaways:output_type -> matchmaking.v1.SharePreReply + 2, // 9: matchmaking.v1.Order.UpdateShareAllStockId:output_type -> matchmaking.v1.SharePreReply + 5, // [5:10] is the sub-list for method output_type + 0, // [0:5] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_order_order_proto_init() } +func file_matchmaking_v1_order_order_proto_init() { + if File_matchmaking_v1_order_order_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_matchmaking_v1_order_order_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*ShareTradeStockIdRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_order_order_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*SharePreRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_order_order_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*SharePreReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_order_order_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*ShareNullRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_order_order_proto_rawDesc, + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_matchmaking_v1_order_order_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_order_order_proto_depIdxs, + MessageInfos: file_matchmaking_v1_order_order_proto_msgTypes, + }.Build() + File_matchmaking_v1_order_order_proto = out.File + file_matchmaking_v1_order_order_proto_rawDesc = nil + file_matchmaking_v1_order_order_proto_goTypes = nil + file_matchmaking_v1_order_order_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/order/order.proto b/api/matchmaking/v1/order/order.proto new file mode 100644 index 0000000..bb0f5ac --- /dev/null +++ b/api/matchmaking/v1/order/order.proto @@ -0,0 +1,67 @@ +syntax = "proto3"; + +package matchmaking.v1; + +import "google/api/annotations.proto"; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +service Order { + // SharePreTrade 新股申购 + rpc SharePreTrade(SharePreRequest)returns(SharePreReply){ + option (google.api.http) = { + post:"/order_sharepre/share_pre_trade", + body:"*", + }; + } + // SharePreTradeByOrderNo 新股申购-订单号 + rpc SharePreTradeByOrderNo(SharePreRequest)returns(SharePreReply){ + option (google.api.http) = { + post:"/order_sharepre/share_pre_trade_by_order_no", + body:"*", + }; + } + // UpdateShareTradeStockId 更新股票代码stock_id + rpc UpdateShareTradeStockId(ShareTradeStockIdRequest)returns(SharePreReply){ + option (google.api.http) = { + post:"/order_sharepre/update_stock_id", + body:"*", + }; + } + // ShareGiveaways 股票赠送 + rpc ShareGiveaways(SharePreRequest)returns(SharePreReply){ + option (google.api.http) = { + post:"/order_sharepre/share_giveaways", + body:"*", + }; + } + // UpdateShareAllStockId 更新全局的股票StockId + rpc UpdateShareAllStockId(ShareNullRequest)returns(SharePreReply){ + option (google.api.http) = { + post:"/order_sharepre/update_all_stock_id", + body:"*", + }; + } +} + +message ShareTradeStockIdRequest{ + string code =1;// 股票代码 + string codeOld =2;// 旧股票代码 + int64 stock =3;// 股票市场 +} + +message SharePreRequest{ + string code =1;// 股票代码 + string id =2;// 新股申购-订单Id + int32 stock =3;// 股票市场 +} + +message SharePreReply{ + int64 code =1;// 状态码 + string data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message ShareNullRequest{ + +} \ No newline at end of file diff --git a/api/matchmaking/v1/order/order_grpc.pb.go b/api/matchmaking/v1/order/order_grpc.pb.go new file mode 100644 index 0000000..5a2a6e7 --- /dev/null +++ b/api/matchmaking/v1/order/order_grpc.pb.go @@ -0,0 +1,272 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.1 +// source: matchmaking/v1/order/order.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + Order_SharePreTrade_FullMethodName = "/matchmaking.v1.Order/SharePreTrade" + Order_SharePreTradeByOrderNo_FullMethodName = "/matchmaking.v1.Order/SharePreTradeByOrderNo" + Order_UpdateShareTradeStockId_FullMethodName = "/matchmaking.v1.Order/UpdateShareTradeStockId" + Order_ShareGiveaways_FullMethodName = "/matchmaking.v1.Order/ShareGiveaways" + Order_UpdateShareAllStockId_FullMethodName = "/matchmaking.v1.Order/UpdateShareAllStockId" +) + +// OrderClient is the client API for Order service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type OrderClient interface { + // SharePreTrade 新股申购 + SharePreTrade(ctx context.Context, in *SharePreRequest, opts ...grpc.CallOption) (*SharePreReply, error) + // SharePreTradeByOrderNo 新股申购-订单号 + SharePreTradeByOrderNo(ctx context.Context, in *SharePreRequest, opts ...grpc.CallOption) (*SharePreReply, error) + // UpdateShareTradeStockId 更新股票代码stock_id + UpdateShareTradeStockId(ctx context.Context, in *ShareTradeStockIdRequest, opts ...grpc.CallOption) (*SharePreReply, error) + // ShareGiveaways 股票赠送 + ShareGiveaways(ctx context.Context, in *SharePreRequest, opts ...grpc.CallOption) (*SharePreReply, error) + // UpdateShareAllStockId 更新全局的股票StockId + UpdateShareAllStockId(ctx context.Context, in *ShareNullRequest, opts ...grpc.CallOption) (*SharePreReply, error) +} + +type orderClient struct { + cc grpc.ClientConnInterface +} + +func NewOrderClient(cc grpc.ClientConnInterface) OrderClient { + return &orderClient{cc} +} + +func (c *orderClient) SharePreTrade(ctx context.Context, in *SharePreRequest, opts ...grpc.CallOption) (*SharePreReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(SharePreReply) + err := c.cc.Invoke(ctx, Order_SharePreTrade_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *orderClient) SharePreTradeByOrderNo(ctx context.Context, in *SharePreRequest, opts ...grpc.CallOption) (*SharePreReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(SharePreReply) + err := c.cc.Invoke(ctx, Order_SharePreTradeByOrderNo_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *orderClient) UpdateShareTradeStockId(ctx context.Context, in *ShareTradeStockIdRequest, opts ...grpc.CallOption) (*SharePreReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(SharePreReply) + err := c.cc.Invoke(ctx, Order_UpdateShareTradeStockId_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *orderClient) ShareGiveaways(ctx context.Context, in *SharePreRequest, opts ...grpc.CallOption) (*SharePreReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(SharePreReply) + err := c.cc.Invoke(ctx, Order_ShareGiveaways_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *orderClient) UpdateShareAllStockId(ctx context.Context, in *ShareNullRequest, opts ...grpc.CallOption) (*SharePreReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(SharePreReply) + err := c.cc.Invoke(ctx, Order_UpdateShareAllStockId_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// OrderServer is the server API for Order service. +// All implementations must embed UnimplementedOrderServer +// for forward compatibility +type OrderServer interface { + // SharePreTrade 新股申购 + SharePreTrade(context.Context, *SharePreRequest) (*SharePreReply, error) + // SharePreTradeByOrderNo 新股申购-订单号 + SharePreTradeByOrderNo(context.Context, *SharePreRequest) (*SharePreReply, error) + // UpdateShareTradeStockId 更新股票代码stock_id + UpdateShareTradeStockId(context.Context, *ShareTradeStockIdRequest) (*SharePreReply, error) + // ShareGiveaways 股票赠送 + ShareGiveaways(context.Context, *SharePreRequest) (*SharePreReply, error) + // UpdateShareAllStockId 更新全局的股票StockId + UpdateShareAllStockId(context.Context, *ShareNullRequest) (*SharePreReply, error) + mustEmbedUnimplementedOrderServer() +} + +// UnimplementedOrderServer must be embedded to have forward compatible implementations. +type UnimplementedOrderServer struct { +} + +func (UnimplementedOrderServer) SharePreTrade(context.Context, *SharePreRequest) (*SharePreReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method SharePreTrade not implemented") +} +func (UnimplementedOrderServer) SharePreTradeByOrderNo(context.Context, *SharePreRequest) (*SharePreReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method SharePreTradeByOrderNo not implemented") +} +func (UnimplementedOrderServer) UpdateShareTradeStockId(context.Context, *ShareTradeStockIdRequest) (*SharePreReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateShareTradeStockId not implemented") +} +func (UnimplementedOrderServer) ShareGiveaways(context.Context, *SharePreRequest) (*SharePreReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareGiveaways not implemented") +} +func (UnimplementedOrderServer) UpdateShareAllStockId(context.Context, *ShareNullRequest) (*SharePreReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateShareAllStockId not implemented") +} +func (UnimplementedOrderServer) mustEmbedUnimplementedOrderServer() {} + +// UnsafeOrderServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to OrderServer will +// result in compilation errors. +type UnsafeOrderServer interface { + mustEmbedUnimplementedOrderServer() +} + +func RegisterOrderServer(s grpc.ServiceRegistrar, srv OrderServer) { + s.RegisterService(&Order_ServiceDesc, srv) +} + +func _Order_SharePreTrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SharePreRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OrderServer).SharePreTrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Order_SharePreTrade_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OrderServer).SharePreTrade(ctx, req.(*SharePreRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Order_SharePreTradeByOrderNo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SharePreRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OrderServer).SharePreTradeByOrderNo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Order_SharePreTradeByOrderNo_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OrderServer).SharePreTradeByOrderNo(ctx, req.(*SharePreRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Order_UpdateShareTradeStockId_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ShareTradeStockIdRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OrderServer).UpdateShareTradeStockId(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Order_UpdateShareTradeStockId_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OrderServer).UpdateShareTradeStockId(ctx, req.(*ShareTradeStockIdRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Order_ShareGiveaways_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SharePreRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OrderServer).ShareGiveaways(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Order_ShareGiveaways_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OrderServer).ShareGiveaways(ctx, req.(*SharePreRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Order_UpdateShareAllStockId_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ShareNullRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OrderServer).UpdateShareAllStockId(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Order_UpdateShareAllStockId_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OrderServer).UpdateShareAllStockId(ctx, req.(*ShareNullRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Order_ServiceDesc is the grpc.ServiceDesc for Order service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Order_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "matchmaking.v1.Order", + HandlerType: (*OrderServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "SharePreTrade", + Handler: _Order_SharePreTrade_Handler, + }, + { + MethodName: "SharePreTradeByOrderNo", + Handler: _Order_SharePreTradeByOrderNo_Handler, + }, + { + MethodName: "UpdateShareTradeStockId", + Handler: _Order_UpdateShareTradeStockId_Handler, + }, + { + MethodName: "ShareGiveaways", + Handler: _Order_ShareGiveaways_Handler, + }, + { + MethodName: "UpdateShareAllStockId", + Handler: _Order_UpdateShareAllStockId_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "matchmaking/v1/order/order.proto", +} diff --git a/api/matchmaking/v1/order/order_http.pb.go b/api/matchmaking/v1/order/order_http.pb.go new file mode 100644 index 0000000..19edf9c --- /dev/null +++ b/api/matchmaking/v1/order/order_http.pb.go @@ -0,0 +1,239 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.3 +// - protoc v5.27.1 +// source: matchmaking/v1/order/order.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationOrderShareGiveaways = "/matchmaking.v1.Order/ShareGiveaways" +const OperationOrderSharePreTrade = "/matchmaking.v1.Order/SharePreTrade" +const OperationOrderSharePreTradeByOrderNo = "/matchmaking.v1.Order/SharePreTradeByOrderNo" +const OperationOrderUpdateShareAllStockId = "/matchmaking.v1.Order/UpdateShareAllStockId" +const OperationOrderUpdateShareTradeStockId = "/matchmaking.v1.Order/UpdateShareTradeStockId" + +type OrderHTTPServer interface { + // ShareGiveaways ShareGiveaways 股票赠送 + ShareGiveaways(context.Context, *SharePreRequest) (*SharePreReply, error) + // SharePreTrade SharePreTrade 新股申购 + SharePreTrade(context.Context, *SharePreRequest) (*SharePreReply, error) + // SharePreTradeByOrderNo SharePreTradeByOrderNo 新股申购-订单号 + SharePreTradeByOrderNo(context.Context, *SharePreRequest) (*SharePreReply, error) + // UpdateShareAllStockId UpdateShareAllStockId 更新全局的股票StockId + UpdateShareAllStockId(context.Context, *ShareNullRequest) (*SharePreReply, error) + // UpdateShareTradeStockId UpdateShareTradeStockId 更新股票代码stock_id + UpdateShareTradeStockId(context.Context, *ShareTradeStockIdRequest) (*SharePreReply, error) +} + +func RegisterOrderHTTPServer(s *http.Server, srv OrderHTTPServer) { + r := s.Route("/") + r.POST("/order_sharepre/share_pre_trade", _Order_SharePreTrade0_HTTP_Handler(srv)) + r.POST("/order_sharepre/share_pre_trade_by_order_no", _Order_SharePreTradeByOrderNo0_HTTP_Handler(srv)) + r.POST("/order_sharepre/update_stock_id", _Order_UpdateShareTradeStockId0_HTTP_Handler(srv)) + r.POST("/order_sharepre/share_giveaways", _Order_ShareGiveaways0_HTTP_Handler(srv)) + r.POST("/order_sharepre/update_all_stock_id", _Order_UpdateShareAllStockId0_HTTP_Handler(srv)) +} + +func _Order_SharePreTrade0_HTTP_Handler(srv OrderHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in SharePreRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationOrderSharePreTrade) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.SharePreTrade(ctx, req.(*SharePreRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*SharePreReply) + return ctx.Result(200, reply) + } +} + +func _Order_SharePreTradeByOrderNo0_HTTP_Handler(srv OrderHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in SharePreRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationOrderSharePreTradeByOrderNo) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.SharePreTradeByOrderNo(ctx, req.(*SharePreRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*SharePreReply) + return ctx.Result(200, reply) + } +} + +func _Order_UpdateShareTradeStockId0_HTTP_Handler(srv OrderHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in ShareTradeStockIdRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationOrderUpdateShareTradeStockId) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.UpdateShareTradeStockId(ctx, req.(*ShareTradeStockIdRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*SharePreReply) + return ctx.Result(200, reply) + } +} + +func _Order_ShareGiveaways0_HTTP_Handler(srv OrderHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in SharePreRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationOrderShareGiveaways) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareGiveaways(ctx, req.(*SharePreRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*SharePreReply) + return ctx.Result(200, reply) + } +} + +func _Order_UpdateShareAllStockId0_HTTP_Handler(srv OrderHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in ShareNullRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationOrderUpdateShareAllStockId) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.UpdateShareAllStockId(ctx, req.(*ShareNullRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*SharePreReply) + return ctx.Result(200, reply) + } +} + +type OrderHTTPClient interface { + ShareGiveaways(ctx context.Context, req *SharePreRequest, opts ...http.CallOption) (rsp *SharePreReply, err error) + SharePreTrade(ctx context.Context, req *SharePreRequest, opts ...http.CallOption) (rsp *SharePreReply, err error) + SharePreTradeByOrderNo(ctx context.Context, req *SharePreRequest, opts ...http.CallOption) (rsp *SharePreReply, err error) + UpdateShareAllStockId(ctx context.Context, req *ShareNullRequest, opts ...http.CallOption) (rsp *SharePreReply, err error) + UpdateShareTradeStockId(ctx context.Context, req *ShareTradeStockIdRequest, opts ...http.CallOption) (rsp *SharePreReply, err error) +} + +type OrderHTTPClientImpl struct { + cc *http.Client +} + +func NewOrderHTTPClient(client *http.Client) OrderHTTPClient { + return &OrderHTTPClientImpl{client} +} + +func (c *OrderHTTPClientImpl) ShareGiveaways(ctx context.Context, in *SharePreRequest, opts ...http.CallOption) (*SharePreReply, error) { + var out SharePreReply + pattern := "/order_sharepre/share_giveaways" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationOrderShareGiveaways)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *OrderHTTPClientImpl) SharePreTrade(ctx context.Context, in *SharePreRequest, opts ...http.CallOption) (*SharePreReply, error) { + var out SharePreReply + pattern := "/order_sharepre/share_pre_trade" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationOrderSharePreTrade)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *OrderHTTPClientImpl) SharePreTradeByOrderNo(ctx context.Context, in *SharePreRequest, opts ...http.CallOption) (*SharePreReply, error) { + var out SharePreReply + pattern := "/order_sharepre/share_pre_trade_by_order_no" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationOrderSharePreTradeByOrderNo)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *OrderHTTPClientImpl) UpdateShareAllStockId(ctx context.Context, in *ShareNullRequest, opts ...http.CallOption) (*SharePreReply, error) { + var out SharePreReply + pattern := "/order_sharepre/update_all_stock_id" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationOrderUpdateShareAllStockId)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *OrderHTTPClientImpl) UpdateShareTradeStockId(ctx context.Context, in *ShareTradeStockIdRequest, opts ...http.CallOption) (*SharePreReply, error) { + var out SharePreReply + pattern := "/order_sharepre/update_stock_id" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationOrderUpdateShareTradeStockId)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/api/matchmaking/v1/share/shareBrl.pb.go b/api/matchmaking/v1/share/shareBrl.pb.go new file mode 100644 index 0000000..2406c12 --- /dev/null +++ b/api/matchmaking/v1/share/shareBrl.pb.go @@ -0,0 +1,1327 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/share/shareBrl.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GetBrlBotStockTradeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status int64 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` // 状态码 + PageSize int64 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,3,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 +} + +func (x *GetBrlBotStockTradeRequest) Reset() { + *x = GetBrlBotStockTradeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBrlBotStockTradeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBrlBotStockTradeRequest) ProtoMessage() {} + +func (x *GetBrlBotStockTradeRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBrlBotStockTradeRequest.ProtoReflect.Descriptor instead. +func (*GetBrlBotStockTradeRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareBrl_proto_rawDescGZIP(), []int{0} +} + +func (x *GetBrlBotStockTradeRequest) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *GetBrlBotStockTradeRequest) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *GetBrlBotStockTradeRequest) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +type GetBotStockBrlTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *BotStockBrlTradeReply `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *GetBotStockBrlTradeReply) Reset() { + *x = GetBotStockBrlTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotStockBrlTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotStockBrlTradeReply) ProtoMessage() {} + +func (x *GetBotStockBrlTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotStockBrlTradeReply.ProtoReflect.Descriptor instead. +func (*GetBotStockBrlTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareBrl_proto_rawDescGZIP(), []int{1} +} + +func (x *GetBotStockBrlTradeReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *GetBotStockBrlTradeReply) GetData() *BotStockBrlTradeReply { + if x != nil { + return x.Data + } + return nil +} + +func (x *GetBotStockBrlTradeReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type BotStockBrlTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PageSize int64 `protobuf:"varint,1,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,2,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + Data []*BotStockBrlTrade `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty"` // 返回结果 + TotalCount int64 `protobuf:"varint,4,opt,name=totalCount,proto3" json:"totalCount,omitempty"` // 总数据 +} + +func (x *BotStockBrlTradeReply) Reset() { + *x = BotStockBrlTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockBrlTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockBrlTradeReply) ProtoMessage() {} + +func (x *BotStockBrlTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockBrlTradeReply.ProtoReflect.Descriptor instead. +func (*BotStockBrlTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareBrl_proto_rawDescGZIP(), []int{2} +} + +func (x *BotStockBrlTradeReply) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *BotStockBrlTradeReply) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *BotStockBrlTradeReply) GetData() []*BotStockBrlTrade { + if x != nil { + return x.Data + } + return nil +} + +func (x *BotStockBrlTradeReply) GetTotalCount() int64 { + if x != nil { + return x.TotalCount + } + return 0 +} + +type BotStockBrlTrade struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID + StockId string `protobuf:"bytes,2,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票代码 + TradeType int64 `protobuf:"varint,3,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型 + DealType int64 `protobuf:"varint,4,opt,name=dealType,proto3" json:"dealType,omitempty"` // 交易方式 + LimitPrice string `protobuf:"bytes,5,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,6,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + DealPrice string `protobuf:"bytes,7,opt,name=dealPrice,proto3" json:"dealPrice,omitempty"` // 开仓价 + ClosingPrice string `protobuf:"bytes,8,opt,name=closingPrice,proto3" json:"closingPrice,omitempty"` // 平仓价 + OrderNumber string `protobuf:"bytes,9,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + ServiceCost string `protobuf:"bytes,13,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 开仓手续费 + MarketMoney string `protobuf:"bytes,14,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderMoney string `protobuf:"bytes,15,opt,name=orderMoney,proto3" json:"orderMoney,omitempty"` // 订单总金额 + Status int64 `protobuf:"varint,16,opt,name=status,proto3" json:"status,omitempty"` // 订单状态 + CreateTime string `protobuf:"bytes,17,opt,name=createTime,proto3" json:"createTime,omitempty"` // 订单创建时间 + UpdateTime string `protobuf:"bytes,18,opt,name=updateTime,proto3" json:"updateTime,omitempty"` // 订单更新时间 + OpenTime string `protobuf:"bytes,19,opt,name=openTime,proto3" json:"openTime,omitempty"` // 订单开仓时间 + ClosingTime string `protobuf:"bytes,20,opt,name=closingTime,proto3" json:"closingTime,omitempty"` // 订单平仓时间 + ClosingCost string `protobuf:"bytes,21,opt,name=closingCost,proto3" json:"closingCost,omitempty"` // 平仓手续费 + FaceValue string `protobuf:"bytes,22,opt,name=faceValue,proto3" json:"faceValue,omitempty"` // 面值 + PryNum string `protobuf:"bytes,23,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 + KeepDecimal string `protobuf:"bytes,24,opt,name=keepDecimal,proto3" json:"keepDecimal,omitempty"` // 保留小数位 + StockName string `protobuf:"bytes,25,opt,name=stockName,proto3" json:"stockName,omitempty"` // 股票名称 +} + +func (x *BotStockBrlTrade) Reset() { + *x = BotStockBrlTrade{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockBrlTrade) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockBrlTrade) ProtoMessage() {} + +func (x *BotStockBrlTrade) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockBrlTrade.ProtoReflect.Descriptor instead. +func (*BotStockBrlTrade) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareBrl_proto_rawDescGZIP(), []int{3} +} + +func (x *BotStockBrlTrade) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *BotStockBrlTrade) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *BotStockBrlTrade) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *BotStockBrlTrade) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *BotStockBrlTrade) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *BotStockBrlTrade) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *BotStockBrlTrade) GetDealPrice() string { + if x != nil { + return x.DealPrice + } + return "" +} + +func (x *BotStockBrlTrade) GetClosingPrice() string { + if x != nil { + return x.ClosingPrice + } + return "" +} + +func (x *BotStockBrlTrade) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *BotStockBrlTrade) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *BotStockBrlTrade) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *BotStockBrlTrade) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *BotStockBrlTrade) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *BotStockBrlTrade) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *BotStockBrlTrade) GetOrderMoney() string { + if x != nil { + return x.OrderMoney + } + return "" +} + +func (x *BotStockBrlTrade) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *BotStockBrlTrade) GetCreateTime() string { + if x != nil { + return x.CreateTime + } + return "" +} + +func (x *BotStockBrlTrade) GetUpdateTime() string { + if x != nil { + return x.UpdateTime + } + return "" +} + +func (x *BotStockBrlTrade) GetOpenTime() string { + if x != nil { + return x.OpenTime + } + return "" +} + +func (x *BotStockBrlTrade) GetClosingTime() string { + if x != nil { + return x.ClosingTime + } + return "" +} + +func (x *BotStockBrlTrade) GetClosingCost() string { + if x != nil { + return x.ClosingCost + } + return "" +} + +func (x *BotStockBrlTrade) GetFaceValue() string { + if x != nil { + return x.FaceValue + } + return "" +} + +func (x *BotStockBrlTrade) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *BotStockBrlTrade) GetKeepDecimal() string { + if x != nil { + return x.KeepDecimal + } + return "" +} + +func (x *BotStockBrlTrade) GetStockName() string { + if x != nil { + return x.StockName + } + return "" +} + +type ShareBrlOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + StockId string `protobuf:"bytes,1,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票Code + TradeType int64 `protobuf:"varint,2,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型:1买入,2卖出 + DealType int64 `protobuf:"varint,3,opt,name=dealType,proto3" json:"dealType,omitempty"` // 委托方式:1限价,2市价 + LimitPrice string `protobuf:"bytes,4,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,5,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + MarketMoney string `protobuf:"bytes,6,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderNumber string `protobuf:"bytes,7,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + ServiceCost string `protobuf:"bytes,8,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 手续费 + StopType int64 `protobuf:"varint,9,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止损止盈设置:1无设置,2止损止盈 + StopLossPrice string `protobuf:"bytes,10,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,11,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止损 + PryNum string `protobuf:"bytes,12,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 +} + +func (x *ShareBrlOrderRequest) Reset() { + *x = ShareBrlOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ShareBrlOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ShareBrlOrderRequest) ProtoMessage() {} + +func (x *ShareBrlOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ShareBrlOrderRequest.ProtoReflect.Descriptor instead. +func (*ShareBrlOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareBrl_proto_rawDescGZIP(), []int{4} +} + +func (x *ShareBrlOrderRequest) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *ShareBrlOrderRequest) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *ShareBrlOrderRequest) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *ShareBrlOrderRequest) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *ShareBrlOrderRequest) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *ShareBrlOrderRequest) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *ShareBrlOrderRequest) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *ShareBrlOrderRequest) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *ShareBrlOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *ShareBrlOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *ShareBrlOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *ShareBrlOrderRequest) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +type UpdateBrlOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id + StopType int64 `protobuf:"varint,2,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,3,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,4,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 +} + +func (x *UpdateBrlOrderRequest) Reset() { + *x = UpdateBrlOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateBrlOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateBrlOrderRequest) ProtoMessage() {} + +func (x *UpdateBrlOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateBrlOrderRequest.ProtoReflect.Descriptor instead. +func (*UpdateBrlOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareBrl_proto_rawDescGZIP(), []int{5} +} + +func (x *UpdateBrlOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *UpdateBrlOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *UpdateBrlOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *UpdateBrlOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +type BrlOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *BrlOrderResult `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *BrlOrderReply) Reset() { + *x = BrlOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BrlOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BrlOrderReply) ProtoMessage() {} + +func (x *BrlOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BrlOrderReply.ProtoReflect.Descriptor instead. +func (*BrlOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareBrl_proto_rawDescGZIP(), []int{6} +} + +func (x *BrlOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *BrlOrderReply) GetData() *BrlOrderResult { + if x != nil { + return x.Data + } + return nil +} + +func (x *BrlOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type BrlOrderResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id +} + +func (x *BrlOrderResult) Reset() { + *x = BrlOrderResult{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BrlOrderResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BrlOrderResult) ProtoMessage() {} + +func (x *BrlOrderResult) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BrlOrderResult.ProtoReflect.Descriptor instead. +func (*BrlOrderResult) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareBrl_proto_rawDescGZIP(), []int{7} +} + +func (x *BrlOrderResult) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type CancelBrlOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID +} + +func (x *CancelBrlOrderRequest) Reset() { + *x = CancelBrlOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CancelBrlOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CancelBrlOrderRequest) ProtoMessage() {} + +func (x *CancelBrlOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CancelBrlOrderRequest.ProtoReflect.Descriptor instead. +func (*CancelBrlOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareBrl_proto_rawDescGZIP(), []int{8} +} + +func (x *CancelBrlOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type AllBrlOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *AllBrlOrderRequest) Reset() { + *x = AllBrlOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllBrlOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllBrlOrderRequest) ProtoMessage() {} + +func (x *AllBrlOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllBrlOrderRequest.ProtoReflect.Descriptor instead. +func (*AllBrlOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareBrl_proto_rawDescGZIP(), []int{9} +} + +type AllBrlOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *AllBrlOrderReply) Reset() { + *x = AllBrlOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllBrlOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllBrlOrderReply) ProtoMessage() {} + +func (x *AllBrlOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareBrl_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllBrlOrderReply.ProtoReflect.Descriptor instead. +func (*AllBrlOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareBrl_proto_rawDescGZIP(), []int{10} +} + +func (x *AllBrlOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *AllBrlOrderReply) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +func (x *AllBrlOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_matchmaking_v1_share_shareBrl_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_share_shareBrl_proto_rawDesc = []byte{ + 0x0a, 0x23, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x42, 0x72, 0x6c, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0x6e, 0x0a, 0x1a, 0x47, 0x65, 0x74, 0x42, 0x72, 0x6c, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, + 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x22, 0x83, 0x01, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, + 0x6f, 0x63, 0x6b, 0x42, 0x72, 0x6c, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, + 0x63, 0x6f, 0x64, 0x65, 0x12, 0x39, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x42, 0x72, 0x6c, 0x54, + 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, + 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xa7, 0x01, 0x0a, 0x15, 0x42, 0x6f, + 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x42, 0x72, 0x6c, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, + 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x34, 0x0a, + 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x42, 0x72, 0x6c, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x04, 0x64, + 0x61, 0x74, 0x61, 0x12, 0x1e, 0x0a, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, + 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x22, 0x9e, 0x06, 0x0a, 0x10, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, + 0x42, 0x72, 0x6c, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, + 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, + 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, + 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, + 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, + 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x65, 0x61, 0x6c, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x64, 0x65, 0x61, + 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, + 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6c, + 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, + 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, + 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, + 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, + 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0c, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, + 0x74, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x43, 0x6f, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, + 0x6e, 0x65, 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, + 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x18, 0x10, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1e, + 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x11, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1e, + 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x12, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1a, + 0x0a, 0x08, 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x13, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x08, 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, + 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, + 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x15, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1c, + 0x0a, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x16, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x16, 0x0a, 0x06, + 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x17, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, + 0x79, 0x4e, 0x75, 0x6d, 0x12, 0x20, 0x0a, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, + 0x6d, 0x61, 0x6c, 0x18, 0x18, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, + 0x65, 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x4e, + 0x61, 0x6d, 0x65, 0x18, 0x19, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x90, 0x03, 0x0a, 0x14, 0x53, 0x68, 0x61, 0x72, 0x65, 0x42, 0x72, + 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, + 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, + 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x72, 0x61, 0x64, + 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, + 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, + 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, + 0x65, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, + 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, + 0x6d, 0x62, 0x65, 0x72, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, + 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, + 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, + 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, + 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, + 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, + 0x16, 0x0a, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x22, 0x97, 0x01, 0x0a, 0x15, 0x55, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x42, 0x72, 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, + 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, + 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, + 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, + 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, + 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x22, 0x71, 0x0a, 0x0d, 0x42, 0x72, 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, + 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x32, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x72, 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x73, 0x75, 0x6c, 0x74, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x22, 0x2a, 0x0a, 0x0e, 0x42, 0x72, 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, + 0x22, 0x31, 0x0a, 0x15, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x42, 0x72, 0x6c, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x49, 0x64, 0x22, 0x14, 0x0a, 0x12, 0x41, 0x6c, 0x6c, 0x42, 0x72, 0x6c, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x54, 0x0a, 0x10, 0x41, 0x6c, 0x6c, + 0x42, 0x72, 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, + 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, + 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, + 0xca, 0x06, 0x0a, 0x08, 0x53, 0x68, 0x61, 0x72, 0x65, 0x42, 0x72, 0x6c, 0x12, 0x92, 0x01, 0x0a, + 0x13, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x42, 0x72, 0x6c, 0x54, + 0x72, 0x61, 0x64, 0x65, 0x12, 0x2a, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x72, 0x6c, 0x42, 0x6f, 0x74, 0x53, + 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x28, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, + 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x42, 0x72, 0x6c, + 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x25, 0x82, 0xd3, 0xe4, 0x93, + 0x02, 0x1f, 0x3a, 0x01, 0x2a, 0x22, 0x1a, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, + 0x61, 0x72, 0x65, 0x62, 0x72, 0x6c, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x6c, 0x69, 0x73, + 0x74, 0x12, 0x87, 0x01, 0x0a, 0x12, 0x53, 0x68, 0x61, 0x72, 0x65, 0x42, 0x72, 0x6c, 0x50, 0x6c, + 0x61, 0x63, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x24, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x42, + 0x72, 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, + 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x42, 0x72, 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2c, 0x82, + 0xd3, 0xe4, 0x93, 0x02, 0x26, 0x3a, 0x01, 0x2a, 0x22, 0x21, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x62, 0x72, 0x6c, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, + 0x70, 0x6c, 0x61, 0x63, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x8a, 0x01, 0x0a, 0x13, + 0x53, 0x68, 0x61, 0x72, 0x65, 0x42, 0x72, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x12, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, + 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x42, 0x72, 0x6c, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x72, 0x6c, 0x4f, + 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93, 0x02, + 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, + 0x72, 0x65, 0x62, 0x72, 0x6c, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x75, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x83, 0x01, 0x0a, 0x10, 0x53, 0x68, 0x61, + 0x72, 0x65, 0x42, 0x72, 0x6c, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x25, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, + 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x42, 0x72, 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x72, 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x29, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x23, 0x3a, 0x01, 0x2a, 0x22, 0x1e, + 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x62, 0x72, 0x6c, 0x2f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x8a, + 0x01, 0x0a, 0x13, 0x53, 0x68, 0x61, 0x72, 0x65, 0x42, 0x72, 0x6c, 0x41, 0x6c, 0x6c, 0x50, 0x6f, + 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x22, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, + 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x42, 0x72, 0x6c, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x42, + 0x72, 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2d, 0x82, 0xd3, + 0xe4, 0x93, 0x02, 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x62, 0x72, 0x6c, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x61, + 0x6c, 0x6c, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x7f, 0x0a, 0x0e, 0x53, + 0x68, 0x61, 0x72, 0x65, 0x42, 0x72, 0x6c, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x12, 0x25, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, + 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x42, 0x72, 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x72, 0x6c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x27, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x21, 0x3a, 0x01, 0x2a, 0x22, 0x1c, + 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x62, 0x72, 0x6c, 0x2f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x42, 0x2a, 0x5a, 0x28, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x73, 0x79, 0x73, 0x74, + 0x65, 0x6d, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_share_shareBrl_proto_rawDescOnce sync.Once + file_matchmaking_v1_share_shareBrl_proto_rawDescData = file_matchmaking_v1_share_shareBrl_proto_rawDesc +) + +func file_matchmaking_v1_share_shareBrl_proto_rawDescGZIP() []byte { + file_matchmaking_v1_share_shareBrl_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_share_shareBrl_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_share_shareBrl_proto_rawDescData) + }) + return file_matchmaking_v1_share_shareBrl_proto_rawDescData +} + +var file_matchmaking_v1_share_shareBrl_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_matchmaking_v1_share_shareBrl_proto_goTypes = []any{ + (*GetBrlBotStockTradeRequest)(nil), // 0: matchmaking.v1.GetBrlBotStockTradeRequest + (*GetBotStockBrlTradeReply)(nil), // 1: matchmaking.v1.GetBotStockBrlTradeReply + (*BotStockBrlTradeReply)(nil), // 2: matchmaking.v1.BotStockBrlTradeReply + (*BotStockBrlTrade)(nil), // 3: matchmaking.v1.BotStockBrlTrade + (*ShareBrlOrderRequest)(nil), // 4: matchmaking.v1.ShareBrlOrderRequest + (*UpdateBrlOrderRequest)(nil), // 5: matchmaking.v1.UpdateBrlOrderRequest + (*BrlOrderReply)(nil), // 6: matchmaking.v1.BrlOrderReply + (*BrlOrderResult)(nil), // 7: matchmaking.v1.BrlOrderResult + (*CancelBrlOrderRequest)(nil), // 8: matchmaking.v1.CancelBrlOrderRequest + (*AllBrlOrderRequest)(nil), // 9: matchmaking.v1.AllBrlOrderRequest + (*AllBrlOrderReply)(nil), // 10: matchmaking.v1.AllBrlOrderReply +} +var file_matchmaking_v1_share_shareBrl_proto_depIdxs = []int32{ + 2, // 0: matchmaking.v1.GetBotStockBrlTradeReply.data:type_name -> matchmaking.v1.BotStockBrlTradeReply + 3, // 1: matchmaking.v1.BotStockBrlTradeReply.data:type_name -> matchmaking.v1.BotStockBrlTrade + 7, // 2: matchmaking.v1.BrlOrderReply.data:type_name -> matchmaking.v1.BrlOrderResult + 0, // 3: matchmaking.v1.ShareBrl.GetBotStockBrlTrade:input_type -> matchmaking.v1.GetBrlBotStockTradeRequest + 4, // 4: matchmaking.v1.ShareBrl.ShareBrlPlaceOrder:input_type -> matchmaking.v1.ShareBrlOrderRequest + 5, // 5: matchmaking.v1.ShareBrl.ShareBrlUpdateOrder:input_type -> matchmaking.v1.UpdateBrlOrderRequest + 8, // 6: matchmaking.v1.ShareBrl.ShareBrlPosition:input_type -> matchmaking.v1.CancelBrlOrderRequest + 9, // 7: matchmaking.v1.ShareBrl.ShareBrlAllPosition:input_type -> matchmaking.v1.AllBrlOrderRequest + 8, // 8: matchmaking.v1.ShareBrl.ShareBrlCancel:input_type -> matchmaking.v1.CancelBrlOrderRequest + 1, // 9: matchmaking.v1.ShareBrl.GetBotStockBrlTrade:output_type -> matchmaking.v1.GetBotStockBrlTradeReply + 6, // 10: matchmaking.v1.ShareBrl.ShareBrlPlaceOrder:output_type -> matchmaking.v1.BrlOrderReply + 6, // 11: matchmaking.v1.ShareBrl.ShareBrlUpdateOrder:output_type -> matchmaking.v1.BrlOrderReply + 6, // 12: matchmaking.v1.ShareBrl.ShareBrlPosition:output_type -> matchmaking.v1.BrlOrderReply + 10, // 13: matchmaking.v1.ShareBrl.ShareBrlAllPosition:output_type -> matchmaking.v1.AllBrlOrderReply + 6, // 14: matchmaking.v1.ShareBrl.ShareBrlCancel:output_type -> matchmaking.v1.BrlOrderReply + 9, // [9:15] is the sub-list for method output_type + 3, // [3:9] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_share_shareBrl_proto_init() } +func file_matchmaking_v1_share_shareBrl_proto_init() { + if File_matchmaking_v1_share_shareBrl_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_matchmaking_v1_share_shareBrl_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*GetBrlBotStockTradeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareBrl_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*GetBotStockBrlTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareBrl_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*BotStockBrlTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareBrl_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*BotStockBrlTrade); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareBrl_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*ShareBrlOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareBrl_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*UpdateBrlOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareBrl_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*BrlOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareBrl_proto_msgTypes[7].Exporter = func(v any, i int) any { + switch v := v.(*BrlOrderResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareBrl_proto_msgTypes[8].Exporter = func(v any, i int) any { + switch v := v.(*CancelBrlOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareBrl_proto_msgTypes[9].Exporter = func(v any, i int) any { + switch v := v.(*AllBrlOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareBrl_proto_msgTypes[10].Exporter = func(v any, i int) any { + switch v := v.(*AllBrlOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_share_shareBrl_proto_rawDesc, + NumEnums: 0, + NumMessages: 11, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_matchmaking_v1_share_shareBrl_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_share_shareBrl_proto_depIdxs, + MessageInfos: file_matchmaking_v1_share_shareBrl_proto_msgTypes, + }.Build() + File_matchmaking_v1_share_shareBrl_proto = out.File + file_matchmaking_v1_share_shareBrl_proto_rawDesc = nil + file_matchmaking_v1_share_shareBrl_proto_goTypes = nil + file_matchmaking_v1_share_shareBrl_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/share/shareBrl.proto b/api/matchmaking/v1/share/shareBrl.proto new file mode 100644 index 0000000..95aaea7 --- /dev/null +++ b/api/matchmaking/v1/share/shareBrl.proto @@ -0,0 +1,144 @@ +syntax = "proto3"; + +package matchmaking.v1; + +import "google/api/annotations.proto"; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +service ShareBrl { + // GetBotStockBrlTrade 巴西国股列表查询 + rpc GetBotStockBrlTrade(GetBrlBotStockTradeRequest)returns(GetBotStockBrlTradeReply){ + option (google.api.http) = { + post:"/order_sharebrl/share_list", + body:"*", + }; + } + // ShareBrlPlaceOrder 巴西国股下单 + rpc ShareBrlPlaceOrder(ShareBrlOrderRequest)returns(BrlOrderReply) { + option (google.api.http) = { + post: "/order_sharebrl/share_place_order", + body: "*", + }; + } + // ShareBrlUpdateOrder 巴西国股设置止盈止损 + rpc ShareBrlUpdateOrder(UpdateBrlOrderRequest)returns(BrlOrderReply){ + option (google.api.http) = { + post:"/order_sharebrl/share_update_order", + body:"*", + }; + } + // ShareBrlPosition 巴西国股平仓 + rpc ShareBrlPosition(CancelBrlOrderRequest)returns(BrlOrderReply){ + option (google.api.http) = { + post:"/order_sharebrl/share_position", + body:"*", + }; + } + // ShareBrlAllPosition 巴西国股一键平仓 + rpc ShareBrlAllPosition(AllBrlOrderRequest)returns(AllBrlOrderReply){ + option (google.api.http) = { + post:"/order_sharebrl/share_all_position", + body:"*", + }; + } + // ShareBrlCancel 巴西国股撤单 + rpc ShareBrlCancel(CancelBrlOrderRequest)returns(BrlOrderReply){ + option (google.api.http) = { + post:"/order_sharebrl/share_cancel", + body:"*", + }; + } +} + +message GetBrlBotStockTradeRequest{ + int64 status =1;// 状态码 + int64 pageSize =2; // 每页显示条数 + int64 pageCount =3;// 开始的位置 +} + +message GetBotStockBrlTradeReply{ + int64 code =1;// 状态码 + BotStockBrlTradeReply data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message BotStockBrlTradeReply{ + int64 pageSize =1; // 每页显示条数 + int64 pageCount =2;// 开始的位置 + repeated BotStockBrlTrade data =3;// 返回结果 + int64 totalCount =4;// 总数据 +} + +message BotStockBrlTrade{ + string orderId =1;// 订单ID + string stockId =2;// 股票代码 + int64 tradeType =3;// 交易类型 + int64 dealType =4;// 交易方式 + string limitPrice =5;// 限价 + string marketPrice =6;// 市价 + string dealPrice =7;// 开仓价 + string closingPrice =8;// 平仓价 + string orderNumber =9;// 订单数量 + int64 stopType =10;// 止盈止损 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string serviceCost =13;// 开仓手续费 + string marketMoney =14;// 订单金额 + string orderMoney =15;// 订单总金额 + int64 status =16;// 订单状态 + string createTime =17;// 订单创建时间 + string updateTime =18;// 订单更新时间 + string openTime =19;// 订单开仓时间 + string closingTime =20;// 订单平仓时间 + string closingCost =21;// 平仓手续费 + string faceValue =22;// 面值 + string pryNum =23;// 杠杆 + string keepDecimal =24;// 保留小数位 + string stockName =25;// 股票名称 +} + +message ShareBrlOrderRequest{ + string stockId =1;// 股票Code + int64 tradeType =2;// 交易类型:1买入,2卖出 + int64 dealType =3;// 委托方式:1限价,2市价 + string limitPrice =4;// 限价 + string marketPrice =5;// 市价 + string marketMoney =6;// 订单金额 + string orderNumber =7;// 订单数量 + string serviceCost =8;// 手续费 + int64 stopType =9;// 止损止盈设置:1无设置,2止损止盈 + string stopLossPrice =10;// 止损 + string stopWinPrice =11;// 止损 + string pryNum =12;// 杠杆 +} + +message UpdateBrlOrderRequest{ + string orderId =1;// 订单Id + int64 stopType =2;// 止盈止损 + string stopLossPrice =3;// 止损 + string stopWinPrice =4;// 止盈 +} + +message BrlOrderReply{ + int64 code =1;// 状态码 + BrlOrderResult data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message BrlOrderResult { + string orderId =1;// 订单Id +} + +message CancelBrlOrderRequest{ + string orderId =1;// 订单ID +} + +message AllBrlOrderRequest{ + +} +message AllBrlOrderReply{ + int64 code =1;// 状态码 + string data =2;// 返回结果 + string message =3;// 返回消息提示 +} \ No newline at end of file diff --git a/api/matchmaking/v1/share/shareBrl_grpc.pb.go b/api/matchmaking/v1/share/shareBrl_grpc.pb.go new file mode 100644 index 0000000..b944dba --- /dev/null +++ b/api/matchmaking/v1/share/shareBrl_grpc.pb.go @@ -0,0 +1,312 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareBrl.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + ShareBrl_GetBotStockBrlTrade_FullMethodName = "/matchmaking.v1.ShareBrl/GetBotStockBrlTrade" + ShareBrl_ShareBrlPlaceOrder_FullMethodName = "/matchmaking.v1.ShareBrl/ShareBrlPlaceOrder" + ShareBrl_ShareBrlUpdateOrder_FullMethodName = "/matchmaking.v1.ShareBrl/ShareBrlUpdateOrder" + ShareBrl_ShareBrlPosition_FullMethodName = "/matchmaking.v1.ShareBrl/ShareBrlPosition" + ShareBrl_ShareBrlAllPosition_FullMethodName = "/matchmaking.v1.ShareBrl/ShareBrlAllPosition" + ShareBrl_ShareBrlCancel_FullMethodName = "/matchmaking.v1.ShareBrl/ShareBrlCancel" +) + +// ShareBrlClient is the client API for ShareBrl service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ShareBrlClient interface { + // GetBotStockBrlTrade 巴西国股列表查询 + GetBotStockBrlTrade(ctx context.Context, in *GetBrlBotStockTradeRequest, opts ...grpc.CallOption) (*GetBotStockBrlTradeReply, error) + // ShareBrlPlaceOrder 巴西国股下单 + ShareBrlPlaceOrder(ctx context.Context, in *ShareBrlOrderRequest, opts ...grpc.CallOption) (*BrlOrderReply, error) + // ShareBrlUpdateOrder 巴西国股设置止盈止损 + ShareBrlUpdateOrder(ctx context.Context, in *UpdateBrlOrderRequest, opts ...grpc.CallOption) (*BrlOrderReply, error) + // ShareBrlPosition 巴西国股平仓 + ShareBrlPosition(ctx context.Context, in *CancelBrlOrderRequest, opts ...grpc.CallOption) (*BrlOrderReply, error) + // ShareBrlAllPosition 巴西国股一键平仓 + ShareBrlAllPosition(ctx context.Context, in *AllBrlOrderRequest, opts ...grpc.CallOption) (*AllBrlOrderReply, error) + // ShareBrlCancel 巴西国股撤单 + ShareBrlCancel(ctx context.Context, in *CancelBrlOrderRequest, opts ...grpc.CallOption) (*BrlOrderReply, error) +} + +type shareBrlClient struct { + cc grpc.ClientConnInterface +} + +func NewShareBrlClient(cc grpc.ClientConnInterface) ShareBrlClient { + return &shareBrlClient{cc} +} + +func (c *shareBrlClient) GetBotStockBrlTrade(ctx context.Context, in *GetBrlBotStockTradeRequest, opts ...grpc.CallOption) (*GetBotStockBrlTradeReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetBotStockBrlTradeReply) + err := c.cc.Invoke(ctx, ShareBrl_GetBotStockBrlTrade_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareBrlClient) ShareBrlPlaceOrder(ctx context.Context, in *ShareBrlOrderRequest, opts ...grpc.CallOption) (*BrlOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(BrlOrderReply) + err := c.cc.Invoke(ctx, ShareBrl_ShareBrlPlaceOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareBrlClient) ShareBrlUpdateOrder(ctx context.Context, in *UpdateBrlOrderRequest, opts ...grpc.CallOption) (*BrlOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(BrlOrderReply) + err := c.cc.Invoke(ctx, ShareBrl_ShareBrlUpdateOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareBrlClient) ShareBrlPosition(ctx context.Context, in *CancelBrlOrderRequest, opts ...grpc.CallOption) (*BrlOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(BrlOrderReply) + err := c.cc.Invoke(ctx, ShareBrl_ShareBrlPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareBrlClient) ShareBrlAllPosition(ctx context.Context, in *AllBrlOrderRequest, opts ...grpc.CallOption) (*AllBrlOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AllBrlOrderReply) + err := c.cc.Invoke(ctx, ShareBrl_ShareBrlAllPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareBrlClient) ShareBrlCancel(ctx context.Context, in *CancelBrlOrderRequest, opts ...grpc.CallOption) (*BrlOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(BrlOrderReply) + err := c.cc.Invoke(ctx, ShareBrl_ShareBrlCancel_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ShareBrlServer is the server API for ShareBrl service. +// All implementations must embed UnimplementedShareBrlServer +// for forward compatibility +type ShareBrlServer interface { + // GetBotStockBrlTrade 巴西国股列表查询 + GetBotStockBrlTrade(context.Context, *GetBrlBotStockTradeRequest) (*GetBotStockBrlTradeReply, error) + // ShareBrlPlaceOrder 巴西国股下单 + ShareBrlPlaceOrder(context.Context, *ShareBrlOrderRequest) (*BrlOrderReply, error) + // ShareBrlUpdateOrder 巴西国股设置止盈止损 + ShareBrlUpdateOrder(context.Context, *UpdateBrlOrderRequest) (*BrlOrderReply, error) + // ShareBrlPosition 巴西国股平仓 + ShareBrlPosition(context.Context, *CancelBrlOrderRequest) (*BrlOrderReply, error) + // ShareBrlAllPosition 巴西国股一键平仓 + ShareBrlAllPosition(context.Context, *AllBrlOrderRequest) (*AllBrlOrderReply, error) + // ShareBrlCancel 巴西国股撤单 + ShareBrlCancel(context.Context, *CancelBrlOrderRequest) (*BrlOrderReply, error) + mustEmbedUnimplementedShareBrlServer() +} + +// UnimplementedShareBrlServer must be embedded to have forward compatible implementations. +type UnimplementedShareBrlServer struct { +} + +func (UnimplementedShareBrlServer) GetBotStockBrlTrade(context.Context, *GetBrlBotStockTradeRequest) (*GetBotStockBrlTradeReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBotStockBrlTrade not implemented") +} +func (UnimplementedShareBrlServer) ShareBrlPlaceOrder(context.Context, *ShareBrlOrderRequest) (*BrlOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareBrlPlaceOrder not implemented") +} +func (UnimplementedShareBrlServer) ShareBrlUpdateOrder(context.Context, *UpdateBrlOrderRequest) (*BrlOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareBrlUpdateOrder not implemented") +} +func (UnimplementedShareBrlServer) ShareBrlPosition(context.Context, *CancelBrlOrderRequest) (*BrlOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareBrlPosition not implemented") +} +func (UnimplementedShareBrlServer) ShareBrlAllPosition(context.Context, *AllBrlOrderRequest) (*AllBrlOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareBrlAllPosition not implemented") +} +func (UnimplementedShareBrlServer) ShareBrlCancel(context.Context, *CancelBrlOrderRequest) (*BrlOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareBrlCancel not implemented") +} +func (UnimplementedShareBrlServer) mustEmbedUnimplementedShareBrlServer() {} + +// UnsafeShareBrlServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ShareBrlServer will +// result in compilation errors. +type UnsafeShareBrlServer interface { + mustEmbedUnimplementedShareBrlServer() +} + +func RegisterShareBrlServer(s grpc.ServiceRegistrar, srv ShareBrlServer) { + s.RegisterService(&ShareBrl_ServiceDesc, srv) +} + +func _ShareBrl_GetBotStockBrlTrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetBrlBotStockTradeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareBrlServer).GetBotStockBrlTrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareBrl_GetBotStockBrlTrade_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareBrlServer).GetBotStockBrlTrade(ctx, req.(*GetBrlBotStockTradeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareBrl_ShareBrlPlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ShareBrlOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareBrlServer).ShareBrlPlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareBrl_ShareBrlPlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareBrlServer).ShareBrlPlaceOrder(ctx, req.(*ShareBrlOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareBrl_ShareBrlUpdateOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateBrlOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareBrlServer).ShareBrlUpdateOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareBrl_ShareBrlUpdateOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareBrlServer).ShareBrlUpdateOrder(ctx, req.(*UpdateBrlOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareBrl_ShareBrlPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelBrlOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareBrlServer).ShareBrlPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareBrl_ShareBrlPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareBrlServer).ShareBrlPosition(ctx, req.(*CancelBrlOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareBrl_ShareBrlAllPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AllBrlOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareBrlServer).ShareBrlAllPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareBrl_ShareBrlAllPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareBrlServer).ShareBrlAllPosition(ctx, req.(*AllBrlOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareBrl_ShareBrlCancel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelBrlOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareBrlServer).ShareBrlCancel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareBrl_ShareBrlCancel_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareBrlServer).ShareBrlCancel(ctx, req.(*CancelBrlOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// ShareBrl_ServiceDesc is the grpc.ServiceDesc for ShareBrl service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ShareBrl_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "matchmaking.v1.ShareBrl", + HandlerType: (*ShareBrlServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetBotStockBrlTrade", + Handler: _ShareBrl_GetBotStockBrlTrade_Handler, + }, + { + MethodName: "ShareBrlPlaceOrder", + Handler: _ShareBrl_ShareBrlPlaceOrder_Handler, + }, + { + MethodName: "ShareBrlUpdateOrder", + Handler: _ShareBrl_ShareBrlUpdateOrder_Handler, + }, + { + MethodName: "ShareBrlPosition", + Handler: _ShareBrl_ShareBrlPosition_Handler, + }, + { + MethodName: "ShareBrlAllPosition", + Handler: _ShareBrl_ShareBrlAllPosition_Handler, + }, + { + MethodName: "ShareBrlCancel", + Handler: _ShareBrl_ShareBrlCancel_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "matchmaking/v1/share/shareBrl.proto", +} diff --git a/api/matchmaking/v1/share/shareBrl_http.pb.go b/api/matchmaking/v1/share/shareBrl_http.pb.go new file mode 100644 index 0000000..5c29e0e --- /dev/null +++ b/api/matchmaking/v1/share/shareBrl_http.pb.go @@ -0,0 +1,279 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.3 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareBrl.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationShareBrlGetBotStockBrlTrade = "/matchmaking.v1.ShareBrl/GetBotStockBrlTrade" +const OperationShareBrlShareBrlAllPosition = "/matchmaking.v1.ShareBrl/ShareBrlAllPosition" +const OperationShareBrlShareBrlCancel = "/matchmaking.v1.ShareBrl/ShareBrlCancel" +const OperationShareBrlShareBrlPlaceOrder = "/matchmaking.v1.ShareBrl/ShareBrlPlaceOrder" +const OperationShareBrlShareBrlPosition = "/matchmaking.v1.ShareBrl/ShareBrlPosition" +const OperationShareBrlShareBrlUpdateOrder = "/matchmaking.v1.ShareBrl/ShareBrlUpdateOrder" + +type ShareBrlHTTPServer interface { + // GetBotStockBrlTrade GetBotStockBrlTrade 巴西国股列表查询 + GetBotStockBrlTrade(context.Context, *GetBrlBotStockTradeRequest) (*GetBotStockBrlTradeReply, error) + // ShareBrlAllPosition ShareBrlAllPosition 巴西国股一键平仓 + ShareBrlAllPosition(context.Context, *AllBrlOrderRequest) (*AllBrlOrderReply, error) + // ShareBrlCancel ShareBrlCancel 巴西国股撤单 + ShareBrlCancel(context.Context, *CancelBrlOrderRequest) (*BrlOrderReply, error) + // ShareBrlPlaceOrder ShareBrlPlaceOrder 巴西国股下单 + ShareBrlPlaceOrder(context.Context, *ShareBrlOrderRequest) (*BrlOrderReply, error) + // ShareBrlPosition ShareBrlPosition 巴西国股平仓 + ShareBrlPosition(context.Context, *CancelBrlOrderRequest) (*BrlOrderReply, error) + // ShareBrlUpdateOrder ShareBrlUpdateOrder 巴西国股设置止盈止损 + ShareBrlUpdateOrder(context.Context, *UpdateBrlOrderRequest) (*BrlOrderReply, error) +} + +func RegisterShareBrlHTTPServer(s *http.Server, srv ShareBrlHTTPServer) { + r := s.Route("/") + r.POST("/order_sharebrl/share_list", _ShareBrl_GetBotStockBrlTrade0_HTTP_Handler(srv)) + r.POST("/order_sharebrl/share_place_order", _ShareBrl_ShareBrlPlaceOrder0_HTTP_Handler(srv)) + r.POST("/order_sharebrl/share_update_order", _ShareBrl_ShareBrlUpdateOrder0_HTTP_Handler(srv)) + r.POST("/order_sharebrl/share_position", _ShareBrl_ShareBrlPosition0_HTTP_Handler(srv)) + r.POST("/order_sharebrl/share_all_position", _ShareBrl_ShareBrlAllPosition0_HTTP_Handler(srv)) + r.POST("/order_sharebrl/share_cancel", _ShareBrl_ShareBrlCancel0_HTTP_Handler(srv)) +} + +func _ShareBrl_GetBotStockBrlTrade0_HTTP_Handler(srv ShareBrlHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetBrlBotStockTradeRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareBrlGetBotStockBrlTrade) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.GetBotStockBrlTrade(ctx, req.(*GetBrlBotStockTradeRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetBotStockBrlTradeReply) + return ctx.Result(200, reply) + } +} + +func _ShareBrl_ShareBrlPlaceOrder0_HTTP_Handler(srv ShareBrlHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in ShareBrlOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareBrlShareBrlPlaceOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareBrlPlaceOrder(ctx, req.(*ShareBrlOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*BrlOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareBrl_ShareBrlUpdateOrder0_HTTP_Handler(srv ShareBrlHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in UpdateBrlOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareBrlShareBrlUpdateOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareBrlUpdateOrder(ctx, req.(*UpdateBrlOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*BrlOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareBrl_ShareBrlPosition0_HTTP_Handler(srv ShareBrlHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelBrlOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareBrlShareBrlPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareBrlPosition(ctx, req.(*CancelBrlOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*BrlOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareBrl_ShareBrlAllPosition0_HTTP_Handler(srv ShareBrlHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in AllBrlOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareBrlShareBrlAllPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareBrlAllPosition(ctx, req.(*AllBrlOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*AllBrlOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareBrl_ShareBrlCancel0_HTTP_Handler(srv ShareBrlHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelBrlOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareBrlShareBrlCancel) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareBrlCancel(ctx, req.(*CancelBrlOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*BrlOrderReply) + return ctx.Result(200, reply) + } +} + +type ShareBrlHTTPClient interface { + GetBotStockBrlTrade(ctx context.Context, req *GetBrlBotStockTradeRequest, opts ...http.CallOption) (rsp *GetBotStockBrlTradeReply, err error) + ShareBrlAllPosition(ctx context.Context, req *AllBrlOrderRequest, opts ...http.CallOption) (rsp *AllBrlOrderReply, err error) + ShareBrlCancel(ctx context.Context, req *CancelBrlOrderRequest, opts ...http.CallOption) (rsp *BrlOrderReply, err error) + ShareBrlPlaceOrder(ctx context.Context, req *ShareBrlOrderRequest, opts ...http.CallOption) (rsp *BrlOrderReply, err error) + ShareBrlPosition(ctx context.Context, req *CancelBrlOrderRequest, opts ...http.CallOption) (rsp *BrlOrderReply, err error) + ShareBrlUpdateOrder(ctx context.Context, req *UpdateBrlOrderRequest, opts ...http.CallOption) (rsp *BrlOrderReply, err error) +} + +type ShareBrlHTTPClientImpl struct { + cc *http.Client +} + +func NewShareBrlHTTPClient(client *http.Client) ShareBrlHTTPClient { + return &ShareBrlHTTPClientImpl{client} +} + +func (c *ShareBrlHTTPClientImpl) GetBotStockBrlTrade(ctx context.Context, in *GetBrlBotStockTradeRequest, opts ...http.CallOption) (*GetBotStockBrlTradeReply, error) { + var out GetBotStockBrlTradeReply + pattern := "/order_sharebrl/share_list" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareBrlGetBotStockBrlTrade)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareBrlHTTPClientImpl) ShareBrlAllPosition(ctx context.Context, in *AllBrlOrderRequest, opts ...http.CallOption) (*AllBrlOrderReply, error) { + var out AllBrlOrderReply + pattern := "/order_sharebrl/share_all_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareBrlShareBrlAllPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareBrlHTTPClientImpl) ShareBrlCancel(ctx context.Context, in *CancelBrlOrderRequest, opts ...http.CallOption) (*BrlOrderReply, error) { + var out BrlOrderReply + pattern := "/order_sharebrl/share_cancel" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareBrlShareBrlCancel)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareBrlHTTPClientImpl) ShareBrlPlaceOrder(ctx context.Context, in *ShareBrlOrderRequest, opts ...http.CallOption) (*BrlOrderReply, error) { + var out BrlOrderReply + pattern := "/order_sharebrl/share_place_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareBrlShareBrlPlaceOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareBrlHTTPClientImpl) ShareBrlPosition(ctx context.Context, in *CancelBrlOrderRequest, opts ...http.CallOption) (*BrlOrderReply, error) { + var out BrlOrderReply + pattern := "/order_sharebrl/share_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareBrlShareBrlPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareBrlHTTPClientImpl) ShareBrlUpdateOrder(ctx context.Context, in *UpdateBrlOrderRequest, opts ...http.CallOption) (*BrlOrderReply, error) { + var out BrlOrderReply + pattern := "/order_sharebrl/share_update_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareBrlShareBrlUpdateOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/api/matchmaking/v1/share/shareEur.pb.go b/api/matchmaking/v1/share/shareEur.pb.go new file mode 100644 index 0000000..111d36f --- /dev/null +++ b/api/matchmaking/v1/share/shareEur.pb.go @@ -0,0 +1,1327 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/share/shareEur.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GetEurBotStockTradeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status int64 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` // 状态码 + PageSize int64 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,3,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 +} + +func (x *GetEurBotStockTradeRequest) Reset() { + *x = GetEurBotStockTradeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetEurBotStockTradeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetEurBotStockTradeRequest) ProtoMessage() {} + +func (x *GetEurBotStockTradeRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetEurBotStockTradeRequest.ProtoReflect.Descriptor instead. +func (*GetEurBotStockTradeRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareEur_proto_rawDescGZIP(), []int{0} +} + +func (x *GetEurBotStockTradeRequest) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *GetEurBotStockTradeRequest) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *GetEurBotStockTradeRequest) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +type GetBotStockEurTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *BotStockEurTradeReply `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *GetBotStockEurTradeReply) Reset() { + *x = GetBotStockEurTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotStockEurTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotStockEurTradeReply) ProtoMessage() {} + +func (x *GetBotStockEurTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotStockEurTradeReply.ProtoReflect.Descriptor instead. +func (*GetBotStockEurTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareEur_proto_rawDescGZIP(), []int{1} +} + +func (x *GetBotStockEurTradeReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *GetBotStockEurTradeReply) GetData() *BotStockEurTradeReply { + if x != nil { + return x.Data + } + return nil +} + +func (x *GetBotStockEurTradeReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type BotStockEurTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PageSize int64 `protobuf:"varint,1,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,2,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + Data []*BotStockEurTrade `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty"` // 返回结果 + TotalCount int64 `protobuf:"varint,4,opt,name=totalCount,proto3" json:"totalCount,omitempty"` // 总数据 +} + +func (x *BotStockEurTradeReply) Reset() { + *x = BotStockEurTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockEurTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockEurTradeReply) ProtoMessage() {} + +func (x *BotStockEurTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockEurTradeReply.ProtoReflect.Descriptor instead. +func (*BotStockEurTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareEur_proto_rawDescGZIP(), []int{2} +} + +func (x *BotStockEurTradeReply) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *BotStockEurTradeReply) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *BotStockEurTradeReply) GetData() []*BotStockEurTrade { + if x != nil { + return x.Data + } + return nil +} + +func (x *BotStockEurTradeReply) GetTotalCount() int64 { + if x != nil { + return x.TotalCount + } + return 0 +} + +type BotStockEurTrade struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID + StockId string `protobuf:"bytes,2,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票代码 + TradeType int64 `protobuf:"varint,3,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型 + DealType int64 `protobuf:"varint,4,opt,name=dealType,proto3" json:"dealType,omitempty"` // 交易方式 + LimitPrice string `protobuf:"bytes,5,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,6,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + DealPrice string `protobuf:"bytes,7,opt,name=dealPrice,proto3" json:"dealPrice,omitempty"` // 开仓价 + ClosingPrice string `protobuf:"bytes,8,opt,name=closingPrice,proto3" json:"closingPrice,omitempty"` // 平仓价 + OrderNumber string `protobuf:"bytes,9,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + ServiceCost string `protobuf:"bytes,13,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 开仓手续费 + MarketMoney string `protobuf:"bytes,14,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderMoney string `protobuf:"bytes,15,opt,name=orderMoney,proto3" json:"orderMoney,omitempty"` // 订单总金额 + Status int64 `protobuf:"varint,16,opt,name=status,proto3" json:"status,omitempty"` // 订单状态 + CreateTime string `protobuf:"bytes,17,opt,name=createTime,proto3" json:"createTime,omitempty"` // 订单创建时间 + UpdateTime string `protobuf:"bytes,18,opt,name=updateTime,proto3" json:"updateTime,omitempty"` // 订单更新时间 + OpenTime string `protobuf:"bytes,19,opt,name=openTime,proto3" json:"openTime,omitempty"` // 订单开仓时间 + ClosingTime string `protobuf:"bytes,20,opt,name=closingTime,proto3" json:"closingTime,omitempty"` // 订单平仓时间 + ClosingCost string `protobuf:"bytes,21,opt,name=closingCost,proto3" json:"closingCost,omitempty"` // 平仓手续费 + FaceValue string `protobuf:"bytes,22,opt,name=faceValue,proto3" json:"faceValue,omitempty"` // 面值 + PryNum string `protobuf:"bytes,23,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 + KeepDecimal string `protobuf:"bytes,24,opt,name=keepDecimal,proto3" json:"keepDecimal,omitempty"` // 保留小数位 + StockName string `protobuf:"bytes,25,opt,name=stockName,proto3" json:"stockName,omitempty"` // 股票名称 +} + +func (x *BotStockEurTrade) Reset() { + *x = BotStockEurTrade{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockEurTrade) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockEurTrade) ProtoMessage() {} + +func (x *BotStockEurTrade) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockEurTrade.ProtoReflect.Descriptor instead. +func (*BotStockEurTrade) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareEur_proto_rawDescGZIP(), []int{3} +} + +func (x *BotStockEurTrade) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *BotStockEurTrade) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *BotStockEurTrade) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *BotStockEurTrade) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *BotStockEurTrade) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *BotStockEurTrade) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *BotStockEurTrade) GetDealPrice() string { + if x != nil { + return x.DealPrice + } + return "" +} + +func (x *BotStockEurTrade) GetClosingPrice() string { + if x != nil { + return x.ClosingPrice + } + return "" +} + +func (x *BotStockEurTrade) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *BotStockEurTrade) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *BotStockEurTrade) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *BotStockEurTrade) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *BotStockEurTrade) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *BotStockEurTrade) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *BotStockEurTrade) GetOrderMoney() string { + if x != nil { + return x.OrderMoney + } + return "" +} + +func (x *BotStockEurTrade) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *BotStockEurTrade) GetCreateTime() string { + if x != nil { + return x.CreateTime + } + return "" +} + +func (x *BotStockEurTrade) GetUpdateTime() string { + if x != nil { + return x.UpdateTime + } + return "" +} + +func (x *BotStockEurTrade) GetOpenTime() string { + if x != nil { + return x.OpenTime + } + return "" +} + +func (x *BotStockEurTrade) GetClosingTime() string { + if x != nil { + return x.ClosingTime + } + return "" +} + +func (x *BotStockEurTrade) GetClosingCost() string { + if x != nil { + return x.ClosingCost + } + return "" +} + +func (x *BotStockEurTrade) GetFaceValue() string { + if x != nil { + return x.FaceValue + } + return "" +} + +func (x *BotStockEurTrade) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *BotStockEurTrade) GetKeepDecimal() string { + if x != nil { + return x.KeepDecimal + } + return "" +} + +func (x *BotStockEurTrade) GetStockName() string { + if x != nil { + return x.StockName + } + return "" +} + +type ShareEurOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + StockId string `protobuf:"bytes,1,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票Code + TradeType int64 `protobuf:"varint,2,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型:1买入,2卖出 + DealType int64 `protobuf:"varint,3,opt,name=dealType,proto3" json:"dealType,omitempty"` // 委托方式:1限价,2市价 + LimitPrice string `protobuf:"bytes,4,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,5,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + MarketMoney string `protobuf:"bytes,6,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderNumber string `protobuf:"bytes,7,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + ServiceCost string `protobuf:"bytes,8,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 手续费 + StopType int64 `protobuf:"varint,9,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止损止盈设置:1无设置,2止损止盈 + StopLossPrice string `protobuf:"bytes,10,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,11,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止损 + PryNum string `protobuf:"bytes,12,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 +} + +func (x *ShareEurOrderRequest) Reset() { + *x = ShareEurOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ShareEurOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ShareEurOrderRequest) ProtoMessage() {} + +func (x *ShareEurOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ShareEurOrderRequest.ProtoReflect.Descriptor instead. +func (*ShareEurOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareEur_proto_rawDescGZIP(), []int{4} +} + +func (x *ShareEurOrderRequest) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *ShareEurOrderRequest) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *ShareEurOrderRequest) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *ShareEurOrderRequest) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *ShareEurOrderRequest) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *ShareEurOrderRequest) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *ShareEurOrderRequest) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *ShareEurOrderRequest) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *ShareEurOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *ShareEurOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *ShareEurOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *ShareEurOrderRequest) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +type UpdateEurOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id + StopType int64 `protobuf:"varint,2,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,3,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,4,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 +} + +func (x *UpdateEurOrderRequest) Reset() { + *x = UpdateEurOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateEurOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateEurOrderRequest) ProtoMessage() {} + +func (x *UpdateEurOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateEurOrderRequest.ProtoReflect.Descriptor instead. +func (*UpdateEurOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareEur_proto_rawDescGZIP(), []int{5} +} + +func (x *UpdateEurOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *UpdateEurOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *UpdateEurOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *UpdateEurOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +type EurOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *EurOrderResult `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *EurOrderReply) Reset() { + *x = EurOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EurOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EurOrderReply) ProtoMessage() {} + +func (x *EurOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EurOrderReply.ProtoReflect.Descriptor instead. +func (*EurOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareEur_proto_rawDescGZIP(), []int{6} +} + +func (x *EurOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *EurOrderReply) GetData() *EurOrderResult { + if x != nil { + return x.Data + } + return nil +} + +func (x *EurOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type EurOrderResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id +} + +func (x *EurOrderResult) Reset() { + *x = EurOrderResult{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EurOrderResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EurOrderResult) ProtoMessage() {} + +func (x *EurOrderResult) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EurOrderResult.ProtoReflect.Descriptor instead. +func (*EurOrderResult) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareEur_proto_rawDescGZIP(), []int{7} +} + +func (x *EurOrderResult) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type CancelEurOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID +} + +func (x *CancelEurOrderRequest) Reset() { + *x = CancelEurOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CancelEurOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CancelEurOrderRequest) ProtoMessage() {} + +func (x *CancelEurOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CancelEurOrderRequest.ProtoReflect.Descriptor instead. +func (*CancelEurOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareEur_proto_rawDescGZIP(), []int{8} +} + +func (x *CancelEurOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type AllEurOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *AllEurOrderRequest) Reset() { + *x = AllEurOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllEurOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllEurOrderRequest) ProtoMessage() {} + +func (x *AllEurOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllEurOrderRequest.ProtoReflect.Descriptor instead. +func (*AllEurOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareEur_proto_rawDescGZIP(), []int{9} +} + +type AllEurOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *AllEurOrderReply) Reset() { + *x = AllEurOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllEurOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllEurOrderReply) ProtoMessage() {} + +func (x *AllEurOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareEur_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllEurOrderReply.ProtoReflect.Descriptor instead. +func (*AllEurOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareEur_proto_rawDescGZIP(), []int{10} +} + +func (x *AllEurOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *AllEurOrderReply) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +func (x *AllEurOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_matchmaking_v1_share_shareEur_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_share_shareEur_proto_rawDesc = []byte{ + 0x0a, 0x23, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x45, 0x75, 0x72, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0x6e, 0x0a, 0x1a, 0x47, 0x65, 0x74, 0x45, 0x75, 0x72, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, + 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x22, 0x83, 0x01, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, + 0x6f, 0x63, 0x6b, 0x45, 0x75, 0x72, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, + 0x63, 0x6f, 0x64, 0x65, 0x12, 0x39, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x45, 0x75, 0x72, 0x54, + 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, + 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xa7, 0x01, 0x0a, 0x15, 0x42, 0x6f, + 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x45, 0x75, 0x72, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, + 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x34, 0x0a, + 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x45, 0x75, 0x72, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x04, 0x64, + 0x61, 0x74, 0x61, 0x12, 0x1e, 0x0a, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, + 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x22, 0x9e, 0x06, 0x0a, 0x10, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, + 0x45, 0x75, 0x72, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, + 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, + 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, + 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, + 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, + 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x65, 0x61, 0x6c, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x64, 0x65, 0x61, + 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, + 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6c, + 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, + 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, + 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, + 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, + 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0c, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, + 0x74, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x43, 0x6f, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, + 0x6e, 0x65, 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, + 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x18, 0x10, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1e, + 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x11, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1e, + 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x12, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1a, + 0x0a, 0x08, 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x13, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x08, 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, + 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, + 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x15, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1c, + 0x0a, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x16, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x16, 0x0a, 0x06, + 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x17, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, + 0x79, 0x4e, 0x75, 0x6d, 0x12, 0x20, 0x0a, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, + 0x6d, 0x61, 0x6c, 0x18, 0x18, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, + 0x65, 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x4e, + 0x61, 0x6d, 0x65, 0x18, 0x19, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x90, 0x03, 0x0a, 0x14, 0x53, 0x68, 0x61, 0x72, 0x65, 0x45, 0x75, + 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, + 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, + 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x72, 0x61, 0x64, + 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, + 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, + 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, + 0x65, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, + 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, + 0x6d, 0x62, 0x65, 0x72, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, + 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, + 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, + 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, + 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, + 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, + 0x16, 0x0a, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x22, 0x97, 0x01, 0x0a, 0x15, 0x55, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x45, 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, + 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, + 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, + 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, + 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, + 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x22, 0x71, 0x0a, 0x0d, 0x45, 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, + 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x32, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x73, 0x75, 0x6c, 0x74, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x22, 0x2a, 0x0a, 0x0e, 0x45, 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, + 0x22, 0x31, 0x0a, 0x15, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x45, 0x75, 0x72, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x49, 0x64, 0x22, 0x14, 0x0a, 0x12, 0x41, 0x6c, 0x6c, 0x45, 0x75, 0x72, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x54, 0x0a, 0x10, 0x41, 0x6c, 0x6c, + 0x45, 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, + 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, + 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, + 0xca, 0x06, 0x0a, 0x08, 0x53, 0x68, 0x61, 0x72, 0x65, 0x45, 0x75, 0x72, 0x12, 0x92, 0x01, 0x0a, + 0x13, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x45, 0x75, 0x72, 0x54, + 0x72, 0x61, 0x64, 0x65, 0x12, 0x2a, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x45, 0x75, 0x72, 0x42, 0x6f, 0x74, 0x53, + 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x28, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, + 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x45, 0x75, 0x72, + 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x25, 0x82, 0xd3, 0xe4, 0x93, + 0x02, 0x1f, 0x3a, 0x01, 0x2a, 0x22, 0x1a, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, + 0x61, 0x72, 0x65, 0x65, 0x75, 0x72, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x6c, 0x69, 0x73, + 0x74, 0x12, 0x87, 0x01, 0x0a, 0x12, 0x53, 0x68, 0x61, 0x72, 0x65, 0x45, 0x75, 0x72, 0x50, 0x6c, + 0x61, 0x63, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x24, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x45, + 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, + 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x45, 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2c, 0x82, + 0xd3, 0xe4, 0x93, 0x02, 0x26, 0x3a, 0x01, 0x2a, 0x22, 0x21, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x65, 0x75, 0x72, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, + 0x70, 0x6c, 0x61, 0x63, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x8a, 0x01, 0x0a, 0x13, + 0x53, 0x68, 0x61, 0x72, 0x65, 0x45, 0x75, 0x72, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x12, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, + 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x45, 0x75, 0x72, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x75, 0x72, 0x4f, + 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93, 0x02, + 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, + 0x72, 0x65, 0x65, 0x75, 0x72, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x75, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x83, 0x01, 0x0a, 0x10, 0x53, 0x68, 0x61, + 0x72, 0x65, 0x45, 0x75, 0x72, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x25, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, + 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x45, 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x29, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x23, 0x3a, 0x01, 0x2a, 0x22, 0x1e, + 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x65, 0x75, 0x72, 0x2f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x8a, + 0x01, 0x0a, 0x13, 0x53, 0x68, 0x61, 0x72, 0x65, 0x45, 0x75, 0x72, 0x41, 0x6c, 0x6c, 0x50, 0x6f, + 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x22, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, + 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x45, 0x75, 0x72, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x45, + 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2d, 0x82, 0xd3, + 0xe4, 0x93, 0x02, 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x65, 0x75, 0x72, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x61, + 0x6c, 0x6c, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x7f, 0x0a, 0x0e, 0x53, + 0x68, 0x61, 0x72, 0x65, 0x45, 0x75, 0x72, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x12, 0x25, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, + 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x45, 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x27, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x21, 0x3a, 0x01, 0x2a, 0x22, 0x1c, + 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x65, 0x75, 0x72, 0x2f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x42, 0x2a, 0x5a, 0x28, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x73, 0x79, 0x73, 0x74, + 0x65, 0x6d, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_share_shareEur_proto_rawDescOnce sync.Once + file_matchmaking_v1_share_shareEur_proto_rawDescData = file_matchmaking_v1_share_shareEur_proto_rawDesc +) + +func file_matchmaking_v1_share_shareEur_proto_rawDescGZIP() []byte { + file_matchmaking_v1_share_shareEur_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_share_shareEur_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_share_shareEur_proto_rawDescData) + }) + return file_matchmaking_v1_share_shareEur_proto_rawDescData +} + +var file_matchmaking_v1_share_shareEur_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_matchmaking_v1_share_shareEur_proto_goTypes = []any{ + (*GetEurBotStockTradeRequest)(nil), // 0: matchmaking.v1.GetEurBotStockTradeRequest + (*GetBotStockEurTradeReply)(nil), // 1: matchmaking.v1.GetBotStockEurTradeReply + (*BotStockEurTradeReply)(nil), // 2: matchmaking.v1.BotStockEurTradeReply + (*BotStockEurTrade)(nil), // 3: matchmaking.v1.BotStockEurTrade + (*ShareEurOrderRequest)(nil), // 4: matchmaking.v1.ShareEurOrderRequest + (*UpdateEurOrderRequest)(nil), // 5: matchmaking.v1.UpdateEurOrderRequest + (*EurOrderReply)(nil), // 6: matchmaking.v1.EurOrderReply + (*EurOrderResult)(nil), // 7: matchmaking.v1.EurOrderResult + (*CancelEurOrderRequest)(nil), // 8: matchmaking.v1.CancelEurOrderRequest + (*AllEurOrderRequest)(nil), // 9: matchmaking.v1.AllEurOrderRequest + (*AllEurOrderReply)(nil), // 10: matchmaking.v1.AllEurOrderReply +} +var file_matchmaking_v1_share_shareEur_proto_depIdxs = []int32{ + 2, // 0: matchmaking.v1.GetBotStockEurTradeReply.data:type_name -> matchmaking.v1.BotStockEurTradeReply + 3, // 1: matchmaking.v1.BotStockEurTradeReply.data:type_name -> matchmaking.v1.BotStockEurTrade + 7, // 2: matchmaking.v1.EurOrderReply.data:type_name -> matchmaking.v1.EurOrderResult + 0, // 3: matchmaking.v1.ShareEur.GetBotStockEurTrade:input_type -> matchmaking.v1.GetEurBotStockTradeRequest + 4, // 4: matchmaking.v1.ShareEur.ShareEurPlaceOrder:input_type -> matchmaking.v1.ShareEurOrderRequest + 5, // 5: matchmaking.v1.ShareEur.ShareEurUpdateOrder:input_type -> matchmaking.v1.UpdateEurOrderRequest + 8, // 6: matchmaking.v1.ShareEur.ShareEurPosition:input_type -> matchmaking.v1.CancelEurOrderRequest + 9, // 7: matchmaking.v1.ShareEur.ShareEurAllPosition:input_type -> matchmaking.v1.AllEurOrderRequest + 8, // 8: matchmaking.v1.ShareEur.ShareEurCancel:input_type -> matchmaking.v1.CancelEurOrderRequest + 1, // 9: matchmaking.v1.ShareEur.GetBotStockEurTrade:output_type -> matchmaking.v1.GetBotStockEurTradeReply + 6, // 10: matchmaking.v1.ShareEur.ShareEurPlaceOrder:output_type -> matchmaking.v1.EurOrderReply + 6, // 11: matchmaking.v1.ShareEur.ShareEurUpdateOrder:output_type -> matchmaking.v1.EurOrderReply + 6, // 12: matchmaking.v1.ShareEur.ShareEurPosition:output_type -> matchmaking.v1.EurOrderReply + 10, // 13: matchmaking.v1.ShareEur.ShareEurAllPosition:output_type -> matchmaking.v1.AllEurOrderReply + 6, // 14: matchmaking.v1.ShareEur.ShareEurCancel:output_type -> matchmaking.v1.EurOrderReply + 9, // [9:15] is the sub-list for method output_type + 3, // [3:9] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_share_shareEur_proto_init() } +func file_matchmaking_v1_share_shareEur_proto_init() { + if File_matchmaking_v1_share_shareEur_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_matchmaking_v1_share_shareEur_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*GetEurBotStockTradeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareEur_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*GetBotStockEurTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareEur_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*BotStockEurTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareEur_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*BotStockEurTrade); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareEur_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*ShareEurOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareEur_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*UpdateEurOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareEur_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*EurOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareEur_proto_msgTypes[7].Exporter = func(v any, i int) any { + switch v := v.(*EurOrderResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareEur_proto_msgTypes[8].Exporter = func(v any, i int) any { + switch v := v.(*CancelEurOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareEur_proto_msgTypes[9].Exporter = func(v any, i int) any { + switch v := v.(*AllEurOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareEur_proto_msgTypes[10].Exporter = func(v any, i int) any { + switch v := v.(*AllEurOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_share_shareEur_proto_rawDesc, + NumEnums: 0, + NumMessages: 11, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_matchmaking_v1_share_shareEur_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_share_shareEur_proto_depIdxs, + MessageInfos: file_matchmaking_v1_share_shareEur_proto_msgTypes, + }.Build() + File_matchmaking_v1_share_shareEur_proto = out.File + file_matchmaking_v1_share_shareEur_proto_rawDesc = nil + file_matchmaking_v1_share_shareEur_proto_goTypes = nil + file_matchmaking_v1_share_shareEur_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/share/shareEur.proto b/api/matchmaking/v1/share/shareEur.proto new file mode 100644 index 0000000..2f6882b --- /dev/null +++ b/api/matchmaking/v1/share/shareEur.proto @@ -0,0 +1,144 @@ +syntax = "proto3"; + +package matchmaking.v1; + +import "google/api/annotations.proto"; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +service ShareEur { + // GetBotStockEurTrade 德国股列表查询 + rpc GetBotStockEurTrade(GetEurBotStockTradeRequest)returns(GetBotStockEurTradeReply){ + option (google.api.http) = { + post:"/order_shareeur/share_list", + body:"*", + }; + } + // ShareEurPlaceOrder 德国股下单 + rpc ShareEurPlaceOrder(ShareEurOrderRequest)returns(EurOrderReply) { + option (google.api.http) = { + post: "/order_shareeur/share_place_order", + body: "*", + }; + } + // ShareEurUpdateOrder 德国股设置止盈止损 + rpc ShareEurUpdateOrder(UpdateEurOrderRequest)returns(EurOrderReply){ + option (google.api.http) = { + post:"/order_shareeur/share_update_order", + body:"*", + }; + } + // ShareEurPosition 德国股平仓 + rpc ShareEurPosition(CancelEurOrderRequest)returns(EurOrderReply){ + option (google.api.http) = { + post:"/order_shareeur/share_position", + body:"*", + }; + } + // ShareEurAllPosition 德国股一键平仓 + rpc ShareEurAllPosition(AllEurOrderRequest)returns(AllEurOrderReply){ + option (google.api.http) = { + post:"/order_shareeur/share_all_position", + body:"*", + }; + } + // ShareEurCancel 德国股撤单 + rpc ShareEurCancel(CancelEurOrderRequest)returns(EurOrderReply){ + option (google.api.http) = { + post:"/order_shareeur/share_cancel", + body:"*", + }; + } +} + +message GetEurBotStockTradeRequest{ + int64 status =1;// 状态码 + int64 pageSize =2; // 每页显示条数 + int64 pageCount =3;// 开始的位置 +} + +message GetBotStockEurTradeReply{ + int64 code =1;// 状态码 + BotStockEurTradeReply data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message BotStockEurTradeReply{ + int64 pageSize =1; // 每页显示条数 + int64 pageCount =2;// 开始的位置 + repeated BotStockEurTrade data =3;// 返回结果 + int64 totalCount =4;// 总数据 +} + +message BotStockEurTrade{ + string orderId =1;// 订单ID + string stockId =2;// 股票代码 + int64 tradeType =3;// 交易类型 + int64 dealType =4;// 交易方式 + string limitPrice =5;// 限价 + string marketPrice =6;// 市价 + string dealPrice =7;// 开仓价 + string closingPrice =8;// 平仓价 + string orderNumber =9;// 订单数量 + int64 stopType =10;// 止盈止损 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string serviceCost =13;// 开仓手续费 + string marketMoney =14;// 订单金额 + string orderMoney =15;// 订单总金额 + int64 status =16;// 订单状态 + string createTime =17;// 订单创建时间 + string updateTime =18;// 订单更新时间 + string openTime =19;// 订单开仓时间 + string closingTime =20;// 订单平仓时间 + string closingCost =21;// 平仓手续费 + string faceValue =22;// 面值 + string pryNum =23;// 杠杆 + string keepDecimal =24;// 保留小数位 + string stockName =25;// 股票名称 +} + +message ShareEurOrderRequest{ + string stockId =1;// 股票Code + int64 tradeType =2;// 交易类型:1买入,2卖出 + int64 dealType =3;// 委托方式:1限价,2市价 + string limitPrice =4;// 限价 + string marketPrice =5;// 市价 + string marketMoney =6;// 订单金额 + string orderNumber =7;// 订单数量 + string serviceCost =8;// 手续费 + int64 stopType =9;// 止损止盈设置:1无设置,2止损止盈 + string stopLossPrice =10;// 止损 + string stopWinPrice =11;// 止损 + string pryNum =12;// 杠杆 +} + +message UpdateEurOrderRequest{ + string orderId =1;// 订单Id + int64 stopType =2;// 止盈止损 + string stopLossPrice =3;// 止损 + string stopWinPrice =4;// 止盈 +} + +message EurOrderReply{ + int64 code =1;// 状态码 + EurOrderResult data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message EurOrderResult { + string orderId =1;// 订单Id +} + +message CancelEurOrderRequest{ + string orderId =1;// 订单ID +} + +message AllEurOrderRequest{ + +} +message AllEurOrderReply{ + int64 code =1;// 状态码 + string data =2;// 返回结果 + string message =3;// 返回消息提示 +} \ No newline at end of file diff --git a/api/matchmaking/v1/share/shareEur_grpc.pb.go b/api/matchmaking/v1/share/shareEur_grpc.pb.go new file mode 100644 index 0000000..3b44efd --- /dev/null +++ b/api/matchmaking/v1/share/shareEur_grpc.pb.go @@ -0,0 +1,312 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareEur.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + ShareEur_GetBotStockEurTrade_FullMethodName = "/matchmaking.v1.ShareEur/GetBotStockEurTrade" + ShareEur_ShareEurPlaceOrder_FullMethodName = "/matchmaking.v1.ShareEur/ShareEurPlaceOrder" + ShareEur_ShareEurUpdateOrder_FullMethodName = "/matchmaking.v1.ShareEur/ShareEurUpdateOrder" + ShareEur_ShareEurPosition_FullMethodName = "/matchmaking.v1.ShareEur/ShareEurPosition" + ShareEur_ShareEurAllPosition_FullMethodName = "/matchmaking.v1.ShareEur/ShareEurAllPosition" + ShareEur_ShareEurCancel_FullMethodName = "/matchmaking.v1.ShareEur/ShareEurCancel" +) + +// ShareEurClient is the client API for ShareEur service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ShareEurClient interface { + // GetBotStockEurTrade 德国股列表查询 + GetBotStockEurTrade(ctx context.Context, in *GetEurBotStockTradeRequest, opts ...grpc.CallOption) (*GetBotStockEurTradeReply, error) + // ShareEurPlaceOrder 德国股下单 + ShareEurPlaceOrder(ctx context.Context, in *ShareEurOrderRequest, opts ...grpc.CallOption) (*EurOrderReply, error) + // ShareEurUpdateOrder 德国股设置止盈止损 + ShareEurUpdateOrder(ctx context.Context, in *UpdateEurOrderRequest, opts ...grpc.CallOption) (*EurOrderReply, error) + // ShareEurPosition 德国股平仓 + ShareEurPosition(ctx context.Context, in *CancelEurOrderRequest, opts ...grpc.CallOption) (*EurOrderReply, error) + // ShareEurAllPosition 德国股一键平仓 + ShareEurAllPosition(ctx context.Context, in *AllEurOrderRequest, opts ...grpc.CallOption) (*AllEurOrderReply, error) + // ShareEurCancel 德国股撤单 + ShareEurCancel(ctx context.Context, in *CancelEurOrderRequest, opts ...grpc.CallOption) (*EurOrderReply, error) +} + +type shareEurClient struct { + cc grpc.ClientConnInterface +} + +func NewShareEurClient(cc grpc.ClientConnInterface) ShareEurClient { + return &shareEurClient{cc} +} + +func (c *shareEurClient) GetBotStockEurTrade(ctx context.Context, in *GetEurBotStockTradeRequest, opts ...grpc.CallOption) (*GetBotStockEurTradeReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetBotStockEurTradeReply) + err := c.cc.Invoke(ctx, ShareEur_GetBotStockEurTrade_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareEurClient) ShareEurPlaceOrder(ctx context.Context, in *ShareEurOrderRequest, opts ...grpc.CallOption) (*EurOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(EurOrderReply) + err := c.cc.Invoke(ctx, ShareEur_ShareEurPlaceOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareEurClient) ShareEurUpdateOrder(ctx context.Context, in *UpdateEurOrderRequest, opts ...grpc.CallOption) (*EurOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(EurOrderReply) + err := c.cc.Invoke(ctx, ShareEur_ShareEurUpdateOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareEurClient) ShareEurPosition(ctx context.Context, in *CancelEurOrderRequest, opts ...grpc.CallOption) (*EurOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(EurOrderReply) + err := c.cc.Invoke(ctx, ShareEur_ShareEurPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareEurClient) ShareEurAllPosition(ctx context.Context, in *AllEurOrderRequest, opts ...grpc.CallOption) (*AllEurOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AllEurOrderReply) + err := c.cc.Invoke(ctx, ShareEur_ShareEurAllPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareEurClient) ShareEurCancel(ctx context.Context, in *CancelEurOrderRequest, opts ...grpc.CallOption) (*EurOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(EurOrderReply) + err := c.cc.Invoke(ctx, ShareEur_ShareEurCancel_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ShareEurServer is the server API for ShareEur service. +// All implementations must embed UnimplementedShareEurServer +// for forward compatibility +type ShareEurServer interface { + // GetBotStockEurTrade 德国股列表查询 + GetBotStockEurTrade(context.Context, *GetEurBotStockTradeRequest) (*GetBotStockEurTradeReply, error) + // ShareEurPlaceOrder 德国股下单 + ShareEurPlaceOrder(context.Context, *ShareEurOrderRequest) (*EurOrderReply, error) + // ShareEurUpdateOrder 德国股设置止盈止损 + ShareEurUpdateOrder(context.Context, *UpdateEurOrderRequest) (*EurOrderReply, error) + // ShareEurPosition 德国股平仓 + ShareEurPosition(context.Context, *CancelEurOrderRequest) (*EurOrderReply, error) + // ShareEurAllPosition 德国股一键平仓 + ShareEurAllPosition(context.Context, *AllEurOrderRequest) (*AllEurOrderReply, error) + // ShareEurCancel 德国股撤单 + ShareEurCancel(context.Context, *CancelEurOrderRequest) (*EurOrderReply, error) + mustEmbedUnimplementedShareEurServer() +} + +// UnimplementedShareEurServer must be embedded to have forward compatible implementations. +type UnimplementedShareEurServer struct { +} + +func (UnimplementedShareEurServer) GetBotStockEurTrade(context.Context, *GetEurBotStockTradeRequest) (*GetBotStockEurTradeReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBotStockEurTrade not implemented") +} +func (UnimplementedShareEurServer) ShareEurPlaceOrder(context.Context, *ShareEurOrderRequest) (*EurOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareEurPlaceOrder not implemented") +} +func (UnimplementedShareEurServer) ShareEurUpdateOrder(context.Context, *UpdateEurOrderRequest) (*EurOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareEurUpdateOrder not implemented") +} +func (UnimplementedShareEurServer) ShareEurPosition(context.Context, *CancelEurOrderRequest) (*EurOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareEurPosition not implemented") +} +func (UnimplementedShareEurServer) ShareEurAllPosition(context.Context, *AllEurOrderRequest) (*AllEurOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareEurAllPosition not implemented") +} +func (UnimplementedShareEurServer) ShareEurCancel(context.Context, *CancelEurOrderRequest) (*EurOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareEurCancel not implemented") +} +func (UnimplementedShareEurServer) mustEmbedUnimplementedShareEurServer() {} + +// UnsafeShareEurServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ShareEurServer will +// result in compilation errors. +type UnsafeShareEurServer interface { + mustEmbedUnimplementedShareEurServer() +} + +func RegisterShareEurServer(s grpc.ServiceRegistrar, srv ShareEurServer) { + s.RegisterService(&ShareEur_ServiceDesc, srv) +} + +func _ShareEur_GetBotStockEurTrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetEurBotStockTradeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareEurServer).GetBotStockEurTrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareEur_GetBotStockEurTrade_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareEurServer).GetBotStockEurTrade(ctx, req.(*GetEurBotStockTradeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareEur_ShareEurPlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ShareEurOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareEurServer).ShareEurPlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareEur_ShareEurPlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareEurServer).ShareEurPlaceOrder(ctx, req.(*ShareEurOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareEur_ShareEurUpdateOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateEurOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareEurServer).ShareEurUpdateOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareEur_ShareEurUpdateOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareEurServer).ShareEurUpdateOrder(ctx, req.(*UpdateEurOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareEur_ShareEurPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelEurOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareEurServer).ShareEurPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareEur_ShareEurPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareEurServer).ShareEurPosition(ctx, req.(*CancelEurOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareEur_ShareEurAllPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AllEurOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareEurServer).ShareEurAllPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareEur_ShareEurAllPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareEurServer).ShareEurAllPosition(ctx, req.(*AllEurOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareEur_ShareEurCancel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelEurOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareEurServer).ShareEurCancel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareEur_ShareEurCancel_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareEurServer).ShareEurCancel(ctx, req.(*CancelEurOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// ShareEur_ServiceDesc is the grpc.ServiceDesc for ShareEur service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ShareEur_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "matchmaking.v1.ShareEur", + HandlerType: (*ShareEurServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetBotStockEurTrade", + Handler: _ShareEur_GetBotStockEurTrade_Handler, + }, + { + MethodName: "ShareEurPlaceOrder", + Handler: _ShareEur_ShareEurPlaceOrder_Handler, + }, + { + MethodName: "ShareEurUpdateOrder", + Handler: _ShareEur_ShareEurUpdateOrder_Handler, + }, + { + MethodName: "ShareEurPosition", + Handler: _ShareEur_ShareEurPosition_Handler, + }, + { + MethodName: "ShareEurAllPosition", + Handler: _ShareEur_ShareEurAllPosition_Handler, + }, + { + MethodName: "ShareEurCancel", + Handler: _ShareEur_ShareEurCancel_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "matchmaking/v1/share/shareEur.proto", +} diff --git a/api/matchmaking/v1/share/shareEur_http.pb.go b/api/matchmaking/v1/share/shareEur_http.pb.go new file mode 100644 index 0000000..5bb0923 --- /dev/null +++ b/api/matchmaking/v1/share/shareEur_http.pb.go @@ -0,0 +1,279 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.3 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareEur.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationShareEurGetBotStockEurTrade = "/matchmaking.v1.ShareEur/GetBotStockEurTrade" +const OperationShareEurShareEurAllPosition = "/matchmaking.v1.ShareEur/ShareEurAllPosition" +const OperationShareEurShareEurCancel = "/matchmaking.v1.ShareEur/ShareEurCancel" +const OperationShareEurShareEurPlaceOrder = "/matchmaking.v1.ShareEur/ShareEurPlaceOrder" +const OperationShareEurShareEurPosition = "/matchmaking.v1.ShareEur/ShareEurPosition" +const OperationShareEurShareEurUpdateOrder = "/matchmaking.v1.ShareEur/ShareEurUpdateOrder" + +type ShareEurHTTPServer interface { + // GetBotStockEurTrade GetBotStockEurTrade 德国股列表查询 + GetBotStockEurTrade(context.Context, *GetEurBotStockTradeRequest) (*GetBotStockEurTradeReply, error) + // ShareEurAllPosition ShareEurAllPosition 德国股一键平仓 + ShareEurAllPosition(context.Context, *AllEurOrderRequest) (*AllEurOrderReply, error) + // ShareEurCancel ShareEurCancel 德国股撤单 + ShareEurCancel(context.Context, *CancelEurOrderRequest) (*EurOrderReply, error) + // ShareEurPlaceOrder ShareEurPlaceOrder 德国股下单 + ShareEurPlaceOrder(context.Context, *ShareEurOrderRequest) (*EurOrderReply, error) + // ShareEurPosition ShareEurPosition 德国股平仓 + ShareEurPosition(context.Context, *CancelEurOrderRequest) (*EurOrderReply, error) + // ShareEurUpdateOrder ShareEurUpdateOrder 德国股设置止盈止损 + ShareEurUpdateOrder(context.Context, *UpdateEurOrderRequest) (*EurOrderReply, error) +} + +func RegisterShareEurHTTPServer(s *http.Server, srv ShareEurHTTPServer) { + r := s.Route("/") + r.POST("/order_shareeur/share_list", _ShareEur_GetBotStockEurTrade0_HTTP_Handler(srv)) + r.POST("/order_shareeur/share_place_order", _ShareEur_ShareEurPlaceOrder0_HTTP_Handler(srv)) + r.POST("/order_shareeur/share_update_order", _ShareEur_ShareEurUpdateOrder0_HTTP_Handler(srv)) + r.POST("/order_shareeur/share_position", _ShareEur_ShareEurPosition0_HTTP_Handler(srv)) + r.POST("/order_shareeur/share_all_position", _ShareEur_ShareEurAllPosition0_HTTP_Handler(srv)) + r.POST("/order_shareeur/share_cancel", _ShareEur_ShareEurCancel0_HTTP_Handler(srv)) +} + +func _ShareEur_GetBotStockEurTrade0_HTTP_Handler(srv ShareEurHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetEurBotStockTradeRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareEurGetBotStockEurTrade) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.GetBotStockEurTrade(ctx, req.(*GetEurBotStockTradeRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetBotStockEurTradeReply) + return ctx.Result(200, reply) + } +} + +func _ShareEur_ShareEurPlaceOrder0_HTTP_Handler(srv ShareEurHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in ShareEurOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareEurShareEurPlaceOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareEurPlaceOrder(ctx, req.(*ShareEurOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*EurOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareEur_ShareEurUpdateOrder0_HTTP_Handler(srv ShareEurHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in UpdateEurOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareEurShareEurUpdateOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareEurUpdateOrder(ctx, req.(*UpdateEurOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*EurOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareEur_ShareEurPosition0_HTTP_Handler(srv ShareEurHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelEurOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareEurShareEurPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareEurPosition(ctx, req.(*CancelEurOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*EurOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareEur_ShareEurAllPosition0_HTTP_Handler(srv ShareEurHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in AllEurOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareEurShareEurAllPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareEurAllPosition(ctx, req.(*AllEurOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*AllEurOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareEur_ShareEurCancel0_HTTP_Handler(srv ShareEurHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelEurOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareEurShareEurCancel) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareEurCancel(ctx, req.(*CancelEurOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*EurOrderReply) + return ctx.Result(200, reply) + } +} + +type ShareEurHTTPClient interface { + GetBotStockEurTrade(ctx context.Context, req *GetEurBotStockTradeRequest, opts ...http.CallOption) (rsp *GetBotStockEurTradeReply, err error) + ShareEurAllPosition(ctx context.Context, req *AllEurOrderRequest, opts ...http.CallOption) (rsp *AllEurOrderReply, err error) + ShareEurCancel(ctx context.Context, req *CancelEurOrderRequest, opts ...http.CallOption) (rsp *EurOrderReply, err error) + ShareEurPlaceOrder(ctx context.Context, req *ShareEurOrderRequest, opts ...http.CallOption) (rsp *EurOrderReply, err error) + ShareEurPosition(ctx context.Context, req *CancelEurOrderRequest, opts ...http.CallOption) (rsp *EurOrderReply, err error) + ShareEurUpdateOrder(ctx context.Context, req *UpdateEurOrderRequest, opts ...http.CallOption) (rsp *EurOrderReply, err error) +} + +type ShareEurHTTPClientImpl struct { + cc *http.Client +} + +func NewShareEurHTTPClient(client *http.Client) ShareEurHTTPClient { + return &ShareEurHTTPClientImpl{client} +} + +func (c *ShareEurHTTPClientImpl) GetBotStockEurTrade(ctx context.Context, in *GetEurBotStockTradeRequest, opts ...http.CallOption) (*GetBotStockEurTradeReply, error) { + var out GetBotStockEurTradeReply + pattern := "/order_shareeur/share_list" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareEurGetBotStockEurTrade)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareEurHTTPClientImpl) ShareEurAllPosition(ctx context.Context, in *AllEurOrderRequest, opts ...http.CallOption) (*AllEurOrderReply, error) { + var out AllEurOrderReply + pattern := "/order_shareeur/share_all_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareEurShareEurAllPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareEurHTTPClientImpl) ShareEurCancel(ctx context.Context, in *CancelEurOrderRequest, opts ...http.CallOption) (*EurOrderReply, error) { + var out EurOrderReply + pattern := "/order_shareeur/share_cancel" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareEurShareEurCancel)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareEurHTTPClientImpl) ShareEurPlaceOrder(ctx context.Context, in *ShareEurOrderRequest, opts ...http.CallOption) (*EurOrderReply, error) { + var out EurOrderReply + pattern := "/order_shareeur/share_place_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareEurShareEurPlaceOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareEurHTTPClientImpl) ShareEurPosition(ctx context.Context, in *CancelEurOrderRequest, opts ...http.CallOption) (*EurOrderReply, error) { + var out EurOrderReply + pattern := "/order_shareeur/share_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareEurShareEurPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareEurHTTPClientImpl) ShareEurUpdateOrder(ctx context.Context, in *UpdateEurOrderRequest, opts ...http.CallOption) (*EurOrderReply, error) { + var out EurOrderReply + pattern := "/order_shareeur/share_update_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareEurShareEurUpdateOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/api/matchmaking/v1/share/shareFur.pb.go b/api/matchmaking/v1/share/shareFur.pb.go new file mode 100644 index 0000000..46a7e46 --- /dev/null +++ b/api/matchmaking/v1/share/shareFur.pb.go @@ -0,0 +1,1327 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/share/shareFur.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GetFurBotStockTradeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status int64 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` // 状态码 + PageSize int64 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,3,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 +} + +func (x *GetFurBotStockTradeRequest) Reset() { + *x = GetFurBotStockTradeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetFurBotStockTradeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetFurBotStockTradeRequest) ProtoMessage() {} + +func (x *GetFurBotStockTradeRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetFurBotStockTradeRequest.ProtoReflect.Descriptor instead. +func (*GetFurBotStockTradeRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareFur_proto_rawDescGZIP(), []int{0} +} + +func (x *GetFurBotStockTradeRequest) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *GetFurBotStockTradeRequest) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *GetFurBotStockTradeRequest) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +type GetBotStockFurTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *BotStockFurTradeReply `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *GetBotStockFurTradeReply) Reset() { + *x = GetBotStockFurTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotStockFurTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotStockFurTradeReply) ProtoMessage() {} + +func (x *GetBotStockFurTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotStockFurTradeReply.ProtoReflect.Descriptor instead. +func (*GetBotStockFurTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareFur_proto_rawDescGZIP(), []int{1} +} + +func (x *GetBotStockFurTradeReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *GetBotStockFurTradeReply) GetData() *BotStockFurTradeReply { + if x != nil { + return x.Data + } + return nil +} + +func (x *GetBotStockFurTradeReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type BotStockFurTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PageSize int64 `protobuf:"varint,1,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,2,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + Data []*BotStockFurTrade `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty"` // 返回结果 + TotalCount int64 `protobuf:"varint,4,opt,name=totalCount,proto3" json:"totalCount,omitempty"` // 总数据 +} + +func (x *BotStockFurTradeReply) Reset() { + *x = BotStockFurTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockFurTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockFurTradeReply) ProtoMessage() {} + +func (x *BotStockFurTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockFurTradeReply.ProtoReflect.Descriptor instead. +func (*BotStockFurTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareFur_proto_rawDescGZIP(), []int{2} +} + +func (x *BotStockFurTradeReply) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *BotStockFurTradeReply) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *BotStockFurTradeReply) GetData() []*BotStockFurTrade { + if x != nil { + return x.Data + } + return nil +} + +func (x *BotStockFurTradeReply) GetTotalCount() int64 { + if x != nil { + return x.TotalCount + } + return 0 +} + +type BotStockFurTrade struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID + StockId string `protobuf:"bytes,2,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票代码 + TradeType int64 `protobuf:"varint,3,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型 + DealType int64 `protobuf:"varint,4,opt,name=dealType,proto3" json:"dealType,omitempty"` // 交易方式 + LimitPrice string `protobuf:"bytes,5,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,6,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + DealPrice string `protobuf:"bytes,7,opt,name=dealPrice,proto3" json:"dealPrice,omitempty"` // 开仓价 + ClosingPrice string `protobuf:"bytes,8,opt,name=closingPrice,proto3" json:"closingPrice,omitempty"` // 平仓价 + OrderNumber string `protobuf:"bytes,9,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + ServiceCost string `protobuf:"bytes,13,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 开仓手续费 + MarketMoney string `protobuf:"bytes,14,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderMoney string `protobuf:"bytes,15,opt,name=orderMoney,proto3" json:"orderMoney,omitempty"` // 订单总金额 + Status int64 `protobuf:"varint,16,opt,name=status,proto3" json:"status,omitempty"` // 订单状态 + CreateTime string `protobuf:"bytes,17,opt,name=createTime,proto3" json:"createTime,omitempty"` // 订单创建时间 + UpdateTime string `protobuf:"bytes,18,opt,name=updateTime,proto3" json:"updateTime,omitempty"` // 订单更新时间 + OpenTime string `protobuf:"bytes,19,opt,name=openTime,proto3" json:"openTime,omitempty"` // 订单开仓时间 + ClosingTime string `protobuf:"bytes,20,opt,name=closingTime,proto3" json:"closingTime,omitempty"` // 订单平仓时间 + ClosingCost string `protobuf:"bytes,21,opt,name=closingCost,proto3" json:"closingCost,omitempty"` // 平仓手续费 + FaceValue string `protobuf:"bytes,22,opt,name=faceValue,proto3" json:"faceValue,omitempty"` // 面值 + PryNum string `protobuf:"bytes,23,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 + KeepDecimal string `protobuf:"bytes,24,opt,name=keepDecimal,proto3" json:"keepDecimal,omitempty"` // 保留小数位 + StockName string `protobuf:"bytes,25,opt,name=stockName,proto3" json:"stockName,omitempty"` // 股票名称 +} + +func (x *BotStockFurTrade) Reset() { + *x = BotStockFurTrade{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockFurTrade) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockFurTrade) ProtoMessage() {} + +func (x *BotStockFurTrade) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockFurTrade.ProtoReflect.Descriptor instead. +func (*BotStockFurTrade) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareFur_proto_rawDescGZIP(), []int{3} +} + +func (x *BotStockFurTrade) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *BotStockFurTrade) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *BotStockFurTrade) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *BotStockFurTrade) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *BotStockFurTrade) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *BotStockFurTrade) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *BotStockFurTrade) GetDealPrice() string { + if x != nil { + return x.DealPrice + } + return "" +} + +func (x *BotStockFurTrade) GetClosingPrice() string { + if x != nil { + return x.ClosingPrice + } + return "" +} + +func (x *BotStockFurTrade) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *BotStockFurTrade) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *BotStockFurTrade) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *BotStockFurTrade) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *BotStockFurTrade) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *BotStockFurTrade) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *BotStockFurTrade) GetOrderMoney() string { + if x != nil { + return x.OrderMoney + } + return "" +} + +func (x *BotStockFurTrade) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *BotStockFurTrade) GetCreateTime() string { + if x != nil { + return x.CreateTime + } + return "" +} + +func (x *BotStockFurTrade) GetUpdateTime() string { + if x != nil { + return x.UpdateTime + } + return "" +} + +func (x *BotStockFurTrade) GetOpenTime() string { + if x != nil { + return x.OpenTime + } + return "" +} + +func (x *BotStockFurTrade) GetClosingTime() string { + if x != nil { + return x.ClosingTime + } + return "" +} + +func (x *BotStockFurTrade) GetClosingCost() string { + if x != nil { + return x.ClosingCost + } + return "" +} + +func (x *BotStockFurTrade) GetFaceValue() string { + if x != nil { + return x.FaceValue + } + return "" +} + +func (x *BotStockFurTrade) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *BotStockFurTrade) GetKeepDecimal() string { + if x != nil { + return x.KeepDecimal + } + return "" +} + +func (x *BotStockFurTrade) GetStockName() string { + if x != nil { + return x.StockName + } + return "" +} + +type ShareFurOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + StockId string `protobuf:"bytes,1,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票Code + TradeType int64 `protobuf:"varint,2,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型:1买入,2卖出 + DealType int64 `protobuf:"varint,3,opt,name=dealType,proto3" json:"dealType,omitempty"` // 委托方式:1限价,2市价 + LimitPrice string `protobuf:"bytes,4,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,5,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + MarketMoney string `protobuf:"bytes,6,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderNumber string `protobuf:"bytes,7,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + ServiceCost string `protobuf:"bytes,8,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 手续费 + StopType int64 `protobuf:"varint,9,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止损止盈设置:1无设置,2止损止盈 + StopLossPrice string `protobuf:"bytes,10,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,11,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止损 + PryNum string `protobuf:"bytes,12,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 +} + +func (x *ShareFurOrderRequest) Reset() { + *x = ShareFurOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ShareFurOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ShareFurOrderRequest) ProtoMessage() {} + +func (x *ShareFurOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ShareFurOrderRequest.ProtoReflect.Descriptor instead. +func (*ShareFurOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareFur_proto_rawDescGZIP(), []int{4} +} + +func (x *ShareFurOrderRequest) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *ShareFurOrderRequest) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *ShareFurOrderRequest) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *ShareFurOrderRequest) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *ShareFurOrderRequest) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *ShareFurOrderRequest) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *ShareFurOrderRequest) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *ShareFurOrderRequest) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *ShareFurOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *ShareFurOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *ShareFurOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *ShareFurOrderRequest) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +type UpdateFurOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id + StopType int64 `protobuf:"varint,2,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,3,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,4,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 +} + +func (x *UpdateFurOrderRequest) Reset() { + *x = UpdateFurOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateFurOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateFurOrderRequest) ProtoMessage() {} + +func (x *UpdateFurOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateFurOrderRequest.ProtoReflect.Descriptor instead. +func (*UpdateFurOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareFur_proto_rawDescGZIP(), []int{5} +} + +func (x *UpdateFurOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *UpdateFurOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *UpdateFurOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *UpdateFurOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +type FurOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *FurOrderResult `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *FurOrderReply) Reset() { + *x = FurOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *FurOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FurOrderReply) ProtoMessage() {} + +func (x *FurOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FurOrderReply.ProtoReflect.Descriptor instead. +func (*FurOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareFur_proto_rawDescGZIP(), []int{6} +} + +func (x *FurOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *FurOrderReply) GetData() *FurOrderResult { + if x != nil { + return x.Data + } + return nil +} + +func (x *FurOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type FurOrderResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id +} + +func (x *FurOrderResult) Reset() { + *x = FurOrderResult{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *FurOrderResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FurOrderResult) ProtoMessage() {} + +func (x *FurOrderResult) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FurOrderResult.ProtoReflect.Descriptor instead. +func (*FurOrderResult) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareFur_proto_rawDescGZIP(), []int{7} +} + +func (x *FurOrderResult) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type CancelFurOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID +} + +func (x *CancelFurOrderRequest) Reset() { + *x = CancelFurOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CancelFurOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CancelFurOrderRequest) ProtoMessage() {} + +func (x *CancelFurOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CancelFurOrderRequest.ProtoReflect.Descriptor instead. +func (*CancelFurOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareFur_proto_rawDescGZIP(), []int{8} +} + +func (x *CancelFurOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type AllFurOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *AllFurOrderRequest) Reset() { + *x = AllFurOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllFurOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllFurOrderRequest) ProtoMessage() {} + +func (x *AllFurOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllFurOrderRequest.ProtoReflect.Descriptor instead. +func (*AllFurOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareFur_proto_rawDescGZIP(), []int{9} +} + +type AllFurOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *AllFurOrderReply) Reset() { + *x = AllFurOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllFurOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllFurOrderReply) ProtoMessage() {} + +func (x *AllFurOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareFur_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllFurOrderReply.ProtoReflect.Descriptor instead. +func (*AllFurOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareFur_proto_rawDescGZIP(), []int{10} +} + +func (x *AllFurOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *AllFurOrderReply) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +func (x *AllFurOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_matchmaking_v1_share_shareFur_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_share_shareFur_proto_rawDesc = []byte{ + 0x0a, 0x23, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x46, 0x75, 0x72, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0x6e, 0x0a, 0x1a, 0x47, 0x65, 0x74, 0x46, 0x75, 0x72, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, + 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x22, 0x83, 0x01, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, + 0x6f, 0x63, 0x6b, 0x46, 0x75, 0x72, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, + 0x63, 0x6f, 0x64, 0x65, 0x12, 0x39, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x46, 0x75, 0x72, 0x54, + 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, + 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xa7, 0x01, 0x0a, 0x15, 0x42, 0x6f, + 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x46, 0x75, 0x72, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, + 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x34, 0x0a, + 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x46, 0x75, 0x72, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x04, 0x64, + 0x61, 0x74, 0x61, 0x12, 0x1e, 0x0a, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, + 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x22, 0x9e, 0x06, 0x0a, 0x10, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, + 0x46, 0x75, 0x72, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, + 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, + 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, + 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, + 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, + 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x65, 0x61, 0x6c, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x64, 0x65, 0x61, + 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, + 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6c, + 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, + 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, + 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, + 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, + 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0c, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, + 0x74, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x43, 0x6f, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, + 0x6e, 0x65, 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, + 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x18, 0x10, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1e, + 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x11, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1e, + 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x12, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1a, + 0x0a, 0x08, 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x13, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x08, 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, + 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, + 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x15, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1c, + 0x0a, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x16, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x16, 0x0a, 0x06, + 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x17, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, + 0x79, 0x4e, 0x75, 0x6d, 0x12, 0x20, 0x0a, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, + 0x6d, 0x61, 0x6c, 0x18, 0x18, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, + 0x65, 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x4e, + 0x61, 0x6d, 0x65, 0x18, 0x19, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x90, 0x03, 0x0a, 0x14, 0x53, 0x68, 0x61, 0x72, 0x65, 0x46, 0x75, + 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, + 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, + 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x72, 0x61, 0x64, + 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, + 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, + 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, + 0x65, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, + 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, + 0x6d, 0x62, 0x65, 0x72, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, + 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, + 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, + 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, + 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, + 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, + 0x16, 0x0a, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x22, 0x97, 0x01, 0x0a, 0x15, 0x55, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x46, 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, + 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, + 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, + 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, + 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, + 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x22, 0x71, 0x0a, 0x0d, 0x46, 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, + 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x32, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x73, 0x75, 0x6c, 0x74, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x22, 0x2a, 0x0a, 0x0e, 0x46, 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, + 0x22, 0x31, 0x0a, 0x15, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x46, 0x75, 0x72, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x49, 0x64, 0x22, 0x14, 0x0a, 0x12, 0x41, 0x6c, 0x6c, 0x46, 0x75, 0x72, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x54, 0x0a, 0x10, 0x41, 0x6c, 0x6c, + 0x46, 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, + 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, + 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, + 0xca, 0x06, 0x0a, 0x08, 0x53, 0x68, 0x61, 0x72, 0x65, 0x46, 0x75, 0x72, 0x12, 0x92, 0x01, 0x0a, + 0x13, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x46, 0x75, 0x72, 0x54, + 0x72, 0x61, 0x64, 0x65, 0x12, 0x2a, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x46, 0x75, 0x72, 0x42, 0x6f, 0x74, 0x53, + 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x28, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, + 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x46, 0x75, 0x72, + 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x25, 0x82, 0xd3, 0xe4, 0x93, + 0x02, 0x1f, 0x3a, 0x01, 0x2a, 0x22, 0x1a, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, + 0x61, 0x72, 0x65, 0x66, 0x75, 0x72, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x6c, 0x69, 0x73, + 0x74, 0x12, 0x87, 0x01, 0x0a, 0x12, 0x53, 0x68, 0x61, 0x72, 0x65, 0x46, 0x75, 0x72, 0x50, 0x6c, + 0x61, 0x63, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x24, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x46, + 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, + 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x46, 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2c, 0x82, + 0xd3, 0xe4, 0x93, 0x02, 0x26, 0x3a, 0x01, 0x2a, 0x22, 0x21, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x66, 0x75, 0x72, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, + 0x70, 0x6c, 0x61, 0x63, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x8a, 0x01, 0x0a, 0x13, + 0x53, 0x68, 0x61, 0x72, 0x65, 0x46, 0x75, 0x72, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x12, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, + 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x46, 0x75, 0x72, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x75, 0x72, 0x4f, + 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93, 0x02, + 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, + 0x72, 0x65, 0x66, 0x75, 0x72, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x75, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x83, 0x01, 0x0a, 0x10, 0x53, 0x68, 0x61, + 0x72, 0x65, 0x46, 0x75, 0x72, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x25, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, + 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x46, 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x29, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x23, 0x3a, 0x01, 0x2a, 0x22, 0x1e, + 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x66, 0x75, 0x72, 0x2f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x8a, + 0x01, 0x0a, 0x13, 0x53, 0x68, 0x61, 0x72, 0x65, 0x46, 0x75, 0x72, 0x41, 0x6c, 0x6c, 0x50, 0x6f, + 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x22, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, + 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x46, 0x75, 0x72, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x46, + 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2d, 0x82, 0xd3, + 0xe4, 0x93, 0x02, 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x66, 0x75, 0x72, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x61, + 0x6c, 0x6c, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x7f, 0x0a, 0x0e, 0x53, + 0x68, 0x61, 0x72, 0x65, 0x46, 0x75, 0x72, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x12, 0x25, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, + 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x46, 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x75, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x27, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x21, 0x3a, 0x01, 0x2a, 0x22, 0x1c, + 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x66, 0x75, 0x72, 0x2f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x42, 0x2a, 0x5a, 0x28, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x73, 0x79, 0x73, 0x74, + 0x65, 0x6d, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_share_shareFur_proto_rawDescOnce sync.Once + file_matchmaking_v1_share_shareFur_proto_rawDescData = file_matchmaking_v1_share_shareFur_proto_rawDesc +) + +func file_matchmaking_v1_share_shareFur_proto_rawDescGZIP() []byte { + file_matchmaking_v1_share_shareFur_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_share_shareFur_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_share_shareFur_proto_rawDescData) + }) + return file_matchmaking_v1_share_shareFur_proto_rawDescData +} + +var file_matchmaking_v1_share_shareFur_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_matchmaking_v1_share_shareFur_proto_goTypes = []any{ + (*GetFurBotStockTradeRequest)(nil), // 0: matchmaking.v1.GetFurBotStockTradeRequest + (*GetBotStockFurTradeReply)(nil), // 1: matchmaking.v1.GetBotStockFurTradeReply + (*BotStockFurTradeReply)(nil), // 2: matchmaking.v1.BotStockFurTradeReply + (*BotStockFurTrade)(nil), // 3: matchmaking.v1.BotStockFurTrade + (*ShareFurOrderRequest)(nil), // 4: matchmaking.v1.ShareFurOrderRequest + (*UpdateFurOrderRequest)(nil), // 5: matchmaking.v1.UpdateFurOrderRequest + (*FurOrderReply)(nil), // 6: matchmaking.v1.FurOrderReply + (*FurOrderResult)(nil), // 7: matchmaking.v1.FurOrderResult + (*CancelFurOrderRequest)(nil), // 8: matchmaking.v1.CancelFurOrderRequest + (*AllFurOrderRequest)(nil), // 9: matchmaking.v1.AllFurOrderRequest + (*AllFurOrderReply)(nil), // 10: matchmaking.v1.AllFurOrderReply +} +var file_matchmaking_v1_share_shareFur_proto_depIdxs = []int32{ + 2, // 0: matchmaking.v1.GetBotStockFurTradeReply.data:type_name -> matchmaking.v1.BotStockFurTradeReply + 3, // 1: matchmaking.v1.BotStockFurTradeReply.data:type_name -> matchmaking.v1.BotStockFurTrade + 7, // 2: matchmaking.v1.FurOrderReply.data:type_name -> matchmaking.v1.FurOrderResult + 0, // 3: matchmaking.v1.ShareFur.GetBotStockFurTrade:input_type -> matchmaking.v1.GetFurBotStockTradeRequest + 4, // 4: matchmaking.v1.ShareFur.ShareFurPlaceOrder:input_type -> matchmaking.v1.ShareFurOrderRequest + 5, // 5: matchmaking.v1.ShareFur.ShareFurUpdateOrder:input_type -> matchmaking.v1.UpdateFurOrderRequest + 8, // 6: matchmaking.v1.ShareFur.ShareFurPosition:input_type -> matchmaking.v1.CancelFurOrderRequest + 9, // 7: matchmaking.v1.ShareFur.ShareFurAllPosition:input_type -> matchmaking.v1.AllFurOrderRequest + 8, // 8: matchmaking.v1.ShareFur.ShareFurCancel:input_type -> matchmaking.v1.CancelFurOrderRequest + 1, // 9: matchmaking.v1.ShareFur.GetBotStockFurTrade:output_type -> matchmaking.v1.GetBotStockFurTradeReply + 6, // 10: matchmaking.v1.ShareFur.ShareFurPlaceOrder:output_type -> matchmaking.v1.FurOrderReply + 6, // 11: matchmaking.v1.ShareFur.ShareFurUpdateOrder:output_type -> matchmaking.v1.FurOrderReply + 6, // 12: matchmaking.v1.ShareFur.ShareFurPosition:output_type -> matchmaking.v1.FurOrderReply + 10, // 13: matchmaking.v1.ShareFur.ShareFurAllPosition:output_type -> matchmaking.v1.AllFurOrderReply + 6, // 14: matchmaking.v1.ShareFur.ShareFurCancel:output_type -> matchmaking.v1.FurOrderReply + 9, // [9:15] is the sub-list for method output_type + 3, // [3:9] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_share_shareFur_proto_init() } +func file_matchmaking_v1_share_shareFur_proto_init() { + if File_matchmaking_v1_share_shareFur_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_matchmaking_v1_share_shareFur_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*GetFurBotStockTradeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareFur_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*GetBotStockFurTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareFur_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*BotStockFurTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareFur_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*BotStockFurTrade); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareFur_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*ShareFurOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareFur_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*UpdateFurOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareFur_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*FurOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareFur_proto_msgTypes[7].Exporter = func(v any, i int) any { + switch v := v.(*FurOrderResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareFur_proto_msgTypes[8].Exporter = func(v any, i int) any { + switch v := v.(*CancelFurOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareFur_proto_msgTypes[9].Exporter = func(v any, i int) any { + switch v := v.(*AllFurOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareFur_proto_msgTypes[10].Exporter = func(v any, i int) any { + switch v := v.(*AllFurOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_share_shareFur_proto_rawDesc, + NumEnums: 0, + NumMessages: 11, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_matchmaking_v1_share_shareFur_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_share_shareFur_proto_depIdxs, + MessageInfos: file_matchmaking_v1_share_shareFur_proto_msgTypes, + }.Build() + File_matchmaking_v1_share_shareFur_proto = out.File + file_matchmaking_v1_share_shareFur_proto_rawDesc = nil + file_matchmaking_v1_share_shareFur_proto_goTypes = nil + file_matchmaking_v1_share_shareFur_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/share/shareFur.proto b/api/matchmaking/v1/share/shareFur.proto new file mode 100644 index 0000000..616c52e --- /dev/null +++ b/api/matchmaking/v1/share/shareFur.proto @@ -0,0 +1,144 @@ +syntax = "proto3"; + +package matchmaking.v1; + +import "google/api/annotations.proto"; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +service ShareFur { + // GetBotStockFurTrade 法国股列表查询 + rpc GetBotStockFurTrade(GetFurBotStockTradeRequest)returns(GetBotStockFurTradeReply){ + option (google.api.http) = { + post:"/order_sharefur/share_list", + body:"*", + }; + } + // ShareFurPlaceOrder 法国股下单 + rpc ShareFurPlaceOrder(ShareFurOrderRequest)returns(FurOrderReply) { + option (google.api.http) = { + post: "/order_sharefur/share_place_order", + body: "*", + }; + } + // ShareFurUpdateOrder 法国股设置止盈止损 + rpc ShareFurUpdateOrder(UpdateFurOrderRequest)returns(FurOrderReply){ + option (google.api.http) = { + post:"/order_sharefur/share_update_order", + body:"*", + }; + } + // ShareFurPosition 法国股平仓 + rpc ShareFurPosition(CancelFurOrderRequest)returns(FurOrderReply){ + option (google.api.http) = { + post:"/order_sharefur/share_position", + body:"*", + }; + } + // ShareFurAllPosition 法国股一键平仓 + rpc ShareFurAllPosition(AllFurOrderRequest)returns(AllFurOrderReply){ + option (google.api.http) = { + post:"/order_sharefur/share_all_position", + body:"*", + }; + } + // ShareFurCancel 法国股撤单 + rpc ShareFurCancel(CancelFurOrderRequest)returns(FurOrderReply){ + option (google.api.http) = { + post:"/order_sharefur/share_cancel", + body:"*", + }; + } +} + +message GetFurBotStockTradeRequest{ + int64 status =1;// 状态码 + int64 pageSize =2; // 每页显示条数 + int64 pageCount =3;// 开始的位置 +} + +message GetBotStockFurTradeReply{ + int64 code =1;// 状态码 + BotStockFurTradeReply data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message BotStockFurTradeReply{ + int64 pageSize =1; // 每页显示条数 + int64 pageCount =2;// 开始的位置 + repeated BotStockFurTrade data =3;// 返回结果 + int64 totalCount =4;// 总数据 +} + +message BotStockFurTrade{ + string orderId =1;// 订单ID + string stockId =2;// 股票代码 + int64 tradeType =3;// 交易类型 + int64 dealType =4;// 交易方式 + string limitPrice =5;// 限价 + string marketPrice =6;// 市价 + string dealPrice =7;// 开仓价 + string closingPrice =8;// 平仓价 + string orderNumber =9;// 订单数量 + int64 stopType =10;// 止盈止损 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string serviceCost =13;// 开仓手续费 + string marketMoney =14;// 订单金额 + string orderMoney =15;// 订单总金额 + int64 status =16;// 订单状态 + string createTime =17;// 订单创建时间 + string updateTime =18;// 订单更新时间 + string openTime =19;// 订单开仓时间 + string closingTime =20;// 订单平仓时间 + string closingCost =21;// 平仓手续费 + string faceValue =22;// 面值 + string pryNum =23;// 杠杆 + string keepDecimal =24;// 保留小数位 + string stockName =25;// 股票名称 +} + +message ShareFurOrderRequest{ + string stockId =1;// 股票Code + int64 tradeType =2;// 交易类型:1买入,2卖出 + int64 dealType =3;// 委托方式:1限价,2市价 + string limitPrice =4;// 限价 + string marketPrice =5;// 市价 + string marketMoney =6;// 订单金额 + string orderNumber =7;// 订单数量 + string serviceCost =8;// 手续费 + int64 stopType =9;// 止损止盈设置:1无设置,2止损止盈 + string stopLossPrice =10;// 止损 + string stopWinPrice =11;// 止损 + string pryNum =12;// 杠杆 +} + +message UpdateFurOrderRequest{ + string orderId =1;// 订单Id + int64 stopType =2;// 止盈止损 + string stopLossPrice =3;// 止损 + string stopWinPrice =4;// 止盈 +} + +message FurOrderReply{ + int64 code =1;// 状态码 + FurOrderResult data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message FurOrderResult { + string orderId =1;// 订单Id +} + +message CancelFurOrderRequest{ + string orderId =1;// 订单ID +} + +message AllFurOrderRequest{ + +} +message AllFurOrderReply{ + int64 code =1;// 状态码 + string data =2;// 返回结果 + string message =3;// 返回消息提示 +} \ No newline at end of file diff --git a/api/matchmaking/v1/share/shareFur_grpc.pb.go b/api/matchmaking/v1/share/shareFur_grpc.pb.go new file mode 100644 index 0000000..d1a0216 --- /dev/null +++ b/api/matchmaking/v1/share/shareFur_grpc.pb.go @@ -0,0 +1,312 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareFur.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + ShareFur_GetBotStockFurTrade_FullMethodName = "/matchmaking.v1.ShareFur/GetBotStockFurTrade" + ShareFur_ShareFurPlaceOrder_FullMethodName = "/matchmaking.v1.ShareFur/ShareFurPlaceOrder" + ShareFur_ShareFurUpdateOrder_FullMethodName = "/matchmaking.v1.ShareFur/ShareFurUpdateOrder" + ShareFur_ShareFurPosition_FullMethodName = "/matchmaking.v1.ShareFur/ShareFurPosition" + ShareFur_ShareFurAllPosition_FullMethodName = "/matchmaking.v1.ShareFur/ShareFurAllPosition" + ShareFur_ShareFurCancel_FullMethodName = "/matchmaking.v1.ShareFur/ShareFurCancel" +) + +// ShareFurClient is the client API for ShareFur service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ShareFurClient interface { + // GetBotStockFurTrade 法国股列表查询 + GetBotStockFurTrade(ctx context.Context, in *GetFurBotStockTradeRequest, opts ...grpc.CallOption) (*GetBotStockFurTradeReply, error) + // ShareFurPlaceOrder 法国股下单 + ShareFurPlaceOrder(ctx context.Context, in *ShareFurOrderRequest, opts ...grpc.CallOption) (*FurOrderReply, error) + // ShareFurUpdateOrder 法国股设置止盈止损 + ShareFurUpdateOrder(ctx context.Context, in *UpdateFurOrderRequest, opts ...grpc.CallOption) (*FurOrderReply, error) + // ShareFurPosition 法国股平仓 + ShareFurPosition(ctx context.Context, in *CancelFurOrderRequest, opts ...grpc.CallOption) (*FurOrderReply, error) + // ShareFurAllPosition 法国股一键平仓 + ShareFurAllPosition(ctx context.Context, in *AllFurOrderRequest, opts ...grpc.CallOption) (*AllFurOrderReply, error) + // ShareFurCancel 法国股撤单 + ShareFurCancel(ctx context.Context, in *CancelFurOrderRequest, opts ...grpc.CallOption) (*FurOrderReply, error) +} + +type shareFurClient struct { + cc grpc.ClientConnInterface +} + +func NewShareFurClient(cc grpc.ClientConnInterface) ShareFurClient { + return &shareFurClient{cc} +} + +func (c *shareFurClient) GetBotStockFurTrade(ctx context.Context, in *GetFurBotStockTradeRequest, opts ...grpc.CallOption) (*GetBotStockFurTradeReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetBotStockFurTradeReply) + err := c.cc.Invoke(ctx, ShareFur_GetBotStockFurTrade_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareFurClient) ShareFurPlaceOrder(ctx context.Context, in *ShareFurOrderRequest, opts ...grpc.CallOption) (*FurOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(FurOrderReply) + err := c.cc.Invoke(ctx, ShareFur_ShareFurPlaceOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareFurClient) ShareFurUpdateOrder(ctx context.Context, in *UpdateFurOrderRequest, opts ...grpc.CallOption) (*FurOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(FurOrderReply) + err := c.cc.Invoke(ctx, ShareFur_ShareFurUpdateOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareFurClient) ShareFurPosition(ctx context.Context, in *CancelFurOrderRequest, opts ...grpc.CallOption) (*FurOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(FurOrderReply) + err := c.cc.Invoke(ctx, ShareFur_ShareFurPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareFurClient) ShareFurAllPosition(ctx context.Context, in *AllFurOrderRequest, opts ...grpc.CallOption) (*AllFurOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AllFurOrderReply) + err := c.cc.Invoke(ctx, ShareFur_ShareFurAllPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareFurClient) ShareFurCancel(ctx context.Context, in *CancelFurOrderRequest, opts ...grpc.CallOption) (*FurOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(FurOrderReply) + err := c.cc.Invoke(ctx, ShareFur_ShareFurCancel_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ShareFurServer is the server API for ShareFur service. +// All implementations must embed UnimplementedShareFurServer +// for forward compatibility +type ShareFurServer interface { + // GetBotStockFurTrade 法国股列表查询 + GetBotStockFurTrade(context.Context, *GetFurBotStockTradeRequest) (*GetBotStockFurTradeReply, error) + // ShareFurPlaceOrder 法国股下单 + ShareFurPlaceOrder(context.Context, *ShareFurOrderRequest) (*FurOrderReply, error) + // ShareFurUpdateOrder 法国股设置止盈止损 + ShareFurUpdateOrder(context.Context, *UpdateFurOrderRequest) (*FurOrderReply, error) + // ShareFurPosition 法国股平仓 + ShareFurPosition(context.Context, *CancelFurOrderRequest) (*FurOrderReply, error) + // ShareFurAllPosition 法国股一键平仓 + ShareFurAllPosition(context.Context, *AllFurOrderRequest) (*AllFurOrderReply, error) + // ShareFurCancel 法国股撤单 + ShareFurCancel(context.Context, *CancelFurOrderRequest) (*FurOrderReply, error) + mustEmbedUnimplementedShareFurServer() +} + +// UnimplementedShareFurServer must be embedded to have forward compatible implementations. +type UnimplementedShareFurServer struct { +} + +func (UnimplementedShareFurServer) GetBotStockFurTrade(context.Context, *GetFurBotStockTradeRequest) (*GetBotStockFurTradeReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBotStockFurTrade not implemented") +} +func (UnimplementedShareFurServer) ShareFurPlaceOrder(context.Context, *ShareFurOrderRequest) (*FurOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareFurPlaceOrder not implemented") +} +func (UnimplementedShareFurServer) ShareFurUpdateOrder(context.Context, *UpdateFurOrderRequest) (*FurOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareFurUpdateOrder not implemented") +} +func (UnimplementedShareFurServer) ShareFurPosition(context.Context, *CancelFurOrderRequest) (*FurOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareFurPosition not implemented") +} +func (UnimplementedShareFurServer) ShareFurAllPosition(context.Context, *AllFurOrderRequest) (*AllFurOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareFurAllPosition not implemented") +} +func (UnimplementedShareFurServer) ShareFurCancel(context.Context, *CancelFurOrderRequest) (*FurOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareFurCancel not implemented") +} +func (UnimplementedShareFurServer) mustEmbedUnimplementedShareFurServer() {} + +// UnsafeShareFurServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ShareFurServer will +// result in compilation errors. +type UnsafeShareFurServer interface { + mustEmbedUnimplementedShareFurServer() +} + +func RegisterShareFurServer(s grpc.ServiceRegistrar, srv ShareFurServer) { + s.RegisterService(&ShareFur_ServiceDesc, srv) +} + +func _ShareFur_GetBotStockFurTrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetFurBotStockTradeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareFurServer).GetBotStockFurTrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareFur_GetBotStockFurTrade_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareFurServer).GetBotStockFurTrade(ctx, req.(*GetFurBotStockTradeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareFur_ShareFurPlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ShareFurOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareFurServer).ShareFurPlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareFur_ShareFurPlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareFurServer).ShareFurPlaceOrder(ctx, req.(*ShareFurOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareFur_ShareFurUpdateOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateFurOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareFurServer).ShareFurUpdateOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareFur_ShareFurUpdateOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareFurServer).ShareFurUpdateOrder(ctx, req.(*UpdateFurOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareFur_ShareFurPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelFurOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareFurServer).ShareFurPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareFur_ShareFurPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareFurServer).ShareFurPosition(ctx, req.(*CancelFurOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareFur_ShareFurAllPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AllFurOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareFurServer).ShareFurAllPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareFur_ShareFurAllPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareFurServer).ShareFurAllPosition(ctx, req.(*AllFurOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareFur_ShareFurCancel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelFurOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareFurServer).ShareFurCancel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareFur_ShareFurCancel_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareFurServer).ShareFurCancel(ctx, req.(*CancelFurOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// ShareFur_ServiceDesc is the grpc.ServiceDesc for ShareFur service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ShareFur_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "matchmaking.v1.ShareFur", + HandlerType: (*ShareFurServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetBotStockFurTrade", + Handler: _ShareFur_GetBotStockFurTrade_Handler, + }, + { + MethodName: "ShareFurPlaceOrder", + Handler: _ShareFur_ShareFurPlaceOrder_Handler, + }, + { + MethodName: "ShareFurUpdateOrder", + Handler: _ShareFur_ShareFurUpdateOrder_Handler, + }, + { + MethodName: "ShareFurPosition", + Handler: _ShareFur_ShareFurPosition_Handler, + }, + { + MethodName: "ShareFurAllPosition", + Handler: _ShareFur_ShareFurAllPosition_Handler, + }, + { + MethodName: "ShareFurCancel", + Handler: _ShareFur_ShareFurCancel_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "matchmaking/v1/share/shareFur.proto", +} diff --git a/api/matchmaking/v1/share/shareFur_http.pb.go b/api/matchmaking/v1/share/shareFur_http.pb.go new file mode 100644 index 0000000..363a09f --- /dev/null +++ b/api/matchmaking/v1/share/shareFur_http.pb.go @@ -0,0 +1,279 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.3 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareFur.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationShareFurGetBotStockFurTrade = "/matchmaking.v1.ShareFur/GetBotStockFurTrade" +const OperationShareFurShareFurAllPosition = "/matchmaking.v1.ShareFur/ShareFurAllPosition" +const OperationShareFurShareFurCancel = "/matchmaking.v1.ShareFur/ShareFurCancel" +const OperationShareFurShareFurPlaceOrder = "/matchmaking.v1.ShareFur/ShareFurPlaceOrder" +const OperationShareFurShareFurPosition = "/matchmaking.v1.ShareFur/ShareFurPosition" +const OperationShareFurShareFurUpdateOrder = "/matchmaking.v1.ShareFur/ShareFurUpdateOrder" + +type ShareFurHTTPServer interface { + // GetBotStockFurTrade GetBotStockFurTrade 法国股列表查询 + GetBotStockFurTrade(context.Context, *GetFurBotStockTradeRequest) (*GetBotStockFurTradeReply, error) + // ShareFurAllPosition ShareFurAllPosition 法国股一键平仓 + ShareFurAllPosition(context.Context, *AllFurOrderRequest) (*AllFurOrderReply, error) + // ShareFurCancel ShareFurCancel 法国股撤单 + ShareFurCancel(context.Context, *CancelFurOrderRequest) (*FurOrderReply, error) + // ShareFurPlaceOrder ShareFurPlaceOrder 法国股下单 + ShareFurPlaceOrder(context.Context, *ShareFurOrderRequest) (*FurOrderReply, error) + // ShareFurPosition ShareFurPosition 法国股平仓 + ShareFurPosition(context.Context, *CancelFurOrderRequest) (*FurOrderReply, error) + // ShareFurUpdateOrder ShareFurUpdateOrder 法国股设置止盈止损 + ShareFurUpdateOrder(context.Context, *UpdateFurOrderRequest) (*FurOrderReply, error) +} + +func RegisterShareFurHTTPServer(s *http.Server, srv ShareFurHTTPServer) { + r := s.Route("/") + r.POST("/order_sharefur/share_list", _ShareFur_GetBotStockFurTrade0_HTTP_Handler(srv)) + r.POST("/order_sharefur/share_place_order", _ShareFur_ShareFurPlaceOrder0_HTTP_Handler(srv)) + r.POST("/order_sharefur/share_update_order", _ShareFur_ShareFurUpdateOrder0_HTTP_Handler(srv)) + r.POST("/order_sharefur/share_position", _ShareFur_ShareFurPosition0_HTTP_Handler(srv)) + r.POST("/order_sharefur/share_all_position", _ShareFur_ShareFurAllPosition0_HTTP_Handler(srv)) + r.POST("/order_sharefur/share_cancel", _ShareFur_ShareFurCancel0_HTTP_Handler(srv)) +} + +func _ShareFur_GetBotStockFurTrade0_HTTP_Handler(srv ShareFurHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetFurBotStockTradeRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareFurGetBotStockFurTrade) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.GetBotStockFurTrade(ctx, req.(*GetFurBotStockTradeRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetBotStockFurTradeReply) + return ctx.Result(200, reply) + } +} + +func _ShareFur_ShareFurPlaceOrder0_HTTP_Handler(srv ShareFurHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in ShareFurOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareFurShareFurPlaceOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareFurPlaceOrder(ctx, req.(*ShareFurOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*FurOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareFur_ShareFurUpdateOrder0_HTTP_Handler(srv ShareFurHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in UpdateFurOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareFurShareFurUpdateOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareFurUpdateOrder(ctx, req.(*UpdateFurOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*FurOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareFur_ShareFurPosition0_HTTP_Handler(srv ShareFurHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelFurOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareFurShareFurPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareFurPosition(ctx, req.(*CancelFurOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*FurOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareFur_ShareFurAllPosition0_HTTP_Handler(srv ShareFurHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in AllFurOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareFurShareFurAllPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareFurAllPosition(ctx, req.(*AllFurOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*AllFurOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareFur_ShareFurCancel0_HTTP_Handler(srv ShareFurHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelFurOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareFurShareFurCancel) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareFurCancel(ctx, req.(*CancelFurOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*FurOrderReply) + return ctx.Result(200, reply) + } +} + +type ShareFurHTTPClient interface { + GetBotStockFurTrade(ctx context.Context, req *GetFurBotStockTradeRequest, opts ...http.CallOption) (rsp *GetBotStockFurTradeReply, err error) + ShareFurAllPosition(ctx context.Context, req *AllFurOrderRequest, opts ...http.CallOption) (rsp *AllFurOrderReply, err error) + ShareFurCancel(ctx context.Context, req *CancelFurOrderRequest, opts ...http.CallOption) (rsp *FurOrderReply, err error) + ShareFurPlaceOrder(ctx context.Context, req *ShareFurOrderRequest, opts ...http.CallOption) (rsp *FurOrderReply, err error) + ShareFurPosition(ctx context.Context, req *CancelFurOrderRequest, opts ...http.CallOption) (rsp *FurOrderReply, err error) + ShareFurUpdateOrder(ctx context.Context, req *UpdateFurOrderRequest, opts ...http.CallOption) (rsp *FurOrderReply, err error) +} + +type ShareFurHTTPClientImpl struct { + cc *http.Client +} + +func NewShareFurHTTPClient(client *http.Client) ShareFurHTTPClient { + return &ShareFurHTTPClientImpl{client} +} + +func (c *ShareFurHTTPClientImpl) GetBotStockFurTrade(ctx context.Context, in *GetFurBotStockTradeRequest, opts ...http.CallOption) (*GetBotStockFurTradeReply, error) { + var out GetBotStockFurTradeReply + pattern := "/order_sharefur/share_list" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareFurGetBotStockFurTrade)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareFurHTTPClientImpl) ShareFurAllPosition(ctx context.Context, in *AllFurOrderRequest, opts ...http.CallOption) (*AllFurOrderReply, error) { + var out AllFurOrderReply + pattern := "/order_sharefur/share_all_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareFurShareFurAllPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareFurHTTPClientImpl) ShareFurCancel(ctx context.Context, in *CancelFurOrderRequest, opts ...http.CallOption) (*FurOrderReply, error) { + var out FurOrderReply + pattern := "/order_sharefur/share_cancel" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareFurShareFurCancel)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareFurHTTPClientImpl) ShareFurPlaceOrder(ctx context.Context, in *ShareFurOrderRequest, opts ...http.CallOption) (*FurOrderReply, error) { + var out FurOrderReply + pattern := "/order_sharefur/share_place_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareFurShareFurPlaceOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareFurHTTPClientImpl) ShareFurPosition(ctx context.Context, in *CancelFurOrderRequest, opts ...http.CallOption) (*FurOrderReply, error) { + var out FurOrderReply + pattern := "/order_sharefur/share_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareFurShareFurPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareFurHTTPClientImpl) ShareFurUpdateOrder(ctx context.Context, in *UpdateFurOrderRequest, opts ...http.CallOption) (*FurOrderReply, error) { + var out FurOrderReply + pattern := "/order_sharefur/share_update_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareFurShareFurUpdateOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/api/matchmaking/v1/share/shareGbx.pb.go b/api/matchmaking/v1/share/shareGbx.pb.go new file mode 100644 index 0000000..e213bb2 --- /dev/null +++ b/api/matchmaking/v1/share/shareGbx.pb.go @@ -0,0 +1,1327 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/share/shareGbx.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GetBotStockGbxTradeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status int64 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` // 状态码 + PageSize int64 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,3,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 +} + +func (x *GetBotStockGbxTradeRequest) Reset() { + *x = GetBotStockGbxTradeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotStockGbxTradeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotStockGbxTradeRequest) ProtoMessage() {} + +func (x *GetBotStockGbxTradeRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotStockGbxTradeRequest.ProtoReflect.Descriptor instead. +func (*GetBotStockGbxTradeRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareGbx_proto_rawDescGZIP(), []int{0} +} + +func (x *GetBotStockGbxTradeRequest) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *GetBotStockGbxTradeRequest) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *GetBotStockGbxTradeRequest) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +type GetBotStockGbxTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *BotStockGbxTradeData `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *GetBotStockGbxTradeReply) Reset() { + *x = GetBotStockGbxTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotStockGbxTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotStockGbxTradeReply) ProtoMessage() {} + +func (x *GetBotStockGbxTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotStockGbxTradeReply.ProtoReflect.Descriptor instead. +func (*GetBotStockGbxTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareGbx_proto_rawDescGZIP(), []int{1} +} + +func (x *GetBotStockGbxTradeReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *GetBotStockGbxTradeReply) GetData() *BotStockGbxTradeData { + if x != nil { + return x.Data + } + return nil +} + +func (x *GetBotStockGbxTradeReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type BotStockGbxTradeData struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PageSize int64 `protobuf:"varint,1,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,2,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + Data []*BotOrderGbxTrade `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty"` // 返回结果 + TotalCount int64 `protobuf:"varint,4,opt,name=totalCount,proto3" json:"totalCount,omitempty"` // 总数据 +} + +func (x *BotStockGbxTradeData) Reset() { + *x = BotStockGbxTradeData{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockGbxTradeData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockGbxTradeData) ProtoMessage() {} + +func (x *BotStockGbxTradeData) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockGbxTradeData.ProtoReflect.Descriptor instead. +func (*BotStockGbxTradeData) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareGbx_proto_rawDescGZIP(), []int{2} +} + +func (x *BotStockGbxTradeData) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *BotStockGbxTradeData) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *BotStockGbxTradeData) GetData() []*BotOrderGbxTrade { + if x != nil { + return x.Data + } + return nil +} + +func (x *BotStockGbxTradeData) GetTotalCount() int64 { + if x != nil { + return x.TotalCount + } + return 0 +} + +type BotOrderGbxTrade struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID + StockId string `protobuf:"bytes,2,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票代码 + TradeType int64 `protobuf:"varint,3,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型 + DealType int64 `protobuf:"varint,4,opt,name=dealType,proto3" json:"dealType,omitempty"` // 交易方式 + LimitPrice string `protobuf:"bytes,5,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,6,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + DealPrice string `protobuf:"bytes,7,opt,name=dealPrice,proto3" json:"dealPrice,omitempty"` // 开仓价 + ClosingPrice string `protobuf:"bytes,8,opt,name=closingPrice,proto3" json:"closingPrice,omitempty"` // 平仓价 + OrderNumber string `protobuf:"bytes,9,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损状态 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + ServiceCost string `protobuf:"bytes,13,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 开仓手续费 + MarketMoney string `protobuf:"bytes,14,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderMoney string `protobuf:"bytes,15,opt,name=orderMoney,proto3" json:"orderMoney,omitempty"` // 订单总金额 + Status int64 `protobuf:"varint,16,opt,name=status,proto3" json:"status,omitempty"` // 订单状态 + CreateTime string `protobuf:"bytes,17,opt,name=createTime,proto3" json:"createTime,omitempty"` // 订单创建时间 + UpdateTime string `protobuf:"bytes,18,opt,name=updateTime,proto3" json:"updateTime,omitempty"` // 订单更新时间 + OpenTime string `protobuf:"bytes,19,opt,name=openTime,proto3" json:"openTime,omitempty"` // 订单开仓时间 + ClosingTime string `protobuf:"bytes,20,opt,name=closingTime,proto3" json:"closingTime,omitempty"` // 订单平仓时间 + ClosingCost string `protobuf:"bytes,21,opt,name=closingCost,proto3" json:"closingCost,omitempty"` // 平仓手续费 + FaceValue string `protobuf:"bytes,22,opt,name=faceValue,proto3" json:"faceValue,omitempty"` // 面值 + PryNum string `protobuf:"bytes,23,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 + KeepDecimal string `protobuf:"bytes,24,opt,name=keepDecimal,proto3" json:"keepDecimal,omitempty"` // 保留小数位 + StockName string `protobuf:"bytes,25,opt,name=stockName,proto3" json:"stockName,omitempty"` // 股票名称 +} + +func (x *BotOrderGbxTrade) Reset() { + *x = BotOrderGbxTrade{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotOrderGbxTrade) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotOrderGbxTrade) ProtoMessage() {} + +func (x *BotOrderGbxTrade) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotOrderGbxTrade.ProtoReflect.Descriptor instead. +func (*BotOrderGbxTrade) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareGbx_proto_rawDescGZIP(), []int{3} +} + +func (x *BotOrderGbxTrade) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *BotOrderGbxTrade) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *BotOrderGbxTrade) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *BotOrderGbxTrade) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *BotOrderGbxTrade) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *BotOrderGbxTrade) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *BotOrderGbxTrade) GetDealPrice() string { + if x != nil { + return x.DealPrice + } + return "" +} + +func (x *BotOrderGbxTrade) GetClosingPrice() string { + if x != nil { + return x.ClosingPrice + } + return "" +} + +func (x *BotOrderGbxTrade) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *BotOrderGbxTrade) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *BotOrderGbxTrade) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *BotOrderGbxTrade) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *BotOrderGbxTrade) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *BotOrderGbxTrade) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *BotOrderGbxTrade) GetOrderMoney() string { + if x != nil { + return x.OrderMoney + } + return "" +} + +func (x *BotOrderGbxTrade) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *BotOrderGbxTrade) GetCreateTime() string { + if x != nil { + return x.CreateTime + } + return "" +} + +func (x *BotOrderGbxTrade) GetUpdateTime() string { + if x != nil { + return x.UpdateTime + } + return "" +} + +func (x *BotOrderGbxTrade) GetOpenTime() string { + if x != nil { + return x.OpenTime + } + return "" +} + +func (x *BotOrderGbxTrade) GetClosingTime() string { + if x != nil { + return x.ClosingTime + } + return "" +} + +func (x *BotOrderGbxTrade) GetClosingCost() string { + if x != nil { + return x.ClosingCost + } + return "" +} + +func (x *BotOrderGbxTrade) GetFaceValue() string { + if x != nil { + return x.FaceValue + } + return "" +} + +func (x *BotOrderGbxTrade) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *BotOrderGbxTrade) GetKeepDecimal() string { + if x != nil { + return x.KeepDecimal + } + return "" +} + +func (x *BotOrderGbxTrade) GetStockName() string { + if x != nil { + return x.StockName + } + return "" +} + +type OrderGbxRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + StockId string `protobuf:"bytes,1,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票Code + TradeType int64 `protobuf:"varint,2,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型:1买入,2卖出 + DealType int64 `protobuf:"varint,3,opt,name=dealType,proto3" json:"dealType,omitempty"` // 委托方式:1限价,2市价 + LimitPrice string `protobuf:"bytes,4,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,5,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + MarketMoney string `protobuf:"bytes,6,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderNumber string `protobuf:"bytes,7,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + ServiceCost string `protobuf:"bytes,8,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 手续费 + StopType int64 `protobuf:"varint,9,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止损止盈设置:1无设置,2止损止盈 + StopLossPrice string `protobuf:"bytes,10,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,11,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止损 + PryNum string `protobuf:"bytes,12,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 +} + +func (x *OrderGbxRequest) Reset() { + *x = OrderGbxRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OrderGbxRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OrderGbxRequest) ProtoMessage() {} + +func (x *OrderGbxRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OrderGbxRequest.ProtoReflect.Descriptor instead. +func (*OrderGbxRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareGbx_proto_rawDescGZIP(), []int{4} +} + +func (x *OrderGbxRequest) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *OrderGbxRequest) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *OrderGbxRequest) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *OrderGbxRequest) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *OrderGbxRequest) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *OrderGbxRequest) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *OrderGbxRequest) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *OrderGbxRequest) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *OrderGbxRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *OrderGbxRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *OrderGbxRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *OrderGbxRequest) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +type UpdateGbxOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id + StopType int64 `protobuf:"varint,2,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,3,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,4,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 +} + +func (x *UpdateGbxOrderRequest) Reset() { + *x = UpdateGbxOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateGbxOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateGbxOrderRequest) ProtoMessage() {} + +func (x *UpdateGbxOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateGbxOrderRequest.ProtoReflect.Descriptor instead. +func (*UpdateGbxOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareGbx_proto_rawDescGZIP(), []int{5} +} + +func (x *UpdateGbxOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *UpdateGbxOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *UpdateGbxOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *UpdateGbxOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +type OrderGbxReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *OrderGbxResult `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *OrderGbxReply) Reset() { + *x = OrderGbxReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OrderGbxReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OrderGbxReply) ProtoMessage() {} + +func (x *OrderGbxReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OrderGbxReply.ProtoReflect.Descriptor instead. +func (*OrderGbxReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareGbx_proto_rawDescGZIP(), []int{6} +} + +func (x *OrderGbxReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *OrderGbxReply) GetData() *OrderGbxResult { + if x != nil { + return x.Data + } + return nil +} + +func (x *OrderGbxReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type AllGbxOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *AllGbxOrderRequest) Reset() { + *x = AllGbxOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllGbxOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllGbxOrderRequest) ProtoMessage() {} + +func (x *AllGbxOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllGbxOrderRequest.ProtoReflect.Descriptor instead. +func (*AllGbxOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareGbx_proto_rawDescGZIP(), []int{7} +} + +type CancelGbxOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID +} + +func (x *CancelGbxOrderRequest) Reset() { + *x = CancelGbxOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CancelGbxOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CancelGbxOrderRequest) ProtoMessage() {} + +func (x *CancelGbxOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CancelGbxOrderRequest.ProtoReflect.Descriptor instead. +func (*CancelGbxOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareGbx_proto_rawDescGZIP(), []int{8} +} + +func (x *CancelGbxOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type AllGbxOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *AllGbxOrderReply) Reset() { + *x = AllGbxOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllGbxOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllGbxOrderReply) ProtoMessage() {} + +func (x *AllGbxOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllGbxOrderReply.ProtoReflect.Descriptor instead. +func (*AllGbxOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareGbx_proto_rawDescGZIP(), []int{9} +} + +func (x *AllGbxOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *AllGbxOrderReply) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +func (x *AllGbxOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type OrderGbxResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id +} + +func (x *OrderGbxResult) Reset() { + *x = OrderGbxResult{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OrderGbxResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OrderGbxResult) ProtoMessage() {} + +func (x *OrderGbxResult) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareGbx_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OrderGbxResult.ProtoReflect.Descriptor instead. +func (*OrderGbxResult) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareGbx_proto_rawDescGZIP(), []int{10} +} + +func (x *OrderGbxResult) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +var File_matchmaking_v1_share_shareGbx_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_share_shareGbx_proto_rawDesc = []byte{ + 0x0a, 0x23, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x47, 0x62, 0x78, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0x6e, 0x0a, 0x1a, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, + 0x63, 0x6b, 0x47, 0x62, 0x78, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, + 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x22, 0x82, 0x01, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, + 0x6f, 0x63, 0x6b, 0x47, 0x62, 0x78, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, + 0x63, 0x6f, 0x64, 0x65, 0x12, 0x38, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x47, 0x62, 0x78, 0x54, + 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, + 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xa6, 0x01, 0x0a, 0x14, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x47, 0x62, 0x78, 0x54, 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, + 0x61, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, + 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x34, 0x0a, 0x04, 0x64, + 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x6d, 0x61, 0x74, 0x63, + 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x47, 0x62, 0x78, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x04, 0x64, 0x61, 0x74, + 0x61, 0x12, 0x1e, 0x0a, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, + 0x74, 0x22, 0x9e, 0x06, 0x0a, 0x10, 0x42, 0x6f, 0x74, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x47, 0x62, + 0x78, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, + 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, + 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, + 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, + 0x54, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, + 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, + 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x65, 0x61, 0x6c, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x64, 0x65, 0x61, 0x6c, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6c, 0x6f, 0x73, + 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, + 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, + 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, + 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, + 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, + 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0c, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, + 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, + 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, + 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, 0x6f, 0x6e, + 0x65, 0x79, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x10, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1e, 0x0a, 0x0a, + 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x11, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1e, 0x0a, 0x0a, + 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x12, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, + 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x13, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, + 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, + 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, + 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, + 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x15, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, + 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x16, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x72, + 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x17, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, 0x79, 0x4e, + 0x75, 0x6d, 0x12, 0x20, 0x0a, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, 0x6d, 0x61, + 0x6c, 0x18, 0x18, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, + 0x69, 0x6d, 0x61, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x4e, 0x61, 0x6d, + 0x65, 0x18, 0x19, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x4e, 0x61, + 0x6d, 0x65, 0x22, 0x8b, 0x03, 0x0a, 0x0f, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x47, 0x62, 0x78, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, + 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, + 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, + 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, + 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, + 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, + 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x20, + 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x07, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, + 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, + 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, + 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x09, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, + 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, + 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, + 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x72, 0x79, 0x4e, + 0x75, 0x6d, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, + 0x22, 0x97, 0x01, 0x0a, 0x15, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x47, 0x62, 0x78, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, + 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, + 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, + 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, + 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x22, 0x71, 0x0a, 0x0d, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x47, 0x62, 0x78, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, + 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, + 0x32, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4f, + 0x72, 0x64, 0x65, 0x72, 0x47, 0x62, 0x78, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x52, 0x04, 0x64, + 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x14, 0x0a, + 0x12, 0x41, 0x6c, 0x6c, 0x47, 0x62, 0x78, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x22, 0x31, 0x0a, 0x15, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x47, 0x62, 0x78, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, + 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x22, 0x54, 0x0a, 0x10, 0x41, 0x6c, 0x6c, 0x47, 0x62, 0x78, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, + 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x12, + 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, + 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x2a, 0x0a, 0x0e, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x47, 0x62, 0x78, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x18, + 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x32, 0xc5, 0x06, 0x0a, 0x08, 0x53, 0x68, 0x61, + 0x72, 0x65, 0x47, 0x62, 0x78, 0x12, 0x92, 0x01, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x47, 0x62, 0x78, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x2a, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, + 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x47, 0x62, 0x78, 0x54, 0x72, 0x61, + 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x28, 0x2e, 0x6d, 0x61, 0x74, 0x63, + 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6f, + 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x47, 0x62, 0x78, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x25, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1f, 0x3a, 0x01, 0x2a, 0x22, 0x1a, + 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x67, 0x62, 0x78, 0x2f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x12, 0x82, 0x01, 0x0a, 0x12, 0x53, + 0x68, 0x61, 0x72, 0x65, 0x47, 0x62, 0x78, 0x50, 0x6c, 0x61, 0x63, 0x65, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x12, 0x1f, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x47, 0x62, 0x78, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x47, 0x62, 0x78, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x22, 0x2c, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x26, 0x3a, 0x01, 0x2a, 0x22, 0x21, 0x2f, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x67, 0x62, 0x78, 0x2f, 0x73, 0x68, + 0x61, 0x72, 0x65, 0x5f, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, + 0x8a, 0x01, 0x0a, 0x13, 0x53, 0x68, 0x61, 0x72, 0x65, 0x47, 0x62, 0x78, 0x55, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, + 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x47, + 0x62, 0x78, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, + 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x47, 0x62, 0x78, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2d, 0x82, + 0xd3, 0xe4, 0x93, 0x02, 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x67, 0x62, 0x78, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, + 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x83, 0x01, 0x0a, + 0x10, 0x53, 0x68, 0x61, 0x72, 0x65, 0x47, 0x62, 0x78, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, + 0x6e, 0x12, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x2e, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x47, 0x62, 0x78, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x47, + 0x62, 0x78, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x29, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x23, 0x3a, + 0x01, 0x2a, 0x22, 0x1e, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, + 0x67, 0x62, 0x78, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, + 0x6f, 0x6e, 0x12, 0x8a, 0x01, 0x0a, 0x13, 0x53, 0x68, 0x61, 0x72, 0x65, 0x47, 0x62, 0x78, 0x41, + 0x6c, 0x6c, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x22, 0x2e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x47, + 0x62, 0x78, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, + 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x41, 0x6c, 0x6c, 0x47, 0x62, 0x78, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x67, 0x62, 0x78, 0x2f, 0x73, 0x68, 0x61, + 0x72, 0x65, 0x5f, 0x61, 0x6c, 0x6c, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, + 0x7f, 0x0a, 0x0e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x47, 0x62, 0x78, 0x43, 0x61, 0x6e, 0x63, 0x65, + 0x6c, 0x12, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x2e, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x47, 0x62, 0x78, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x47, + 0x62, 0x78, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x27, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x21, 0x3a, + 0x01, 0x2a, 0x22, 0x1c, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, + 0x67, 0x62, 0x78, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6e, 0x63, 0x65, 0x6c, + 0x42, 0x2a, 0x5a, 0x28, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2d, + 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_share_shareGbx_proto_rawDescOnce sync.Once + file_matchmaking_v1_share_shareGbx_proto_rawDescData = file_matchmaking_v1_share_shareGbx_proto_rawDesc +) + +func file_matchmaking_v1_share_shareGbx_proto_rawDescGZIP() []byte { + file_matchmaking_v1_share_shareGbx_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_share_shareGbx_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_share_shareGbx_proto_rawDescData) + }) + return file_matchmaking_v1_share_shareGbx_proto_rawDescData +} + +var file_matchmaking_v1_share_shareGbx_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_matchmaking_v1_share_shareGbx_proto_goTypes = []any{ + (*GetBotStockGbxTradeRequest)(nil), // 0: matchmaking.v1.GetBotStockGbxTradeRequest + (*GetBotStockGbxTradeReply)(nil), // 1: matchmaking.v1.GetBotStockGbxTradeReply + (*BotStockGbxTradeData)(nil), // 2: matchmaking.v1.BotStockGbxTradeData + (*BotOrderGbxTrade)(nil), // 3: matchmaking.v1.BotOrderGbxTrade + (*OrderGbxRequest)(nil), // 4: matchmaking.v1.OrderGbxRequest + (*UpdateGbxOrderRequest)(nil), // 5: matchmaking.v1.UpdateGbxOrderRequest + (*OrderGbxReply)(nil), // 6: matchmaking.v1.OrderGbxReply + (*AllGbxOrderRequest)(nil), // 7: matchmaking.v1.AllGbxOrderRequest + (*CancelGbxOrderRequest)(nil), // 8: matchmaking.v1.CancelGbxOrderRequest + (*AllGbxOrderReply)(nil), // 9: matchmaking.v1.AllGbxOrderReply + (*OrderGbxResult)(nil), // 10: matchmaking.v1.OrderGbxResult +} +var file_matchmaking_v1_share_shareGbx_proto_depIdxs = []int32{ + 2, // 0: matchmaking.v1.GetBotStockGbxTradeReply.data:type_name -> matchmaking.v1.BotStockGbxTradeData + 3, // 1: matchmaking.v1.BotStockGbxTradeData.data:type_name -> matchmaking.v1.BotOrderGbxTrade + 10, // 2: matchmaking.v1.OrderGbxReply.data:type_name -> matchmaking.v1.OrderGbxResult + 0, // 3: matchmaking.v1.ShareGbx.GetBotStockGbxTrade:input_type -> matchmaking.v1.GetBotStockGbxTradeRequest + 4, // 4: matchmaking.v1.ShareGbx.ShareGbxPlaceOrder:input_type -> matchmaking.v1.OrderGbxRequest + 5, // 5: matchmaking.v1.ShareGbx.ShareGbxUpdateOrder:input_type -> matchmaking.v1.UpdateGbxOrderRequest + 8, // 6: matchmaking.v1.ShareGbx.ShareGbxPosition:input_type -> matchmaking.v1.CancelGbxOrderRequest + 7, // 7: matchmaking.v1.ShareGbx.ShareGbxAllPosition:input_type -> matchmaking.v1.AllGbxOrderRequest + 8, // 8: matchmaking.v1.ShareGbx.ShareGbxCancel:input_type -> matchmaking.v1.CancelGbxOrderRequest + 1, // 9: matchmaking.v1.ShareGbx.GetBotStockGbxTrade:output_type -> matchmaking.v1.GetBotStockGbxTradeReply + 6, // 10: matchmaking.v1.ShareGbx.ShareGbxPlaceOrder:output_type -> matchmaking.v1.OrderGbxReply + 6, // 11: matchmaking.v1.ShareGbx.ShareGbxUpdateOrder:output_type -> matchmaking.v1.OrderGbxReply + 6, // 12: matchmaking.v1.ShareGbx.ShareGbxPosition:output_type -> matchmaking.v1.OrderGbxReply + 9, // 13: matchmaking.v1.ShareGbx.ShareGbxAllPosition:output_type -> matchmaking.v1.AllGbxOrderReply + 6, // 14: matchmaking.v1.ShareGbx.ShareGbxCancel:output_type -> matchmaking.v1.OrderGbxReply + 9, // [9:15] is the sub-list for method output_type + 3, // [3:9] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_share_shareGbx_proto_init() } +func file_matchmaking_v1_share_shareGbx_proto_init() { + if File_matchmaking_v1_share_shareGbx_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_matchmaking_v1_share_shareGbx_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*GetBotStockGbxTradeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareGbx_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*GetBotStockGbxTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareGbx_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*BotStockGbxTradeData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareGbx_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*BotOrderGbxTrade); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareGbx_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*OrderGbxRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareGbx_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*UpdateGbxOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareGbx_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*OrderGbxReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareGbx_proto_msgTypes[7].Exporter = func(v any, i int) any { + switch v := v.(*AllGbxOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareGbx_proto_msgTypes[8].Exporter = func(v any, i int) any { + switch v := v.(*CancelGbxOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareGbx_proto_msgTypes[9].Exporter = func(v any, i int) any { + switch v := v.(*AllGbxOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareGbx_proto_msgTypes[10].Exporter = func(v any, i int) any { + switch v := v.(*OrderGbxResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_share_shareGbx_proto_rawDesc, + NumEnums: 0, + NumMessages: 11, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_matchmaking_v1_share_shareGbx_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_share_shareGbx_proto_depIdxs, + MessageInfos: file_matchmaking_v1_share_shareGbx_proto_msgTypes, + }.Build() + File_matchmaking_v1_share_shareGbx_proto = out.File + file_matchmaking_v1_share_shareGbx_proto_rawDesc = nil + file_matchmaking_v1_share_shareGbx_proto_goTypes = nil + file_matchmaking_v1_share_shareGbx_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/share/shareGbx.proto b/api/matchmaking/v1/share/shareGbx.proto new file mode 100644 index 0000000..7b5a066 --- /dev/null +++ b/api/matchmaking/v1/share/shareGbx.proto @@ -0,0 +1,145 @@ +syntax = "proto3"; + +package matchmaking.v1; + +import "google/api/annotations.proto"; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +service ShareGbx { + // GetBotStockGbxTrade 英股列表查询 + rpc GetBotStockGbxTrade(GetBotStockGbxTradeRequest)returns(GetBotStockGbxTradeReply){ + option (google.api.http) = { + post:"/order_sharegbx/share_list", + body:"*", + }; + } + // ShareGbxPlaceOrder 英股下单 + rpc ShareGbxPlaceOrder(OrderGbxRequest)returns(OrderGbxReply) { + option (google.api.http) = { + post: "/order_sharegbx/share_place_order", + body: "*", + }; + } + // ShareGbxUpdateOrder 英股设置止盈止损 + rpc ShareGbxUpdateOrder(UpdateGbxOrderRequest)returns(OrderGbxReply){ + option (google.api.http) = { + post:"/order_sharegbx/share_update_order", + body:"*", + }; + } + // ShareGbxPosition 英股平仓 + rpc ShareGbxPosition(CancelGbxOrderRequest)returns(OrderGbxReply){ + option (google.api.http) = { + post:"/order_sharegbx/share_position", + body:"*", + }; + } + // ShareGbxAllPosition 英股一键平仓 + rpc ShareGbxAllPosition(AllGbxOrderRequest)returns(AllGbxOrderReply){ + option (google.api.http) = { + post:"/order_sharegbx/share_all_position", + body:"*", + }; + } + // ShareGbxCancel 英股撤单 + rpc ShareGbxCancel(CancelGbxOrderRequest)returns(OrderGbxReply){ + option (google.api.http) = { + post:"/order_sharegbx/share_cancel", + body:"*", + }; + } +} + +message GetBotStockGbxTradeRequest{ + int64 status =1;// 状态码 + int64 pageSize =2; // 每页显示条数 + int64 pageCount =3;// 开始的位置 +} + +message GetBotStockGbxTradeReply{ + int64 code =1;// 状态码 + BotStockGbxTradeData data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message BotStockGbxTradeData{ + int64 pageSize =1; // 每页显示条数 + int64 pageCount =2;// 开始的位置 + repeated BotOrderGbxTrade data =3;// 返回结果 + int64 totalCount =4;// 总数据 +} + +message BotOrderGbxTrade{ + string orderId =1;// 订单ID + string stockId =2;// 股票代码 + int64 tradeType =3;// 交易类型 + int64 dealType =4;// 交易方式 + string limitPrice =5;// 限价 + string marketPrice =6;// 市价 + string dealPrice =7;// 开仓价 + string closingPrice =8;// 平仓价 + string orderNumber =9;// 订单数量 + int64 stopType =10;// 止盈止损状态 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string serviceCost =13;// 开仓手续费 + string marketMoney =14;// 订单金额 + string orderMoney =15;// 订单总金额 + int64 status =16;// 订单状态 + string createTime =17;// 订单创建时间 + string updateTime =18;// 订单更新时间 + string openTime =19;// 订单开仓时间 + string closingTime =20;// 订单平仓时间 + string closingCost =21;// 平仓手续费 + string faceValue =22;// 面值 + string pryNum =23;// 杠杆 + string keepDecimal =24;// 保留小数位 + string stockName =25;// 股票名称 +} + +message OrderGbxRequest{ + string stockId =1;// 股票Code + int64 tradeType =2;// 交易类型:1买入,2卖出 + int64 dealType =3;// 委托方式:1限价,2市价 + string limitPrice =4;// 限价 + string marketPrice =5;// 市价 + string marketMoney =6;// 订单金额 + string orderNumber =7;// 订单数量 + string serviceCost =8;// 手续费 + int64 stopType =9;// 止损止盈设置:1无设置,2止损止盈 + string stopLossPrice =10;// 止损 + string stopWinPrice =11;// 止损 + string pryNum =12;// 杠杆 +} + +message UpdateGbxOrderRequest{ + string orderId =1;// 订单Id + int64 stopType =2;// 止盈止损 + string stopLossPrice =3;// 止损 + string stopWinPrice =4;// 止盈 +} + +message OrderGbxReply{ + int64 code =1;// 状态码 + OrderGbxResult data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message AllGbxOrderRequest{ + +} + +message CancelGbxOrderRequest{ + string orderId =1;// 订单ID +} + +message AllGbxOrderReply{ + int64 code =1;// 状态码 + string data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message OrderGbxResult { + string orderId =1;// 订单Id +} \ No newline at end of file diff --git a/api/matchmaking/v1/share/shareGbx_grpc.pb.go b/api/matchmaking/v1/share/shareGbx_grpc.pb.go new file mode 100644 index 0000000..df2c9ad --- /dev/null +++ b/api/matchmaking/v1/share/shareGbx_grpc.pb.go @@ -0,0 +1,312 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareGbx.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + ShareGbx_GetBotStockGbxTrade_FullMethodName = "/matchmaking.v1.ShareGbx/GetBotStockGbxTrade" + ShareGbx_ShareGbxPlaceOrder_FullMethodName = "/matchmaking.v1.ShareGbx/ShareGbxPlaceOrder" + ShareGbx_ShareGbxUpdateOrder_FullMethodName = "/matchmaking.v1.ShareGbx/ShareGbxUpdateOrder" + ShareGbx_ShareGbxPosition_FullMethodName = "/matchmaking.v1.ShareGbx/ShareGbxPosition" + ShareGbx_ShareGbxAllPosition_FullMethodName = "/matchmaking.v1.ShareGbx/ShareGbxAllPosition" + ShareGbx_ShareGbxCancel_FullMethodName = "/matchmaking.v1.ShareGbx/ShareGbxCancel" +) + +// ShareGbxClient is the client API for ShareGbx service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ShareGbxClient interface { + // GetBotStockGbxTrade 英股列表查询 + GetBotStockGbxTrade(ctx context.Context, in *GetBotStockGbxTradeRequest, opts ...grpc.CallOption) (*GetBotStockGbxTradeReply, error) + // ShareGbxPlaceOrder 英股下单 + ShareGbxPlaceOrder(ctx context.Context, in *OrderGbxRequest, opts ...grpc.CallOption) (*OrderGbxReply, error) + // ShareGbxUpdateOrder 英股设置止盈止损 + ShareGbxUpdateOrder(ctx context.Context, in *UpdateGbxOrderRequest, opts ...grpc.CallOption) (*OrderGbxReply, error) + // ShareGbxPosition 英股平仓 + ShareGbxPosition(ctx context.Context, in *CancelGbxOrderRequest, opts ...grpc.CallOption) (*OrderGbxReply, error) + // ShareGbxAllPosition 英股一键平仓 + ShareGbxAllPosition(ctx context.Context, in *AllGbxOrderRequest, opts ...grpc.CallOption) (*AllGbxOrderReply, error) + // ShareGbxCancel 英股撤单 + ShareGbxCancel(ctx context.Context, in *CancelGbxOrderRequest, opts ...grpc.CallOption) (*OrderGbxReply, error) +} + +type shareGbxClient struct { + cc grpc.ClientConnInterface +} + +func NewShareGbxClient(cc grpc.ClientConnInterface) ShareGbxClient { + return &shareGbxClient{cc} +} + +func (c *shareGbxClient) GetBotStockGbxTrade(ctx context.Context, in *GetBotStockGbxTradeRequest, opts ...grpc.CallOption) (*GetBotStockGbxTradeReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetBotStockGbxTradeReply) + err := c.cc.Invoke(ctx, ShareGbx_GetBotStockGbxTrade_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareGbxClient) ShareGbxPlaceOrder(ctx context.Context, in *OrderGbxRequest, opts ...grpc.CallOption) (*OrderGbxReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(OrderGbxReply) + err := c.cc.Invoke(ctx, ShareGbx_ShareGbxPlaceOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareGbxClient) ShareGbxUpdateOrder(ctx context.Context, in *UpdateGbxOrderRequest, opts ...grpc.CallOption) (*OrderGbxReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(OrderGbxReply) + err := c.cc.Invoke(ctx, ShareGbx_ShareGbxUpdateOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareGbxClient) ShareGbxPosition(ctx context.Context, in *CancelGbxOrderRequest, opts ...grpc.CallOption) (*OrderGbxReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(OrderGbxReply) + err := c.cc.Invoke(ctx, ShareGbx_ShareGbxPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareGbxClient) ShareGbxAllPosition(ctx context.Context, in *AllGbxOrderRequest, opts ...grpc.CallOption) (*AllGbxOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AllGbxOrderReply) + err := c.cc.Invoke(ctx, ShareGbx_ShareGbxAllPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareGbxClient) ShareGbxCancel(ctx context.Context, in *CancelGbxOrderRequest, opts ...grpc.CallOption) (*OrderGbxReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(OrderGbxReply) + err := c.cc.Invoke(ctx, ShareGbx_ShareGbxCancel_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ShareGbxServer is the server API for ShareGbx service. +// All implementations must embed UnimplementedShareGbxServer +// for forward compatibility +type ShareGbxServer interface { + // GetBotStockGbxTrade 英股列表查询 + GetBotStockGbxTrade(context.Context, *GetBotStockGbxTradeRequest) (*GetBotStockGbxTradeReply, error) + // ShareGbxPlaceOrder 英股下单 + ShareGbxPlaceOrder(context.Context, *OrderGbxRequest) (*OrderGbxReply, error) + // ShareGbxUpdateOrder 英股设置止盈止损 + ShareGbxUpdateOrder(context.Context, *UpdateGbxOrderRequest) (*OrderGbxReply, error) + // ShareGbxPosition 英股平仓 + ShareGbxPosition(context.Context, *CancelGbxOrderRequest) (*OrderGbxReply, error) + // ShareGbxAllPosition 英股一键平仓 + ShareGbxAllPosition(context.Context, *AllGbxOrderRequest) (*AllGbxOrderReply, error) + // ShareGbxCancel 英股撤单 + ShareGbxCancel(context.Context, *CancelGbxOrderRequest) (*OrderGbxReply, error) + mustEmbedUnimplementedShareGbxServer() +} + +// UnimplementedShareGbxServer must be embedded to have forward compatible implementations. +type UnimplementedShareGbxServer struct { +} + +func (UnimplementedShareGbxServer) GetBotStockGbxTrade(context.Context, *GetBotStockGbxTradeRequest) (*GetBotStockGbxTradeReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBotStockGbxTrade not implemented") +} +func (UnimplementedShareGbxServer) ShareGbxPlaceOrder(context.Context, *OrderGbxRequest) (*OrderGbxReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareGbxPlaceOrder not implemented") +} +func (UnimplementedShareGbxServer) ShareGbxUpdateOrder(context.Context, *UpdateGbxOrderRequest) (*OrderGbxReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareGbxUpdateOrder not implemented") +} +func (UnimplementedShareGbxServer) ShareGbxPosition(context.Context, *CancelGbxOrderRequest) (*OrderGbxReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareGbxPosition not implemented") +} +func (UnimplementedShareGbxServer) ShareGbxAllPosition(context.Context, *AllGbxOrderRequest) (*AllGbxOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareGbxAllPosition not implemented") +} +func (UnimplementedShareGbxServer) ShareGbxCancel(context.Context, *CancelGbxOrderRequest) (*OrderGbxReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareGbxCancel not implemented") +} +func (UnimplementedShareGbxServer) mustEmbedUnimplementedShareGbxServer() {} + +// UnsafeShareGbxServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ShareGbxServer will +// result in compilation errors. +type UnsafeShareGbxServer interface { + mustEmbedUnimplementedShareGbxServer() +} + +func RegisterShareGbxServer(s grpc.ServiceRegistrar, srv ShareGbxServer) { + s.RegisterService(&ShareGbx_ServiceDesc, srv) +} + +func _ShareGbx_GetBotStockGbxTrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetBotStockGbxTradeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareGbxServer).GetBotStockGbxTrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareGbx_GetBotStockGbxTrade_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareGbxServer).GetBotStockGbxTrade(ctx, req.(*GetBotStockGbxTradeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareGbx_ShareGbxPlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(OrderGbxRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareGbxServer).ShareGbxPlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareGbx_ShareGbxPlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareGbxServer).ShareGbxPlaceOrder(ctx, req.(*OrderGbxRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareGbx_ShareGbxUpdateOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateGbxOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareGbxServer).ShareGbxUpdateOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareGbx_ShareGbxUpdateOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareGbxServer).ShareGbxUpdateOrder(ctx, req.(*UpdateGbxOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareGbx_ShareGbxPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelGbxOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareGbxServer).ShareGbxPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareGbx_ShareGbxPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareGbxServer).ShareGbxPosition(ctx, req.(*CancelGbxOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareGbx_ShareGbxAllPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AllGbxOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareGbxServer).ShareGbxAllPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareGbx_ShareGbxAllPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareGbxServer).ShareGbxAllPosition(ctx, req.(*AllGbxOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareGbx_ShareGbxCancel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelGbxOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareGbxServer).ShareGbxCancel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareGbx_ShareGbxCancel_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareGbxServer).ShareGbxCancel(ctx, req.(*CancelGbxOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// ShareGbx_ServiceDesc is the grpc.ServiceDesc for ShareGbx service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ShareGbx_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "matchmaking.v1.ShareGbx", + HandlerType: (*ShareGbxServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetBotStockGbxTrade", + Handler: _ShareGbx_GetBotStockGbxTrade_Handler, + }, + { + MethodName: "ShareGbxPlaceOrder", + Handler: _ShareGbx_ShareGbxPlaceOrder_Handler, + }, + { + MethodName: "ShareGbxUpdateOrder", + Handler: _ShareGbx_ShareGbxUpdateOrder_Handler, + }, + { + MethodName: "ShareGbxPosition", + Handler: _ShareGbx_ShareGbxPosition_Handler, + }, + { + MethodName: "ShareGbxAllPosition", + Handler: _ShareGbx_ShareGbxAllPosition_Handler, + }, + { + MethodName: "ShareGbxCancel", + Handler: _ShareGbx_ShareGbxCancel_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "matchmaking/v1/share/shareGbx.proto", +} diff --git a/api/matchmaking/v1/share/shareGbx_http.pb.go b/api/matchmaking/v1/share/shareGbx_http.pb.go new file mode 100644 index 0000000..ce109aa --- /dev/null +++ b/api/matchmaking/v1/share/shareGbx_http.pb.go @@ -0,0 +1,279 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.3 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareGbx.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationShareGbxGetBotStockGbxTrade = "/matchmaking.v1.ShareGbx/GetBotStockGbxTrade" +const OperationShareGbxShareGbxAllPosition = "/matchmaking.v1.ShareGbx/ShareGbxAllPosition" +const OperationShareGbxShareGbxCancel = "/matchmaking.v1.ShareGbx/ShareGbxCancel" +const OperationShareGbxShareGbxPlaceOrder = "/matchmaking.v1.ShareGbx/ShareGbxPlaceOrder" +const OperationShareGbxShareGbxPosition = "/matchmaking.v1.ShareGbx/ShareGbxPosition" +const OperationShareGbxShareGbxUpdateOrder = "/matchmaking.v1.ShareGbx/ShareGbxUpdateOrder" + +type ShareGbxHTTPServer interface { + // GetBotStockGbxTrade GetBotStockGbxTrade 英股列表查询 + GetBotStockGbxTrade(context.Context, *GetBotStockGbxTradeRequest) (*GetBotStockGbxTradeReply, error) + // ShareGbxAllPosition ShareGbxAllPosition 英股一键平仓 + ShareGbxAllPosition(context.Context, *AllGbxOrderRequest) (*AllGbxOrderReply, error) + // ShareGbxCancel ShareGbxCancel 英股撤单 + ShareGbxCancel(context.Context, *CancelGbxOrderRequest) (*OrderGbxReply, error) + // ShareGbxPlaceOrder ShareGbxPlaceOrder 英股下单 + ShareGbxPlaceOrder(context.Context, *OrderGbxRequest) (*OrderGbxReply, error) + // ShareGbxPosition ShareGbxPosition 英股平仓 + ShareGbxPosition(context.Context, *CancelGbxOrderRequest) (*OrderGbxReply, error) + // ShareGbxUpdateOrder ShareGbxUpdateOrder 英股设置止盈止损 + ShareGbxUpdateOrder(context.Context, *UpdateGbxOrderRequest) (*OrderGbxReply, error) +} + +func RegisterShareGbxHTTPServer(s *http.Server, srv ShareGbxHTTPServer) { + r := s.Route("/") + r.POST("/order_sharegbx/share_list", _ShareGbx_GetBotStockGbxTrade0_HTTP_Handler(srv)) + r.POST("/order_sharegbx/share_place_order", _ShareGbx_ShareGbxPlaceOrder0_HTTP_Handler(srv)) + r.POST("/order_sharegbx/share_update_order", _ShareGbx_ShareGbxUpdateOrder0_HTTP_Handler(srv)) + r.POST("/order_sharegbx/share_position", _ShareGbx_ShareGbxPosition0_HTTP_Handler(srv)) + r.POST("/order_sharegbx/share_all_position", _ShareGbx_ShareGbxAllPosition0_HTTP_Handler(srv)) + r.POST("/order_sharegbx/share_cancel", _ShareGbx_ShareGbxCancel0_HTTP_Handler(srv)) +} + +func _ShareGbx_GetBotStockGbxTrade0_HTTP_Handler(srv ShareGbxHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetBotStockGbxTradeRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareGbxGetBotStockGbxTrade) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.GetBotStockGbxTrade(ctx, req.(*GetBotStockGbxTradeRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetBotStockGbxTradeReply) + return ctx.Result(200, reply) + } +} + +func _ShareGbx_ShareGbxPlaceOrder0_HTTP_Handler(srv ShareGbxHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in OrderGbxRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareGbxShareGbxPlaceOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareGbxPlaceOrder(ctx, req.(*OrderGbxRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*OrderGbxReply) + return ctx.Result(200, reply) + } +} + +func _ShareGbx_ShareGbxUpdateOrder0_HTTP_Handler(srv ShareGbxHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in UpdateGbxOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareGbxShareGbxUpdateOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareGbxUpdateOrder(ctx, req.(*UpdateGbxOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*OrderGbxReply) + return ctx.Result(200, reply) + } +} + +func _ShareGbx_ShareGbxPosition0_HTTP_Handler(srv ShareGbxHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelGbxOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareGbxShareGbxPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareGbxPosition(ctx, req.(*CancelGbxOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*OrderGbxReply) + return ctx.Result(200, reply) + } +} + +func _ShareGbx_ShareGbxAllPosition0_HTTP_Handler(srv ShareGbxHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in AllGbxOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareGbxShareGbxAllPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareGbxAllPosition(ctx, req.(*AllGbxOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*AllGbxOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareGbx_ShareGbxCancel0_HTTP_Handler(srv ShareGbxHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelGbxOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareGbxShareGbxCancel) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareGbxCancel(ctx, req.(*CancelGbxOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*OrderGbxReply) + return ctx.Result(200, reply) + } +} + +type ShareGbxHTTPClient interface { + GetBotStockGbxTrade(ctx context.Context, req *GetBotStockGbxTradeRequest, opts ...http.CallOption) (rsp *GetBotStockGbxTradeReply, err error) + ShareGbxAllPosition(ctx context.Context, req *AllGbxOrderRequest, opts ...http.CallOption) (rsp *AllGbxOrderReply, err error) + ShareGbxCancel(ctx context.Context, req *CancelGbxOrderRequest, opts ...http.CallOption) (rsp *OrderGbxReply, err error) + ShareGbxPlaceOrder(ctx context.Context, req *OrderGbxRequest, opts ...http.CallOption) (rsp *OrderGbxReply, err error) + ShareGbxPosition(ctx context.Context, req *CancelGbxOrderRequest, opts ...http.CallOption) (rsp *OrderGbxReply, err error) + ShareGbxUpdateOrder(ctx context.Context, req *UpdateGbxOrderRequest, opts ...http.CallOption) (rsp *OrderGbxReply, err error) +} + +type ShareGbxHTTPClientImpl struct { + cc *http.Client +} + +func NewShareGbxHTTPClient(client *http.Client) ShareGbxHTTPClient { + return &ShareGbxHTTPClientImpl{client} +} + +func (c *ShareGbxHTTPClientImpl) GetBotStockGbxTrade(ctx context.Context, in *GetBotStockGbxTradeRequest, opts ...http.CallOption) (*GetBotStockGbxTradeReply, error) { + var out GetBotStockGbxTradeReply + pattern := "/order_sharegbx/share_list" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareGbxGetBotStockGbxTrade)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareGbxHTTPClientImpl) ShareGbxAllPosition(ctx context.Context, in *AllGbxOrderRequest, opts ...http.CallOption) (*AllGbxOrderReply, error) { + var out AllGbxOrderReply + pattern := "/order_sharegbx/share_all_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareGbxShareGbxAllPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareGbxHTTPClientImpl) ShareGbxCancel(ctx context.Context, in *CancelGbxOrderRequest, opts ...http.CallOption) (*OrderGbxReply, error) { + var out OrderGbxReply + pattern := "/order_sharegbx/share_cancel" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareGbxShareGbxCancel)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareGbxHTTPClientImpl) ShareGbxPlaceOrder(ctx context.Context, in *OrderGbxRequest, opts ...http.CallOption) (*OrderGbxReply, error) { + var out OrderGbxReply + pattern := "/order_sharegbx/share_place_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareGbxShareGbxPlaceOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareGbxHTTPClientImpl) ShareGbxPosition(ctx context.Context, in *CancelGbxOrderRequest, opts ...http.CallOption) (*OrderGbxReply, error) { + var out OrderGbxReply + pattern := "/order_sharegbx/share_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareGbxShareGbxPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareGbxHTTPClientImpl) ShareGbxUpdateOrder(ctx context.Context, in *UpdateGbxOrderRequest, opts ...http.CallOption) (*OrderGbxReply, error) { + var out OrderGbxReply + pattern := "/order_sharegbx/share_update_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareGbxShareGbxUpdateOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/api/matchmaking/v1/share/shareHkd.pb.go b/api/matchmaking/v1/share/shareHkd.pb.go new file mode 100644 index 0000000..2548362 --- /dev/null +++ b/api/matchmaking/v1/share/shareHkd.pb.go @@ -0,0 +1,1327 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/share/shareHkd.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GetBotStockHkdTradeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status int64 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` // 状态码 + PageSize int64 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,3,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 +} + +func (x *GetBotStockHkdTradeRequest) Reset() { + *x = GetBotStockHkdTradeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotStockHkdTradeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotStockHkdTradeRequest) ProtoMessage() {} + +func (x *GetBotStockHkdTradeRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotStockHkdTradeRequest.ProtoReflect.Descriptor instead. +func (*GetBotStockHkdTradeRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareHkd_proto_rawDescGZIP(), []int{0} +} + +func (x *GetBotStockHkdTradeRequest) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *GetBotStockHkdTradeRequest) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *GetBotStockHkdTradeRequest) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +type GetBotStockHkdTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *BotStockHkdTradeData `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *GetBotStockHkdTradeReply) Reset() { + *x = GetBotStockHkdTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotStockHkdTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotStockHkdTradeReply) ProtoMessage() {} + +func (x *GetBotStockHkdTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotStockHkdTradeReply.ProtoReflect.Descriptor instead. +func (*GetBotStockHkdTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareHkd_proto_rawDescGZIP(), []int{1} +} + +func (x *GetBotStockHkdTradeReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *GetBotStockHkdTradeReply) GetData() *BotStockHkdTradeData { + if x != nil { + return x.Data + } + return nil +} + +func (x *GetBotStockHkdTradeReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type BotStockHkdTradeData struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PageSize int64 `protobuf:"varint,1,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,2,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + Data []*BotOrderHkdTrade `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty"` // 返回结果 + TotalCount int64 `protobuf:"varint,4,opt,name=totalCount,proto3" json:"totalCount,omitempty"` // 总数据 +} + +func (x *BotStockHkdTradeData) Reset() { + *x = BotStockHkdTradeData{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockHkdTradeData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockHkdTradeData) ProtoMessage() {} + +func (x *BotStockHkdTradeData) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockHkdTradeData.ProtoReflect.Descriptor instead. +func (*BotStockHkdTradeData) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareHkd_proto_rawDescGZIP(), []int{2} +} + +func (x *BotStockHkdTradeData) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *BotStockHkdTradeData) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *BotStockHkdTradeData) GetData() []*BotOrderHkdTrade { + if x != nil { + return x.Data + } + return nil +} + +func (x *BotStockHkdTradeData) GetTotalCount() int64 { + if x != nil { + return x.TotalCount + } + return 0 +} + +type BotOrderHkdTrade struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID + StockId string `protobuf:"bytes,2,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票代码 + TradeType int64 `protobuf:"varint,3,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型 + DealType int64 `protobuf:"varint,4,opt,name=dealType,proto3" json:"dealType,omitempty"` // 交易方式 + LimitPrice string `protobuf:"bytes,5,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,6,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + DealPrice string `protobuf:"bytes,7,opt,name=dealPrice,proto3" json:"dealPrice,omitempty"` // 开仓价 + ClosingPrice string `protobuf:"bytes,8,opt,name=closingPrice,proto3" json:"closingPrice,omitempty"` // 平仓价 + OrderNumber string `protobuf:"bytes,9,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损状态 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + ServiceCost string `protobuf:"bytes,13,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 开仓手续费 + MarketMoney string `protobuf:"bytes,14,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderMoney string `protobuf:"bytes,15,opt,name=orderMoney,proto3" json:"orderMoney,omitempty"` // 订单总金额 + Status int64 `protobuf:"varint,16,opt,name=status,proto3" json:"status,omitempty"` // 订单状态 + CreateTime string `protobuf:"bytes,17,opt,name=createTime,proto3" json:"createTime,omitempty"` // 订单创建时间 + UpdateTime string `protobuf:"bytes,18,opt,name=updateTime,proto3" json:"updateTime,omitempty"` // 订单更新时间 + OpenTime string `protobuf:"bytes,19,opt,name=openTime,proto3" json:"openTime,omitempty"` // 订单开仓时间 + ClosingTime string `protobuf:"bytes,20,opt,name=closingTime,proto3" json:"closingTime,omitempty"` // 订单平仓时间 + ClosingCost string `protobuf:"bytes,21,opt,name=closingCost,proto3" json:"closingCost,omitempty"` // 平仓手续费 + FaceValue string `protobuf:"bytes,22,opt,name=faceValue,proto3" json:"faceValue,omitempty"` // 面值 + PryNum string `protobuf:"bytes,23,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 + KeepDecimal string `protobuf:"bytes,24,opt,name=keepDecimal,proto3" json:"keepDecimal,omitempty"` // 保留小数位 + StockName string `protobuf:"bytes,25,opt,name=stockName,proto3" json:"stockName,omitempty"` // 股票名称 +} + +func (x *BotOrderHkdTrade) Reset() { + *x = BotOrderHkdTrade{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotOrderHkdTrade) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotOrderHkdTrade) ProtoMessage() {} + +func (x *BotOrderHkdTrade) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotOrderHkdTrade.ProtoReflect.Descriptor instead. +func (*BotOrderHkdTrade) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareHkd_proto_rawDescGZIP(), []int{3} +} + +func (x *BotOrderHkdTrade) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *BotOrderHkdTrade) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *BotOrderHkdTrade) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *BotOrderHkdTrade) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *BotOrderHkdTrade) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *BotOrderHkdTrade) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *BotOrderHkdTrade) GetDealPrice() string { + if x != nil { + return x.DealPrice + } + return "" +} + +func (x *BotOrderHkdTrade) GetClosingPrice() string { + if x != nil { + return x.ClosingPrice + } + return "" +} + +func (x *BotOrderHkdTrade) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *BotOrderHkdTrade) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *BotOrderHkdTrade) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *BotOrderHkdTrade) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *BotOrderHkdTrade) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *BotOrderHkdTrade) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *BotOrderHkdTrade) GetOrderMoney() string { + if x != nil { + return x.OrderMoney + } + return "" +} + +func (x *BotOrderHkdTrade) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *BotOrderHkdTrade) GetCreateTime() string { + if x != nil { + return x.CreateTime + } + return "" +} + +func (x *BotOrderHkdTrade) GetUpdateTime() string { + if x != nil { + return x.UpdateTime + } + return "" +} + +func (x *BotOrderHkdTrade) GetOpenTime() string { + if x != nil { + return x.OpenTime + } + return "" +} + +func (x *BotOrderHkdTrade) GetClosingTime() string { + if x != nil { + return x.ClosingTime + } + return "" +} + +func (x *BotOrderHkdTrade) GetClosingCost() string { + if x != nil { + return x.ClosingCost + } + return "" +} + +func (x *BotOrderHkdTrade) GetFaceValue() string { + if x != nil { + return x.FaceValue + } + return "" +} + +func (x *BotOrderHkdTrade) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *BotOrderHkdTrade) GetKeepDecimal() string { + if x != nil { + return x.KeepDecimal + } + return "" +} + +func (x *BotOrderHkdTrade) GetStockName() string { + if x != nil { + return x.StockName + } + return "" +} + +type OrderHkdRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + StockId string `protobuf:"bytes,1,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票Code + TradeType int64 `protobuf:"varint,2,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型:1买入,2卖出 + DealType int64 `protobuf:"varint,3,opt,name=dealType,proto3" json:"dealType,omitempty"` // 委托方式:1限价,2市价 + LimitPrice string `protobuf:"bytes,4,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,5,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + MarketMoney string `protobuf:"bytes,6,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderNumber string `protobuf:"bytes,7,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + ServiceCost string `protobuf:"bytes,8,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 手续费 + StopType int64 `protobuf:"varint,9,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止损止盈设置:1无设置,2止损止盈 + StopLossPrice string `protobuf:"bytes,10,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,11,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止损 + PryNum string `protobuf:"bytes,12,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 +} + +func (x *OrderHkdRequest) Reset() { + *x = OrderHkdRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OrderHkdRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OrderHkdRequest) ProtoMessage() {} + +func (x *OrderHkdRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OrderHkdRequest.ProtoReflect.Descriptor instead. +func (*OrderHkdRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareHkd_proto_rawDescGZIP(), []int{4} +} + +func (x *OrderHkdRequest) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *OrderHkdRequest) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *OrderHkdRequest) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *OrderHkdRequest) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *OrderHkdRequest) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *OrderHkdRequest) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *OrderHkdRequest) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *OrderHkdRequest) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *OrderHkdRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *OrderHkdRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *OrderHkdRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *OrderHkdRequest) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +type UpdateHkdOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id + StopType int64 `protobuf:"varint,2,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,3,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,4,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 +} + +func (x *UpdateHkdOrderRequest) Reset() { + *x = UpdateHkdOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateHkdOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateHkdOrderRequest) ProtoMessage() {} + +func (x *UpdateHkdOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateHkdOrderRequest.ProtoReflect.Descriptor instead. +func (*UpdateHkdOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareHkd_proto_rawDescGZIP(), []int{5} +} + +func (x *UpdateHkdOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *UpdateHkdOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *UpdateHkdOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *UpdateHkdOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +type OrderHkdReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *OrderHkdResult `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *OrderHkdReply) Reset() { + *x = OrderHkdReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OrderHkdReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OrderHkdReply) ProtoMessage() {} + +func (x *OrderHkdReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OrderHkdReply.ProtoReflect.Descriptor instead. +func (*OrderHkdReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareHkd_proto_rawDescGZIP(), []int{6} +} + +func (x *OrderHkdReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *OrderHkdReply) GetData() *OrderHkdResult { + if x != nil { + return x.Data + } + return nil +} + +func (x *OrderHkdReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type AllHkdOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *AllHkdOrderRequest) Reset() { + *x = AllHkdOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllHkdOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllHkdOrderRequest) ProtoMessage() {} + +func (x *AllHkdOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllHkdOrderRequest.ProtoReflect.Descriptor instead. +func (*AllHkdOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareHkd_proto_rawDescGZIP(), []int{7} +} + +type CancelHkdOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID +} + +func (x *CancelHkdOrderRequest) Reset() { + *x = CancelHkdOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CancelHkdOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CancelHkdOrderRequest) ProtoMessage() {} + +func (x *CancelHkdOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CancelHkdOrderRequest.ProtoReflect.Descriptor instead. +func (*CancelHkdOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareHkd_proto_rawDescGZIP(), []int{8} +} + +func (x *CancelHkdOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type AllHkdOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *AllHkdOrderReply) Reset() { + *x = AllHkdOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllHkdOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllHkdOrderReply) ProtoMessage() {} + +func (x *AllHkdOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllHkdOrderReply.ProtoReflect.Descriptor instead. +func (*AllHkdOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareHkd_proto_rawDescGZIP(), []int{9} +} + +func (x *AllHkdOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *AllHkdOrderReply) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +func (x *AllHkdOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type OrderHkdResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id +} + +func (x *OrderHkdResult) Reset() { + *x = OrderHkdResult{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OrderHkdResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OrderHkdResult) ProtoMessage() {} + +func (x *OrderHkdResult) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareHkd_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OrderHkdResult.ProtoReflect.Descriptor instead. +func (*OrderHkdResult) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareHkd_proto_rawDescGZIP(), []int{10} +} + +func (x *OrderHkdResult) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +var File_matchmaking_v1_share_shareHkd_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_share_shareHkd_proto_rawDesc = []byte{ + 0x0a, 0x23, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x48, 0x6b, 0x64, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0x6e, 0x0a, 0x1a, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, + 0x63, 0x6b, 0x48, 0x6b, 0x64, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, + 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x22, 0x82, 0x01, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, + 0x6f, 0x63, 0x6b, 0x48, 0x6b, 0x64, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, + 0x63, 0x6f, 0x64, 0x65, 0x12, 0x38, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x48, 0x6b, 0x64, 0x54, + 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, + 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xa6, 0x01, 0x0a, 0x14, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x48, 0x6b, 0x64, 0x54, 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, + 0x61, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, + 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x34, 0x0a, 0x04, 0x64, + 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x6d, 0x61, 0x74, 0x63, + 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x48, 0x6b, 0x64, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x04, 0x64, 0x61, 0x74, + 0x61, 0x12, 0x1e, 0x0a, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, + 0x74, 0x22, 0x9e, 0x06, 0x0a, 0x10, 0x42, 0x6f, 0x74, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x48, 0x6b, + 0x64, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, + 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, + 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, + 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, + 0x54, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, + 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, + 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x65, 0x61, 0x6c, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x64, 0x65, 0x61, 0x6c, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6c, 0x6f, 0x73, + 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, + 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, + 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, + 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, + 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, + 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0c, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, + 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, + 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, + 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, 0x6f, 0x6e, + 0x65, 0x79, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x10, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1e, 0x0a, 0x0a, + 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x11, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1e, 0x0a, 0x0a, + 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x12, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, + 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x13, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, + 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, + 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, + 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, + 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x15, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, + 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x16, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x72, + 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x17, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, 0x79, 0x4e, + 0x75, 0x6d, 0x12, 0x20, 0x0a, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, 0x6d, 0x61, + 0x6c, 0x18, 0x18, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, + 0x69, 0x6d, 0x61, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x4e, 0x61, 0x6d, + 0x65, 0x18, 0x19, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x4e, 0x61, + 0x6d, 0x65, 0x22, 0x8b, 0x03, 0x0a, 0x0f, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x48, 0x6b, 0x64, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, + 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, + 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, + 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, + 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, + 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, + 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x20, + 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x07, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, + 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, + 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, + 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x09, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, + 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, + 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, + 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x72, 0x79, 0x4e, + 0x75, 0x6d, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, + 0x22, 0x97, 0x01, 0x0a, 0x15, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x48, 0x6b, 0x64, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, + 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, + 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, + 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, + 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x22, 0x71, 0x0a, 0x0d, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x48, 0x6b, 0x64, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, + 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, + 0x32, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4f, + 0x72, 0x64, 0x65, 0x72, 0x48, 0x6b, 0x64, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x52, 0x04, 0x64, + 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x14, 0x0a, + 0x12, 0x41, 0x6c, 0x6c, 0x48, 0x6b, 0x64, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x22, 0x31, 0x0a, 0x15, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x48, 0x6b, 0x64, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, + 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x22, 0x54, 0x0a, 0x10, 0x41, 0x6c, 0x6c, 0x48, 0x6b, 0x64, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, + 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x12, + 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, + 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x2a, 0x0a, 0x0e, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x48, 0x6b, 0x64, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x18, + 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x32, 0xc5, 0x06, 0x0a, 0x08, 0x53, 0x68, 0x61, + 0x72, 0x65, 0x48, 0x6b, 0x64, 0x12, 0x92, 0x01, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x48, 0x6b, 0x64, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x2a, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, + 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x48, 0x6b, 0x64, 0x54, 0x72, 0x61, + 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x28, 0x2e, 0x6d, 0x61, 0x74, 0x63, + 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6f, + 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x48, 0x6b, 0x64, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x25, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1f, 0x3a, 0x01, 0x2a, 0x22, 0x1a, + 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x68, 0x6b, 0x64, 0x2f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x12, 0x82, 0x01, 0x0a, 0x12, 0x53, + 0x68, 0x61, 0x72, 0x65, 0x48, 0x6b, 0x64, 0x50, 0x6c, 0x61, 0x63, 0x65, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x12, 0x1f, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x48, 0x6b, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x48, 0x6b, 0x64, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x22, 0x2c, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x26, 0x3a, 0x01, 0x2a, 0x22, 0x21, 0x2f, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x68, 0x6b, 0x64, 0x2f, 0x73, 0x68, + 0x61, 0x72, 0x65, 0x5f, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, + 0x8a, 0x01, 0x0a, 0x13, 0x53, 0x68, 0x61, 0x72, 0x65, 0x48, 0x6b, 0x64, 0x55, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, + 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x48, + 0x6b, 0x64, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, + 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x48, 0x6b, 0x64, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2d, 0x82, + 0xd3, 0xe4, 0x93, 0x02, 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x68, 0x6b, 0x64, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, + 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x83, 0x01, 0x0a, + 0x10, 0x53, 0x68, 0x61, 0x72, 0x65, 0x48, 0x6b, 0x64, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, + 0x6e, 0x12, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x2e, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x48, 0x6b, 0x64, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x48, + 0x6b, 0x64, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x29, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x23, 0x3a, + 0x01, 0x2a, 0x22, 0x1e, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, + 0x68, 0x6b, 0x64, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, + 0x6f, 0x6e, 0x12, 0x8a, 0x01, 0x0a, 0x13, 0x53, 0x68, 0x61, 0x72, 0x65, 0x48, 0x6b, 0x64, 0x41, + 0x6c, 0x6c, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x22, 0x2e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x48, + 0x6b, 0x64, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, + 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x41, 0x6c, 0x6c, 0x48, 0x6b, 0x64, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x68, 0x6b, 0x64, 0x2f, 0x73, 0x68, 0x61, + 0x72, 0x65, 0x5f, 0x61, 0x6c, 0x6c, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, + 0x7f, 0x0a, 0x0e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x48, 0x6b, 0x64, 0x43, 0x61, 0x6e, 0x63, 0x65, + 0x6c, 0x12, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x2e, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x48, 0x6b, 0x64, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x48, + 0x6b, 0x64, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x27, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x21, 0x3a, + 0x01, 0x2a, 0x22, 0x1c, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, + 0x68, 0x6b, 0x64, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6e, 0x63, 0x65, 0x6c, + 0x42, 0x2a, 0x5a, 0x28, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2d, + 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_share_shareHkd_proto_rawDescOnce sync.Once + file_matchmaking_v1_share_shareHkd_proto_rawDescData = file_matchmaking_v1_share_shareHkd_proto_rawDesc +) + +func file_matchmaking_v1_share_shareHkd_proto_rawDescGZIP() []byte { + file_matchmaking_v1_share_shareHkd_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_share_shareHkd_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_share_shareHkd_proto_rawDescData) + }) + return file_matchmaking_v1_share_shareHkd_proto_rawDescData +} + +var file_matchmaking_v1_share_shareHkd_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_matchmaking_v1_share_shareHkd_proto_goTypes = []any{ + (*GetBotStockHkdTradeRequest)(nil), // 0: matchmaking.v1.GetBotStockHkdTradeRequest + (*GetBotStockHkdTradeReply)(nil), // 1: matchmaking.v1.GetBotStockHkdTradeReply + (*BotStockHkdTradeData)(nil), // 2: matchmaking.v1.BotStockHkdTradeData + (*BotOrderHkdTrade)(nil), // 3: matchmaking.v1.BotOrderHkdTrade + (*OrderHkdRequest)(nil), // 4: matchmaking.v1.OrderHkdRequest + (*UpdateHkdOrderRequest)(nil), // 5: matchmaking.v1.UpdateHkdOrderRequest + (*OrderHkdReply)(nil), // 6: matchmaking.v1.OrderHkdReply + (*AllHkdOrderRequest)(nil), // 7: matchmaking.v1.AllHkdOrderRequest + (*CancelHkdOrderRequest)(nil), // 8: matchmaking.v1.CancelHkdOrderRequest + (*AllHkdOrderReply)(nil), // 9: matchmaking.v1.AllHkdOrderReply + (*OrderHkdResult)(nil), // 10: matchmaking.v1.OrderHkdResult +} +var file_matchmaking_v1_share_shareHkd_proto_depIdxs = []int32{ + 2, // 0: matchmaking.v1.GetBotStockHkdTradeReply.data:type_name -> matchmaking.v1.BotStockHkdTradeData + 3, // 1: matchmaking.v1.BotStockHkdTradeData.data:type_name -> matchmaking.v1.BotOrderHkdTrade + 10, // 2: matchmaking.v1.OrderHkdReply.data:type_name -> matchmaking.v1.OrderHkdResult + 0, // 3: matchmaking.v1.ShareHkd.GetBotStockHkdTrade:input_type -> matchmaking.v1.GetBotStockHkdTradeRequest + 4, // 4: matchmaking.v1.ShareHkd.ShareHkdPlaceOrder:input_type -> matchmaking.v1.OrderHkdRequest + 5, // 5: matchmaking.v1.ShareHkd.ShareHkdUpdateOrder:input_type -> matchmaking.v1.UpdateHkdOrderRequest + 8, // 6: matchmaking.v1.ShareHkd.ShareHkdPosition:input_type -> matchmaking.v1.CancelHkdOrderRequest + 7, // 7: matchmaking.v1.ShareHkd.ShareHkdAllPosition:input_type -> matchmaking.v1.AllHkdOrderRequest + 8, // 8: matchmaking.v1.ShareHkd.ShareHkdCancel:input_type -> matchmaking.v1.CancelHkdOrderRequest + 1, // 9: matchmaking.v1.ShareHkd.GetBotStockHkdTrade:output_type -> matchmaking.v1.GetBotStockHkdTradeReply + 6, // 10: matchmaking.v1.ShareHkd.ShareHkdPlaceOrder:output_type -> matchmaking.v1.OrderHkdReply + 6, // 11: matchmaking.v1.ShareHkd.ShareHkdUpdateOrder:output_type -> matchmaking.v1.OrderHkdReply + 6, // 12: matchmaking.v1.ShareHkd.ShareHkdPosition:output_type -> matchmaking.v1.OrderHkdReply + 9, // 13: matchmaking.v1.ShareHkd.ShareHkdAllPosition:output_type -> matchmaking.v1.AllHkdOrderReply + 6, // 14: matchmaking.v1.ShareHkd.ShareHkdCancel:output_type -> matchmaking.v1.OrderHkdReply + 9, // [9:15] is the sub-list for method output_type + 3, // [3:9] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_share_shareHkd_proto_init() } +func file_matchmaking_v1_share_shareHkd_proto_init() { + if File_matchmaking_v1_share_shareHkd_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_matchmaking_v1_share_shareHkd_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*GetBotStockHkdTradeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareHkd_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*GetBotStockHkdTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareHkd_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*BotStockHkdTradeData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareHkd_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*BotOrderHkdTrade); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareHkd_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*OrderHkdRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareHkd_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*UpdateHkdOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareHkd_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*OrderHkdReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareHkd_proto_msgTypes[7].Exporter = func(v any, i int) any { + switch v := v.(*AllHkdOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareHkd_proto_msgTypes[8].Exporter = func(v any, i int) any { + switch v := v.(*CancelHkdOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareHkd_proto_msgTypes[9].Exporter = func(v any, i int) any { + switch v := v.(*AllHkdOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareHkd_proto_msgTypes[10].Exporter = func(v any, i int) any { + switch v := v.(*OrderHkdResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_share_shareHkd_proto_rawDesc, + NumEnums: 0, + NumMessages: 11, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_matchmaking_v1_share_shareHkd_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_share_shareHkd_proto_depIdxs, + MessageInfos: file_matchmaking_v1_share_shareHkd_proto_msgTypes, + }.Build() + File_matchmaking_v1_share_shareHkd_proto = out.File + file_matchmaking_v1_share_shareHkd_proto_rawDesc = nil + file_matchmaking_v1_share_shareHkd_proto_goTypes = nil + file_matchmaking_v1_share_shareHkd_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/share/shareHkd.proto b/api/matchmaking/v1/share/shareHkd.proto new file mode 100644 index 0000000..ee33539 --- /dev/null +++ b/api/matchmaking/v1/share/shareHkd.proto @@ -0,0 +1,145 @@ +syntax = "proto3"; + +package matchmaking.v1; + +import "google/api/annotations.proto"; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +service ShareHkd { + // GetBotStockHkdTrade 港股列表查询 + rpc GetBotStockHkdTrade(GetBotStockHkdTradeRequest)returns(GetBotStockHkdTradeReply){ + option (google.api.http) = { + post:"/order_sharehkd/share_list", + body:"*", + }; + } + // ShareHkdPlaceOrder 港股下单 + rpc ShareHkdPlaceOrder(OrderHkdRequest)returns(OrderHkdReply) { + option (google.api.http) = { + post: "/order_sharehkd/share_place_order", + body: "*", + }; + } + // ShareHkdUpdateOrder 港股设置止盈止损 + rpc ShareHkdUpdateOrder(UpdateHkdOrderRequest)returns(OrderHkdReply){ + option (google.api.http) = { + post:"/order_sharehkd/share_update_order", + body:"*", + }; + } + // ShareHkdPosition 港股平仓 + rpc ShareHkdPosition(CancelHkdOrderRequest)returns(OrderHkdReply){ + option (google.api.http) = { + post:"/order_sharehkd/share_position", + body:"*", + }; + } + // ShareHkdAllPosition 港股一键平仓 + rpc ShareHkdAllPosition(AllHkdOrderRequest)returns(AllHkdOrderReply){ + option (google.api.http) = { + post:"/order_sharehkd/share_all_position", + body:"*", + }; + } + // ShareHkdCancel 港股撤单 + rpc ShareHkdCancel(CancelHkdOrderRequest)returns(OrderHkdReply){ + option (google.api.http) = { + post:"/order_sharehkd/share_cancel", + body:"*", + }; + } +} + +message GetBotStockHkdTradeRequest{ + int64 status =1;// 状态码 + int64 pageSize =2; // 每页显示条数 + int64 pageCount =3;// 开始的位置 +} + +message GetBotStockHkdTradeReply{ + int64 code =1;// 状态码 + BotStockHkdTradeData data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message BotStockHkdTradeData{ + int64 pageSize =1; // 每页显示条数 + int64 pageCount =2;// 开始的位置 + repeated BotOrderHkdTrade data =3;// 返回结果 + int64 totalCount =4;// 总数据 +} + +message BotOrderHkdTrade{ + string orderId =1;// 订单ID + string stockId =2;// 股票代码 + int64 tradeType =3;// 交易类型 + int64 dealType =4;// 交易方式 + string limitPrice =5;// 限价 + string marketPrice =6;// 市价 + string dealPrice =7;// 开仓价 + string closingPrice =8;// 平仓价 + string orderNumber =9;// 订单数量 + int64 stopType =10;// 止盈止损状态 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string serviceCost =13;// 开仓手续费 + string marketMoney =14;// 订单金额 + string orderMoney =15;// 订单总金额 + int64 status =16;// 订单状态 + string createTime =17;// 订单创建时间 + string updateTime =18;// 订单更新时间 + string openTime =19;// 订单开仓时间 + string closingTime =20;// 订单平仓时间 + string closingCost =21;// 平仓手续费 + string faceValue =22;// 面值 + string pryNum =23;// 杠杆 + string keepDecimal =24;// 保留小数位 + string stockName =25;// 股票名称 +} + +message OrderHkdRequest{ + string stockId =1;// 股票Code + int64 tradeType =2;// 交易类型:1买入,2卖出 + int64 dealType =3;// 委托方式:1限价,2市价 + string limitPrice =4;// 限价 + string marketPrice =5;// 市价 + string marketMoney =6;// 订单金额 + string orderNumber =7;// 订单数量 + string serviceCost =8;// 手续费 + int64 stopType =9;// 止损止盈设置:1无设置,2止损止盈 + string stopLossPrice =10;// 止损 + string stopWinPrice =11;// 止损 + string pryNum =12;// 杠杆 +} + +message UpdateHkdOrderRequest{ + string orderId =1;// 订单Id + int64 stopType =2;// 止盈止损 + string stopLossPrice =3;// 止损 + string stopWinPrice =4;// 止盈 +} + +message OrderHkdReply{ + int64 code =1;// 状态码 + OrderHkdResult data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message AllHkdOrderRequest{ + +} + +message CancelHkdOrderRequest{ + string orderId =1;// 订单ID +} + +message AllHkdOrderReply{ + int64 code =1;// 状态码 + string data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message OrderHkdResult { + string orderId =1;// 订单Id +} \ No newline at end of file diff --git a/api/matchmaking/v1/share/shareHkd_grpc.pb.go b/api/matchmaking/v1/share/shareHkd_grpc.pb.go new file mode 100644 index 0000000..0dcc9df --- /dev/null +++ b/api/matchmaking/v1/share/shareHkd_grpc.pb.go @@ -0,0 +1,312 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareHkd.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + ShareHkd_GetBotStockHkdTrade_FullMethodName = "/matchmaking.v1.ShareHkd/GetBotStockHkdTrade" + ShareHkd_ShareHkdPlaceOrder_FullMethodName = "/matchmaking.v1.ShareHkd/ShareHkdPlaceOrder" + ShareHkd_ShareHkdUpdateOrder_FullMethodName = "/matchmaking.v1.ShareHkd/ShareHkdUpdateOrder" + ShareHkd_ShareHkdPosition_FullMethodName = "/matchmaking.v1.ShareHkd/ShareHkdPosition" + ShareHkd_ShareHkdAllPosition_FullMethodName = "/matchmaking.v1.ShareHkd/ShareHkdAllPosition" + ShareHkd_ShareHkdCancel_FullMethodName = "/matchmaking.v1.ShareHkd/ShareHkdCancel" +) + +// ShareHkdClient is the client API for ShareHkd service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ShareHkdClient interface { + // GetBotStockHkdTrade 港股列表查询 + GetBotStockHkdTrade(ctx context.Context, in *GetBotStockHkdTradeRequest, opts ...grpc.CallOption) (*GetBotStockHkdTradeReply, error) + // ShareHkdPlaceOrder 港股下单 + ShareHkdPlaceOrder(ctx context.Context, in *OrderHkdRequest, opts ...grpc.CallOption) (*OrderHkdReply, error) + // ShareHkdUpdateOrder 港股设置止盈止损 + ShareHkdUpdateOrder(ctx context.Context, in *UpdateHkdOrderRequest, opts ...grpc.CallOption) (*OrderHkdReply, error) + // ShareHkdPosition 港股平仓 + ShareHkdPosition(ctx context.Context, in *CancelHkdOrderRequest, opts ...grpc.CallOption) (*OrderHkdReply, error) + // ShareHkdAllPosition 港股一键平仓 + ShareHkdAllPosition(ctx context.Context, in *AllHkdOrderRequest, opts ...grpc.CallOption) (*AllHkdOrderReply, error) + // ShareHkdCancel 港股撤单 + ShareHkdCancel(ctx context.Context, in *CancelHkdOrderRequest, opts ...grpc.CallOption) (*OrderHkdReply, error) +} + +type shareHkdClient struct { + cc grpc.ClientConnInterface +} + +func NewShareHkdClient(cc grpc.ClientConnInterface) ShareHkdClient { + return &shareHkdClient{cc} +} + +func (c *shareHkdClient) GetBotStockHkdTrade(ctx context.Context, in *GetBotStockHkdTradeRequest, opts ...grpc.CallOption) (*GetBotStockHkdTradeReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetBotStockHkdTradeReply) + err := c.cc.Invoke(ctx, ShareHkd_GetBotStockHkdTrade_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareHkdClient) ShareHkdPlaceOrder(ctx context.Context, in *OrderHkdRequest, opts ...grpc.CallOption) (*OrderHkdReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(OrderHkdReply) + err := c.cc.Invoke(ctx, ShareHkd_ShareHkdPlaceOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareHkdClient) ShareHkdUpdateOrder(ctx context.Context, in *UpdateHkdOrderRequest, opts ...grpc.CallOption) (*OrderHkdReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(OrderHkdReply) + err := c.cc.Invoke(ctx, ShareHkd_ShareHkdUpdateOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareHkdClient) ShareHkdPosition(ctx context.Context, in *CancelHkdOrderRequest, opts ...grpc.CallOption) (*OrderHkdReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(OrderHkdReply) + err := c.cc.Invoke(ctx, ShareHkd_ShareHkdPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareHkdClient) ShareHkdAllPosition(ctx context.Context, in *AllHkdOrderRequest, opts ...grpc.CallOption) (*AllHkdOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AllHkdOrderReply) + err := c.cc.Invoke(ctx, ShareHkd_ShareHkdAllPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareHkdClient) ShareHkdCancel(ctx context.Context, in *CancelHkdOrderRequest, opts ...grpc.CallOption) (*OrderHkdReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(OrderHkdReply) + err := c.cc.Invoke(ctx, ShareHkd_ShareHkdCancel_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ShareHkdServer is the server API for ShareHkd service. +// All implementations must embed UnimplementedShareHkdServer +// for forward compatibility +type ShareHkdServer interface { + // GetBotStockHkdTrade 港股列表查询 + GetBotStockHkdTrade(context.Context, *GetBotStockHkdTradeRequest) (*GetBotStockHkdTradeReply, error) + // ShareHkdPlaceOrder 港股下单 + ShareHkdPlaceOrder(context.Context, *OrderHkdRequest) (*OrderHkdReply, error) + // ShareHkdUpdateOrder 港股设置止盈止损 + ShareHkdUpdateOrder(context.Context, *UpdateHkdOrderRequest) (*OrderHkdReply, error) + // ShareHkdPosition 港股平仓 + ShareHkdPosition(context.Context, *CancelHkdOrderRequest) (*OrderHkdReply, error) + // ShareHkdAllPosition 港股一键平仓 + ShareHkdAllPosition(context.Context, *AllHkdOrderRequest) (*AllHkdOrderReply, error) + // ShareHkdCancel 港股撤单 + ShareHkdCancel(context.Context, *CancelHkdOrderRequest) (*OrderHkdReply, error) + mustEmbedUnimplementedShareHkdServer() +} + +// UnimplementedShareHkdServer must be embedded to have forward compatible implementations. +type UnimplementedShareHkdServer struct { +} + +func (UnimplementedShareHkdServer) GetBotStockHkdTrade(context.Context, *GetBotStockHkdTradeRequest) (*GetBotStockHkdTradeReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBotStockHkdTrade not implemented") +} +func (UnimplementedShareHkdServer) ShareHkdPlaceOrder(context.Context, *OrderHkdRequest) (*OrderHkdReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareHkdPlaceOrder not implemented") +} +func (UnimplementedShareHkdServer) ShareHkdUpdateOrder(context.Context, *UpdateHkdOrderRequest) (*OrderHkdReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareHkdUpdateOrder not implemented") +} +func (UnimplementedShareHkdServer) ShareHkdPosition(context.Context, *CancelHkdOrderRequest) (*OrderHkdReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareHkdPosition not implemented") +} +func (UnimplementedShareHkdServer) ShareHkdAllPosition(context.Context, *AllHkdOrderRequest) (*AllHkdOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareHkdAllPosition not implemented") +} +func (UnimplementedShareHkdServer) ShareHkdCancel(context.Context, *CancelHkdOrderRequest) (*OrderHkdReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareHkdCancel not implemented") +} +func (UnimplementedShareHkdServer) mustEmbedUnimplementedShareHkdServer() {} + +// UnsafeShareHkdServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ShareHkdServer will +// result in compilation errors. +type UnsafeShareHkdServer interface { + mustEmbedUnimplementedShareHkdServer() +} + +func RegisterShareHkdServer(s grpc.ServiceRegistrar, srv ShareHkdServer) { + s.RegisterService(&ShareHkd_ServiceDesc, srv) +} + +func _ShareHkd_GetBotStockHkdTrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetBotStockHkdTradeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareHkdServer).GetBotStockHkdTrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareHkd_GetBotStockHkdTrade_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareHkdServer).GetBotStockHkdTrade(ctx, req.(*GetBotStockHkdTradeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareHkd_ShareHkdPlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(OrderHkdRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareHkdServer).ShareHkdPlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareHkd_ShareHkdPlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareHkdServer).ShareHkdPlaceOrder(ctx, req.(*OrderHkdRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareHkd_ShareHkdUpdateOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateHkdOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareHkdServer).ShareHkdUpdateOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareHkd_ShareHkdUpdateOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareHkdServer).ShareHkdUpdateOrder(ctx, req.(*UpdateHkdOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareHkd_ShareHkdPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelHkdOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareHkdServer).ShareHkdPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareHkd_ShareHkdPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareHkdServer).ShareHkdPosition(ctx, req.(*CancelHkdOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareHkd_ShareHkdAllPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AllHkdOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareHkdServer).ShareHkdAllPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareHkd_ShareHkdAllPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareHkdServer).ShareHkdAllPosition(ctx, req.(*AllHkdOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareHkd_ShareHkdCancel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelHkdOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareHkdServer).ShareHkdCancel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareHkd_ShareHkdCancel_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareHkdServer).ShareHkdCancel(ctx, req.(*CancelHkdOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// ShareHkd_ServiceDesc is the grpc.ServiceDesc for ShareHkd service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ShareHkd_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "matchmaking.v1.ShareHkd", + HandlerType: (*ShareHkdServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetBotStockHkdTrade", + Handler: _ShareHkd_GetBotStockHkdTrade_Handler, + }, + { + MethodName: "ShareHkdPlaceOrder", + Handler: _ShareHkd_ShareHkdPlaceOrder_Handler, + }, + { + MethodName: "ShareHkdUpdateOrder", + Handler: _ShareHkd_ShareHkdUpdateOrder_Handler, + }, + { + MethodName: "ShareHkdPosition", + Handler: _ShareHkd_ShareHkdPosition_Handler, + }, + { + MethodName: "ShareHkdAllPosition", + Handler: _ShareHkd_ShareHkdAllPosition_Handler, + }, + { + MethodName: "ShareHkdCancel", + Handler: _ShareHkd_ShareHkdCancel_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "matchmaking/v1/share/shareHkd.proto", +} diff --git a/api/matchmaking/v1/share/shareHkd_http.pb.go b/api/matchmaking/v1/share/shareHkd_http.pb.go new file mode 100644 index 0000000..59b7608 --- /dev/null +++ b/api/matchmaking/v1/share/shareHkd_http.pb.go @@ -0,0 +1,279 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.3 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareHkd.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationShareHkdGetBotStockHkdTrade = "/matchmaking.v1.ShareHkd/GetBotStockHkdTrade" +const OperationShareHkdShareHkdAllPosition = "/matchmaking.v1.ShareHkd/ShareHkdAllPosition" +const OperationShareHkdShareHkdCancel = "/matchmaking.v1.ShareHkd/ShareHkdCancel" +const OperationShareHkdShareHkdPlaceOrder = "/matchmaking.v1.ShareHkd/ShareHkdPlaceOrder" +const OperationShareHkdShareHkdPosition = "/matchmaking.v1.ShareHkd/ShareHkdPosition" +const OperationShareHkdShareHkdUpdateOrder = "/matchmaking.v1.ShareHkd/ShareHkdUpdateOrder" + +type ShareHkdHTTPServer interface { + // GetBotStockHkdTrade GetBotStockHkdTrade 港股列表查询 + GetBotStockHkdTrade(context.Context, *GetBotStockHkdTradeRequest) (*GetBotStockHkdTradeReply, error) + // ShareHkdAllPosition ShareHkdAllPosition 港股一键平仓 + ShareHkdAllPosition(context.Context, *AllHkdOrderRequest) (*AllHkdOrderReply, error) + // ShareHkdCancel ShareHkdCancel 港股撤单 + ShareHkdCancel(context.Context, *CancelHkdOrderRequest) (*OrderHkdReply, error) + // ShareHkdPlaceOrder ShareHkdPlaceOrder 港股下单 + ShareHkdPlaceOrder(context.Context, *OrderHkdRequest) (*OrderHkdReply, error) + // ShareHkdPosition ShareHkdPosition 港股平仓 + ShareHkdPosition(context.Context, *CancelHkdOrderRequest) (*OrderHkdReply, error) + // ShareHkdUpdateOrder ShareHkdUpdateOrder 港股设置止盈止损 + ShareHkdUpdateOrder(context.Context, *UpdateHkdOrderRequest) (*OrderHkdReply, error) +} + +func RegisterShareHkdHTTPServer(s *http.Server, srv ShareHkdHTTPServer) { + r := s.Route("/") + r.POST("/order_sharehkd/share_list", _ShareHkd_GetBotStockHkdTrade0_HTTP_Handler(srv)) + r.POST("/order_sharehkd/share_place_order", _ShareHkd_ShareHkdPlaceOrder0_HTTP_Handler(srv)) + r.POST("/order_sharehkd/share_update_order", _ShareHkd_ShareHkdUpdateOrder0_HTTP_Handler(srv)) + r.POST("/order_sharehkd/share_position", _ShareHkd_ShareHkdPosition0_HTTP_Handler(srv)) + r.POST("/order_sharehkd/share_all_position", _ShareHkd_ShareHkdAllPosition0_HTTP_Handler(srv)) + r.POST("/order_sharehkd/share_cancel", _ShareHkd_ShareHkdCancel0_HTTP_Handler(srv)) +} + +func _ShareHkd_GetBotStockHkdTrade0_HTTP_Handler(srv ShareHkdHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetBotStockHkdTradeRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareHkdGetBotStockHkdTrade) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.GetBotStockHkdTrade(ctx, req.(*GetBotStockHkdTradeRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetBotStockHkdTradeReply) + return ctx.Result(200, reply) + } +} + +func _ShareHkd_ShareHkdPlaceOrder0_HTTP_Handler(srv ShareHkdHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in OrderHkdRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareHkdShareHkdPlaceOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareHkdPlaceOrder(ctx, req.(*OrderHkdRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*OrderHkdReply) + return ctx.Result(200, reply) + } +} + +func _ShareHkd_ShareHkdUpdateOrder0_HTTP_Handler(srv ShareHkdHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in UpdateHkdOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareHkdShareHkdUpdateOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareHkdUpdateOrder(ctx, req.(*UpdateHkdOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*OrderHkdReply) + return ctx.Result(200, reply) + } +} + +func _ShareHkd_ShareHkdPosition0_HTTP_Handler(srv ShareHkdHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelHkdOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareHkdShareHkdPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareHkdPosition(ctx, req.(*CancelHkdOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*OrderHkdReply) + return ctx.Result(200, reply) + } +} + +func _ShareHkd_ShareHkdAllPosition0_HTTP_Handler(srv ShareHkdHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in AllHkdOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareHkdShareHkdAllPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareHkdAllPosition(ctx, req.(*AllHkdOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*AllHkdOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareHkd_ShareHkdCancel0_HTTP_Handler(srv ShareHkdHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelHkdOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareHkdShareHkdCancel) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareHkdCancel(ctx, req.(*CancelHkdOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*OrderHkdReply) + return ctx.Result(200, reply) + } +} + +type ShareHkdHTTPClient interface { + GetBotStockHkdTrade(ctx context.Context, req *GetBotStockHkdTradeRequest, opts ...http.CallOption) (rsp *GetBotStockHkdTradeReply, err error) + ShareHkdAllPosition(ctx context.Context, req *AllHkdOrderRequest, opts ...http.CallOption) (rsp *AllHkdOrderReply, err error) + ShareHkdCancel(ctx context.Context, req *CancelHkdOrderRequest, opts ...http.CallOption) (rsp *OrderHkdReply, err error) + ShareHkdPlaceOrder(ctx context.Context, req *OrderHkdRequest, opts ...http.CallOption) (rsp *OrderHkdReply, err error) + ShareHkdPosition(ctx context.Context, req *CancelHkdOrderRequest, opts ...http.CallOption) (rsp *OrderHkdReply, err error) + ShareHkdUpdateOrder(ctx context.Context, req *UpdateHkdOrderRequest, opts ...http.CallOption) (rsp *OrderHkdReply, err error) +} + +type ShareHkdHTTPClientImpl struct { + cc *http.Client +} + +func NewShareHkdHTTPClient(client *http.Client) ShareHkdHTTPClient { + return &ShareHkdHTTPClientImpl{client} +} + +func (c *ShareHkdHTTPClientImpl) GetBotStockHkdTrade(ctx context.Context, in *GetBotStockHkdTradeRequest, opts ...http.CallOption) (*GetBotStockHkdTradeReply, error) { + var out GetBotStockHkdTradeReply + pattern := "/order_sharehkd/share_list" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareHkdGetBotStockHkdTrade)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareHkdHTTPClientImpl) ShareHkdAllPosition(ctx context.Context, in *AllHkdOrderRequest, opts ...http.CallOption) (*AllHkdOrderReply, error) { + var out AllHkdOrderReply + pattern := "/order_sharehkd/share_all_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareHkdShareHkdAllPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareHkdHTTPClientImpl) ShareHkdCancel(ctx context.Context, in *CancelHkdOrderRequest, opts ...http.CallOption) (*OrderHkdReply, error) { + var out OrderHkdReply + pattern := "/order_sharehkd/share_cancel" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareHkdShareHkdCancel)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareHkdHTTPClientImpl) ShareHkdPlaceOrder(ctx context.Context, in *OrderHkdRequest, opts ...http.CallOption) (*OrderHkdReply, error) { + var out OrderHkdReply + pattern := "/order_sharehkd/share_place_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareHkdShareHkdPlaceOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareHkdHTTPClientImpl) ShareHkdPosition(ctx context.Context, in *CancelHkdOrderRequest, opts ...http.CallOption) (*OrderHkdReply, error) { + var out OrderHkdReply + pattern := "/order_sharehkd/share_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareHkdShareHkdPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareHkdHTTPClientImpl) ShareHkdUpdateOrder(ctx context.Context, in *UpdateHkdOrderRequest, opts ...http.CallOption) (*OrderHkdReply, error) { + var out OrderHkdReply + pattern := "/order_sharehkd/share_update_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareHkdShareHkdUpdateOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/api/matchmaking/v1/share/shareIdn.pb.go b/api/matchmaking/v1/share/shareIdn.pb.go new file mode 100644 index 0000000..faac9f2 --- /dev/null +++ b/api/matchmaking/v1/share/shareIdn.pb.go @@ -0,0 +1,1327 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/share/shareIdn.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GetIdnBotStockTradeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status int64 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` // 状态码 + PageSize int64 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,3,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 +} + +func (x *GetIdnBotStockTradeRequest) Reset() { + *x = GetIdnBotStockTradeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetIdnBotStockTradeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetIdnBotStockTradeRequest) ProtoMessage() {} + +func (x *GetIdnBotStockTradeRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetIdnBotStockTradeRequest.ProtoReflect.Descriptor instead. +func (*GetIdnBotStockTradeRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareIdn_proto_rawDescGZIP(), []int{0} +} + +func (x *GetIdnBotStockTradeRequest) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *GetIdnBotStockTradeRequest) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *GetIdnBotStockTradeRequest) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +type GetBotStockIdnTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *BotStockIdnTradeData `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *GetBotStockIdnTradeReply) Reset() { + *x = GetBotStockIdnTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotStockIdnTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotStockIdnTradeReply) ProtoMessage() {} + +func (x *GetBotStockIdnTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotStockIdnTradeReply.ProtoReflect.Descriptor instead. +func (*GetBotStockIdnTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareIdn_proto_rawDescGZIP(), []int{1} +} + +func (x *GetBotStockIdnTradeReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *GetBotStockIdnTradeReply) GetData() *BotStockIdnTradeData { + if x != nil { + return x.Data + } + return nil +} + +func (x *GetBotStockIdnTradeReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type BotStockIdnTradeData struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PageSize int64 `protobuf:"varint,1,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,2,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + Data []*BotStockIdnTrade `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty"` // 返回结果 + TotalCount int64 `protobuf:"varint,4,opt,name=totalCount,proto3" json:"totalCount,omitempty"` // 总数据 +} + +func (x *BotStockIdnTradeData) Reset() { + *x = BotStockIdnTradeData{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockIdnTradeData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockIdnTradeData) ProtoMessage() {} + +func (x *BotStockIdnTradeData) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockIdnTradeData.ProtoReflect.Descriptor instead. +func (*BotStockIdnTradeData) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareIdn_proto_rawDescGZIP(), []int{2} +} + +func (x *BotStockIdnTradeData) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *BotStockIdnTradeData) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *BotStockIdnTradeData) GetData() []*BotStockIdnTrade { + if x != nil { + return x.Data + } + return nil +} + +func (x *BotStockIdnTradeData) GetTotalCount() int64 { + if x != nil { + return x.TotalCount + } + return 0 +} + +type BotStockIdnTrade struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID + StockId string `protobuf:"bytes,2,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票代码 + TradeType int64 `protobuf:"varint,3,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型 + DealType int64 `protobuf:"varint,4,opt,name=dealType,proto3" json:"dealType,omitempty"` // 交易方式 + LimitPrice string `protobuf:"bytes,5,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,6,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + DealPrice string `protobuf:"bytes,7,opt,name=dealPrice,proto3" json:"dealPrice,omitempty"` // 开仓价 + ClosingPrice string `protobuf:"bytes,8,opt,name=closingPrice,proto3" json:"closingPrice,omitempty"` // 平仓价 + OrderNumber string `protobuf:"bytes,9,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + ServiceCost string `protobuf:"bytes,13,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 开仓手续费 + MarketMoney string `protobuf:"bytes,14,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderMoney string `protobuf:"bytes,15,opt,name=orderMoney,proto3" json:"orderMoney,omitempty"` // 订单总金额 + Status int64 `protobuf:"varint,16,opt,name=status,proto3" json:"status,omitempty"` // 订单状态 + CreateTime string `protobuf:"bytes,17,opt,name=createTime,proto3" json:"createTime,omitempty"` // 订单创建时间 + UpdateTime string `protobuf:"bytes,18,opt,name=updateTime,proto3" json:"updateTime,omitempty"` // 订单更新时间 + OpenTime string `protobuf:"bytes,19,opt,name=openTime,proto3" json:"openTime,omitempty"` // 订单开仓时间 + ClosingTime string `protobuf:"bytes,20,opt,name=closingTime,proto3" json:"closingTime,omitempty"` // 订单平仓时间 + ClosingCost string `protobuf:"bytes,21,opt,name=closingCost,proto3" json:"closingCost,omitempty"` // 平仓手续费 + FaceValue string `protobuf:"bytes,22,opt,name=faceValue,proto3" json:"faceValue,omitempty"` // 面值 + PryNum string `protobuf:"bytes,23,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 + KeepDecimal string `protobuf:"bytes,24,opt,name=keepDecimal,proto3" json:"keepDecimal,omitempty"` // 保留小数位 + StockName string `protobuf:"bytes,25,opt,name=stockName,proto3" json:"stockName,omitempty"` // 股票名称 +} + +func (x *BotStockIdnTrade) Reset() { + *x = BotStockIdnTrade{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockIdnTrade) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockIdnTrade) ProtoMessage() {} + +func (x *BotStockIdnTrade) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockIdnTrade.ProtoReflect.Descriptor instead. +func (*BotStockIdnTrade) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareIdn_proto_rawDescGZIP(), []int{3} +} + +func (x *BotStockIdnTrade) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *BotStockIdnTrade) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *BotStockIdnTrade) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *BotStockIdnTrade) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *BotStockIdnTrade) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *BotStockIdnTrade) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *BotStockIdnTrade) GetDealPrice() string { + if x != nil { + return x.DealPrice + } + return "" +} + +func (x *BotStockIdnTrade) GetClosingPrice() string { + if x != nil { + return x.ClosingPrice + } + return "" +} + +func (x *BotStockIdnTrade) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *BotStockIdnTrade) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *BotStockIdnTrade) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *BotStockIdnTrade) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *BotStockIdnTrade) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *BotStockIdnTrade) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *BotStockIdnTrade) GetOrderMoney() string { + if x != nil { + return x.OrderMoney + } + return "" +} + +func (x *BotStockIdnTrade) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *BotStockIdnTrade) GetCreateTime() string { + if x != nil { + return x.CreateTime + } + return "" +} + +func (x *BotStockIdnTrade) GetUpdateTime() string { + if x != nil { + return x.UpdateTime + } + return "" +} + +func (x *BotStockIdnTrade) GetOpenTime() string { + if x != nil { + return x.OpenTime + } + return "" +} + +func (x *BotStockIdnTrade) GetClosingTime() string { + if x != nil { + return x.ClosingTime + } + return "" +} + +func (x *BotStockIdnTrade) GetClosingCost() string { + if x != nil { + return x.ClosingCost + } + return "" +} + +func (x *BotStockIdnTrade) GetFaceValue() string { + if x != nil { + return x.FaceValue + } + return "" +} + +func (x *BotStockIdnTrade) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *BotStockIdnTrade) GetKeepDecimal() string { + if x != nil { + return x.KeepDecimal + } + return "" +} + +func (x *BotStockIdnTrade) GetStockName() string { + if x != nil { + return x.StockName + } + return "" +} + +type ShareIdnOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + StockId string `protobuf:"bytes,1,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票Code + TradeType int64 `protobuf:"varint,2,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型:1买入,2卖出 + DealType int64 `protobuf:"varint,3,opt,name=dealType,proto3" json:"dealType,omitempty"` // 委托方式:1限价,2市价 + LimitPrice string `protobuf:"bytes,4,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,5,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + MarketMoney string `protobuf:"bytes,6,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderNumber string `protobuf:"bytes,7,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + ServiceCost string `protobuf:"bytes,8,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 手续费 + StopType int64 `protobuf:"varint,9,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止损止盈设置:1无设置,2止损止盈 + StopLossPrice string `protobuf:"bytes,10,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,11,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止损 + PryNum string `protobuf:"bytes,12,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 +} + +func (x *ShareIdnOrderRequest) Reset() { + *x = ShareIdnOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ShareIdnOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ShareIdnOrderRequest) ProtoMessage() {} + +func (x *ShareIdnOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ShareIdnOrderRequest.ProtoReflect.Descriptor instead. +func (*ShareIdnOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareIdn_proto_rawDescGZIP(), []int{4} +} + +func (x *ShareIdnOrderRequest) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *ShareIdnOrderRequest) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *ShareIdnOrderRequest) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *ShareIdnOrderRequest) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *ShareIdnOrderRequest) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *ShareIdnOrderRequest) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *ShareIdnOrderRequest) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *ShareIdnOrderRequest) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *ShareIdnOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *ShareIdnOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *ShareIdnOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *ShareIdnOrderRequest) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +type UpdateIdnOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id + StopType int64 `protobuf:"varint,2,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,3,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,4,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 +} + +func (x *UpdateIdnOrderRequest) Reset() { + *x = UpdateIdnOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateIdnOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateIdnOrderRequest) ProtoMessage() {} + +func (x *UpdateIdnOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateIdnOrderRequest.ProtoReflect.Descriptor instead. +func (*UpdateIdnOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareIdn_proto_rawDescGZIP(), []int{5} +} + +func (x *UpdateIdnOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *UpdateIdnOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *UpdateIdnOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *UpdateIdnOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +type IdnOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *IdnOrderResult `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *IdnOrderReply) Reset() { + *x = IdnOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *IdnOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*IdnOrderReply) ProtoMessage() {} + +func (x *IdnOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use IdnOrderReply.ProtoReflect.Descriptor instead. +func (*IdnOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareIdn_proto_rawDescGZIP(), []int{6} +} + +func (x *IdnOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *IdnOrderReply) GetData() *IdnOrderResult { + if x != nil { + return x.Data + } + return nil +} + +func (x *IdnOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type IdnOrderResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id +} + +func (x *IdnOrderResult) Reset() { + *x = IdnOrderResult{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *IdnOrderResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*IdnOrderResult) ProtoMessage() {} + +func (x *IdnOrderResult) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use IdnOrderResult.ProtoReflect.Descriptor instead. +func (*IdnOrderResult) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareIdn_proto_rawDescGZIP(), []int{7} +} + +func (x *IdnOrderResult) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type AllIdnOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *AllIdnOrderRequest) Reset() { + *x = AllIdnOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllIdnOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllIdnOrderRequest) ProtoMessage() {} + +func (x *AllIdnOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllIdnOrderRequest.ProtoReflect.Descriptor instead. +func (*AllIdnOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareIdn_proto_rawDescGZIP(), []int{8} +} + +type AllIdnOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *AllIdnOrderReply) Reset() { + *x = AllIdnOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllIdnOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllIdnOrderReply) ProtoMessage() {} + +func (x *AllIdnOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllIdnOrderReply.ProtoReflect.Descriptor instead. +func (*AllIdnOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareIdn_proto_rawDescGZIP(), []int{9} +} + +func (x *AllIdnOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *AllIdnOrderReply) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +func (x *AllIdnOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type CancelIdnOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID +} + +func (x *CancelIdnOrderRequest) Reset() { + *x = CancelIdnOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CancelIdnOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CancelIdnOrderRequest) ProtoMessage() {} + +func (x *CancelIdnOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareIdn_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CancelIdnOrderRequest.ProtoReflect.Descriptor instead. +func (*CancelIdnOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareIdn_proto_rawDescGZIP(), []int{10} +} + +func (x *CancelIdnOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +var File_matchmaking_v1_share_shareIdn_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_share_shareIdn_proto_rawDesc = []byte{ + 0x0a, 0x23, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x49, 0x64, 0x6e, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0x6e, 0x0a, 0x1a, 0x47, 0x65, 0x74, 0x49, 0x64, 0x6e, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, + 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x22, 0x82, 0x01, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, + 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x6e, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, + 0x63, 0x6f, 0x64, 0x65, 0x12, 0x38, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x6e, 0x54, + 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, + 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xa6, 0x01, 0x0a, 0x14, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x6e, 0x54, 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, + 0x61, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, + 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x34, 0x0a, 0x04, 0x64, + 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x6d, 0x61, 0x74, 0x63, + 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x53, 0x74, + 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x6e, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x04, 0x64, 0x61, 0x74, + 0x61, 0x12, 0x1e, 0x0a, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, + 0x74, 0x22, 0x9e, 0x06, 0x0a, 0x10, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, + 0x6e, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, + 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, + 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, + 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, + 0x54, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, + 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, + 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x65, 0x61, 0x6c, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x64, 0x65, 0x61, 0x6c, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6c, 0x6f, 0x73, + 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, + 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, + 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, + 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, + 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, + 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0c, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, + 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, + 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, + 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, 0x6f, 0x6e, + 0x65, 0x79, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x10, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1e, 0x0a, 0x0a, + 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x11, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1e, 0x0a, 0x0a, + 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x12, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, + 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x13, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, + 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, + 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, + 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, + 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x15, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, + 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x16, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x72, + 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x17, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, 0x79, 0x4e, + 0x75, 0x6d, 0x12, 0x20, 0x0a, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, 0x6d, 0x61, + 0x6c, 0x18, 0x18, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, + 0x69, 0x6d, 0x61, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x4e, 0x61, 0x6d, + 0x65, 0x18, 0x19, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x4e, 0x61, + 0x6d, 0x65, 0x22, 0x90, 0x03, 0x0a, 0x14, 0x53, 0x68, 0x61, 0x72, 0x65, 0x49, 0x64, 0x6e, 0x4f, + 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, + 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, + 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, + 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, + 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, + 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, + 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, + 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, + 0x6e, 0x65, 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, + 0x65, 0x72, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, + 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x43, 0x6f, 0x73, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, + 0x79, 0x70, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, + 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, 0x6f, 0x70, + 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x74, 0x6f, + 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x16, 0x0a, + 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, + 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x22, 0x97, 0x01, 0x0a, 0x15, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x49, 0x64, 0x6e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, + 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, + 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, + 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, + 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, + 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x22, + 0x71, 0x0a, 0x0d, 0x49, 0x64, 0x6e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, + 0x63, 0x6f, 0x64, 0x65, 0x12, 0x32, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x64, 0x6e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x73, 0x75, + 0x6c, 0x74, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x22, 0x2a, 0x0a, 0x0e, 0x49, 0x64, 0x6e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x73, 0x75, 0x6c, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x22, 0x14, + 0x0a, 0x12, 0x41, 0x6c, 0x6c, 0x49, 0x64, 0x6e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x22, 0x54, 0x0a, 0x10, 0x41, 0x6c, 0x6c, 0x49, 0x64, 0x6e, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x12, 0x0a, 0x04, + 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, + 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x31, 0x0a, 0x15, 0x43, 0x61, + 0x6e, 0x63, 0x65, 0x6c, 0x49, 0x64, 0x6e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x32, 0xca, 0x06, + 0x0a, 0x08, 0x53, 0x68, 0x61, 0x72, 0x65, 0x49, 0x64, 0x6e, 0x12, 0x92, 0x01, 0x0a, 0x13, 0x47, + 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x6e, 0x54, 0x72, 0x61, + 0x64, 0x65, 0x12, 0x2a, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x49, 0x64, 0x6e, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, + 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x28, + 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x6e, 0x54, 0x72, + 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x25, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1f, + 0x3a, 0x01, 0x2a, 0x22, 0x1a, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, + 0x65, 0x69, 0x64, 0x6e, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x12, + 0x87, 0x01, 0x0a, 0x12, 0x53, 0x68, 0x61, 0x72, 0x65, 0x49, 0x64, 0x6e, 0x50, 0x6c, 0x61, 0x63, + 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x24, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, + 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x49, 0x64, 0x6e, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, + 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x64, + 0x6e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2c, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x26, 0x3a, 0x01, 0x2a, 0x22, 0x21, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, + 0x68, 0x61, 0x72, 0x65, 0x69, 0x64, 0x6e, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x70, 0x6c, + 0x61, 0x63, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x8a, 0x01, 0x0a, 0x13, 0x53, 0x68, + 0x61, 0x72, 0x65, 0x49, 0x64, 0x6e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x12, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x49, 0x64, 0x6e, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x64, 0x6e, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x27, 0x3a, + 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, + 0x69, 0x64, 0x6e, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x83, 0x01, 0x0a, 0x10, 0x53, 0x68, 0x61, 0x72, 0x65, + 0x49, 0x64, 0x6e, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x25, 0x2e, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x61, 0x6e, + 0x63, 0x65, 0x6c, 0x49, 0x64, 0x6e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x64, 0x6e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x22, 0x29, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x23, 0x3a, 0x01, 0x2a, 0x22, 0x1e, 0x2f, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x69, 0x64, 0x6e, 0x2f, 0x73, 0x68, + 0x61, 0x72, 0x65, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x8a, 0x01, 0x0a, + 0x13, 0x53, 0x68, 0x61, 0x72, 0x65, 0x49, 0x64, 0x6e, 0x41, 0x6c, 0x6c, 0x50, 0x6f, 0x73, 0x69, + 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x22, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x49, 0x64, 0x6e, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x49, 0x64, 0x6e, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93, + 0x02, 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, + 0x61, 0x72, 0x65, 0x69, 0x64, 0x6e, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x61, 0x6c, 0x6c, + 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x7f, 0x0a, 0x0e, 0x53, 0x68, 0x61, + 0x72, 0x65, 0x49, 0x64, 0x6e, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x12, 0x25, 0x2e, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x61, 0x6e, + 0x63, 0x65, 0x6c, 0x49, 0x64, 0x6e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x64, 0x6e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x22, 0x27, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x21, 0x3a, 0x01, 0x2a, 0x22, 0x1c, 0x2f, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x69, 0x64, 0x6e, 0x2f, 0x73, 0x68, + 0x61, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x42, 0x2a, 0x5a, 0x28, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, + 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_share_shareIdn_proto_rawDescOnce sync.Once + file_matchmaking_v1_share_shareIdn_proto_rawDescData = file_matchmaking_v1_share_shareIdn_proto_rawDesc +) + +func file_matchmaking_v1_share_shareIdn_proto_rawDescGZIP() []byte { + file_matchmaking_v1_share_shareIdn_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_share_shareIdn_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_share_shareIdn_proto_rawDescData) + }) + return file_matchmaking_v1_share_shareIdn_proto_rawDescData +} + +var file_matchmaking_v1_share_shareIdn_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_matchmaking_v1_share_shareIdn_proto_goTypes = []any{ + (*GetIdnBotStockTradeRequest)(nil), // 0: matchmaking.v1.GetIdnBotStockTradeRequest + (*GetBotStockIdnTradeReply)(nil), // 1: matchmaking.v1.GetBotStockIdnTradeReply + (*BotStockIdnTradeData)(nil), // 2: matchmaking.v1.BotStockIdnTradeData + (*BotStockIdnTrade)(nil), // 3: matchmaking.v1.BotStockIdnTrade + (*ShareIdnOrderRequest)(nil), // 4: matchmaking.v1.ShareIdnOrderRequest + (*UpdateIdnOrderRequest)(nil), // 5: matchmaking.v1.UpdateIdnOrderRequest + (*IdnOrderReply)(nil), // 6: matchmaking.v1.IdnOrderReply + (*IdnOrderResult)(nil), // 7: matchmaking.v1.IdnOrderResult + (*AllIdnOrderRequest)(nil), // 8: matchmaking.v1.AllIdnOrderRequest + (*AllIdnOrderReply)(nil), // 9: matchmaking.v1.AllIdnOrderReply + (*CancelIdnOrderRequest)(nil), // 10: matchmaking.v1.CancelIdnOrderRequest +} +var file_matchmaking_v1_share_shareIdn_proto_depIdxs = []int32{ + 2, // 0: matchmaking.v1.GetBotStockIdnTradeReply.data:type_name -> matchmaking.v1.BotStockIdnTradeData + 3, // 1: matchmaking.v1.BotStockIdnTradeData.data:type_name -> matchmaking.v1.BotStockIdnTrade + 7, // 2: matchmaking.v1.IdnOrderReply.data:type_name -> matchmaking.v1.IdnOrderResult + 0, // 3: matchmaking.v1.ShareIdn.GetBotStockIdnTrade:input_type -> matchmaking.v1.GetIdnBotStockTradeRequest + 4, // 4: matchmaking.v1.ShareIdn.ShareIdnPlaceOrder:input_type -> matchmaking.v1.ShareIdnOrderRequest + 5, // 5: matchmaking.v1.ShareIdn.ShareIdnUpdateOrder:input_type -> matchmaking.v1.UpdateIdnOrderRequest + 10, // 6: matchmaking.v1.ShareIdn.ShareIdnPosition:input_type -> matchmaking.v1.CancelIdnOrderRequest + 8, // 7: matchmaking.v1.ShareIdn.ShareIdnAllPosition:input_type -> matchmaking.v1.AllIdnOrderRequest + 10, // 8: matchmaking.v1.ShareIdn.ShareIdnCancel:input_type -> matchmaking.v1.CancelIdnOrderRequest + 1, // 9: matchmaking.v1.ShareIdn.GetBotStockIdnTrade:output_type -> matchmaking.v1.GetBotStockIdnTradeReply + 6, // 10: matchmaking.v1.ShareIdn.ShareIdnPlaceOrder:output_type -> matchmaking.v1.IdnOrderReply + 6, // 11: matchmaking.v1.ShareIdn.ShareIdnUpdateOrder:output_type -> matchmaking.v1.IdnOrderReply + 6, // 12: matchmaking.v1.ShareIdn.ShareIdnPosition:output_type -> matchmaking.v1.IdnOrderReply + 9, // 13: matchmaking.v1.ShareIdn.ShareIdnAllPosition:output_type -> matchmaking.v1.AllIdnOrderReply + 6, // 14: matchmaking.v1.ShareIdn.ShareIdnCancel:output_type -> matchmaking.v1.IdnOrderReply + 9, // [9:15] is the sub-list for method output_type + 3, // [3:9] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_share_shareIdn_proto_init() } +func file_matchmaking_v1_share_shareIdn_proto_init() { + if File_matchmaking_v1_share_shareIdn_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_matchmaking_v1_share_shareIdn_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*GetIdnBotStockTradeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareIdn_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*GetBotStockIdnTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareIdn_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*BotStockIdnTradeData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareIdn_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*BotStockIdnTrade); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareIdn_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*ShareIdnOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareIdn_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*UpdateIdnOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareIdn_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*IdnOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareIdn_proto_msgTypes[7].Exporter = func(v any, i int) any { + switch v := v.(*IdnOrderResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareIdn_proto_msgTypes[8].Exporter = func(v any, i int) any { + switch v := v.(*AllIdnOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareIdn_proto_msgTypes[9].Exporter = func(v any, i int) any { + switch v := v.(*AllIdnOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareIdn_proto_msgTypes[10].Exporter = func(v any, i int) any { + switch v := v.(*CancelIdnOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_share_shareIdn_proto_rawDesc, + NumEnums: 0, + NumMessages: 11, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_matchmaking_v1_share_shareIdn_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_share_shareIdn_proto_depIdxs, + MessageInfos: file_matchmaking_v1_share_shareIdn_proto_msgTypes, + }.Build() + File_matchmaking_v1_share_shareIdn_proto = out.File + file_matchmaking_v1_share_shareIdn_proto_rawDesc = nil + file_matchmaking_v1_share_shareIdn_proto_goTypes = nil + file_matchmaking_v1_share_shareIdn_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/share/shareIdn.proto b/api/matchmaking/v1/share/shareIdn.proto new file mode 100644 index 0000000..8be3ca6 --- /dev/null +++ b/api/matchmaking/v1/share/shareIdn.proto @@ -0,0 +1,144 @@ +syntax = "proto3"; + +package matchmaking.v1; + +import "google/api/annotations.proto"; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +service ShareIdn { + // GetBotStockIdnTrade 印尼股列表查询 + rpc GetBotStockIdnTrade(GetIdnBotStockTradeRequest)returns(GetBotStockIdnTradeReply){ + option (google.api.http) = { + post:"/order_shareidn/share_list", + body:"*", + }; + } + // ShareIdnPlaceOrder 印尼股下单 + rpc ShareIdnPlaceOrder(ShareIdnOrderRequest)returns(IdnOrderReply) { + option (google.api.http) = { + post: "/order_shareidn/share_place_order", + body: "*", + }; + } + // ShareIdnUpdateOrder 印尼股设置止盈止损 + rpc ShareIdnUpdateOrder(UpdateIdnOrderRequest)returns(IdnOrderReply){ + option (google.api.http) = { + post:"/order_shareidn/share_update_order", + body:"*", + }; + } + // ShareIdnPosition 印尼股平仓 + rpc ShareIdnPosition(CancelIdnOrderRequest)returns(IdnOrderReply){ + option (google.api.http) = { + post:"/order_shareidn/share_position", + body:"*", + }; + } + // ShareIdnAllPosition 印尼股一键平仓 + rpc ShareIdnAllPosition(AllIdnOrderRequest)returns(AllIdnOrderReply){ + option (google.api.http) = { + post:"/order_shareidn/share_all_position", + body:"*", + }; + } + // ShareIdnCancel 印尼股撤单 + rpc ShareIdnCancel(CancelIdnOrderRequest)returns(IdnOrderReply){ + option (google.api.http) = { + post:"/order_shareidn/share_cancel", + body:"*", + }; + } +} + +message GetIdnBotStockTradeRequest{ + int64 status =1;// 状态码 + int64 pageSize =2; // 每页显示条数 + int64 pageCount =3;// 开始的位置 +} +message GetBotStockIdnTradeReply{ + int64 code =1;// 状态码 + BotStockIdnTradeData data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message BotStockIdnTradeData{ + int64 pageSize =1; // 每页显示条数 + int64 pageCount =2;// 开始的位置 + repeated BotStockIdnTrade data =3;// 返回结果 + int64 totalCount =4;// 总数据 +} + +message BotStockIdnTrade{ + string orderId =1;// 订单ID + string stockId =2;// 股票代码 + int64 tradeType =3;// 交易类型 + int64 dealType =4;// 交易方式 + string limitPrice =5;// 限价 + string marketPrice =6;// 市价 + string dealPrice =7;// 开仓价 + string closingPrice =8;// 平仓价 + string orderNumber =9;// 订单数量 + int64 stopType =10;// 止盈止损 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string serviceCost =13;// 开仓手续费 + string marketMoney =14;// 订单金额 + string orderMoney =15;// 订单总金额 + int64 status =16;// 订单状态 + string createTime =17;// 订单创建时间 + string updateTime =18;// 订单更新时间 + string openTime =19;// 订单开仓时间 + string closingTime =20;// 订单平仓时间 + string closingCost =21;// 平仓手续费 + string faceValue =22;// 面值 + string pryNum =23;// 杠杆 + string keepDecimal =24;// 保留小数位 + string stockName =25;// 股票名称 +} + +message ShareIdnOrderRequest{ + string stockId =1;// 股票Code + int64 tradeType =2;// 交易类型:1买入,2卖出 + int64 dealType =3;// 委托方式:1限价,2市价 + string limitPrice =4;// 限价 + string marketPrice =5;// 市价 + string marketMoney =6;// 订单金额 + string orderNumber =7;// 订单数量 + string serviceCost =8;// 手续费 + int64 stopType =9;// 止损止盈设置:1无设置,2止损止盈 + string stopLossPrice =10;// 止损 + string stopWinPrice =11;// 止损 + string pryNum =12;// 杠杆 +} + +message UpdateIdnOrderRequest{ + string orderId =1;// 订单Id + int64 stopType =2;// 止盈止损 + string stopLossPrice =3;// 止损 + string stopWinPrice =4;// 止盈 +} + +message IdnOrderReply{ + int64 code =1;// 状态码 + IdnOrderResult data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message IdnOrderResult { + string orderId =1;// 订单Id +} + +message AllIdnOrderRequest{ + +} + +message AllIdnOrderReply{ + int64 code =1;// 状态码 + string data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message CancelIdnOrderRequest{ + string orderId =1;// 订单ID +} \ No newline at end of file diff --git a/api/matchmaking/v1/share/shareIdn_grpc.pb.go b/api/matchmaking/v1/share/shareIdn_grpc.pb.go new file mode 100644 index 0000000..06aeb88 --- /dev/null +++ b/api/matchmaking/v1/share/shareIdn_grpc.pb.go @@ -0,0 +1,312 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareIdn.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + ShareIdn_GetBotStockIdnTrade_FullMethodName = "/matchmaking.v1.ShareIdn/GetBotStockIdnTrade" + ShareIdn_ShareIdnPlaceOrder_FullMethodName = "/matchmaking.v1.ShareIdn/ShareIdnPlaceOrder" + ShareIdn_ShareIdnUpdateOrder_FullMethodName = "/matchmaking.v1.ShareIdn/ShareIdnUpdateOrder" + ShareIdn_ShareIdnPosition_FullMethodName = "/matchmaking.v1.ShareIdn/ShareIdnPosition" + ShareIdn_ShareIdnAllPosition_FullMethodName = "/matchmaking.v1.ShareIdn/ShareIdnAllPosition" + ShareIdn_ShareIdnCancel_FullMethodName = "/matchmaking.v1.ShareIdn/ShareIdnCancel" +) + +// ShareIdnClient is the client API for ShareIdn service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ShareIdnClient interface { + // GetBotStockIdnTrade 印尼股列表查询 + GetBotStockIdnTrade(ctx context.Context, in *GetIdnBotStockTradeRequest, opts ...grpc.CallOption) (*GetBotStockIdnTradeReply, error) + // ShareIdnPlaceOrder 印尼股下单 + ShareIdnPlaceOrder(ctx context.Context, in *ShareIdnOrderRequest, opts ...grpc.CallOption) (*IdnOrderReply, error) + // ShareIdnUpdateOrder 印尼股设置止盈止损 + ShareIdnUpdateOrder(ctx context.Context, in *UpdateIdnOrderRequest, opts ...grpc.CallOption) (*IdnOrderReply, error) + // ShareIdnPosition 印尼股平仓 + ShareIdnPosition(ctx context.Context, in *CancelIdnOrderRequest, opts ...grpc.CallOption) (*IdnOrderReply, error) + // ShareIdnAllPosition 印尼股一键平仓 + ShareIdnAllPosition(ctx context.Context, in *AllIdnOrderRequest, opts ...grpc.CallOption) (*AllIdnOrderReply, error) + // ShareIdnCancel 印尼股撤单 + ShareIdnCancel(ctx context.Context, in *CancelIdnOrderRequest, opts ...grpc.CallOption) (*IdnOrderReply, error) +} + +type shareIdnClient struct { + cc grpc.ClientConnInterface +} + +func NewShareIdnClient(cc grpc.ClientConnInterface) ShareIdnClient { + return &shareIdnClient{cc} +} + +func (c *shareIdnClient) GetBotStockIdnTrade(ctx context.Context, in *GetIdnBotStockTradeRequest, opts ...grpc.CallOption) (*GetBotStockIdnTradeReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetBotStockIdnTradeReply) + err := c.cc.Invoke(ctx, ShareIdn_GetBotStockIdnTrade_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareIdnClient) ShareIdnPlaceOrder(ctx context.Context, in *ShareIdnOrderRequest, opts ...grpc.CallOption) (*IdnOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(IdnOrderReply) + err := c.cc.Invoke(ctx, ShareIdn_ShareIdnPlaceOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareIdnClient) ShareIdnUpdateOrder(ctx context.Context, in *UpdateIdnOrderRequest, opts ...grpc.CallOption) (*IdnOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(IdnOrderReply) + err := c.cc.Invoke(ctx, ShareIdn_ShareIdnUpdateOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareIdnClient) ShareIdnPosition(ctx context.Context, in *CancelIdnOrderRequest, opts ...grpc.CallOption) (*IdnOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(IdnOrderReply) + err := c.cc.Invoke(ctx, ShareIdn_ShareIdnPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareIdnClient) ShareIdnAllPosition(ctx context.Context, in *AllIdnOrderRequest, opts ...grpc.CallOption) (*AllIdnOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AllIdnOrderReply) + err := c.cc.Invoke(ctx, ShareIdn_ShareIdnAllPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareIdnClient) ShareIdnCancel(ctx context.Context, in *CancelIdnOrderRequest, opts ...grpc.CallOption) (*IdnOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(IdnOrderReply) + err := c.cc.Invoke(ctx, ShareIdn_ShareIdnCancel_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ShareIdnServer is the server API for ShareIdn service. +// All implementations must embed UnimplementedShareIdnServer +// for forward compatibility +type ShareIdnServer interface { + // GetBotStockIdnTrade 印尼股列表查询 + GetBotStockIdnTrade(context.Context, *GetIdnBotStockTradeRequest) (*GetBotStockIdnTradeReply, error) + // ShareIdnPlaceOrder 印尼股下单 + ShareIdnPlaceOrder(context.Context, *ShareIdnOrderRequest) (*IdnOrderReply, error) + // ShareIdnUpdateOrder 印尼股设置止盈止损 + ShareIdnUpdateOrder(context.Context, *UpdateIdnOrderRequest) (*IdnOrderReply, error) + // ShareIdnPosition 印尼股平仓 + ShareIdnPosition(context.Context, *CancelIdnOrderRequest) (*IdnOrderReply, error) + // ShareIdnAllPosition 印尼股一键平仓 + ShareIdnAllPosition(context.Context, *AllIdnOrderRequest) (*AllIdnOrderReply, error) + // ShareIdnCancel 印尼股撤单 + ShareIdnCancel(context.Context, *CancelIdnOrderRequest) (*IdnOrderReply, error) + mustEmbedUnimplementedShareIdnServer() +} + +// UnimplementedShareIdnServer must be embedded to have forward compatible implementations. +type UnimplementedShareIdnServer struct { +} + +func (UnimplementedShareIdnServer) GetBotStockIdnTrade(context.Context, *GetIdnBotStockTradeRequest) (*GetBotStockIdnTradeReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBotStockIdnTrade not implemented") +} +func (UnimplementedShareIdnServer) ShareIdnPlaceOrder(context.Context, *ShareIdnOrderRequest) (*IdnOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareIdnPlaceOrder not implemented") +} +func (UnimplementedShareIdnServer) ShareIdnUpdateOrder(context.Context, *UpdateIdnOrderRequest) (*IdnOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareIdnUpdateOrder not implemented") +} +func (UnimplementedShareIdnServer) ShareIdnPosition(context.Context, *CancelIdnOrderRequest) (*IdnOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareIdnPosition not implemented") +} +func (UnimplementedShareIdnServer) ShareIdnAllPosition(context.Context, *AllIdnOrderRequest) (*AllIdnOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareIdnAllPosition not implemented") +} +func (UnimplementedShareIdnServer) ShareIdnCancel(context.Context, *CancelIdnOrderRequest) (*IdnOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareIdnCancel not implemented") +} +func (UnimplementedShareIdnServer) mustEmbedUnimplementedShareIdnServer() {} + +// UnsafeShareIdnServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ShareIdnServer will +// result in compilation errors. +type UnsafeShareIdnServer interface { + mustEmbedUnimplementedShareIdnServer() +} + +func RegisterShareIdnServer(s grpc.ServiceRegistrar, srv ShareIdnServer) { + s.RegisterService(&ShareIdn_ServiceDesc, srv) +} + +func _ShareIdn_GetBotStockIdnTrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetIdnBotStockTradeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareIdnServer).GetBotStockIdnTrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareIdn_GetBotStockIdnTrade_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareIdnServer).GetBotStockIdnTrade(ctx, req.(*GetIdnBotStockTradeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareIdn_ShareIdnPlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ShareIdnOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareIdnServer).ShareIdnPlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareIdn_ShareIdnPlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareIdnServer).ShareIdnPlaceOrder(ctx, req.(*ShareIdnOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareIdn_ShareIdnUpdateOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateIdnOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareIdnServer).ShareIdnUpdateOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareIdn_ShareIdnUpdateOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareIdnServer).ShareIdnUpdateOrder(ctx, req.(*UpdateIdnOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareIdn_ShareIdnPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelIdnOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareIdnServer).ShareIdnPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareIdn_ShareIdnPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareIdnServer).ShareIdnPosition(ctx, req.(*CancelIdnOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareIdn_ShareIdnAllPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AllIdnOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareIdnServer).ShareIdnAllPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareIdn_ShareIdnAllPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareIdnServer).ShareIdnAllPosition(ctx, req.(*AllIdnOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareIdn_ShareIdnCancel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelIdnOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareIdnServer).ShareIdnCancel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareIdn_ShareIdnCancel_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareIdnServer).ShareIdnCancel(ctx, req.(*CancelIdnOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// ShareIdn_ServiceDesc is the grpc.ServiceDesc for ShareIdn service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ShareIdn_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "matchmaking.v1.ShareIdn", + HandlerType: (*ShareIdnServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetBotStockIdnTrade", + Handler: _ShareIdn_GetBotStockIdnTrade_Handler, + }, + { + MethodName: "ShareIdnPlaceOrder", + Handler: _ShareIdn_ShareIdnPlaceOrder_Handler, + }, + { + MethodName: "ShareIdnUpdateOrder", + Handler: _ShareIdn_ShareIdnUpdateOrder_Handler, + }, + { + MethodName: "ShareIdnPosition", + Handler: _ShareIdn_ShareIdnPosition_Handler, + }, + { + MethodName: "ShareIdnAllPosition", + Handler: _ShareIdn_ShareIdnAllPosition_Handler, + }, + { + MethodName: "ShareIdnCancel", + Handler: _ShareIdn_ShareIdnCancel_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "matchmaking/v1/share/shareIdn.proto", +} diff --git a/api/matchmaking/v1/share/shareIdn_http.pb.go b/api/matchmaking/v1/share/shareIdn_http.pb.go new file mode 100644 index 0000000..c3f98ed --- /dev/null +++ b/api/matchmaking/v1/share/shareIdn_http.pb.go @@ -0,0 +1,279 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.3 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareIdn.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationShareIdnGetBotStockIdnTrade = "/matchmaking.v1.ShareIdn/GetBotStockIdnTrade" +const OperationShareIdnShareIdnAllPosition = "/matchmaking.v1.ShareIdn/ShareIdnAllPosition" +const OperationShareIdnShareIdnCancel = "/matchmaking.v1.ShareIdn/ShareIdnCancel" +const OperationShareIdnShareIdnPlaceOrder = "/matchmaking.v1.ShareIdn/ShareIdnPlaceOrder" +const OperationShareIdnShareIdnPosition = "/matchmaking.v1.ShareIdn/ShareIdnPosition" +const OperationShareIdnShareIdnUpdateOrder = "/matchmaking.v1.ShareIdn/ShareIdnUpdateOrder" + +type ShareIdnHTTPServer interface { + // GetBotStockIdnTrade GetBotStockIdnTrade 印尼股列表查询 + GetBotStockIdnTrade(context.Context, *GetIdnBotStockTradeRequest) (*GetBotStockIdnTradeReply, error) + // ShareIdnAllPosition ShareIdnAllPosition 印尼股一键平仓 + ShareIdnAllPosition(context.Context, *AllIdnOrderRequest) (*AllIdnOrderReply, error) + // ShareIdnCancel ShareIdnCancel 印尼股撤单 + ShareIdnCancel(context.Context, *CancelIdnOrderRequest) (*IdnOrderReply, error) + // ShareIdnPlaceOrder ShareIdnPlaceOrder 印尼股下单 + ShareIdnPlaceOrder(context.Context, *ShareIdnOrderRequest) (*IdnOrderReply, error) + // ShareIdnPosition ShareIdnPosition 印尼股平仓 + ShareIdnPosition(context.Context, *CancelIdnOrderRequest) (*IdnOrderReply, error) + // ShareIdnUpdateOrder ShareIdnUpdateOrder 印尼股设置止盈止损 + ShareIdnUpdateOrder(context.Context, *UpdateIdnOrderRequest) (*IdnOrderReply, error) +} + +func RegisterShareIdnHTTPServer(s *http.Server, srv ShareIdnHTTPServer) { + r := s.Route("/") + r.POST("/order_shareidn/share_list", _ShareIdn_GetBotStockIdnTrade0_HTTP_Handler(srv)) + r.POST("/order_shareidn/share_place_order", _ShareIdn_ShareIdnPlaceOrder0_HTTP_Handler(srv)) + r.POST("/order_shareidn/share_update_order", _ShareIdn_ShareIdnUpdateOrder0_HTTP_Handler(srv)) + r.POST("/order_shareidn/share_position", _ShareIdn_ShareIdnPosition0_HTTP_Handler(srv)) + r.POST("/order_shareidn/share_all_position", _ShareIdn_ShareIdnAllPosition0_HTTP_Handler(srv)) + r.POST("/order_shareidn/share_cancel", _ShareIdn_ShareIdnCancel0_HTTP_Handler(srv)) +} + +func _ShareIdn_GetBotStockIdnTrade0_HTTP_Handler(srv ShareIdnHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetIdnBotStockTradeRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareIdnGetBotStockIdnTrade) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.GetBotStockIdnTrade(ctx, req.(*GetIdnBotStockTradeRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetBotStockIdnTradeReply) + return ctx.Result(200, reply) + } +} + +func _ShareIdn_ShareIdnPlaceOrder0_HTTP_Handler(srv ShareIdnHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in ShareIdnOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareIdnShareIdnPlaceOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareIdnPlaceOrder(ctx, req.(*ShareIdnOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*IdnOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareIdn_ShareIdnUpdateOrder0_HTTP_Handler(srv ShareIdnHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in UpdateIdnOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareIdnShareIdnUpdateOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareIdnUpdateOrder(ctx, req.(*UpdateIdnOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*IdnOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareIdn_ShareIdnPosition0_HTTP_Handler(srv ShareIdnHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelIdnOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareIdnShareIdnPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareIdnPosition(ctx, req.(*CancelIdnOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*IdnOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareIdn_ShareIdnAllPosition0_HTTP_Handler(srv ShareIdnHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in AllIdnOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareIdnShareIdnAllPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareIdnAllPosition(ctx, req.(*AllIdnOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*AllIdnOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareIdn_ShareIdnCancel0_HTTP_Handler(srv ShareIdnHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelIdnOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareIdnShareIdnCancel) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareIdnCancel(ctx, req.(*CancelIdnOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*IdnOrderReply) + return ctx.Result(200, reply) + } +} + +type ShareIdnHTTPClient interface { + GetBotStockIdnTrade(ctx context.Context, req *GetIdnBotStockTradeRequest, opts ...http.CallOption) (rsp *GetBotStockIdnTradeReply, err error) + ShareIdnAllPosition(ctx context.Context, req *AllIdnOrderRequest, opts ...http.CallOption) (rsp *AllIdnOrderReply, err error) + ShareIdnCancel(ctx context.Context, req *CancelIdnOrderRequest, opts ...http.CallOption) (rsp *IdnOrderReply, err error) + ShareIdnPlaceOrder(ctx context.Context, req *ShareIdnOrderRequest, opts ...http.CallOption) (rsp *IdnOrderReply, err error) + ShareIdnPosition(ctx context.Context, req *CancelIdnOrderRequest, opts ...http.CallOption) (rsp *IdnOrderReply, err error) + ShareIdnUpdateOrder(ctx context.Context, req *UpdateIdnOrderRequest, opts ...http.CallOption) (rsp *IdnOrderReply, err error) +} + +type ShareIdnHTTPClientImpl struct { + cc *http.Client +} + +func NewShareIdnHTTPClient(client *http.Client) ShareIdnHTTPClient { + return &ShareIdnHTTPClientImpl{client} +} + +func (c *ShareIdnHTTPClientImpl) GetBotStockIdnTrade(ctx context.Context, in *GetIdnBotStockTradeRequest, opts ...http.CallOption) (*GetBotStockIdnTradeReply, error) { + var out GetBotStockIdnTradeReply + pattern := "/order_shareidn/share_list" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareIdnGetBotStockIdnTrade)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareIdnHTTPClientImpl) ShareIdnAllPosition(ctx context.Context, in *AllIdnOrderRequest, opts ...http.CallOption) (*AllIdnOrderReply, error) { + var out AllIdnOrderReply + pattern := "/order_shareidn/share_all_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareIdnShareIdnAllPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareIdnHTTPClientImpl) ShareIdnCancel(ctx context.Context, in *CancelIdnOrderRequest, opts ...http.CallOption) (*IdnOrderReply, error) { + var out IdnOrderReply + pattern := "/order_shareidn/share_cancel" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareIdnShareIdnCancel)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareIdnHTTPClientImpl) ShareIdnPlaceOrder(ctx context.Context, in *ShareIdnOrderRequest, opts ...http.CallOption) (*IdnOrderReply, error) { + var out IdnOrderReply + pattern := "/order_shareidn/share_place_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareIdnShareIdnPlaceOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareIdnHTTPClientImpl) ShareIdnPosition(ctx context.Context, in *CancelIdnOrderRequest, opts ...http.CallOption) (*IdnOrderReply, error) { + var out IdnOrderReply + pattern := "/order_shareidn/share_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareIdnShareIdnPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareIdnHTTPClientImpl) ShareIdnUpdateOrder(ctx context.Context, in *UpdateIdnOrderRequest, opts ...http.CallOption) (*IdnOrderReply, error) { + var out IdnOrderReply + pattern := "/order_shareidn/share_update_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareIdnShareIdnUpdateOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/api/matchmaking/v1/share/shareInr.pb.go b/api/matchmaking/v1/share/shareInr.pb.go new file mode 100644 index 0000000..bd2098f --- /dev/null +++ b/api/matchmaking/v1/share/shareInr.pb.go @@ -0,0 +1,1327 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/share/shareInr.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type CancelInrOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID +} + +func (x *CancelInrOrderRequest) Reset() { + *x = CancelInrOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CancelInrOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CancelInrOrderRequest) ProtoMessage() {} + +func (x *CancelInrOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CancelInrOrderRequest.ProtoReflect.Descriptor instead. +func (*CancelInrOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareInr_proto_rawDescGZIP(), []int{0} +} + +func (x *CancelInrOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type UpdateInrOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id + StopType int64 `protobuf:"varint,2,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,3,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,4,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 +} + +func (x *UpdateInrOrderRequest) Reset() { + *x = UpdateInrOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateInrOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateInrOrderRequest) ProtoMessage() {} + +func (x *UpdateInrOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateInrOrderRequest.ProtoReflect.Descriptor instead. +func (*UpdateInrOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareInr_proto_rawDescGZIP(), []int{1} +} + +func (x *UpdateInrOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *UpdateInrOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *UpdateInrOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *UpdateInrOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +type ShareInrOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + StockId string `protobuf:"bytes,1,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票Code + TradeType int64 `protobuf:"varint,2,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型:1买入,2卖出 + DealType int64 `protobuf:"varint,3,opt,name=dealType,proto3" json:"dealType,omitempty"` // 委托方式:1限价,2市价 + LimitPrice string `protobuf:"bytes,4,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,5,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + MarketMoney string `protobuf:"bytes,6,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderNumber string `protobuf:"bytes,7,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + ServiceCost string `protobuf:"bytes,8,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 手续费 + StopType int64 `protobuf:"varint,9,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止损止盈设置:1无设置,2止损止盈 + StopLossPrice string `protobuf:"bytes,10,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,11,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止损 + PryNum string `protobuf:"bytes,12,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 +} + +func (x *ShareInrOrderRequest) Reset() { + *x = ShareInrOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ShareInrOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ShareInrOrderRequest) ProtoMessage() {} + +func (x *ShareInrOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ShareInrOrderRequest.ProtoReflect.Descriptor instead. +func (*ShareInrOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareInr_proto_rawDescGZIP(), []int{2} +} + +func (x *ShareInrOrderRequest) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *ShareInrOrderRequest) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *ShareInrOrderRequest) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *ShareInrOrderRequest) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *ShareInrOrderRequest) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *ShareInrOrderRequest) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *ShareInrOrderRequest) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *ShareInrOrderRequest) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *ShareInrOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *ShareInrOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *ShareInrOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *ShareInrOrderRequest) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +type GetInrBotStockTradeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status int64 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` // 状态码 + PageSize int64 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,3,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 +} + +func (x *GetInrBotStockTradeRequest) Reset() { + *x = GetInrBotStockTradeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetInrBotStockTradeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetInrBotStockTradeRequest) ProtoMessage() {} + +func (x *GetInrBotStockTradeRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetInrBotStockTradeRequest.ProtoReflect.Descriptor instead. +func (*GetInrBotStockTradeRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareInr_proto_rawDescGZIP(), []int{3} +} + +func (x *GetInrBotStockTradeRequest) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *GetInrBotStockTradeRequest) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *GetInrBotStockTradeRequest) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +type GetBotStockInrTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *BotStockInrTradeData `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *GetBotStockInrTradeReply) Reset() { + *x = GetBotStockInrTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotStockInrTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotStockInrTradeReply) ProtoMessage() {} + +func (x *GetBotStockInrTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotStockInrTradeReply.ProtoReflect.Descriptor instead. +func (*GetBotStockInrTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareInr_proto_rawDescGZIP(), []int{4} +} + +func (x *GetBotStockInrTradeReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *GetBotStockInrTradeReply) GetData() *BotStockInrTradeData { + if x != nil { + return x.Data + } + return nil +} + +func (x *GetBotStockInrTradeReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type BotStockInrTradeData struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PageSize int64 `protobuf:"varint,1,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,2,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + Data []*BotStockInrTrade `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty"` // 返回结果 + TotalCount int64 `protobuf:"varint,4,opt,name=totalCount,proto3" json:"totalCount,omitempty"` // 总数据 +} + +func (x *BotStockInrTradeData) Reset() { + *x = BotStockInrTradeData{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockInrTradeData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockInrTradeData) ProtoMessage() {} + +func (x *BotStockInrTradeData) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockInrTradeData.ProtoReflect.Descriptor instead. +func (*BotStockInrTradeData) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareInr_proto_rawDescGZIP(), []int{5} +} + +func (x *BotStockInrTradeData) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *BotStockInrTradeData) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *BotStockInrTradeData) GetData() []*BotStockInrTrade { + if x != nil { + return x.Data + } + return nil +} + +func (x *BotStockInrTradeData) GetTotalCount() int64 { + if x != nil { + return x.TotalCount + } + return 0 +} + +type BotStockInrTrade struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID + StockId string `protobuf:"bytes,2,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票代码 + TradeType int64 `protobuf:"varint,3,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型 + DealType int64 `protobuf:"varint,4,opt,name=dealType,proto3" json:"dealType,omitempty"` // 交易方式 + LimitPrice string `protobuf:"bytes,5,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,6,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + DealPrice string `protobuf:"bytes,7,opt,name=dealPrice,proto3" json:"dealPrice,omitempty"` // 开仓价 + ClosingPrice string `protobuf:"bytes,8,opt,name=closingPrice,proto3" json:"closingPrice,omitempty"` // 平仓价 + OrderNumber string `protobuf:"bytes,9,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + ServiceCost string `protobuf:"bytes,13,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 开仓手续费 + MarketMoney string `protobuf:"bytes,14,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderMoney string `protobuf:"bytes,15,opt,name=orderMoney,proto3" json:"orderMoney,omitempty"` // 订单总金额 + Status int64 `protobuf:"varint,16,opt,name=status,proto3" json:"status,omitempty"` // 订单状态 + CreateTime string `protobuf:"bytes,17,opt,name=createTime,proto3" json:"createTime,omitempty"` // 订单创建时间 + UpdateTime string `protobuf:"bytes,18,opt,name=updateTime,proto3" json:"updateTime,omitempty"` // 订单更新时间 + OpenTime string `protobuf:"bytes,19,opt,name=openTime,proto3" json:"openTime,omitempty"` // 订单开仓时间 + ClosingTime string `protobuf:"bytes,20,opt,name=closingTime,proto3" json:"closingTime,omitempty"` // 订单平仓时间 + ClosingCost string `protobuf:"bytes,21,opt,name=closingCost,proto3" json:"closingCost,omitempty"` // 平仓手续费 + FaceValue string `protobuf:"bytes,22,opt,name=faceValue,proto3" json:"faceValue,omitempty"` // 面值 + PryNum string `protobuf:"bytes,23,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 + KeepDecimal string `protobuf:"bytes,24,opt,name=keepDecimal,proto3" json:"keepDecimal,omitempty"` // 保留小数位 + StockName string `protobuf:"bytes,25,opt,name=stockName,proto3" json:"stockName,omitempty"` // 股票名称 +} + +func (x *BotStockInrTrade) Reset() { + *x = BotStockInrTrade{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockInrTrade) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockInrTrade) ProtoMessage() {} + +func (x *BotStockInrTrade) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockInrTrade.ProtoReflect.Descriptor instead. +func (*BotStockInrTrade) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareInr_proto_rawDescGZIP(), []int{6} +} + +func (x *BotStockInrTrade) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *BotStockInrTrade) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *BotStockInrTrade) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *BotStockInrTrade) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *BotStockInrTrade) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *BotStockInrTrade) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *BotStockInrTrade) GetDealPrice() string { + if x != nil { + return x.DealPrice + } + return "" +} + +func (x *BotStockInrTrade) GetClosingPrice() string { + if x != nil { + return x.ClosingPrice + } + return "" +} + +func (x *BotStockInrTrade) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *BotStockInrTrade) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *BotStockInrTrade) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *BotStockInrTrade) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *BotStockInrTrade) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *BotStockInrTrade) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *BotStockInrTrade) GetOrderMoney() string { + if x != nil { + return x.OrderMoney + } + return "" +} + +func (x *BotStockInrTrade) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *BotStockInrTrade) GetCreateTime() string { + if x != nil { + return x.CreateTime + } + return "" +} + +func (x *BotStockInrTrade) GetUpdateTime() string { + if x != nil { + return x.UpdateTime + } + return "" +} + +func (x *BotStockInrTrade) GetOpenTime() string { + if x != nil { + return x.OpenTime + } + return "" +} + +func (x *BotStockInrTrade) GetClosingTime() string { + if x != nil { + return x.ClosingTime + } + return "" +} + +func (x *BotStockInrTrade) GetClosingCost() string { + if x != nil { + return x.ClosingCost + } + return "" +} + +func (x *BotStockInrTrade) GetFaceValue() string { + if x != nil { + return x.FaceValue + } + return "" +} + +func (x *BotStockInrTrade) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *BotStockInrTrade) GetKeepDecimal() string { + if x != nil { + return x.KeepDecimal + } + return "" +} + +func (x *BotStockInrTrade) GetStockName() string { + if x != nil { + return x.StockName + } + return "" +} + +type InrOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *InrOrderResult `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *InrOrderReply) Reset() { + *x = InrOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *InrOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*InrOrderReply) ProtoMessage() {} + +func (x *InrOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use InrOrderReply.ProtoReflect.Descriptor instead. +func (*InrOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareInr_proto_rawDescGZIP(), []int{7} +} + +func (x *InrOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *InrOrderReply) GetData() *InrOrderResult { + if x != nil { + return x.Data + } + return nil +} + +func (x *InrOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type InrOrderResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id +} + +func (x *InrOrderResult) Reset() { + *x = InrOrderResult{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *InrOrderResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*InrOrderResult) ProtoMessage() {} + +func (x *InrOrderResult) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use InrOrderResult.ProtoReflect.Descriptor instead. +func (*InrOrderResult) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareInr_proto_rawDescGZIP(), []int{8} +} + +func (x *InrOrderResult) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type AllInrOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *AllInrOrderRequest) Reset() { + *x = AllInrOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllInrOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllInrOrderRequest) ProtoMessage() {} + +func (x *AllInrOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllInrOrderRequest.ProtoReflect.Descriptor instead. +func (*AllInrOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareInr_proto_rawDescGZIP(), []int{9} +} + +type AllInrOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *AllInrOrderReply) Reset() { + *x = AllInrOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllInrOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllInrOrderReply) ProtoMessage() {} + +func (x *AllInrOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareInr_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllInrOrderReply.ProtoReflect.Descriptor instead. +func (*AllInrOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareInr_proto_rawDescGZIP(), []int{10} +} + +func (x *AllInrOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *AllInrOrderReply) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +func (x *AllInrOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_matchmaking_v1_share_shareInr_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_share_shareInr_proto_rawDesc = []byte{ + 0x0a, 0x23, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x49, 0x6e, 0x72, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0x31, 0x0a, 0x15, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x49, 0x6e, 0x72, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, + 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x22, 0x97, 0x01, 0x0a, 0x15, 0x55, 0x70, 0x64, 0x61, 0x74, + 0x65, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, + 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, + 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, + 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, + 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, + 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x22, 0x90, 0x03, 0x0a, 0x14, 0x53, 0x68, 0x61, 0x72, 0x65, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, + 0x63, 0x6b, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x63, + 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, + 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, + 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, + 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, + 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x06, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, + 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, + 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, + 0x62, 0x65, 0x72, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, + 0x73, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, + 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, + 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, + 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, + 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, + 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x70, + 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, 0x79, + 0x4e, 0x75, 0x6d, 0x22, 0x6e, 0x0a, 0x1a, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x72, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, + 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x22, 0x82, 0x01, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, + 0x6f, 0x63, 0x6b, 0x49, 0x6e, 0x72, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, + 0x63, 0x6f, 0x64, 0x65, 0x12, 0x38, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x6e, 0x72, 0x54, + 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, + 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xa6, 0x01, 0x0a, 0x14, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x6e, 0x72, 0x54, 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, + 0x61, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, + 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x34, 0x0a, 0x04, 0x64, + 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x6d, 0x61, 0x74, 0x63, + 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x53, 0x74, + 0x6f, 0x63, 0x6b, 0x49, 0x6e, 0x72, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x04, 0x64, 0x61, 0x74, + 0x61, 0x12, 0x1e, 0x0a, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, + 0x74, 0x22, 0x9e, 0x06, 0x0a, 0x10, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x6e, + 0x72, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, + 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, + 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, + 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, + 0x54, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, + 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, + 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x65, 0x61, 0x6c, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x64, 0x65, 0x61, 0x6c, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6c, 0x6f, 0x73, + 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, + 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, + 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, + 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, + 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, + 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0c, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, + 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, + 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, + 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, 0x6f, 0x6e, + 0x65, 0x79, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x10, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1e, 0x0a, 0x0a, + 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x11, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1e, 0x0a, 0x0a, + 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x12, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, + 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x13, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, + 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, + 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, + 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, + 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x15, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, + 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x16, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x72, + 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x17, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, 0x79, 0x4e, + 0x75, 0x6d, 0x12, 0x20, 0x0a, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, 0x6d, 0x61, + 0x6c, 0x18, 0x18, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, + 0x69, 0x6d, 0x61, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x4e, 0x61, 0x6d, + 0x65, 0x18, 0x19, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x4e, 0x61, + 0x6d, 0x65, 0x22, 0x71, 0x0a, 0x0d, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x32, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, + 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, + 0x65, 0x73, 0x75, 0x6c, 0x74, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x2a, 0x0a, 0x0e, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, + 0x64, 0x22, 0x14, 0x0a, 0x12, 0x41, 0x6c, 0x6c, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x54, 0x0a, 0x10, 0x41, 0x6c, 0x6c, 0x49, 0x6e, + 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, + 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, + 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, + 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0xca, 0x06, + 0x0a, 0x08, 0x53, 0x68, 0x61, 0x72, 0x65, 0x49, 0x6e, 0x72, 0x12, 0x92, 0x01, 0x0a, 0x13, 0x47, + 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x6e, 0x72, 0x54, 0x72, 0x61, + 0x64, 0x65, 0x12, 0x2a, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x72, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, + 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x28, + 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x6e, 0x72, 0x54, 0x72, + 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x25, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1f, + 0x3a, 0x01, 0x2a, 0x22, 0x1a, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, + 0x65, 0x69, 0x6e, 0x72, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x12, + 0x87, 0x01, 0x0a, 0x12, 0x53, 0x68, 0x61, 0x72, 0x65, 0x49, 0x6e, 0x72, 0x50, 0x6c, 0x61, 0x63, + 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x24, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, + 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x49, 0x6e, 0x72, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, + 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, + 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2c, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x26, 0x3a, 0x01, 0x2a, 0x22, 0x21, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, + 0x68, 0x61, 0x72, 0x65, 0x69, 0x6e, 0x72, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x70, 0x6c, + 0x61, 0x63, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x8a, 0x01, 0x0a, 0x13, 0x53, 0x68, + 0x61, 0x72, 0x65, 0x49, 0x6e, 0x72, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x12, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x27, 0x3a, + 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, + 0x69, 0x6e, 0x72, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x83, 0x01, 0x0a, 0x10, 0x53, 0x68, 0x61, 0x72, 0x65, + 0x49, 0x6e, 0x72, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x25, 0x2e, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x61, 0x6e, + 0x63, 0x65, 0x6c, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x22, 0x29, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x23, 0x3a, 0x01, 0x2a, 0x22, 0x1e, 0x2f, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x69, 0x6e, 0x72, 0x2f, 0x73, 0x68, + 0x61, 0x72, 0x65, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x8a, 0x01, 0x0a, + 0x13, 0x53, 0x68, 0x61, 0x72, 0x65, 0x49, 0x6e, 0x72, 0x41, 0x6c, 0x6c, 0x50, 0x6f, 0x73, 0x69, + 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x22, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x49, 0x6e, 0x72, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93, + 0x02, 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, + 0x61, 0x72, 0x65, 0x69, 0x6e, 0x72, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x61, 0x6c, 0x6c, + 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x7f, 0x0a, 0x0e, 0x53, 0x68, 0x61, + 0x72, 0x65, 0x49, 0x6e, 0x72, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x12, 0x25, 0x2e, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x61, 0x6e, + 0x63, 0x65, 0x6c, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x72, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x22, 0x27, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x21, 0x3a, 0x01, 0x2a, 0x22, 0x1c, 0x2f, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x69, 0x6e, 0x72, 0x2f, 0x73, 0x68, + 0x61, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x42, 0x2a, 0x5a, 0x28, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, + 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_share_shareInr_proto_rawDescOnce sync.Once + file_matchmaking_v1_share_shareInr_proto_rawDescData = file_matchmaking_v1_share_shareInr_proto_rawDesc +) + +func file_matchmaking_v1_share_shareInr_proto_rawDescGZIP() []byte { + file_matchmaking_v1_share_shareInr_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_share_shareInr_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_share_shareInr_proto_rawDescData) + }) + return file_matchmaking_v1_share_shareInr_proto_rawDescData +} + +var file_matchmaking_v1_share_shareInr_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_matchmaking_v1_share_shareInr_proto_goTypes = []any{ + (*CancelInrOrderRequest)(nil), // 0: matchmaking.v1.CancelInrOrderRequest + (*UpdateInrOrderRequest)(nil), // 1: matchmaking.v1.UpdateInrOrderRequest + (*ShareInrOrderRequest)(nil), // 2: matchmaking.v1.ShareInrOrderRequest + (*GetInrBotStockTradeRequest)(nil), // 3: matchmaking.v1.GetInrBotStockTradeRequest + (*GetBotStockInrTradeReply)(nil), // 4: matchmaking.v1.GetBotStockInrTradeReply + (*BotStockInrTradeData)(nil), // 5: matchmaking.v1.BotStockInrTradeData + (*BotStockInrTrade)(nil), // 6: matchmaking.v1.BotStockInrTrade + (*InrOrderReply)(nil), // 7: matchmaking.v1.InrOrderReply + (*InrOrderResult)(nil), // 8: matchmaking.v1.InrOrderResult + (*AllInrOrderRequest)(nil), // 9: matchmaking.v1.AllInrOrderRequest + (*AllInrOrderReply)(nil), // 10: matchmaking.v1.AllInrOrderReply +} +var file_matchmaking_v1_share_shareInr_proto_depIdxs = []int32{ + 5, // 0: matchmaking.v1.GetBotStockInrTradeReply.data:type_name -> matchmaking.v1.BotStockInrTradeData + 6, // 1: matchmaking.v1.BotStockInrTradeData.data:type_name -> matchmaking.v1.BotStockInrTrade + 8, // 2: matchmaking.v1.InrOrderReply.data:type_name -> matchmaking.v1.InrOrderResult + 3, // 3: matchmaking.v1.ShareInr.GetBotStockInrTrade:input_type -> matchmaking.v1.GetInrBotStockTradeRequest + 2, // 4: matchmaking.v1.ShareInr.ShareInrPlaceOrder:input_type -> matchmaking.v1.ShareInrOrderRequest + 1, // 5: matchmaking.v1.ShareInr.ShareInrUpdateOrder:input_type -> matchmaking.v1.UpdateInrOrderRequest + 0, // 6: matchmaking.v1.ShareInr.ShareInrPosition:input_type -> matchmaking.v1.CancelInrOrderRequest + 9, // 7: matchmaking.v1.ShareInr.ShareInrAllPosition:input_type -> matchmaking.v1.AllInrOrderRequest + 0, // 8: matchmaking.v1.ShareInr.ShareInrCancel:input_type -> matchmaking.v1.CancelInrOrderRequest + 4, // 9: matchmaking.v1.ShareInr.GetBotStockInrTrade:output_type -> matchmaking.v1.GetBotStockInrTradeReply + 7, // 10: matchmaking.v1.ShareInr.ShareInrPlaceOrder:output_type -> matchmaking.v1.InrOrderReply + 7, // 11: matchmaking.v1.ShareInr.ShareInrUpdateOrder:output_type -> matchmaking.v1.InrOrderReply + 7, // 12: matchmaking.v1.ShareInr.ShareInrPosition:output_type -> matchmaking.v1.InrOrderReply + 10, // 13: matchmaking.v1.ShareInr.ShareInrAllPosition:output_type -> matchmaking.v1.AllInrOrderReply + 7, // 14: matchmaking.v1.ShareInr.ShareInrCancel:output_type -> matchmaking.v1.InrOrderReply + 9, // [9:15] is the sub-list for method output_type + 3, // [3:9] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_share_shareInr_proto_init() } +func file_matchmaking_v1_share_shareInr_proto_init() { + if File_matchmaking_v1_share_shareInr_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_matchmaking_v1_share_shareInr_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*CancelInrOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareInr_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*UpdateInrOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareInr_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*ShareInrOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareInr_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*GetInrBotStockTradeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareInr_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*GetBotStockInrTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareInr_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*BotStockInrTradeData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareInr_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*BotStockInrTrade); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareInr_proto_msgTypes[7].Exporter = func(v any, i int) any { + switch v := v.(*InrOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareInr_proto_msgTypes[8].Exporter = func(v any, i int) any { + switch v := v.(*InrOrderResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareInr_proto_msgTypes[9].Exporter = func(v any, i int) any { + switch v := v.(*AllInrOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareInr_proto_msgTypes[10].Exporter = func(v any, i int) any { + switch v := v.(*AllInrOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_share_shareInr_proto_rawDesc, + NumEnums: 0, + NumMessages: 11, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_matchmaking_v1_share_shareInr_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_share_shareInr_proto_depIdxs, + MessageInfos: file_matchmaking_v1_share_shareInr_proto_msgTypes, + }.Build() + File_matchmaking_v1_share_shareInr_proto = out.File + file_matchmaking_v1_share_shareInr_proto_rawDesc = nil + file_matchmaking_v1_share_shareInr_proto_goTypes = nil + file_matchmaking_v1_share_shareInr_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/share/shareInr.proto b/api/matchmaking/v1/share/shareInr.proto new file mode 100644 index 0000000..3a2772d --- /dev/null +++ b/api/matchmaking/v1/share/shareInr.proto @@ -0,0 +1,145 @@ +syntax = "proto3"; + +package matchmaking.v1; + +import "google/api/annotations.proto"; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +service ShareInr { + // GetBotStockInrTrade 印度股列表查询 + rpc GetBotStockInrTrade(GetInrBotStockTradeRequest)returns(GetBotStockInrTradeReply){ + option (google.api.http) = { + post:"/order_shareinr/share_list", + body:"*", + }; + } + // ShareInrPlaceOrder 印度股下单 + rpc ShareInrPlaceOrder(ShareInrOrderRequest)returns(InrOrderReply) { + option (google.api.http) = { + post: "/order_shareinr/share_place_order", + body: "*", + }; + } + // ShareInrUpdateOrder 印度股设置止盈止损 + rpc ShareInrUpdateOrder(UpdateInrOrderRequest)returns(InrOrderReply){ + option (google.api.http) = { + post:"/order_shareinr/share_update_order", + body:"*", + }; + } + // ShareInrPosition 印度股平仓 + rpc ShareInrPosition(CancelInrOrderRequest)returns(InrOrderReply){ + option (google.api.http) = { + post:"/order_shareinr/share_position", + body:"*", + }; + } + // ShareInrAllPosition 印度股一键平仓 + rpc ShareInrAllPosition(AllInrOrderRequest)returns(AllInrOrderReply){ + option (google.api.http) = { + post:"/order_shareinr/share_all_position", + body:"*", + }; + } + // ShareInrCancel 印度股撤单 + rpc ShareInrCancel(CancelInrOrderRequest)returns(InrOrderReply){ + option (google.api.http) = { + post:"/order_shareinr/share_cancel", + body:"*", + }; + } +} + +message CancelInrOrderRequest{ + string orderId =1;// 订单ID +} + +message UpdateInrOrderRequest{ + string orderId =1;// 订单Id + int64 stopType =2;// 止盈止损 + string stopLossPrice =3;// 止损 + string stopWinPrice =4;// 止盈 +} + +message ShareInrOrderRequest{ + string stockId =1;// 股票Code + int64 tradeType =2;// 交易类型:1买入,2卖出 + int64 dealType =3;// 委托方式:1限价,2市价 + string limitPrice =4;// 限价 + string marketPrice =5;// 市价 + string marketMoney =6;// 订单金额 + string orderNumber =7;// 订单数量 + string serviceCost =8;// 手续费 + int64 stopType =9;// 止损止盈设置:1无设置,2止损止盈 + string stopLossPrice =10;// 止损 + string stopWinPrice =11;// 止损 + string pryNum =12;// 杠杆 +} + +message GetInrBotStockTradeRequest{ + int64 status =1;// 状态码 + int64 pageSize =2; // 每页显示条数 + int64 pageCount =3;// 开始的位置 +} + +message GetBotStockInrTradeReply{ + int64 code =1;// 状态码 + BotStockInrTradeData data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message BotStockInrTradeData{ + int64 pageSize =1; // 每页显示条数 + int64 pageCount =2;// 开始的位置 + repeated BotStockInrTrade data =3;// 返回结果 + int64 totalCount =4;// 总数据 +} + +message BotStockInrTrade{ + string orderId =1;// 订单ID + string stockId =2;// 股票代码 + int64 tradeType =3;// 交易类型 + int64 dealType =4;// 交易方式 + string limitPrice =5;// 限价 + string marketPrice =6;// 市价 + string dealPrice =7;// 开仓价 + string closingPrice =8;// 平仓价 + string orderNumber =9;// 订单数量 + int64 stopType =10;// 止盈止损 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string serviceCost =13;// 开仓手续费 + string marketMoney =14;// 订单金额 + string orderMoney =15;// 订单总金额 + int64 status =16;// 订单状态 + string createTime =17;// 订单创建时间 + string updateTime =18;// 订单更新时间 + string openTime =19;// 订单开仓时间 + string closingTime =20;// 订单平仓时间 + string closingCost =21;// 平仓手续费 + string faceValue =22;// 面值 + string pryNum =23;// 杠杆 + string keepDecimal =24;// 保留小数位 + string stockName =25;// 股票名称 +} + +message InrOrderReply{ + int64 code =1;// 状态码 + InrOrderResult data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message InrOrderResult { + string orderId =1;// 订单Id +} + +message AllInrOrderRequest{ + +} + +message AllInrOrderReply{ + int64 code =1;// 状态码 + string data =2;// 返回结果 + string message =3;// 返回消息提示 +} \ No newline at end of file diff --git a/api/matchmaking/v1/share/shareInr_grpc.pb.go b/api/matchmaking/v1/share/shareInr_grpc.pb.go new file mode 100644 index 0000000..b723aba --- /dev/null +++ b/api/matchmaking/v1/share/shareInr_grpc.pb.go @@ -0,0 +1,312 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareInr.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + ShareInr_GetBotStockInrTrade_FullMethodName = "/matchmaking.v1.ShareInr/GetBotStockInrTrade" + ShareInr_ShareInrPlaceOrder_FullMethodName = "/matchmaking.v1.ShareInr/ShareInrPlaceOrder" + ShareInr_ShareInrUpdateOrder_FullMethodName = "/matchmaking.v1.ShareInr/ShareInrUpdateOrder" + ShareInr_ShareInrPosition_FullMethodName = "/matchmaking.v1.ShareInr/ShareInrPosition" + ShareInr_ShareInrAllPosition_FullMethodName = "/matchmaking.v1.ShareInr/ShareInrAllPosition" + ShareInr_ShareInrCancel_FullMethodName = "/matchmaking.v1.ShareInr/ShareInrCancel" +) + +// ShareInrClient is the client API for ShareInr service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ShareInrClient interface { + // GetBotStockInrTrade 印度股列表查询 + GetBotStockInrTrade(ctx context.Context, in *GetInrBotStockTradeRequest, opts ...grpc.CallOption) (*GetBotStockInrTradeReply, error) + // ShareInrPlaceOrder 印度股下单 + ShareInrPlaceOrder(ctx context.Context, in *ShareInrOrderRequest, opts ...grpc.CallOption) (*InrOrderReply, error) + // ShareInrUpdateOrder 印度股设置止盈止损 + ShareInrUpdateOrder(ctx context.Context, in *UpdateInrOrderRequest, opts ...grpc.CallOption) (*InrOrderReply, error) + // ShareInrPosition 印度股平仓 + ShareInrPosition(ctx context.Context, in *CancelInrOrderRequest, opts ...grpc.CallOption) (*InrOrderReply, error) + // ShareInrAllPosition 印度股一键平仓 + ShareInrAllPosition(ctx context.Context, in *AllInrOrderRequest, opts ...grpc.CallOption) (*AllInrOrderReply, error) + // ShareInrCancel 印度股撤单 + ShareInrCancel(ctx context.Context, in *CancelInrOrderRequest, opts ...grpc.CallOption) (*InrOrderReply, error) +} + +type shareInrClient struct { + cc grpc.ClientConnInterface +} + +func NewShareInrClient(cc grpc.ClientConnInterface) ShareInrClient { + return &shareInrClient{cc} +} + +func (c *shareInrClient) GetBotStockInrTrade(ctx context.Context, in *GetInrBotStockTradeRequest, opts ...grpc.CallOption) (*GetBotStockInrTradeReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetBotStockInrTradeReply) + err := c.cc.Invoke(ctx, ShareInr_GetBotStockInrTrade_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareInrClient) ShareInrPlaceOrder(ctx context.Context, in *ShareInrOrderRequest, opts ...grpc.CallOption) (*InrOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(InrOrderReply) + err := c.cc.Invoke(ctx, ShareInr_ShareInrPlaceOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareInrClient) ShareInrUpdateOrder(ctx context.Context, in *UpdateInrOrderRequest, opts ...grpc.CallOption) (*InrOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(InrOrderReply) + err := c.cc.Invoke(ctx, ShareInr_ShareInrUpdateOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareInrClient) ShareInrPosition(ctx context.Context, in *CancelInrOrderRequest, opts ...grpc.CallOption) (*InrOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(InrOrderReply) + err := c.cc.Invoke(ctx, ShareInr_ShareInrPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareInrClient) ShareInrAllPosition(ctx context.Context, in *AllInrOrderRequest, opts ...grpc.CallOption) (*AllInrOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AllInrOrderReply) + err := c.cc.Invoke(ctx, ShareInr_ShareInrAllPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareInrClient) ShareInrCancel(ctx context.Context, in *CancelInrOrderRequest, opts ...grpc.CallOption) (*InrOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(InrOrderReply) + err := c.cc.Invoke(ctx, ShareInr_ShareInrCancel_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ShareInrServer is the server API for ShareInr service. +// All implementations must embed UnimplementedShareInrServer +// for forward compatibility +type ShareInrServer interface { + // GetBotStockInrTrade 印度股列表查询 + GetBotStockInrTrade(context.Context, *GetInrBotStockTradeRequest) (*GetBotStockInrTradeReply, error) + // ShareInrPlaceOrder 印度股下单 + ShareInrPlaceOrder(context.Context, *ShareInrOrderRequest) (*InrOrderReply, error) + // ShareInrUpdateOrder 印度股设置止盈止损 + ShareInrUpdateOrder(context.Context, *UpdateInrOrderRequest) (*InrOrderReply, error) + // ShareInrPosition 印度股平仓 + ShareInrPosition(context.Context, *CancelInrOrderRequest) (*InrOrderReply, error) + // ShareInrAllPosition 印度股一键平仓 + ShareInrAllPosition(context.Context, *AllInrOrderRequest) (*AllInrOrderReply, error) + // ShareInrCancel 印度股撤单 + ShareInrCancel(context.Context, *CancelInrOrderRequest) (*InrOrderReply, error) + mustEmbedUnimplementedShareInrServer() +} + +// UnimplementedShareInrServer must be embedded to have forward compatible implementations. +type UnimplementedShareInrServer struct { +} + +func (UnimplementedShareInrServer) GetBotStockInrTrade(context.Context, *GetInrBotStockTradeRequest) (*GetBotStockInrTradeReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBotStockInrTrade not implemented") +} +func (UnimplementedShareInrServer) ShareInrPlaceOrder(context.Context, *ShareInrOrderRequest) (*InrOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareInrPlaceOrder not implemented") +} +func (UnimplementedShareInrServer) ShareInrUpdateOrder(context.Context, *UpdateInrOrderRequest) (*InrOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareInrUpdateOrder not implemented") +} +func (UnimplementedShareInrServer) ShareInrPosition(context.Context, *CancelInrOrderRequest) (*InrOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareInrPosition not implemented") +} +func (UnimplementedShareInrServer) ShareInrAllPosition(context.Context, *AllInrOrderRequest) (*AllInrOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareInrAllPosition not implemented") +} +func (UnimplementedShareInrServer) ShareInrCancel(context.Context, *CancelInrOrderRequest) (*InrOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareInrCancel not implemented") +} +func (UnimplementedShareInrServer) mustEmbedUnimplementedShareInrServer() {} + +// UnsafeShareInrServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ShareInrServer will +// result in compilation errors. +type UnsafeShareInrServer interface { + mustEmbedUnimplementedShareInrServer() +} + +func RegisterShareInrServer(s grpc.ServiceRegistrar, srv ShareInrServer) { + s.RegisterService(&ShareInr_ServiceDesc, srv) +} + +func _ShareInr_GetBotStockInrTrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetInrBotStockTradeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareInrServer).GetBotStockInrTrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareInr_GetBotStockInrTrade_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareInrServer).GetBotStockInrTrade(ctx, req.(*GetInrBotStockTradeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareInr_ShareInrPlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ShareInrOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareInrServer).ShareInrPlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareInr_ShareInrPlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareInrServer).ShareInrPlaceOrder(ctx, req.(*ShareInrOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareInr_ShareInrUpdateOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateInrOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareInrServer).ShareInrUpdateOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareInr_ShareInrUpdateOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareInrServer).ShareInrUpdateOrder(ctx, req.(*UpdateInrOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareInr_ShareInrPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelInrOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareInrServer).ShareInrPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareInr_ShareInrPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareInrServer).ShareInrPosition(ctx, req.(*CancelInrOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareInr_ShareInrAllPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AllInrOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareInrServer).ShareInrAllPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareInr_ShareInrAllPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareInrServer).ShareInrAllPosition(ctx, req.(*AllInrOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareInr_ShareInrCancel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelInrOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareInrServer).ShareInrCancel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareInr_ShareInrCancel_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareInrServer).ShareInrCancel(ctx, req.(*CancelInrOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// ShareInr_ServiceDesc is the grpc.ServiceDesc for ShareInr service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ShareInr_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "matchmaking.v1.ShareInr", + HandlerType: (*ShareInrServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetBotStockInrTrade", + Handler: _ShareInr_GetBotStockInrTrade_Handler, + }, + { + MethodName: "ShareInrPlaceOrder", + Handler: _ShareInr_ShareInrPlaceOrder_Handler, + }, + { + MethodName: "ShareInrUpdateOrder", + Handler: _ShareInr_ShareInrUpdateOrder_Handler, + }, + { + MethodName: "ShareInrPosition", + Handler: _ShareInr_ShareInrPosition_Handler, + }, + { + MethodName: "ShareInrAllPosition", + Handler: _ShareInr_ShareInrAllPosition_Handler, + }, + { + MethodName: "ShareInrCancel", + Handler: _ShareInr_ShareInrCancel_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "matchmaking/v1/share/shareInr.proto", +} diff --git a/api/matchmaking/v1/share/shareInr_http.pb.go b/api/matchmaking/v1/share/shareInr_http.pb.go new file mode 100644 index 0000000..41d20e1 --- /dev/null +++ b/api/matchmaking/v1/share/shareInr_http.pb.go @@ -0,0 +1,279 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.3 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareInr.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationShareInrGetBotStockInrTrade = "/matchmaking.v1.ShareInr/GetBotStockInrTrade" +const OperationShareInrShareInrAllPosition = "/matchmaking.v1.ShareInr/ShareInrAllPosition" +const OperationShareInrShareInrCancel = "/matchmaking.v1.ShareInr/ShareInrCancel" +const OperationShareInrShareInrPlaceOrder = "/matchmaking.v1.ShareInr/ShareInrPlaceOrder" +const OperationShareInrShareInrPosition = "/matchmaking.v1.ShareInr/ShareInrPosition" +const OperationShareInrShareInrUpdateOrder = "/matchmaking.v1.ShareInr/ShareInrUpdateOrder" + +type ShareInrHTTPServer interface { + // GetBotStockInrTrade GetBotStockInrTrade 印度股列表查询 + GetBotStockInrTrade(context.Context, *GetInrBotStockTradeRequest) (*GetBotStockInrTradeReply, error) + // ShareInrAllPosition ShareInrAllPosition 印度股一键平仓 + ShareInrAllPosition(context.Context, *AllInrOrderRequest) (*AllInrOrderReply, error) + // ShareInrCancel ShareInrCancel 印度股撤单 + ShareInrCancel(context.Context, *CancelInrOrderRequest) (*InrOrderReply, error) + // ShareInrPlaceOrder ShareInrPlaceOrder 印度股下单 + ShareInrPlaceOrder(context.Context, *ShareInrOrderRequest) (*InrOrderReply, error) + // ShareInrPosition ShareInrPosition 印度股平仓 + ShareInrPosition(context.Context, *CancelInrOrderRequest) (*InrOrderReply, error) + // ShareInrUpdateOrder ShareInrUpdateOrder 印度股设置止盈止损 + ShareInrUpdateOrder(context.Context, *UpdateInrOrderRequest) (*InrOrderReply, error) +} + +func RegisterShareInrHTTPServer(s *http.Server, srv ShareInrHTTPServer) { + r := s.Route("/") + r.POST("/order_shareinr/share_list", _ShareInr_GetBotStockInrTrade0_HTTP_Handler(srv)) + r.POST("/order_shareinr/share_place_order", _ShareInr_ShareInrPlaceOrder0_HTTP_Handler(srv)) + r.POST("/order_shareinr/share_update_order", _ShareInr_ShareInrUpdateOrder0_HTTP_Handler(srv)) + r.POST("/order_shareinr/share_position", _ShareInr_ShareInrPosition0_HTTP_Handler(srv)) + r.POST("/order_shareinr/share_all_position", _ShareInr_ShareInrAllPosition0_HTTP_Handler(srv)) + r.POST("/order_shareinr/share_cancel", _ShareInr_ShareInrCancel0_HTTP_Handler(srv)) +} + +func _ShareInr_GetBotStockInrTrade0_HTTP_Handler(srv ShareInrHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetInrBotStockTradeRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareInrGetBotStockInrTrade) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.GetBotStockInrTrade(ctx, req.(*GetInrBotStockTradeRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetBotStockInrTradeReply) + return ctx.Result(200, reply) + } +} + +func _ShareInr_ShareInrPlaceOrder0_HTTP_Handler(srv ShareInrHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in ShareInrOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareInrShareInrPlaceOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareInrPlaceOrder(ctx, req.(*ShareInrOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*InrOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareInr_ShareInrUpdateOrder0_HTTP_Handler(srv ShareInrHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in UpdateInrOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareInrShareInrUpdateOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareInrUpdateOrder(ctx, req.(*UpdateInrOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*InrOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareInr_ShareInrPosition0_HTTP_Handler(srv ShareInrHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelInrOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareInrShareInrPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareInrPosition(ctx, req.(*CancelInrOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*InrOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareInr_ShareInrAllPosition0_HTTP_Handler(srv ShareInrHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in AllInrOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareInrShareInrAllPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareInrAllPosition(ctx, req.(*AllInrOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*AllInrOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareInr_ShareInrCancel0_HTTP_Handler(srv ShareInrHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelInrOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareInrShareInrCancel) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareInrCancel(ctx, req.(*CancelInrOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*InrOrderReply) + return ctx.Result(200, reply) + } +} + +type ShareInrHTTPClient interface { + GetBotStockInrTrade(ctx context.Context, req *GetInrBotStockTradeRequest, opts ...http.CallOption) (rsp *GetBotStockInrTradeReply, err error) + ShareInrAllPosition(ctx context.Context, req *AllInrOrderRequest, opts ...http.CallOption) (rsp *AllInrOrderReply, err error) + ShareInrCancel(ctx context.Context, req *CancelInrOrderRequest, opts ...http.CallOption) (rsp *InrOrderReply, err error) + ShareInrPlaceOrder(ctx context.Context, req *ShareInrOrderRequest, opts ...http.CallOption) (rsp *InrOrderReply, err error) + ShareInrPosition(ctx context.Context, req *CancelInrOrderRequest, opts ...http.CallOption) (rsp *InrOrderReply, err error) + ShareInrUpdateOrder(ctx context.Context, req *UpdateInrOrderRequest, opts ...http.CallOption) (rsp *InrOrderReply, err error) +} + +type ShareInrHTTPClientImpl struct { + cc *http.Client +} + +func NewShareInrHTTPClient(client *http.Client) ShareInrHTTPClient { + return &ShareInrHTTPClientImpl{client} +} + +func (c *ShareInrHTTPClientImpl) GetBotStockInrTrade(ctx context.Context, in *GetInrBotStockTradeRequest, opts ...http.CallOption) (*GetBotStockInrTradeReply, error) { + var out GetBotStockInrTradeReply + pattern := "/order_shareinr/share_list" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareInrGetBotStockInrTrade)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareInrHTTPClientImpl) ShareInrAllPosition(ctx context.Context, in *AllInrOrderRequest, opts ...http.CallOption) (*AllInrOrderReply, error) { + var out AllInrOrderReply + pattern := "/order_shareinr/share_all_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareInrShareInrAllPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareInrHTTPClientImpl) ShareInrCancel(ctx context.Context, in *CancelInrOrderRequest, opts ...http.CallOption) (*InrOrderReply, error) { + var out InrOrderReply + pattern := "/order_shareinr/share_cancel" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareInrShareInrCancel)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareInrHTTPClientImpl) ShareInrPlaceOrder(ctx context.Context, in *ShareInrOrderRequest, opts ...http.CallOption) (*InrOrderReply, error) { + var out InrOrderReply + pattern := "/order_shareinr/share_place_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareInrShareInrPlaceOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareInrHTTPClientImpl) ShareInrPosition(ctx context.Context, in *CancelInrOrderRequest, opts ...http.CallOption) (*InrOrderReply, error) { + var out InrOrderReply + pattern := "/order_shareinr/share_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareInrShareInrPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareInrHTTPClientImpl) ShareInrUpdateOrder(ctx context.Context, in *UpdateInrOrderRequest, opts ...http.CallOption) (*InrOrderReply, error) { + var out InrOrderReply + pattern := "/order_shareinr/share_update_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareInrShareInrUpdateOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/api/matchmaking/v1/share/shareJpy.pb.go b/api/matchmaking/v1/share/shareJpy.pb.go new file mode 100644 index 0000000..dd2879d --- /dev/null +++ b/api/matchmaking/v1/share/shareJpy.pb.go @@ -0,0 +1,1327 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/share/shareJpy.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GetJpyBotStockTradeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status int64 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` // 状态码 + PageSize int64 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,3,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 +} + +func (x *GetJpyBotStockTradeRequest) Reset() { + *x = GetJpyBotStockTradeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetJpyBotStockTradeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetJpyBotStockTradeRequest) ProtoMessage() {} + +func (x *GetJpyBotStockTradeRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetJpyBotStockTradeRequest.ProtoReflect.Descriptor instead. +func (*GetJpyBotStockTradeRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareJpy_proto_rawDescGZIP(), []int{0} +} + +func (x *GetJpyBotStockTradeRequest) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *GetJpyBotStockTradeRequest) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *GetJpyBotStockTradeRequest) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +type GetBotStockJpyTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *BotStockJpyTradeReply `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *GetBotStockJpyTradeReply) Reset() { + *x = GetBotStockJpyTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotStockJpyTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotStockJpyTradeReply) ProtoMessage() {} + +func (x *GetBotStockJpyTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotStockJpyTradeReply.ProtoReflect.Descriptor instead. +func (*GetBotStockJpyTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareJpy_proto_rawDescGZIP(), []int{1} +} + +func (x *GetBotStockJpyTradeReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *GetBotStockJpyTradeReply) GetData() *BotStockJpyTradeReply { + if x != nil { + return x.Data + } + return nil +} + +func (x *GetBotStockJpyTradeReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type BotStockJpyTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PageSize int64 `protobuf:"varint,1,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,2,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + Data []*BotStockJpyTrade `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty"` // 返回结果 + TotalCount int64 `protobuf:"varint,4,opt,name=totalCount,proto3" json:"totalCount,omitempty"` // 总数据 +} + +func (x *BotStockJpyTradeReply) Reset() { + *x = BotStockJpyTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockJpyTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockJpyTradeReply) ProtoMessage() {} + +func (x *BotStockJpyTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockJpyTradeReply.ProtoReflect.Descriptor instead. +func (*BotStockJpyTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareJpy_proto_rawDescGZIP(), []int{2} +} + +func (x *BotStockJpyTradeReply) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *BotStockJpyTradeReply) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *BotStockJpyTradeReply) GetData() []*BotStockJpyTrade { + if x != nil { + return x.Data + } + return nil +} + +func (x *BotStockJpyTradeReply) GetTotalCount() int64 { + if x != nil { + return x.TotalCount + } + return 0 +} + +type BotStockJpyTrade struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID + StockId string `protobuf:"bytes,2,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票代码 + TradeType int64 `protobuf:"varint,3,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型 + DealType int64 `protobuf:"varint,4,opt,name=dealType,proto3" json:"dealType,omitempty"` // 交易方式 + LimitPrice string `protobuf:"bytes,5,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,6,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + DealPrice string `protobuf:"bytes,7,opt,name=dealPrice,proto3" json:"dealPrice,omitempty"` // 开仓价 + ClosingPrice string `protobuf:"bytes,8,opt,name=closingPrice,proto3" json:"closingPrice,omitempty"` // 平仓价 + OrderNumber string `protobuf:"bytes,9,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + ServiceCost string `protobuf:"bytes,13,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 开仓手续费 + MarketMoney string `protobuf:"bytes,14,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderMoney string `protobuf:"bytes,15,opt,name=orderMoney,proto3" json:"orderMoney,omitempty"` // 订单总金额 + Status int64 `protobuf:"varint,16,opt,name=status,proto3" json:"status,omitempty"` // 订单状态 + CreateTime string `protobuf:"bytes,17,opt,name=createTime,proto3" json:"createTime,omitempty"` // 订单创建时间 + UpdateTime string `protobuf:"bytes,18,opt,name=updateTime,proto3" json:"updateTime,omitempty"` // 订单更新时间 + OpenTime string `protobuf:"bytes,19,opt,name=openTime,proto3" json:"openTime,omitempty"` // 订单开仓时间 + ClosingTime string `protobuf:"bytes,20,opt,name=closingTime,proto3" json:"closingTime,omitempty"` // 订单平仓时间 + ClosingCost string `protobuf:"bytes,21,opt,name=closingCost,proto3" json:"closingCost,omitempty"` // 平仓手续费 + FaceValue string `protobuf:"bytes,22,opt,name=faceValue,proto3" json:"faceValue,omitempty"` // 面值 + PryNum string `protobuf:"bytes,23,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 + KeepDecimal string `protobuf:"bytes,24,opt,name=keepDecimal,proto3" json:"keepDecimal,omitempty"` // 保留小数位 + StockName string `protobuf:"bytes,25,opt,name=stockName,proto3" json:"stockName,omitempty"` // 股票名称 +} + +func (x *BotStockJpyTrade) Reset() { + *x = BotStockJpyTrade{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockJpyTrade) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockJpyTrade) ProtoMessage() {} + +func (x *BotStockJpyTrade) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockJpyTrade.ProtoReflect.Descriptor instead. +func (*BotStockJpyTrade) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareJpy_proto_rawDescGZIP(), []int{3} +} + +func (x *BotStockJpyTrade) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *BotStockJpyTrade) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *BotStockJpyTrade) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *BotStockJpyTrade) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *BotStockJpyTrade) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *BotStockJpyTrade) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *BotStockJpyTrade) GetDealPrice() string { + if x != nil { + return x.DealPrice + } + return "" +} + +func (x *BotStockJpyTrade) GetClosingPrice() string { + if x != nil { + return x.ClosingPrice + } + return "" +} + +func (x *BotStockJpyTrade) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *BotStockJpyTrade) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *BotStockJpyTrade) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *BotStockJpyTrade) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *BotStockJpyTrade) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *BotStockJpyTrade) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *BotStockJpyTrade) GetOrderMoney() string { + if x != nil { + return x.OrderMoney + } + return "" +} + +func (x *BotStockJpyTrade) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *BotStockJpyTrade) GetCreateTime() string { + if x != nil { + return x.CreateTime + } + return "" +} + +func (x *BotStockJpyTrade) GetUpdateTime() string { + if x != nil { + return x.UpdateTime + } + return "" +} + +func (x *BotStockJpyTrade) GetOpenTime() string { + if x != nil { + return x.OpenTime + } + return "" +} + +func (x *BotStockJpyTrade) GetClosingTime() string { + if x != nil { + return x.ClosingTime + } + return "" +} + +func (x *BotStockJpyTrade) GetClosingCost() string { + if x != nil { + return x.ClosingCost + } + return "" +} + +func (x *BotStockJpyTrade) GetFaceValue() string { + if x != nil { + return x.FaceValue + } + return "" +} + +func (x *BotStockJpyTrade) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *BotStockJpyTrade) GetKeepDecimal() string { + if x != nil { + return x.KeepDecimal + } + return "" +} + +func (x *BotStockJpyTrade) GetStockName() string { + if x != nil { + return x.StockName + } + return "" +} + +type ShareJpyOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + StockId string `protobuf:"bytes,1,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票Code + TradeType int64 `protobuf:"varint,2,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型:1买入,2卖出 + DealType int64 `protobuf:"varint,3,opt,name=dealType,proto3" json:"dealType,omitempty"` // 委托方式:1限价,2市价 + LimitPrice string `protobuf:"bytes,4,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,5,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + MarketMoney string `protobuf:"bytes,6,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderNumber string `protobuf:"bytes,7,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + ServiceCost string `protobuf:"bytes,8,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 手续费 + StopType int64 `protobuf:"varint,9,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止损止盈设置:1无设置,2止损止盈 + StopLossPrice string `protobuf:"bytes,10,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,11,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止损 + PryNum string `protobuf:"bytes,12,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 +} + +func (x *ShareJpyOrderRequest) Reset() { + *x = ShareJpyOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ShareJpyOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ShareJpyOrderRequest) ProtoMessage() {} + +func (x *ShareJpyOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ShareJpyOrderRequest.ProtoReflect.Descriptor instead. +func (*ShareJpyOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareJpy_proto_rawDescGZIP(), []int{4} +} + +func (x *ShareJpyOrderRequest) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *ShareJpyOrderRequest) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *ShareJpyOrderRequest) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *ShareJpyOrderRequest) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *ShareJpyOrderRequest) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *ShareJpyOrderRequest) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *ShareJpyOrderRequest) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *ShareJpyOrderRequest) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *ShareJpyOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *ShareJpyOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *ShareJpyOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *ShareJpyOrderRequest) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +type UpdateJpyOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id + StopType int64 `protobuf:"varint,2,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,3,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,4,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 +} + +func (x *UpdateJpyOrderRequest) Reset() { + *x = UpdateJpyOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateJpyOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateJpyOrderRequest) ProtoMessage() {} + +func (x *UpdateJpyOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateJpyOrderRequest.ProtoReflect.Descriptor instead. +func (*UpdateJpyOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareJpy_proto_rawDescGZIP(), []int{5} +} + +func (x *UpdateJpyOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *UpdateJpyOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *UpdateJpyOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *UpdateJpyOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +type JpyOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *JpyOrderResult `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *JpyOrderReply) Reset() { + *x = JpyOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *JpyOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*JpyOrderReply) ProtoMessage() {} + +func (x *JpyOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use JpyOrderReply.ProtoReflect.Descriptor instead. +func (*JpyOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareJpy_proto_rawDescGZIP(), []int{6} +} + +func (x *JpyOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *JpyOrderReply) GetData() *JpyOrderResult { + if x != nil { + return x.Data + } + return nil +} + +func (x *JpyOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type JpyOrderResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id +} + +func (x *JpyOrderResult) Reset() { + *x = JpyOrderResult{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *JpyOrderResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*JpyOrderResult) ProtoMessage() {} + +func (x *JpyOrderResult) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use JpyOrderResult.ProtoReflect.Descriptor instead. +func (*JpyOrderResult) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareJpy_proto_rawDescGZIP(), []int{7} +} + +func (x *JpyOrderResult) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type CancelJpyOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID +} + +func (x *CancelJpyOrderRequest) Reset() { + *x = CancelJpyOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CancelJpyOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CancelJpyOrderRequest) ProtoMessage() {} + +func (x *CancelJpyOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CancelJpyOrderRequest.ProtoReflect.Descriptor instead. +func (*CancelJpyOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareJpy_proto_rawDescGZIP(), []int{8} +} + +func (x *CancelJpyOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type AllJpyOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *AllJpyOrderRequest) Reset() { + *x = AllJpyOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllJpyOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllJpyOrderRequest) ProtoMessage() {} + +func (x *AllJpyOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllJpyOrderRequest.ProtoReflect.Descriptor instead. +func (*AllJpyOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareJpy_proto_rawDescGZIP(), []int{9} +} + +type AllJpyOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *AllJpyOrderReply) Reset() { + *x = AllJpyOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllJpyOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllJpyOrderReply) ProtoMessage() {} + +func (x *AllJpyOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareJpy_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllJpyOrderReply.ProtoReflect.Descriptor instead. +func (*AllJpyOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareJpy_proto_rawDescGZIP(), []int{10} +} + +func (x *AllJpyOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *AllJpyOrderReply) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +func (x *AllJpyOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_matchmaking_v1_share_shareJpy_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_share_shareJpy_proto_rawDesc = []byte{ + 0x0a, 0x23, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x4a, 0x70, 0x79, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0x6e, 0x0a, 0x1a, 0x47, 0x65, 0x74, 0x4a, 0x70, 0x79, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, + 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x22, 0x83, 0x01, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, + 0x6f, 0x63, 0x6b, 0x4a, 0x70, 0x79, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, + 0x63, 0x6f, 0x64, 0x65, 0x12, 0x39, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x4a, 0x70, 0x79, 0x54, + 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, + 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xa7, 0x01, 0x0a, 0x15, 0x42, 0x6f, + 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x4a, 0x70, 0x79, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, + 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x34, 0x0a, + 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x4a, 0x70, 0x79, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x04, 0x64, + 0x61, 0x74, 0x61, 0x12, 0x1e, 0x0a, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, + 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x22, 0x9e, 0x06, 0x0a, 0x10, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, + 0x4a, 0x70, 0x79, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, + 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, + 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, + 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, + 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, + 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x65, 0x61, 0x6c, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x64, 0x65, 0x61, + 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, + 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6c, + 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, + 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, + 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, + 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, + 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0c, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, + 0x74, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x43, 0x6f, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, + 0x6e, 0x65, 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, + 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x18, 0x10, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1e, + 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x11, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1e, + 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x12, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1a, + 0x0a, 0x08, 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x13, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x08, 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, + 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, + 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x15, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1c, + 0x0a, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x16, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x16, 0x0a, 0x06, + 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x17, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, + 0x79, 0x4e, 0x75, 0x6d, 0x12, 0x20, 0x0a, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, + 0x6d, 0x61, 0x6c, 0x18, 0x18, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, + 0x65, 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x4e, + 0x61, 0x6d, 0x65, 0x18, 0x19, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x90, 0x03, 0x0a, 0x14, 0x53, 0x68, 0x61, 0x72, 0x65, 0x4a, 0x70, + 0x79, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, + 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, + 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x72, 0x61, 0x64, + 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, + 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, + 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, + 0x65, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, + 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, + 0x6d, 0x62, 0x65, 0x72, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, + 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, + 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, + 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, + 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, + 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, + 0x16, 0x0a, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x22, 0x97, 0x01, 0x0a, 0x15, 0x55, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x4a, 0x70, 0x79, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, + 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, + 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, + 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, + 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, + 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x22, 0x71, 0x0a, 0x0d, 0x4a, 0x70, 0x79, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, + 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x32, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4a, 0x70, 0x79, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x73, 0x75, 0x6c, 0x74, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x22, 0x2a, 0x0a, 0x0e, 0x4a, 0x70, 0x79, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, + 0x22, 0x31, 0x0a, 0x15, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x4a, 0x70, 0x79, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x49, 0x64, 0x22, 0x14, 0x0a, 0x12, 0x41, 0x6c, 0x6c, 0x4a, 0x70, 0x79, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x54, 0x0a, 0x10, 0x41, 0x6c, 0x6c, + 0x4a, 0x70, 0x79, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, + 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, + 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, + 0xca, 0x06, 0x0a, 0x08, 0x53, 0x68, 0x61, 0x72, 0x65, 0x4a, 0x70, 0x79, 0x12, 0x92, 0x01, 0x0a, + 0x13, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x4a, 0x70, 0x79, 0x54, + 0x72, 0x61, 0x64, 0x65, 0x12, 0x2a, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x4a, 0x70, 0x79, 0x42, 0x6f, 0x74, 0x53, + 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x28, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, + 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x4a, 0x70, 0x79, + 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x25, 0x82, 0xd3, 0xe4, 0x93, + 0x02, 0x1f, 0x3a, 0x01, 0x2a, 0x22, 0x1a, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, + 0x61, 0x72, 0x65, 0x6a, 0x70, 0x79, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x6c, 0x69, 0x73, + 0x74, 0x12, 0x87, 0x01, 0x0a, 0x12, 0x53, 0x68, 0x61, 0x72, 0x65, 0x4a, 0x70, 0x79, 0x50, 0x6c, + 0x61, 0x63, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x24, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x4a, + 0x70, 0x79, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, + 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x4a, 0x70, 0x79, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2c, 0x82, + 0xd3, 0xe4, 0x93, 0x02, 0x26, 0x3a, 0x01, 0x2a, 0x22, 0x21, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x6a, 0x70, 0x79, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, + 0x70, 0x6c, 0x61, 0x63, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x8a, 0x01, 0x0a, 0x13, + 0x53, 0x68, 0x61, 0x72, 0x65, 0x4a, 0x70, 0x79, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x12, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, + 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4a, 0x70, 0x79, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4a, 0x70, 0x79, 0x4f, + 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93, 0x02, + 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, + 0x72, 0x65, 0x6a, 0x70, 0x79, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x75, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x83, 0x01, 0x0a, 0x10, 0x53, 0x68, 0x61, + 0x72, 0x65, 0x4a, 0x70, 0x79, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x25, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, + 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x4a, 0x70, 0x79, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4a, 0x70, 0x79, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x29, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x23, 0x3a, 0x01, 0x2a, 0x22, 0x1e, + 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x6a, 0x70, 0x79, 0x2f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x8a, + 0x01, 0x0a, 0x13, 0x53, 0x68, 0x61, 0x72, 0x65, 0x4a, 0x70, 0x79, 0x41, 0x6c, 0x6c, 0x50, 0x6f, + 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x22, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, + 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x4a, 0x70, 0x79, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x4a, + 0x70, 0x79, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2d, 0x82, 0xd3, + 0xe4, 0x93, 0x02, 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x6a, 0x70, 0x79, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x61, + 0x6c, 0x6c, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x7f, 0x0a, 0x0e, 0x53, + 0x68, 0x61, 0x72, 0x65, 0x4a, 0x70, 0x79, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x12, 0x25, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, + 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x4a, 0x70, 0x79, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4a, 0x70, 0x79, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x27, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x21, 0x3a, 0x01, 0x2a, 0x22, 0x1c, + 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x6a, 0x70, 0x79, 0x2f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x42, 0x2a, 0x5a, 0x28, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x73, 0x79, 0x73, 0x74, + 0x65, 0x6d, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_share_shareJpy_proto_rawDescOnce sync.Once + file_matchmaking_v1_share_shareJpy_proto_rawDescData = file_matchmaking_v1_share_shareJpy_proto_rawDesc +) + +func file_matchmaking_v1_share_shareJpy_proto_rawDescGZIP() []byte { + file_matchmaking_v1_share_shareJpy_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_share_shareJpy_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_share_shareJpy_proto_rawDescData) + }) + return file_matchmaking_v1_share_shareJpy_proto_rawDescData +} + +var file_matchmaking_v1_share_shareJpy_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_matchmaking_v1_share_shareJpy_proto_goTypes = []any{ + (*GetJpyBotStockTradeRequest)(nil), // 0: matchmaking.v1.GetJpyBotStockTradeRequest + (*GetBotStockJpyTradeReply)(nil), // 1: matchmaking.v1.GetBotStockJpyTradeReply + (*BotStockJpyTradeReply)(nil), // 2: matchmaking.v1.BotStockJpyTradeReply + (*BotStockJpyTrade)(nil), // 3: matchmaking.v1.BotStockJpyTrade + (*ShareJpyOrderRequest)(nil), // 4: matchmaking.v1.ShareJpyOrderRequest + (*UpdateJpyOrderRequest)(nil), // 5: matchmaking.v1.UpdateJpyOrderRequest + (*JpyOrderReply)(nil), // 6: matchmaking.v1.JpyOrderReply + (*JpyOrderResult)(nil), // 7: matchmaking.v1.JpyOrderResult + (*CancelJpyOrderRequest)(nil), // 8: matchmaking.v1.CancelJpyOrderRequest + (*AllJpyOrderRequest)(nil), // 9: matchmaking.v1.AllJpyOrderRequest + (*AllJpyOrderReply)(nil), // 10: matchmaking.v1.AllJpyOrderReply +} +var file_matchmaking_v1_share_shareJpy_proto_depIdxs = []int32{ + 2, // 0: matchmaking.v1.GetBotStockJpyTradeReply.data:type_name -> matchmaking.v1.BotStockJpyTradeReply + 3, // 1: matchmaking.v1.BotStockJpyTradeReply.data:type_name -> matchmaking.v1.BotStockJpyTrade + 7, // 2: matchmaking.v1.JpyOrderReply.data:type_name -> matchmaking.v1.JpyOrderResult + 0, // 3: matchmaking.v1.ShareJpy.GetBotStockJpyTrade:input_type -> matchmaking.v1.GetJpyBotStockTradeRequest + 4, // 4: matchmaking.v1.ShareJpy.ShareJpyPlaceOrder:input_type -> matchmaking.v1.ShareJpyOrderRequest + 5, // 5: matchmaking.v1.ShareJpy.ShareJpyUpdateOrder:input_type -> matchmaking.v1.UpdateJpyOrderRequest + 8, // 6: matchmaking.v1.ShareJpy.ShareJpyPosition:input_type -> matchmaking.v1.CancelJpyOrderRequest + 9, // 7: matchmaking.v1.ShareJpy.ShareJpyAllPosition:input_type -> matchmaking.v1.AllJpyOrderRequest + 8, // 8: matchmaking.v1.ShareJpy.ShareJpyCancel:input_type -> matchmaking.v1.CancelJpyOrderRequest + 1, // 9: matchmaking.v1.ShareJpy.GetBotStockJpyTrade:output_type -> matchmaking.v1.GetBotStockJpyTradeReply + 6, // 10: matchmaking.v1.ShareJpy.ShareJpyPlaceOrder:output_type -> matchmaking.v1.JpyOrderReply + 6, // 11: matchmaking.v1.ShareJpy.ShareJpyUpdateOrder:output_type -> matchmaking.v1.JpyOrderReply + 6, // 12: matchmaking.v1.ShareJpy.ShareJpyPosition:output_type -> matchmaking.v1.JpyOrderReply + 10, // 13: matchmaking.v1.ShareJpy.ShareJpyAllPosition:output_type -> matchmaking.v1.AllJpyOrderReply + 6, // 14: matchmaking.v1.ShareJpy.ShareJpyCancel:output_type -> matchmaking.v1.JpyOrderReply + 9, // [9:15] is the sub-list for method output_type + 3, // [3:9] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_share_shareJpy_proto_init() } +func file_matchmaking_v1_share_shareJpy_proto_init() { + if File_matchmaking_v1_share_shareJpy_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_matchmaking_v1_share_shareJpy_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*GetJpyBotStockTradeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareJpy_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*GetBotStockJpyTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareJpy_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*BotStockJpyTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareJpy_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*BotStockJpyTrade); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareJpy_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*ShareJpyOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareJpy_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*UpdateJpyOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareJpy_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*JpyOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareJpy_proto_msgTypes[7].Exporter = func(v any, i int) any { + switch v := v.(*JpyOrderResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareJpy_proto_msgTypes[8].Exporter = func(v any, i int) any { + switch v := v.(*CancelJpyOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareJpy_proto_msgTypes[9].Exporter = func(v any, i int) any { + switch v := v.(*AllJpyOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareJpy_proto_msgTypes[10].Exporter = func(v any, i int) any { + switch v := v.(*AllJpyOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_share_shareJpy_proto_rawDesc, + NumEnums: 0, + NumMessages: 11, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_matchmaking_v1_share_shareJpy_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_share_shareJpy_proto_depIdxs, + MessageInfos: file_matchmaking_v1_share_shareJpy_proto_msgTypes, + }.Build() + File_matchmaking_v1_share_shareJpy_proto = out.File + file_matchmaking_v1_share_shareJpy_proto_rawDesc = nil + file_matchmaking_v1_share_shareJpy_proto_goTypes = nil + file_matchmaking_v1_share_shareJpy_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/share/shareJpy.proto b/api/matchmaking/v1/share/shareJpy.proto new file mode 100644 index 0000000..9c18a56 --- /dev/null +++ b/api/matchmaking/v1/share/shareJpy.proto @@ -0,0 +1,144 @@ +syntax = "proto3"; + +package matchmaking.v1; + +import "google/api/annotations.proto"; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +service ShareJpy { + // GetBotStockJpyTrade 日本股列表查询 + rpc GetBotStockJpyTrade(GetJpyBotStockTradeRequest)returns(GetBotStockJpyTradeReply){ + option (google.api.http) = { + post:"/order_sharejpy/share_list", + body:"*", + }; + } + // ShareJpyPlaceOrder 日本股下单 + rpc ShareJpyPlaceOrder(ShareJpyOrderRequest)returns(JpyOrderReply) { + option (google.api.http) = { + post: "/order_sharejpy/share_place_order", + body: "*", + }; + } + // ShareJpyUpdateOrder 日本股设置止盈止损 + rpc ShareJpyUpdateOrder(UpdateJpyOrderRequest)returns(JpyOrderReply){ + option (google.api.http) = { + post:"/order_sharejpy/share_update_order", + body:"*", + }; + } + // ShareJpyPosition 日本股平仓 + rpc ShareJpyPosition(CancelJpyOrderRequest)returns(JpyOrderReply){ + option (google.api.http) = { + post:"/order_sharejpy/share_position", + body:"*", + }; + } + // ShareJpyAllPosition 日本股一键平仓 + rpc ShareJpyAllPosition(AllJpyOrderRequest)returns(AllJpyOrderReply){ + option (google.api.http) = { + post:"/order_sharejpy/share_all_position", + body:"*", + }; + } + // ShareJpyCancel 日本股撤单 + rpc ShareJpyCancel(CancelJpyOrderRequest)returns(JpyOrderReply){ + option (google.api.http) = { + post:"/order_sharejpy/share_cancel", + body:"*", + }; + } +} + +message GetJpyBotStockTradeRequest{ + int64 status =1;// 状态码 + int64 pageSize =2; // 每页显示条数 + int64 pageCount =3;// 开始的位置 +} + +message GetBotStockJpyTradeReply{ + int64 code =1;// 状态码 + BotStockJpyTradeReply data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message BotStockJpyTradeReply{ + int64 pageSize =1; // 每页显示条数 + int64 pageCount =2;// 开始的位置 + repeated BotStockJpyTrade data =3;// 返回结果 + int64 totalCount =4;// 总数据 +} + +message BotStockJpyTrade{ + string orderId =1;// 订单ID + string stockId =2;// 股票代码 + int64 tradeType =3;// 交易类型 + int64 dealType =4;// 交易方式 + string limitPrice =5;// 限价 + string marketPrice =6;// 市价 + string dealPrice =7;// 开仓价 + string closingPrice =8;// 平仓价 + string orderNumber =9;// 订单数量 + int64 stopType =10;// 止盈止损 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string serviceCost =13;// 开仓手续费 + string marketMoney =14;// 订单金额 + string orderMoney =15;// 订单总金额 + int64 status =16;// 订单状态 + string createTime =17;// 订单创建时间 + string updateTime =18;// 订单更新时间 + string openTime =19;// 订单开仓时间 + string closingTime =20;// 订单平仓时间 + string closingCost =21;// 平仓手续费 + string faceValue =22;// 面值 + string pryNum =23;// 杠杆 + string keepDecimal =24;// 保留小数位 + string stockName =25;// 股票名称 +} + +message ShareJpyOrderRequest{ + string stockId =1;// 股票Code + int64 tradeType =2;// 交易类型:1买入,2卖出 + int64 dealType =3;// 委托方式:1限价,2市价 + string limitPrice =4;// 限价 + string marketPrice =5;// 市价 + string marketMoney =6;// 订单金额 + string orderNumber =7;// 订单数量 + string serviceCost =8;// 手续费 + int64 stopType =9;// 止损止盈设置:1无设置,2止损止盈 + string stopLossPrice =10;// 止损 + string stopWinPrice =11;// 止损 + string pryNum =12;// 杠杆 +} + +message UpdateJpyOrderRequest{ + string orderId =1;// 订单Id + int64 stopType =2;// 止盈止损 + string stopLossPrice =3;// 止损 + string stopWinPrice =4;// 止盈 +} + +message JpyOrderReply{ + int64 code =1;// 状态码 + JpyOrderResult data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message JpyOrderResult { + string orderId =1;// 订单Id +} + +message CancelJpyOrderRequest{ + string orderId =1;// 订单ID +} + +message AllJpyOrderRequest{ + +} +message AllJpyOrderReply{ + int64 code =1;// 状态码 + string data =2;// 返回结果 + string message =3;// 返回消息提示 +} \ No newline at end of file diff --git a/api/matchmaking/v1/share/shareJpy_grpc.pb.go b/api/matchmaking/v1/share/shareJpy_grpc.pb.go new file mode 100644 index 0000000..dab63f0 --- /dev/null +++ b/api/matchmaking/v1/share/shareJpy_grpc.pb.go @@ -0,0 +1,312 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareJpy.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + ShareJpy_GetBotStockJpyTrade_FullMethodName = "/matchmaking.v1.ShareJpy/GetBotStockJpyTrade" + ShareJpy_ShareJpyPlaceOrder_FullMethodName = "/matchmaking.v1.ShareJpy/ShareJpyPlaceOrder" + ShareJpy_ShareJpyUpdateOrder_FullMethodName = "/matchmaking.v1.ShareJpy/ShareJpyUpdateOrder" + ShareJpy_ShareJpyPosition_FullMethodName = "/matchmaking.v1.ShareJpy/ShareJpyPosition" + ShareJpy_ShareJpyAllPosition_FullMethodName = "/matchmaking.v1.ShareJpy/ShareJpyAllPosition" + ShareJpy_ShareJpyCancel_FullMethodName = "/matchmaking.v1.ShareJpy/ShareJpyCancel" +) + +// ShareJpyClient is the client API for ShareJpy service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ShareJpyClient interface { + // GetBotStockJpyTrade 日本股列表查询 + GetBotStockJpyTrade(ctx context.Context, in *GetJpyBotStockTradeRequest, opts ...grpc.CallOption) (*GetBotStockJpyTradeReply, error) + // ShareJpyPlaceOrder 日本股下单 + ShareJpyPlaceOrder(ctx context.Context, in *ShareJpyOrderRequest, opts ...grpc.CallOption) (*JpyOrderReply, error) + // ShareJpyUpdateOrder 日本股设置止盈止损 + ShareJpyUpdateOrder(ctx context.Context, in *UpdateJpyOrderRequest, opts ...grpc.CallOption) (*JpyOrderReply, error) + // ShareJpyPosition 日本股平仓 + ShareJpyPosition(ctx context.Context, in *CancelJpyOrderRequest, opts ...grpc.CallOption) (*JpyOrderReply, error) + // ShareJpyAllPosition 日本股一键平仓 + ShareJpyAllPosition(ctx context.Context, in *AllJpyOrderRequest, opts ...grpc.CallOption) (*AllJpyOrderReply, error) + // ShareJpyCancel 日本股撤单 + ShareJpyCancel(ctx context.Context, in *CancelJpyOrderRequest, opts ...grpc.CallOption) (*JpyOrderReply, error) +} + +type shareJpyClient struct { + cc grpc.ClientConnInterface +} + +func NewShareJpyClient(cc grpc.ClientConnInterface) ShareJpyClient { + return &shareJpyClient{cc} +} + +func (c *shareJpyClient) GetBotStockJpyTrade(ctx context.Context, in *GetJpyBotStockTradeRequest, opts ...grpc.CallOption) (*GetBotStockJpyTradeReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetBotStockJpyTradeReply) + err := c.cc.Invoke(ctx, ShareJpy_GetBotStockJpyTrade_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareJpyClient) ShareJpyPlaceOrder(ctx context.Context, in *ShareJpyOrderRequest, opts ...grpc.CallOption) (*JpyOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(JpyOrderReply) + err := c.cc.Invoke(ctx, ShareJpy_ShareJpyPlaceOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareJpyClient) ShareJpyUpdateOrder(ctx context.Context, in *UpdateJpyOrderRequest, opts ...grpc.CallOption) (*JpyOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(JpyOrderReply) + err := c.cc.Invoke(ctx, ShareJpy_ShareJpyUpdateOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareJpyClient) ShareJpyPosition(ctx context.Context, in *CancelJpyOrderRequest, opts ...grpc.CallOption) (*JpyOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(JpyOrderReply) + err := c.cc.Invoke(ctx, ShareJpy_ShareJpyPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareJpyClient) ShareJpyAllPosition(ctx context.Context, in *AllJpyOrderRequest, opts ...grpc.CallOption) (*AllJpyOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AllJpyOrderReply) + err := c.cc.Invoke(ctx, ShareJpy_ShareJpyAllPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareJpyClient) ShareJpyCancel(ctx context.Context, in *CancelJpyOrderRequest, opts ...grpc.CallOption) (*JpyOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(JpyOrderReply) + err := c.cc.Invoke(ctx, ShareJpy_ShareJpyCancel_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ShareJpyServer is the server API for ShareJpy service. +// All implementations must embed UnimplementedShareJpyServer +// for forward compatibility +type ShareJpyServer interface { + // GetBotStockJpyTrade 日本股列表查询 + GetBotStockJpyTrade(context.Context, *GetJpyBotStockTradeRequest) (*GetBotStockJpyTradeReply, error) + // ShareJpyPlaceOrder 日本股下单 + ShareJpyPlaceOrder(context.Context, *ShareJpyOrderRequest) (*JpyOrderReply, error) + // ShareJpyUpdateOrder 日本股设置止盈止损 + ShareJpyUpdateOrder(context.Context, *UpdateJpyOrderRequest) (*JpyOrderReply, error) + // ShareJpyPosition 日本股平仓 + ShareJpyPosition(context.Context, *CancelJpyOrderRequest) (*JpyOrderReply, error) + // ShareJpyAllPosition 日本股一键平仓 + ShareJpyAllPosition(context.Context, *AllJpyOrderRequest) (*AllJpyOrderReply, error) + // ShareJpyCancel 日本股撤单 + ShareJpyCancel(context.Context, *CancelJpyOrderRequest) (*JpyOrderReply, error) + mustEmbedUnimplementedShareJpyServer() +} + +// UnimplementedShareJpyServer must be embedded to have forward compatible implementations. +type UnimplementedShareJpyServer struct { +} + +func (UnimplementedShareJpyServer) GetBotStockJpyTrade(context.Context, *GetJpyBotStockTradeRequest) (*GetBotStockJpyTradeReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBotStockJpyTrade not implemented") +} +func (UnimplementedShareJpyServer) ShareJpyPlaceOrder(context.Context, *ShareJpyOrderRequest) (*JpyOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareJpyPlaceOrder not implemented") +} +func (UnimplementedShareJpyServer) ShareJpyUpdateOrder(context.Context, *UpdateJpyOrderRequest) (*JpyOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareJpyUpdateOrder not implemented") +} +func (UnimplementedShareJpyServer) ShareJpyPosition(context.Context, *CancelJpyOrderRequest) (*JpyOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareJpyPosition not implemented") +} +func (UnimplementedShareJpyServer) ShareJpyAllPosition(context.Context, *AllJpyOrderRequest) (*AllJpyOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareJpyAllPosition not implemented") +} +func (UnimplementedShareJpyServer) ShareJpyCancel(context.Context, *CancelJpyOrderRequest) (*JpyOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareJpyCancel not implemented") +} +func (UnimplementedShareJpyServer) mustEmbedUnimplementedShareJpyServer() {} + +// UnsafeShareJpyServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ShareJpyServer will +// result in compilation errors. +type UnsafeShareJpyServer interface { + mustEmbedUnimplementedShareJpyServer() +} + +func RegisterShareJpyServer(s grpc.ServiceRegistrar, srv ShareJpyServer) { + s.RegisterService(&ShareJpy_ServiceDesc, srv) +} + +func _ShareJpy_GetBotStockJpyTrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetJpyBotStockTradeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareJpyServer).GetBotStockJpyTrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareJpy_GetBotStockJpyTrade_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareJpyServer).GetBotStockJpyTrade(ctx, req.(*GetJpyBotStockTradeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareJpy_ShareJpyPlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ShareJpyOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareJpyServer).ShareJpyPlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareJpy_ShareJpyPlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareJpyServer).ShareJpyPlaceOrder(ctx, req.(*ShareJpyOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareJpy_ShareJpyUpdateOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateJpyOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareJpyServer).ShareJpyUpdateOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareJpy_ShareJpyUpdateOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareJpyServer).ShareJpyUpdateOrder(ctx, req.(*UpdateJpyOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareJpy_ShareJpyPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelJpyOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareJpyServer).ShareJpyPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareJpy_ShareJpyPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareJpyServer).ShareJpyPosition(ctx, req.(*CancelJpyOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareJpy_ShareJpyAllPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AllJpyOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareJpyServer).ShareJpyAllPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareJpy_ShareJpyAllPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareJpyServer).ShareJpyAllPosition(ctx, req.(*AllJpyOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareJpy_ShareJpyCancel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelJpyOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareJpyServer).ShareJpyCancel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareJpy_ShareJpyCancel_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareJpyServer).ShareJpyCancel(ctx, req.(*CancelJpyOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// ShareJpy_ServiceDesc is the grpc.ServiceDesc for ShareJpy service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ShareJpy_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "matchmaking.v1.ShareJpy", + HandlerType: (*ShareJpyServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetBotStockJpyTrade", + Handler: _ShareJpy_GetBotStockJpyTrade_Handler, + }, + { + MethodName: "ShareJpyPlaceOrder", + Handler: _ShareJpy_ShareJpyPlaceOrder_Handler, + }, + { + MethodName: "ShareJpyUpdateOrder", + Handler: _ShareJpy_ShareJpyUpdateOrder_Handler, + }, + { + MethodName: "ShareJpyPosition", + Handler: _ShareJpy_ShareJpyPosition_Handler, + }, + { + MethodName: "ShareJpyAllPosition", + Handler: _ShareJpy_ShareJpyAllPosition_Handler, + }, + { + MethodName: "ShareJpyCancel", + Handler: _ShareJpy_ShareJpyCancel_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "matchmaking/v1/share/shareJpy.proto", +} diff --git a/api/matchmaking/v1/share/shareJpy_http.pb.go b/api/matchmaking/v1/share/shareJpy_http.pb.go new file mode 100644 index 0000000..b2144a7 --- /dev/null +++ b/api/matchmaking/v1/share/shareJpy_http.pb.go @@ -0,0 +1,279 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.3 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareJpy.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationShareJpyGetBotStockJpyTrade = "/matchmaking.v1.ShareJpy/GetBotStockJpyTrade" +const OperationShareJpyShareJpyAllPosition = "/matchmaking.v1.ShareJpy/ShareJpyAllPosition" +const OperationShareJpyShareJpyCancel = "/matchmaking.v1.ShareJpy/ShareJpyCancel" +const OperationShareJpyShareJpyPlaceOrder = "/matchmaking.v1.ShareJpy/ShareJpyPlaceOrder" +const OperationShareJpyShareJpyPosition = "/matchmaking.v1.ShareJpy/ShareJpyPosition" +const OperationShareJpyShareJpyUpdateOrder = "/matchmaking.v1.ShareJpy/ShareJpyUpdateOrder" + +type ShareJpyHTTPServer interface { + // GetBotStockJpyTrade GetBotStockJpyTrade 日本股列表查询 + GetBotStockJpyTrade(context.Context, *GetJpyBotStockTradeRequest) (*GetBotStockJpyTradeReply, error) + // ShareJpyAllPosition ShareJpyAllPosition 日本股一键平仓 + ShareJpyAllPosition(context.Context, *AllJpyOrderRequest) (*AllJpyOrderReply, error) + // ShareJpyCancel ShareJpyCancel 日本股撤单 + ShareJpyCancel(context.Context, *CancelJpyOrderRequest) (*JpyOrderReply, error) + // ShareJpyPlaceOrder ShareJpyPlaceOrder 日本股下单 + ShareJpyPlaceOrder(context.Context, *ShareJpyOrderRequest) (*JpyOrderReply, error) + // ShareJpyPosition ShareJpyPosition 日本股平仓 + ShareJpyPosition(context.Context, *CancelJpyOrderRequest) (*JpyOrderReply, error) + // ShareJpyUpdateOrder ShareJpyUpdateOrder 日本股设置止盈止损 + ShareJpyUpdateOrder(context.Context, *UpdateJpyOrderRequest) (*JpyOrderReply, error) +} + +func RegisterShareJpyHTTPServer(s *http.Server, srv ShareJpyHTTPServer) { + r := s.Route("/") + r.POST("/order_sharejpy/share_list", _ShareJpy_GetBotStockJpyTrade0_HTTP_Handler(srv)) + r.POST("/order_sharejpy/share_place_order", _ShareJpy_ShareJpyPlaceOrder0_HTTP_Handler(srv)) + r.POST("/order_sharejpy/share_update_order", _ShareJpy_ShareJpyUpdateOrder0_HTTP_Handler(srv)) + r.POST("/order_sharejpy/share_position", _ShareJpy_ShareJpyPosition0_HTTP_Handler(srv)) + r.POST("/order_sharejpy/share_all_position", _ShareJpy_ShareJpyAllPosition0_HTTP_Handler(srv)) + r.POST("/order_sharejpy/share_cancel", _ShareJpy_ShareJpyCancel0_HTTP_Handler(srv)) +} + +func _ShareJpy_GetBotStockJpyTrade0_HTTP_Handler(srv ShareJpyHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetJpyBotStockTradeRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareJpyGetBotStockJpyTrade) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.GetBotStockJpyTrade(ctx, req.(*GetJpyBotStockTradeRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetBotStockJpyTradeReply) + return ctx.Result(200, reply) + } +} + +func _ShareJpy_ShareJpyPlaceOrder0_HTTP_Handler(srv ShareJpyHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in ShareJpyOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareJpyShareJpyPlaceOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareJpyPlaceOrder(ctx, req.(*ShareJpyOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*JpyOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareJpy_ShareJpyUpdateOrder0_HTTP_Handler(srv ShareJpyHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in UpdateJpyOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareJpyShareJpyUpdateOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareJpyUpdateOrder(ctx, req.(*UpdateJpyOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*JpyOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareJpy_ShareJpyPosition0_HTTP_Handler(srv ShareJpyHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelJpyOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareJpyShareJpyPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareJpyPosition(ctx, req.(*CancelJpyOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*JpyOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareJpy_ShareJpyAllPosition0_HTTP_Handler(srv ShareJpyHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in AllJpyOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareJpyShareJpyAllPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareJpyAllPosition(ctx, req.(*AllJpyOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*AllJpyOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareJpy_ShareJpyCancel0_HTTP_Handler(srv ShareJpyHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelJpyOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareJpyShareJpyCancel) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareJpyCancel(ctx, req.(*CancelJpyOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*JpyOrderReply) + return ctx.Result(200, reply) + } +} + +type ShareJpyHTTPClient interface { + GetBotStockJpyTrade(ctx context.Context, req *GetJpyBotStockTradeRequest, opts ...http.CallOption) (rsp *GetBotStockJpyTradeReply, err error) + ShareJpyAllPosition(ctx context.Context, req *AllJpyOrderRequest, opts ...http.CallOption) (rsp *AllJpyOrderReply, err error) + ShareJpyCancel(ctx context.Context, req *CancelJpyOrderRequest, opts ...http.CallOption) (rsp *JpyOrderReply, err error) + ShareJpyPlaceOrder(ctx context.Context, req *ShareJpyOrderRequest, opts ...http.CallOption) (rsp *JpyOrderReply, err error) + ShareJpyPosition(ctx context.Context, req *CancelJpyOrderRequest, opts ...http.CallOption) (rsp *JpyOrderReply, err error) + ShareJpyUpdateOrder(ctx context.Context, req *UpdateJpyOrderRequest, opts ...http.CallOption) (rsp *JpyOrderReply, err error) +} + +type ShareJpyHTTPClientImpl struct { + cc *http.Client +} + +func NewShareJpyHTTPClient(client *http.Client) ShareJpyHTTPClient { + return &ShareJpyHTTPClientImpl{client} +} + +func (c *ShareJpyHTTPClientImpl) GetBotStockJpyTrade(ctx context.Context, in *GetJpyBotStockTradeRequest, opts ...http.CallOption) (*GetBotStockJpyTradeReply, error) { + var out GetBotStockJpyTradeReply + pattern := "/order_sharejpy/share_list" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareJpyGetBotStockJpyTrade)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareJpyHTTPClientImpl) ShareJpyAllPosition(ctx context.Context, in *AllJpyOrderRequest, opts ...http.CallOption) (*AllJpyOrderReply, error) { + var out AllJpyOrderReply + pattern := "/order_sharejpy/share_all_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareJpyShareJpyAllPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareJpyHTTPClientImpl) ShareJpyCancel(ctx context.Context, in *CancelJpyOrderRequest, opts ...http.CallOption) (*JpyOrderReply, error) { + var out JpyOrderReply + pattern := "/order_sharejpy/share_cancel" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareJpyShareJpyCancel)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareJpyHTTPClientImpl) ShareJpyPlaceOrder(ctx context.Context, in *ShareJpyOrderRequest, opts ...http.CallOption) (*JpyOrderReply, error) { + var out JpyOrderReply + pattern := "/order_sharejpy/share_place_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareJpyShareJpyPlaceOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareJpyHTTPClientImpl) ShareJpyPosition(ctx context.Context, in *CancelJpyOrderRequest, opts ...http.CallOption) (*JpyOrderReply, error) { + var out JpyOrderReply + pattern := "/order_sharejpy/share_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareJpyShareJpyPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareJpyHTTPClientImpl) ShareJpyUpdateOrder(ctx context.Context, in *UpdateJpyOrderRequest, opts ...http.CallOption) (*JpyOrderReply, error) { + var out JpyOrderReply + pattern := "/order_sharejpy/share_update_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareJpyShareJpyUpdateOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/api/matchmaking/v1/share/shareMys.pb.go b/api/matchmaking/v1/share/shareMys.pb.go new file mode 100644 index 0000000..4ea2f6d --- /dev/null +++ b/api/matchmaking/v1/share/shareMys.pb.go @@ -0,0 +1,1337 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/share/shareMys.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GetMysBotStockTradeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status int64 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` // 状态码 + PageSize int64 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,3,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 +} + +func (x *GetMysBotStockTradeRequest) Reset() { + *x = GetMysBotStockTradeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetMysBotStockTradeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetMysBotStockTradeRequest) ProtoMessage() {} + +func (x *GetMysBotStockTradeRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetMysBotStockTradeRequest.ProtoReflect.Descriptor instead. +func (*GetMysBotStockTradeRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareMys_proto_rawDescGZIP(), []int{0} +} + +func (x *GetMysBotStockTradeRequest) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *GetMysBotStockTradeRequest) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *GetMysBotStockTradeRequest) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +type GetBotStockMysTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *BotStockMysTradeData `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *GetBotStockMysTradeReply) Reset() { + *x = GetBotStockMysTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotStockMysTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotStockMysTradeReply) ProtoMessage() {} + +func (x *GetBotStockMysTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotStockMysTradeReply.ProtoReflect.Descriptor instead. +func (*GetBotStockMysTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareMys_proto_rawDescGZIP(), []int{1} +} + +func (x *GetBotStockMysTradeReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *GetBotStockMysTradeReply) GetData() *BotStockMysTradeData { + if x != nil { + return x.Data + } + return nil +} + +func (x *GetBotStockMysTradeReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type BotStockMysTradeData struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PageSize int64 `protobuf:"varint,1,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,2,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + Data []*BotStockMysTrade `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty"` // 返回结果 + TotalCount int64 `protobuf:"varint,4,opt,name=totalCount,proto3" json:"totalCount,omitempty"` // 总数据 +} + +func (x *BotStockMysTradeData) Reset() { + *x = BotStockMysTradeData{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockMysTradeData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockMysTradeData) ProtoMessage() {} + +func (x *BotStockMysTradeData) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockMysTradeData.ProtoReflect.Descriptor instead. +func (*BotStockMysTradeData) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareMys_proto_rawDescGZIP(), []int{2} +} + +func (x *BotStockMysTradeData) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *BotStockMysTradeData) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *BotStockMysTradeData) GetData() []*BotStockMysTrade { + if x != nil { + return x.Data + } + return nil +} + +func (x *BotStockMysTradeData) GetTotalCount() int64 { + if x != nil { + return x.TotalCount + } + return 0 +} + +type BotStockMysTrade struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID + StockId string `protobuf:"bytes,2,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票代码 + TradeType int64 `protobuf:"varint,3,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型 + DealType int64 `protobuf:"varint,4,opt,name=dealType,proto3" json:"dealType,omitempty"` // 交易方式 + LimitPrice string `protobuf:"bytes,5,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,6,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + DealPrice string `protobuf:"bytes,7,opt,name=dealPrice,proto3" json:"dealPrice,omitempty"` // 开仓价 + ClosingPrice string `protobuf:"bytes,8,opt,name=closingPrice,proto3" json:"closingPrice,omitempty"` // 平仓价 + OrderNumber string `protobuf:"bytes,9,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + ServiceCost string `protobuf:"bytes,13,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 开仓手续费 + MarketMoney string `protobuf:"bytes,14,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderMoney string `protobuf:"bytes,15,opt,name=orderMoney,proto3" json:"orderMoney,omitempty"` // 订单总金额 + Status int64 `protobuf:"varint,16,opt,name=status,proto3" json:"status,omitempty"` // 订单状态 + CreateTime string `protobuf:"bytes,17,opt,name=createTime,proto3" json:"createTime,omitempty"` // 订单创建时间 + UpdateTime string `protobuf:"bytes,18,opt,name=updateTime,proto3" json:"updateTime,omitempty"` // 订单更新时间 + OpenTime string `protobuf:"bytes,19,opt,name=openTime,proto3" json:"openTime,omitempty"` // 订单开仓时间 + ClosingTime string `protobuf:"bytes,20,opt,name=closingTime,proto3" json:"closingTime,omitempty"` // 订单平仓时间 + ClosingCost string `protobuf:"bytes,21,opt,name=closingCost,proto3" json:"closingCost,omitempty"` // 订单平仓手续费 + FaceValue string `protobuf:"bytes,22,opt,name=faceValue,proto3" json:"faceValue,omitempty"` // 面值 + PryNum string `protobuf:"bytes,23,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 + KeepDecimal string `protobuf:"bytes,24,opt,name=keepDecimal,proto3" json:"keepDecimal,omitempty"` // 保留小数位 + StockName string `protobuf:"bytes,25,opt,name=stockName,proto3" json:"stockName,omitempty"` // 股票名称 + NumericCode string `protobuf:"bytes,26,opt,name=numericCode,proto3" json:"numericCode,omitempty"` // 股票数字代码 +} + +func (x *BotStockMysTrade) Reset() { + *x = BotStockMysTrade{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockMysTrade) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockMysTrade) ProtoMessage() {} + +func (x *BotStockMysTrade) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockMysTrade.ProtoReflect.Descriptor instead. +func (*BotStockMysTrade) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareMys_proto_rawDescGZIP(), []int{3} +} + +func (x *BotStockMysTrade) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *BotStockMysTrade) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *BotStockMysTrade) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *BotStockMysTrade) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *BotStockMysTrade) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *BotStockMysTrade) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *BotStockMysTrade) GetDealPrice() string { + if x != nil { + return x.DealPrice + } + return "" +} + +func (x *BotStockMysTrade) GetClosingPrice() string { + if x != nil { + return x.ClosingPrice + } + return "" +} + +func (x *BotStockMysTrade) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *BotStockMysTrade) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *BotStockMysTrade) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *BotStockMysTrade) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *BotStockMysTrade) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *BotStockMysTrade) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *BotStockMysTrade) GetOrderMoney() string { + if x != nil { + return x.OrderMoney + } + return "" +} + +func (x *BotStockMysTrade) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *BotStockMysTrade) GetCreateTime() string { + if x != nil { + return x.CreateTime + } + return "" +} + +func (x *BotStockMysTrade) GetUpdateTime() string { + if x != nil { + return x.UpdateTime + } + return "" +} + +func (x *BotStockMysTrade) GetOpenTime() string { + if x != nil { + return x.OpenTime + } + return "" +} + +func (x *BotStockMysTrade) GetClosingTime() string { + if x != nil { + return x.ClosingTime + } + return "" +} + +func (x *BotStockMysTrade) GetClosingCost() string { + if x != nil { + return x.ClosingCost + } + return "" +} + +func (x *BotStockMysTrade) GetFaceValue() string { + if x != nil { + return x.FaceValue + } + return "" +} + +func (x *BotStockMysTrade) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *BotStockMysTrade) GetKeepDecimal() string { + if x != nil { + return x.KeepDecimal + } + return "" +} + +func (x *BotStockMysTrade) GetStockName() string { + if x != nil { + return x.StockName + } + return "" +} + +func (x *BotStockMysTrade) GetNumericCode() string { + if x != nil { + return x.NumericCode + } + return "" +} + +type UpdateMysOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id + StopType int64 `protobuf:"varint,2,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,3,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,4,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 +} + +func (x *UpdateMysOrderRequest) Reset() { + *x = UpdateMysOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateMysOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateMysOrderRequest) ProtoMessage() {} + +func (x *UpdateMysOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateMysOrderRequest.ProtoReflect.Descriptor instead. +func (*UpdateMysOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareMys_proto_rawDescGZIP(), []int{4} +} + +func (x *UpdateMysOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *UpdateMysOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *UpdateMysOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *UpdateMysOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +type ShareMysOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + StockId string `protobuf:"bytes,1,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票Code + TradeType int64 `protobuf:"varint,2,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型:1买入,2卖出 + DealType int64 `protobuf:"varint,3,opt,name=dealType,proto3" json:"dealType,omitempty"` // 委托方式:1限价,2市价 + LimitPrice string `protobuf:"bytes,4,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,5,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + MarketMoney string `protobuf:"bytes,6,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderNumber string `protobuf:"bytes,7,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + ServiceCost string `protobuf:"bytes,8,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 手续费 + StopType int64 `protobuf:"varint,9,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止损止盈设置:1无设置,2止损止盈 + StopLossPrice string `protobuf:"bytes,10,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,11,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止损 + PryNum string `protobuf:"bytes,12,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 +} + +func (x *ShareMysOrderRequest) Reset() { + *x = ShareMysOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ShareMysOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ShareMysOrderRequest) ProtoMessage() {} + +func (x *ShareMysOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ShareMysOrderRequest.ProtoReflect.Descriptor instead. +func (*ShareMysOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareMys_proto_rawDescGZIP(), []int{5} +} + +func (x *ShareMysOrderRequest) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *ShareMysOrderRequest) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *ShareMysOrderRequest) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *ShareMysOrderRequest) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *ShareMysOrderRequest) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *ShareMysOrderRequest) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *ShareMysOrderRequest) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *ShareMysOrderRequest) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *ShareMysOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *ShareMysOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *ShareMysOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *ShareMysOrderRequest) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +type MysOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *ShareMysResult `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *MysOrderReply) Reset() { + *x = MysOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MysOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MysOrderReply) ProtoMessage() {} + +func (x *MysOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MysOrderReply.ProtoReflect.Descriptor instead. +func (*MysOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareMys_proto_rawDescGZIP(), []int{6} +} + +func (x *MysOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *MysOrderReply) GetData() *ShareMysResult { + if x != nil { + return x.Data + } + return nil +} + +func (x *MysOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type ShareMysResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id +} + +func (x *ShareMysResult) Reset() { + *x = ShareMysResult{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ShareMysResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ShareMysResult) ProtoMessage() {} + +func (x *ShareMysResult) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ShareMysResult.ProtoReflect.Descriptor instead. +func (*ShareMysResult) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareMys_proto_rawDescGZIP(), []int{7} +} + +func (x *ShareMysResult) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type CancelMysOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID +} + +func (x *CancelMysOrderRequest) Reset() { + *x = CancelMysOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CancelMysOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CancelMysOrderRequest) ProtoMessage() {} + +func (x *CancelMysOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CancelMysOrderRequest.ProtoReflect.Descriptor instead. +func (*CancelMysOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareMys_proto_rawDescGZIP(), []int{8} +} + +func (x *CancelMysOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type AllMysOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *AllMysOrderRequest) Reset() { + *x = AllMysOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllMysOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllMysOrderRequest) ProtoMessage() {} + +func (x *AllMysOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllMysOrderRequest.ProtoReflect.Descriptor instead. +func (*AllMysOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareMys_proto_rawDescGZIP(), []int{9} +} + +type AllMysOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *AllMysOrderReply) Reset() { + *x = AllMysOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllMysOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllMysOrderReply) ProtoMessage() {} + +func (x *AllMysOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareMys_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllMysOrderReply.ProtoReflect.Descriptor instead. +func (*AllMysOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareMys_proto_rawDescGZIP(), []int{10} +} + +func (x *AllMysOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *AllMysOrderReply) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +func (x *AllMysOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_matchmaking_v1_share_shareMys_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_share_shareMys_proto_rawDesc = []byte{ + 0x0a, 0x23, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x4d, 0x79, 0x73, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0x6e, 0x0a, 0x1a, 0x47, 0x65, 0x74, 0x4d, 0x79, 0x73, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, + 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x22, 0x82, 0x01, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, + 0x6f, 0x63, 0x6b, 0x4d, 0x79, 0x73, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, + 0x63, 0x6f, 0x64, 0x65, 0x12, 0x38, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x4d, 0x79, 0x73, 0x54, + 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, + 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xa6, 0x01, 0x0a, 0x14, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x4d, 0x79, 0x73, 0x54, 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, + 0x61, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, + 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x34, 0x0a, 0x04, 0x64, + 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x6d, 0x61, 0x74, 0x63, + 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x53, 0x74, + 0x6f, 0x63, 0x6b, 0x4d, 0x79, 0x73, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x04, 0x64, 0x61, 0x74, + 0x61, 0x12, 0x1e, 0x0a, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, + 0x74, 0x22, 0xc0, 0x06, 0x0a, 0x10, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x4d, 0x79, + 0x73, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, + 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, + 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, + 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, + 0x54, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, + 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, + 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x65, 0x61, 0x6c, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x64, 0x65, 0x61, 0x6c, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6c, 0x6f, 0x73, + 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, + 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, + 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, + 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, + 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, + 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0c, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, + 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, + 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, + 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, 0x6f, 0x6e, + 0x65, 0x79, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x10, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1e, 0x0a, 0x0a, + 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x11, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1e, 0x0a, 0x0a, + 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x12, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, + 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x13, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, + 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, + 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, + 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, + 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x15, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, + 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x16, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x72, + 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x17, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, 0x79, 0x4e, + 0x75, 0x6d, 0x12, 0x20, 0x0a, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, 0x6d, 0x61, + 0x6c, 0x18, 0x18, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, + 0x69, 0x6d, 0x61, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x4e, 0x61, 0x6d, + 0x65, 0x18, 0x19, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x4e, 0x61, + 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x69, 0x63, 0x43, 0x6f, 0x64, + 0x65, 0x18, 0x1a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x69, 0x63, + 0x43, 0x6f, 0x64, 0x65, 0x22, 0x97, 0x01, 0x0a, 0x15, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, + 0x79, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, + 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, + 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, + 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, 0x6f, + 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x74, + 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x22, 0x90, + 0x03, 0x0a, 0x14, 0x53, 0x68, 0x61, 0x72, 0x65, 0x4d, 0x79, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, + 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, + 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, + 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, + 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, + 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x06, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, + 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x07, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, + 0x72, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, + 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, + 0x6f, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, + 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, + 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, + 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x72, 0x79, + 0x4e, 0x75, 0x6d, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, + 0x6d, 0x22, 0x71, 0x0a, 0x0d, 0x4d, 0x79, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, + 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x32, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x4d, 0x79, 0x73, 0x52, 0x65, + 0x73, 0x75, 0x6c, 0x74, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x22, 0x2a, 0x0a, 0x0e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x4d, 0x79, 0x73, + 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, + 0x22, 0x31, 0x0a, 0x15, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x4d, 0x79, 0x73, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x49, 0x64, 0x22, 0x14, 0x0a, 0x12, 0x41, 0x6c, 0x6c, 0x4d, 0x79, 0x73, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x54, 0x0a, 0x10, 0x41, 0x6c, 0x6c, + 0x4d, 0x79, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, + 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, + 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, + 0xca, 0x06, 0x0a, 0x08, 0x53, 0x68, 0x61, 0x72, 0x65, 0x4d, 0x79, 0x73, 0x12, 0x92, 0x01, 0x0a, + 0x13, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x4d, 0x79, 0x73, 0x54, + 0x72, 0x61, 0x64, 0x65, 0x12, 0x2a, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x4d, 0x79, 0x73, 0x42, 0x6f, 0x74, 0x53, + 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x28, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, + 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x4d, 0x79, 0x73, + 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x25, 0x82, 0xd3, 0xe4, 0x93, + 0x02, 0x1f, 0x3a, 0x01, 0x2a, 0x22, 0x1a, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, + 0x61, 0x72, 0x65, 0x6d, 0x79, 0x73, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x6c, 0x69, 0x73, + 0x74, 0x12, 0x87, 0x01, 0x0a, 0x12, 0x53, 0x68, 0x61, 0x72, 0x65, 0x4d, 0x79, 0x73, 0x50, 0x6c, + 0x61, 0x63, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x24, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x4d, + 0x79, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, + 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x4d, 0x79, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2c, 0x82, + 0xd3, 0xe4, 0x93, 0x02, 0x26, 0x3a, 0x01, 0x2a, 0x22, 0x21, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x6d, 0x79, 0x73, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, + 0x70, 0x6c, 0x61, 0x63, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x8a, 0x01, 0x0a, 0x13, + 0x53, 0x68, 0x61, 0x72, 0x65, 0x4d, 0x79, 0x73, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x12, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, + 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x79, 0x73, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x79, 0x73, 0x4f, + 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93, 0x02, + 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, + 0x72, 0x65, 0x6d, 0x79, 0x73, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x75, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x83, 0x01, 0x0a, 0x10, 0x53, 0x68, 0x61, + 0x72, 0x65, 0x4d, 0x79, 0x73, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x25, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, + 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x4d, 0x79, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x79, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x29, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x23, 0x3a, 0x01, 0x2a, 0x22, 0x1e, + 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x6d, 0x79, 0x73, 0x2f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x8a, + 0x01, 0x0a, 0x13, 0x53, 0x68, 0x61, 0x72, 0x65, 0x4d, 0x79, 0x73, 0x41, 0x6c, 0x6c, 0x50, 0x6f, + 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x22, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, + 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x4d, 0x79, 0x73, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x4d, + 0x79, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2d, 0x82, 0xd3, + 0xe4, 0x93, 0x02, 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x6d, 0x79, 0x73, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x61, + 0x6c, 0x6c, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x7f, 0x0a, 0x0e, 0x53, + 0x68, 0x61, 0x72, 0x65, 0x4d, 0x79, 0x73, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x12, 0x25, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, + 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x4d, 0x79, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x79, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x27, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x21, 0x3a, 0x01, 0x2a, 0x22, 0x1c, + 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x6d, 0x79, 0x73, 0x2f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x42, 0x2a, 0x5a, 0x28, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x73, 0x79, 0x73, 0x74, + 0x65, 0x6d, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_share_shareMys_proto_rawDescOnce sync.Once + file_matchmaking_v1_share_shareMys_proto_rawDescData = file_matchmaking_v1_share_shareMys_proto_rawDesc +) + +func file_matchmaking_v1_share_shareMys_proto_rawDescGZIP() []byte { + file_matchmaking_v1_share_shareMys_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_share_shareMys_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_share_shareMys_proto_rawDescData) + }) + return file_matchmaking_v1_share_shareMys_proto_rawDescData +} + +var file_matchmaking_v1_share_shareMys_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_matchmaking_v1_share_shareMys_proto_goTypes = []any{ + (*GetMysBotStockTradeRequest)(nil), // 0: matchmaking.v1.GetMysBotStockTradeRequest + (*GetBotStockMysTradeReply)(nil), // 1: matchmaking.v1.GetBotStockMysTradeReply + (*BotStockMysTradeData)(nil), // 2: matchmaking.v1.BotStockMysTradeData + (*BotStockMysTrade)(nil), // 3: matchmaking.v1.BotStockMysTrade + (*UpdateMysOrderRequest)(nil), // 4: matchmaking.v1.UpdateMysOrderRequest + (*ShareMysOrderRequest)(nil), // 5: matchmaking.v1.ShareMysOrderRequest + (*MysOrderReply)(nil), // 6: matchmaking.v1.MysOrderReply + (*ShareMysResult)(nil), // 7: matchmaking.v1.ShareMysResult + (*CancelMysOrderRequest)(nil), // 8: matchmaking.v1.CancelMysOrderRequest + (*AllMysOrderRequest)(nil), // 9: matchmaking.v1.AllMysOrderRequest + (*AllMysOrderReply)(nil), // 10: matchmaking.v1.AllMysOrderReply +} +var file_matchmaking_v1_share_shareMys_proto_depIdxs = []int32{ + 2, // 0: matchmaking.v1.GetBotStockMysTradeReply.data:type_name -> matchmaking.v1.BotStockMysTradeData + 3, // 1: matchmaking.v1.BotStockMysTradeData.data:type_name -> matchmaking.v1.BotStockMysTrade + 7, // 2: matchmaking.v1.MysOrderReply.data:type_name -> matchmaking.v1.ShareMysResult + 0, // 3: matchmaking.v1.ShareMys.GetBotStockMysTrade:input_type -> matchmaking.v1.GetMysBotStockTradeRequest + 5, // 4: matchmaking.v1.ShareMys.ShareMysPlaceOrder:input_type -> matchmaking.v1.ShareMysOrderRequest + 4, // 5: matchmaking.v1.ShareMys.ShareMysUpdateOrder:input_type -> matchmaking.v1.UpdateMysOrderRequest + 8, // 6: matchmaking.v1.ShareMys.ShareMysPosition:input_type -> matchmaking.v1.CancelMysOrderRequest + 9, // 7: matchmaking.v1.ShareMys.ShareMysAllPosition:input_type -> matchmaking.v1.AllMysOrderRequest + 8, // 8: matchmaking.v1.ShareMys.ShareMysCancel:input_type -> matchmaking.v1.CancelMysOrderRequest + 1, // 9: matchmaking.v1.ShareMys.GetBotStockMysTrade:output_type -> matchmaking.v1.GetBotStockMysTradeReply + 6, // 10: matchmaking.v1.ShareMys.ShareMysPlaceOrder:output_type -> matchmaking.v1.MysOrderReply + 6, // 11: matchmaking.v1.ShareMys.ShareMysUpdateOrder:output_type -> matchmaking.v1.MysOrderReply + 6, // 12: matchmaking.v1.ShareMys.ShareMysPosition:output_type -> matchmaking.v1.MysOrderReply + 10, // 13: matchmaking.v1.ShareMys.ShareMysAllPosition:output_type -> matchmaking.v1.AllMysOrderReply + 6, // 14: matchmaking.v1.ShareMys.ShareMysCancel:output_type -> matchmaking.v1.MysOrderReply + 9, // [9:15] is the sub-list for method output_type + 3, // [3:9] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_share_shareMys_proto_init() } +func file_matchmaking_v1_share_shareMys_proto_init() { + if File_matchmaking_v1_share_shareMys_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_matchmaking_v1_share_shareMys_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*GetMysBotStockTradeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareMys_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*GetBotStockMysTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareMys_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*BotStockMysTradeData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareMys_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*BotStockMysTrade); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareMys_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*UpdateMysOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareMys_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*ShareMysOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareMys_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*MysOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareMys_proto_msgTypes[7].Exporter = func(v any, i int) any { + switch v := v.(*ShareMysResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareMys_proto_msgTypes[8].Exporter = func(v any, i int) any { + switch v := v.(*CancelMysOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareMys_proto_msgTypes[9].Exporter = func(v any, i int) any { + switch v := v.(*AllMysOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareMys_proto_msgTypes[10].Exporter = func(v any, i int) any { + switch v := v.(*AllMysOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_share_shareMys_proto_rawDesc, + NumEnums: 0, + NumMessages: 11, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_matchmaking_v1_share_shareMys_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_share_shareMys_proto_depIdxs, + MessageInfos: file_matchmaking_v1_share_shareMys_proto_msgTypes, + }.Build() + File_matchmaking_v1_share_shareMys_proto = out.File + file_matchmaking_v1_share_shareMys_proto_rawDesc = nil + file_matchmaking_v1_share_shareMys_proto_goTypes = nil + file_matchmaking_v1_share_shareMys_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/share/shareMys.proto b/api/matchmaking/v1/share/shareMys.proto new file mode 100644 index 0000000..ec62622 --- /dev/null +++ b/api/matchmaking/v1/share/shareMys.proto @@ -0,0 +1,146 @@ +syntax = "proto3"; + +package matchmaking.v1; + +import "google/api/annotations.proto"; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +service ShareMys { + // GetBotStockMysTrade 马股列表查询 + rpc GetBotStockMysTrade(GetMysBotStockTradeRequest)returns(GetBotStockMysTradeReply){ + option (google.api.http) = { + post:"/order_sharemys/share_list", + body:"*", + }; + } + // ShareMysPlaceOrder 马股下单 + rpc ShareMysPlaceOrder(ShareMysOrderRequest)returns(MysOrderReply) { + option (google.api.http) = { + post: "/order_sharemys/share_place_order", + body: "*", + }; + } + // ShareMysUpdateOrder 马股设置止盈止损 + rpc ShareMysUpdateOrder(UpdateMysOrderRequest)returns(MysOrderReply){ + option (google.api.http) = { + post:"/order_sharemys/share_update_order", + body:"*", + }; + } + // ShareMysPosition 马股平仓 + rpc ShareMysPosition(CancelMysOrderRequest)returns(MysOrderReply){ + option (google.api.http) = { + post:"/order_sharemys/share_position", + body:"*", + }; + } + // ShareMysAllPosition 马股一键平仓 + rpc ShareMysAllPosition(AllMysOrderRequest)returns(AllMysOrderReply){ + option (google.api.http) = { + post:"/order_sharemys/share_all_position", + body:"*", + }; + } + // ShareMysCancel 马股撤单 + rpc ShareMysCancel(CancelMysOrderRequest)returns(MysOrderReply){ + option (google.api.http) = { + post:"/order_sharemys/share_cancel", + body:"*", + }; + } +} + +message GetMysBotStockTradeRequest{ + int64 status =1;// 状态码 + int64 pageSize =2; // 每页显示条数 + int64 pageCount =3;// 开始的位置 +} + +message GetBotStockMysTradeReply{ + int64 code =1;// 状态码 + BotStockMysTradeData data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message BotStockMysTradeData{ + int64 pageSize =1; // 每页显示条数 + int64 pageCount =2;// 开始的位置 + repeated BotStockMysTrade data =3;// 返回结果 + int64 totalCount =4;// 总数据 +} + +message BotStockMysTrade{ + string orderId =1;// 订单ID + string stockId =2;// 股票代码 + int64 tradeType =3;// 交易类型 + int64 dealType =4;// 交易方式 + string limitPrice =5;// 限价 + string marketPrice =6;// 市价 + string dealPrice =7;// 开仓价 + string closingPrice =8;// 平仓价 + string orderNumber =9;// 订单数量 + int64 stopType =10;// 止盈止损 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string serviceCost =13;// 开仓手续费 + string marketMoney =14;// 订单金额 + string orderMoney =15;// 订单总金额 + int64 status =16;// 订单状态 + string createTime =17;// 订单创建时间 + string updateTime =18;// 订单更新时间 + string openTime =19;// 订单开仓时间 + string closingTime =20;// 订单平仓时间 + string closingCost =21;// 订单平仓手续费 + string faceValue =22;// 面值 + string pryNum =23;// 杠杆 + string keepDecimal =24;// 保留小数位 + string stockName =25;// 股票名称 + string numericCode =26;// 股票数字代码 +} + +message UpdateMysOrderRequest{ + string orderId =1;// 订单Id + int64 stopType =2;// 止盈止损 + string stopLossPrice =3;// 止损 + string stopWinPrice =4;// 止盈 +} + +message ShareMysOrderRequest{ + string stockId =1;// 股票Code + int64 tradeType =2;// 交易类型:1买入,2卖出 + int64 dealType =3;// 委托方式:1限价,2市价 + string limitPrice =4;// 限价 + string marketPrice =5;// 市价 + string marketMoney =6;// 订单金额 + string orderNumber =7;// 订单数量 + string serviceCost =8;// 手续费 + int64 stopType =9;// 止损止盈设置:1无设置,2止损止盈 + string stopLossPrice =10;// 止损 + string stopWinPrice =11;// 止损 + string pryNum =12;// 杠杆 +} + +message MysOrderReply{ + int64 code =1;// 状态码 + ShareMysResult data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message ShareMysResult { + string orderId =1;// 订单Id +} + +message CancelMysOrderRequest{ + string orderId =1;// 订单ID +} + +message AllMysOrderRequest{ + +} + +message AllMysOrderReply{ + int64 code =1;// 状态码 + string data =2;// 返回结果 + string message =3;// 返回消息提示 +} diff --git a/api/matchmaking/v1/share/shareMys_grpc.pb.go b/api/matchmaking/v1/share/shareMys_grpc.pb.go new file mode 100644 index 0000000..6cc2b83 --- /dev/null +++ b/api/matchmaking/v1/share/shareMys_grpc.pb.go @@ -0,0 +1,312 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareMys.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + ShareMys_GetBotStockMysTrade_FullMethodName = "/matchmaking.v1.ShareMys/GetBotStockMysTrade" + ShareMys_ShareMysPlaceOrder_FullMethodName = "/matchmaking.v1.ShareMys/ShareMysPlaceOrder" + ShareMys_ShareMysUpdateOrder_FullMethodName = "/matchmaking.v1.ShareMys/ShareMysUpdateOrder" + ShareMys_ShareMysPosition_FullMethodName = "/matchmaking.v1.ShareMys/ShareMysPosition" + ShareMys_ShareMysAllPosition_FullMethodName = "/matchmaking.v1.ShareMys/ShareMysAllPosition" + ShareMys_ShareMysCancel_FullMethodName = "/matchmaking.v1.ShareMys/ShareMysCancel" +) + +// ShareMysClient is the client API for ShareMys service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ShareMysClient interface { + // GetBotStockMysTrade 马股列表查询 + GetBotStockMysTrade(ctx context.Context, in *GetMysBotStockTradeRequest, opts ...grpc.CallOption) (*GetBotStockMysTradeReply, error) + // ShareMysPlaceOrder 马股下单 + ShareMysPlaceOrder(ctx context.Context, in *ShareMysOrderRequest, opts ...grpc.CallOption) (*MysOrderReply, error) + // ShareMysUpdateOrder 马股设置止盈止损 + ShareMysUpdateOrder(ctx context.Context, in *UpdateMysOrderRequest, opts ...grpc.CallOption) (*MysOrderReply, error) + // ShareMysPosition 马股平仓 + ShareMysPosition(ctx context.Context, in *CancelMysOrderRequest, opts ...grpc.CallOption) (*MysOrderReply, error) + // ShareMysAllPosition 马股一键平仓 + ShareMysAllPosition(ctx context.Context, in *AllMysOrderRequest, opts ...grpc.CallOption) (*AllMysOrderReply, error) + // ShareMysCancel 马股撤单 + ShareMysCancel(ctx context.Context, in *CancelMysOrderRequest, opts ...grpc.CallOption) (*MysOrderReply, error) +} + +type shareMysClient struct { + cc grpc.ClientConnInterface +} + +func NewShareMysClient(cc grpc.ClientConnInterface) ShareMysClient { + return &shareMysClient{cc} +} + +func (c *shareMysClient) GetBotStockMysTrade(ctx context.Context, in *GetMysBotStockTradeRequest, opts ...grpc.CallOption) (*GetBotStockMysTradeReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetBotStockMysTradeReply) + err := c.cc.Invoke(ctx, ShareMys_GetBotStockMysTrade_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareMysClient) ShareMysPlaceOrder(ctx context.Context, in *ShareMysOrderRequest, opts ...grpc.CallOption) (*MysOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(MysOrderReply) + err := c.cc.Invoke(ctx, ShareMys_ShareMysPlaceOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareMysClient) ShareMysUpdateOrder(ctx context.Context, in *UpdateMysOrderRequest, opts ...grpc.CallOption) (*MysOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(MysOrderReply) + err := c.cc.Invoke(ctx, ShareMys_ShareMysUpdateOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareMysClient) ShareMysPosition(ctx context.Context, in *CancelMysOrderRequest, opts ...grpc.CallOption) (*MysOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(MysOrderReply) + err := c.cc.Invoke(ctx, ShareMys_ShareMysPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareMysClient) ShareMysAllPosition(ctx context.Context, in *AllMysOrderRequest, opts ...grpc.CallOption) (*AllMysOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AllMysOrderReply) + err := c.cc.Invoke(ctx, ShareMys_ShareMysAllPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareMysClient) ShareMysCancel(ctx context.Context, in *CancelMysOrderRequest, opts ...grpc.CallOption) (*MysOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(MysOrderReply) + err := c.cc.Invoke(ctx, ShareMys_ShareMysCancel_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ShareMysServer is the server API for ShareMys service. +// All implementations must embed UnimplementedShareMysServer +// for forward compatibility +type ShareMysServer interface { + // GetBotStockMysTrade 马股列表查询 + GetBotStockMysTrade(context.Context, *GetMysBotStockTradeRequest) (*GetBotStockMysTradeReply, error) + // ShareMysPlaceOrder 马股下单 + ShareMysPlaceOrder(context.Context, *ShareMysOrderRequest) (*MysOrderReply, error) + // ShareMysUpdateOrder 马股设置止盈止损 + ShareMysUpdateOrder(context.Context, *UpdateMysOrderRequest) (*MysOrderReply, error) + // ShareMysPosition 马股平仓 + ShareMysPosition(context.Context, *CancelMysOrderRequest) (*MysOrderReply, error) + // ShareMysAllPosition 马股一键平仓 + ShareMysAllPosition(context.Context, *AllMysOrderRequest) (*AllMysOrderReply, error) + // ShareMysCancel 马股撤单 + ShareMysCancel(context.Context, *CancelMysOrderRequest) (*MysOrderReply, error) + mustEmbedUnimplementedShareMysServer() +} + +// UnimplementedShareMysServer must be embedded to have forward compatible implementations. +type UnimplementedShareMysServer struct { +} + +func (UnimplementedShareMysServer) GetBotStockMysTrade(context.Context, *GetMysBotStockTradeRequest) (*GetBotStockMysTradeReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBotStockMysTrade not implemented") +} +func (UnimplementedShareMysServer) ShareMysPlaceOrder(context.Context, *ShareMysOrderRequest) (*MysOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareMysPlaceOrder not implemented") +} +func (UnimplementedShareMysServer) ShareMysUpdateOrder(context.Context, *UpdateMysOrderRequest) (*MysOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareMysUpdateOrder not implemented") +} +func (UnimplementedShareMysServer) ShareMysPosition(context.Context, *CancelMysOrderRequest) (*MysOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareMysPosition not implemented") +} +func (UnimplementedShareMysServer) ShareMysAllPosition(context.Context, *AllMysOrderRequest) (*AllMysOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareMysAllPosition not implemented") +} +func (UnimplementedShareMysServer) ShareMysCancel(context.Context, *CancelMysOrderRequest) (*MysOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareMysCancel not implemented") +} +func (UnimplementedShareMysServer) mustEmbedUnimplementedShareMysServer() {} + +// UnsafeShareMysServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ShareMysServer will +// result in compilation errors. +type UnsafeShareMysServer interface { + mustEmbedUnimplementedShareMysServer() +} + +func RegisterShareMysServer(s grpc.ServiceRegistrar, srv ShareMysServer) { + s.RegisterService(&ShareMys_ServiceDesc, srv) +} + +func _ShareMys_GetBotStockMysTrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetMysBotStockTradeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareMysServer).GetBotStockMysTrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareMys_GetBotStockMysTrade_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareMysServer).GetBotStockMysTrade(ctx, req.(*GetMysBotStockTradeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareMys_ShareMysPlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ShareMysOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareMysServer).ShareMysPlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareMys_ShareMysPlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareMysServer).ShareMysPlaceOrder(ctx, req.(*ShareMysOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareMys_ShareMysUpdateOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateMysOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareMysServer).ShareMysUpdateOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareMys_ShareMysUpdateOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareMysServer).ShareMysUpdateOrder(ctx, req.(*UpdateMysOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareMys_ShareMysPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelMysOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareMysServer).ShareMysPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareMys_ShareMysPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareMysServer).ShareMysPosition(ctx, req.(*CancelMysOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareMys_ShareMysAllPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AllMysOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareMysServer).ShareMysAllPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareMys_ShareMysAllPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareMysServer).ShareMysAllPosition(ctx, req.(*AllMysOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareMys_ShareMysCancel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelMysOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareMysServer).ShareMysCancel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareMys_ShareMysCancel_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareMysServer).ShareMysCancel(ctx, req.(*CancelMysOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// ShareMys_ServiceDesc is the grpc.ServiceDesc for ShareMys service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ShareMys_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "matchmaking.v1.ShareMys", + HandlerType: (*ShareMysServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetBotStockMysTrade", + Handler: _ShareMys_GetBotStockMysTrade_Handler, + }, + { + MethodName: "ShareMysPlaceOrder", + Handler: _ShareMys_ShareMysPlaceOrder_Handler, + }, + { + MethodName: "ShareMysUpdateOrder", + Handler: _ShareMys_ShareMysUpdateOrder_Handler, + }, + { + MethodName: "ShareMysPosition", + Handler: _ShareMys_ShareMysPosition_Handler, + }, + { + MethodName: "ShareMysAllPosition", + Handler: _ShareMys_ShareMysAllPosition_Handler, + }, + { + MethodName: "ShareMysCancel", + Handler: _ShareMys_ShareMysCancel_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "matchmaking/v1/share/shareMys.proto", +} diff --git a/api/matchmaking/v1/share/shareMys_http.pb.go b/api/matchmaking/v1/share/shareMys_http.pb.go new file mode 100644 index 0000000..d56e151 --- /dev/null +++ b/api/matchmaking/v1/share/shareMys_http.pb.go @@ -0,0 +1,279 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.3 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareMys.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationShareMysGetBotStockMysTrade = "/matchmaking.v1.ShareMys/GetBotStockMysTrade" +const OperationShareMysShareMysAllPosition = "/matchmaking.v1.ShareMys/ShareMysAllPosition" +const OperationShareMysShareMysCancel = "/matchmaking.v1.ShareMys/ShareMysCancel" +const OperationShareMysShareMysPlaceOrder = "/matchmaking.v1.ShareMys/ShareMysPlaceOrder" +const OperationShareMysShareMysPosition = "/matchmaking.v1.ShareMys/ShareMysPosition" +const OperationShareMysShareMysUpdateOrder = "/matchmaking.v1.ShareMys/ShareMysUpdateOrder" + +type ShareMysHTTPServer interface { + // GetBotStockMysTrade GetBotStockMysTrade 马股列表查询 + GetBotStockMysTrade(context.Context, *GetMysBotStockTradeRequest) (*GetBotStockMysTradeReply, error) + // ShareMysAllPosition ShareMysAllPosition 马股一键平仓 + ShareMysAllPosition(context.Context, *AllMysOrderRequest) (*AllMysOrderReply, error) + // ShareMysCancel ShareMysCancel 马股撤单 + ShareMysCancel(context.Context, *CancelMysOrderRequest) (*MysOrderReply, error) + // ShareMysPlaceOrder ShareMysPlaceOrder 马股下单 + ShareMysPlaceOrder(context.Context, *ShareMysOrderRequest) (*MysOrderReply, error) + // ShareMysPosition ShareMysPosition 马股平仓 + ShareMysPosition(context.Context, *CancelMysOrderRequest) (*MysOrderReply, error) + // ShareMysUpdateOrder ShareMysUpdateOrder 马股设置止盈止损 + ShareMysUpdateOrder(context.Context, *UpdateMysOrderRequest) (*MysOrderReply, error) +} + +func RegisterShareMysHTTPServer(s *http.Server, srv ShareMysHTTPServer) { + r := s.Route("/") + r.POST("/order_sharemys/share_list", _ShareMys_GetBotStockMysTrade0_HTTP_Handler(srv)) + r.POST("/order_sharemys/share_place_order", _ShareMys_ShareMysPlaceOrder0_HTTP_Handler(srv)) + r.POST("/order_sharemys/share_update_order", _ShareMys_ShareMysUpdateOrder0_HTTP_Handler(srv)) + r.POST("/order_sharemys/share_position", _ShareMys_ShareMysPosition0_HTTP_Handler(srv)) + r.POST("/order_sharemys/share_all_position", _ShareMys_ShareMysAllPosition0_HTTP_Handler(srv)) + r.POST("/order_sharemys/share_cancel", _ShareMys_ShareMysCancel0_HTTP_Handler(srv)) +} + +func _ShareMys_GetBotStockMysTrade0_HTTP_Handler(srv ShareMysHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetMysBotStockTradeRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareMysGetBotStockMysTrade) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.GetBotStockMysTrade(ctx, req.(*GetMysBotStockTradeRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetBotStockMysTradeReply) + return ctx.Result(200, reply) + } +} + +func _ShareMys_ShareMysPlaceOrder0_HTTP_Handler(srv ShareMysHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in ShareMysOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareMysShareMysPlaceOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareMysPlaceOrder(ctx, req.(*ShareMysOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*MysOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareMys_ShareMysUpdateOrder0_HTTP_Handler(srv ShareMysHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in UpdateMysOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareMysShareMysUpdateOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareMysUpdateOrder(ctx, req.(*UpdateMysOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*MysOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareMys_ShareMysPosition0_HTTP_Handler(srv ShareMysHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelMysOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareMysShareMysPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareMysPosition(ctx, req.(*CancelMysOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*MysOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareMys_ShareMysAllPosition0_HTTP_Handler(srv ShareMysHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in AllMysOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareMysShareMysAllPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareMysAllPosition(ctx, req.(*AllMysOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*AllMysOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareMys_ShareMysCancel0_HTTP_Handler(srv ShareMysHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelMysOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareMysShareMysCancel) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareMysCancel(ctx, req.(*CancelMysOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*MysOrderReply) + return ctx.Result(200, reply) + } +} + +type ShareMysHTTPClient interface { + GetBotStockMysTrade(ctx context.Context, req *GetMysBotStockTradeRequest, opts ...http.CallOption) (rsp *GetBotStockMysTradeReply, err error) + ShareMysAllPosition(ctx context.Context, req *AllMysOrderRequest, opts ...http.CallOption) (rsp *AllMysOrderReply, err error) + ShareMysCancel(ctx context.Context, req *CancelMysOrderRequest, opts ...http.CallOption) (rsp *MysOrderReply, err error) + ShareMysPlaceOrder(ctx context.Context, req *ShareMysOrderRequest, opts ...http.CallOption) (rsp *MysOrderReply, err error) + ShareMysPosition(ctx context.Context, req *CancelMysOrderRequest, opts ...http.CallOption) (rsp *MysOrderReply, err error) + ShareMysUpdateOrder(ctx context.Context, req *UpdateMysOrderRequest, opts ...http.CallOption) (rsp *MysOrderReply, err error) +} + +type ShareMysHTTPClientImpl struct { + cc *http.Client +} + +func NewShareMysHTTPClient(client *http.Client) ShareMysHTTPClient { + return &ShareMysHTTPClientImpl{client} +} + +func (c *ShareMysHTTPClientImpl) GetBotStockMysTrade(ctx context.Context, in *GetMysBotStockTradeRequest, opts ...http.CallOption) (*GetBotStockMysTradeReply, error) { + var out GetBotStockMysTradeReply + pattern := "/order_sharemys/share_list" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareMysGetBotStockMysTrade)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareMysHTTPClientImpl) ShareMysAllPosition(ctx context.Context, in *AllMysOrderRequest, opts ...http.CallOption) (*AllMysOrderReply, error) { + var out AllMysOrderReply + pattern := "/order_sharemys/share_all_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareMysShareMysAllPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareMysHTTPClientImpl) ShareMysCancel(ctx context.Context, in *CancelMysOrderRequest, opts ...http.CallOption) (*MysOrderReply, error) { + var out MysOrderReply + pattern := "/order_sharemys/share_cancel" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareMysShareMysCancel)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareMysHTTPClientImpl) ShareMysPlaceOrder(ctx context.Context, in *ShareMysOrderRequest, opts ...http.CallOption) (*MysOrderReply, error) { + var out MysOrderReply + pattern := "/order_sharemys/share_place_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareMysShareMysPlaceOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareMysHTTPClientImpl) ShareMysPosition(ctx context.Context, in *CancelMysOrderRequest, opts ...http.CallOption) (*MysOrderReply, error) { + var out MysOrderReply + pattern := "/order_sharemys/share_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareMysShareMysPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareMysHTTPClientImpl) ShareMysUpdateOrder(ctx context.Context, in *UpdateMysOrderRequest, opts ...http.CallOption) (*MysOrderReply, error) { + var out MysOrderReply + pattern := "/order_sharemys/share_update_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareMysShareMysUpdateOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/api/matchmaking/v1/share/shareSgd.pb.go b/api/matchmaking/v1/share/shareSgd.pb.go new file mode 100644 index 0000000..93fb7d1 --- /dev/null +++ b/api/matchmaking/v1/share/shareSgd.pb.go @@ -0,0 +1,1327 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/share/shareSgd.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GetSgdBotStockTradeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status int64 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` // 状态码 + PageSize int64 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,3,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 +} + +func (x *GetSgdBotStockTradeRequest) Reset() { + *x = GetSgdBotStockTradeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetSgdBotStockTradeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetSgdBotStockTradeRequest) ProtoMessage() {} + +func (x *GetSgdBotStockTradeRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetSgdBotStockTradeRequest.ProtoReflect.Descriptor instead. +func (*GetSgdBotStockTradeRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareSgd_proto_rawDescGZIP(), []int{0} +} + +func (x *GetSgdBotStockTradeRequest) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *GetSgdBotStockTradeRequest) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *GetSgdBotStockTradeRequest) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +type GetBotStockSgdTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *BotStockSgdTradeReply `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *GetBotStockSgdTradeReply) Reset() { + *x = GetBotStockSgdTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotStockSgdTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotStockSgdTradeReply) ProtoMessage() {} + +func (x *GetBotStockSgdTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotStockSgdTradeReply.ProtoReflect.Descriptor instead. +func (*GetBotStockSgdTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareSgd_proto_rawDescGZIP(), []int{1} +} + +func (x *GetBotStockSgdTradeReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *GetBotStockSgdTradeReply) GetData() *BotStockSgdTradeReply { + if x != nil { + return x.Data + } + return nil +} + +func (x *GetBotStockSgdTradeReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type BotStockSgdTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PageSize int64 `protobuf:"varint,1,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,2,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + Data []*BotStockSgdTrade `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty"` // 返回结果 + TotalCount int64 `protobuf:"varint,4,opt,name=totalCount,proto3" json:"totalCount,omitempty"` // 总数据 +} + +func (x *BotStockSgdTradeReply) Reset() { + *x = BotStockSgdTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockSgdTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockSgdTradeReply) ProtoMessage() {} + +func (x *BotStockSgdTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockSgdTradeReply.ProtoReflect.Descriptor instead. +func (*BotStockSgdTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareSgd_proto_rawDescGZIP(), []int{2} +} + +func (x *BotStockSgdTradeReply) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *BotStockSgdTradeReply) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *BotStockSgdTradeReply) GetData() []*BotStockSgdTrade { + if x != nil { + return x.Data + } + return nil +} + +func (x *BotStockSgdTradeReply) GetTotalCount() int64 { + if x != nil { + return x.TotalCount + } + return 0 +} + +type BotStockSgdTrade struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID + StockId string `protobuf:"bytes,2,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票代码 + TradeType int64 `protobuf:"varint,3,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型 + DealType int64 `protobuf:"varint,4,opt,name=dealType,proto3" json:"dealType,omitempty"` // 交易方式 + LimitPrice string `protobuf:"bytes,5,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,6,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + DealPrice string `protobuf:"bytes,7,opt,name=dealPrice,proto3" json:"dealPrice,omitempty"` // 开仓价 + ClosingPrice string `protobuf:"bytes,8,opt,name=closingPrice,proto3" json:"closingPrice,omitempty"` // 平仓价 + OrderNumber string `protobuf:"bytes,9,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + ServiceCost string `protobuf:"bytes,13,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 开仓手续费 + MarketMoney string `protobuf:"bytes,14,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderMoney string `protobuf:"bytes,15,opt,name=orderMoney,proto3" json:"orderMoney,omitempty"` // 订单总金额 + Status int64 `protobuf:"varint,16,opt,name=status,proto3" json:"status,omitempty"` // 订单状态 + CreateTime string `protobuf:"bytes,17,opt,name=createTime,proto3" json:"createTime,omitempty"` // 订单创建时间 + UpdateTime string `protobuf:"bytes,18,opt,name=updateTime,proto3" json:"updateTime,omitempty"` // 订单更新时间 + OpenTime string `protobuf:"bytes,19,opt,name=openTime,proto3" json:"openTime,omitempty"` // 订单开仓时间 + ClosingTime string `protobuf:"bytes,20,opt,name=closingTime,proto3" json:"closingTime,omitempty"` // 订单平仓时间 + ClosingCost string `protobuf:"bytes,21,opt,name=closingCost,proto3" json:"closingCost,omitempty"` // 平仓手续费 + FaceValue string `protobuf:"bytes,22,opt,name=faceValue,proto3" json:"faceValue,omitempty"` // 面值 + PryNum string `protobuf:"bytes,23,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 + KeepDecimal string `protobuf:"bytes,24,opt,name=keepDecimal,proto3" json:"keepDecimal,omitempty"` // 保留小数位 + StockName string `protobuf:"bytes,25,opt,name=stockName,proto3" json:"stockName,omitempty"` // 股票名称 +} + +func (x *BotStockSgdTrade) Reset() { + *x = BotStockSgdTrade{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockSgdTrade) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockSgdTrade) ProtoMessage() {} + +func (x *BotStockSgdTrade) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockSgdTrade.ProtoReflect.Descriptor instead. +func (*BotStockSgdTrade) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareSgd_proto_rawDescGZIP(), []int{3} +} + +func (x *BotStockSgdTrade) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *BotStockSgdTrade) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *BotStockSgdTrade) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *BotStockSgdTrade) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *BotStockSgdTrade) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *BotStockSgdTrade) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *BotStockSgdTrade) GetDealPrice() string { + if x != nil { + return x.DealPrice + } + return "" +} + +func (x *BotStockSgdTrade) GetClosingPrice() string { + if x != nil { + return x.ClosingPrice + } + return "" +} + +func (x *BotStockSgdTrade) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *BotStockSgdTrade) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *BotStockSgdTrade) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *BotStockSgdTrade) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *BotStockSgdTrade) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *BotStockSgdTrade) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *BotStockSgdTrade) GetOrderMoney() string { + if x != nil { + return x.OrderMoney + } + return "" +} + +func (x *BotStockSgdTrade) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *BotStockSgdTrade) GetCreateTime() string { + if x != nil { + return x.CreateTime + } + return "" +} + +func (x *BotStockSgdTrade) GetUpdateTime() string { + if x != nil { + return x.UpdateTime + } + return "" +} + +func (x *BotStockSgdTrade) GetOpenTime() string { + if x != nil { + return x.OpenTime + } + return "" +} + +func (x *BotStockSgdTrade) GetClosingTime() string { + if x != nil { + return x.ClosingTime + } + return "" +} + +func (x *BotStockSgdTrade) GetClosingCost() string { + if x != nil { + return x.ClosingCost + } + return "" +} + +func (x *BotStockSgdTrade) GetFaceValue() string { + if x != nil { + return x.FaceValue + } + return "" +} + +func (x *BotStockSgdTrade) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *BotStockSgdTrade) GetKeepDecimal() string { + if x != nil { + return x.KeepDecimal + } + return "" +} + +func (x *BotStockSgdTrade) GetStockName() string { + if x != nil { + return x.StockName + } + return "" +} + +type ShareSgdOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + StockId string `protobuf:"bytes,1,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票Code + TradeType int64 `protobuf:"varint,2,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型:1买入,2卖出 + DealType int64 `protobuf:"varint,3,opt,name=dealType,proto3" json:"dealType,omitempty"` // 委托方式:1限价,2市价 + LimitPrice string `protobuf:"bytes,4,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,5,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + MarketMoney string `protobuf:"bytes,6,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderNumber string `protobuf:"bytes,7,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + ServiceCost string `protobuf:"bytes,8,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 手续费 + StopType int64 `protobuf:"varint,9,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止损止盈设置:1无设置,2止损止盈 + StopLossPrice string `protobuf:"bytes,10,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,11,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止损 + PryNum string `protobuf:"bytes,12,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 +} + +func (x *ShareSgdOrderRequest) Reset() { + *x = ShareSgdOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ShareSgdOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ShareSgdOrderRequest) ProtoMessage() {} + +func (x *ShareSgdOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ShareSgdOrderRequest.ProtoReflect.Descriptor instead. +func (*ShareSgdOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareSgd_proto_rawDescGZIP(), []int{4} +} + +func (x *ShareSgdOrderRequest) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *ShareSgdOrderRequest) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *ShareSgdOrderRequest) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *ShareSgdOrderRequest) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *ShareSgdOrderRequest) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *ShareSgdOrderRequest) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *ShareSgdOrderRequest) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *ShareSgdOrderRequest) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *ShareSgdOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *ShareSgdOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *ShareSgdOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *ShareSgdOrderRequest) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +type UpdateSgdOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id + StopType int64 `protobuf:"varint,2,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,3,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,4,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 +} + +func (x *UpdateSgdOrderRequest) Reset() { + *x = UpdateSgdOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateSgdOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateSgdOrderRequest) ProtoMessage() {} + +func (x *UpdateSgdOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateSgdOrderRequest.ProtoReflect.Descriptor instead. +func (*UpdateSgdOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareSgd_proto_rawDescGZIP(), []int{5} +} + +func (x *UpdateSgdOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *UpdateSgdOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *UpdateSgdOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *UpdateSgdOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +type SgdOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *SgdOrderResult `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *SgdOrderReply) Reset() { + *x = SgdOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SgdOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SgdOrderReply) ProtoMessage() {} + +func (x *SgdOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SgdOrderReply.ProtoReflect.Descriptor instead. +func (*SgdOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareSgd_proto_rawDescGZIP(), []int{6} +} + +func (x *SgdOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *SgdOrderReply) GetData() *SgdOrderResult { + if x != nil { + return x.Data + } + return nil +} + +func (x *SgdOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type SgdOrderResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id +} + +func (x *SgdOrderResult) Reset() { + *x = SgdOrderResult{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SgdOrderResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SgdOrderResult) ProtoMessage() {} + +func (x *SgdOrderResult) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SgdOrderResult.ProtoReflect.Descriptor instead. +func (*SgdOrderResult) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareSgd_proto_rawDescGZIP(), []int{7} +} + +func (x *SgdOrderResult) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type CancelSgdOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID +} + +func (x *CancelSgdOrderRequest) Reset() { + *x = CancelSgdOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CancelSgdOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CancelSgdOrderRequest) ProtoMessage() {} + +func (x *CancelSgdOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CancelSgdOrderRequest.ProtoReflect.Descriptor instead. +func (*CancelSgdOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareSgd_proto_rawDescGZIP(), []int{8} +} + +func (x *CancelSgdOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type AllSgdOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *AllSgdOrderRequest) Reset() { + *x = AllSgdOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllSgdOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllSgdOrderRequest) ProtoMessage() {} + +func (x *AllSgdOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllSgdOrderRequest.ProtoReflect.Descriptor instead. +func (*AllSgdOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareSgd_proto_rawDescGZIP(), []int{9} +} + +type AllSgdOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *AllSgdOrderReply) Reset() { + *x = AllSgdOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllSgdOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllSgdOrderReply) ProtoMessage() {} + +func (x *AllSgdOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareSgd_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllSgdOrderReply.ProtoReflect.Descriptor instead. +func (*AllSgdOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareSgd_proto_rawDescGZIP(), []int{10} +} + +func (x *AllSgdOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *AllSgdOrderReply) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +func (x *AllSgdOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_matchmaking_v1_share_shareSgd_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_share_shareSgd_proto_rawDesc = []byte{ + 0x0a, 0x23, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x53, 0x67, 0x64, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0x6e, 0x0a, 0x1a, 0x47, 0x65, 0x74, 0x53, 0x67, 0x64, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, + 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x22, 0x83, 0x01, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, + 0x6f, 0x63, 0x6b, 0x53, 0x67, 0x64, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, + 0x63, 0x6f, 0x64, 0x65, 0x12, 0x39, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x53, 0x67, 0x64, 0x54, + 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, + 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xa7, 0x01, 0x0a, 0x15, 0x42, 0x6f, + 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x53, 0x67, 0x64, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, + 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x34, 0x0a, + 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x53, 0x67, 0x64, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x04, 0x64, + 0x61, 0x74, 0x61, 0x12, 0x1e, 0x0a, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, + 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x22, 0x9e, 0x06, 0x0a, 0x10, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, + 0x53, 0x67, 0x64, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, + 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, + 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, + 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, + 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, + 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x65, 0x61, 0x6c, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x64, 0x65, 0x61, + 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, + 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6c, + 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, + 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, + 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, + 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, + 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0c, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, + 0x74, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x43, 0x6f, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, + 0x6e, 0x65, 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, + 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x18, 0x10, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1e, + 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x11, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1e, + 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x12, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1a, + 0x0a, 0x08, 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x13, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x08, 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, + 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, + 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x15, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1c, + 0x0a, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x16, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x16, 0x0a, 0x06, + 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x17, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, + 0x79, 0x4e, 0x75, 0x6d, 0x12, 0x20, 0x0a, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, + 0x6d, 0x61, 0x6c, 0x18, 0x18, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, + 0x65, 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x4e, + 0x61, 0x6d, 0x65, 0x18, 0x19, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, + 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x90, 0x03, 0x0a, 0x14, 0x53, 0x68, 0x61, 0x72, 0x65, 0x53, 0x67, + 0x64, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, + 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, + 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x72, 0x61, 0x64, + 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, + 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, + 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, + 0x65, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, + 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, + 0x6d, 0x62, 0x65, 0x72, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, + 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, + 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, + 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, + 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, + 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, + 0x16, 0x0a, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x22, 0x97, 0x01, 0x0a, 0x15, 0x55, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x53, 0x67, 0x64, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, + 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, + 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, + 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, + 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, + 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x22, 0x71, 0x0a, 0x0d, 0x53, 0x67, 0x64, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, + 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x32, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x67, 0x64, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x73, 0x75, 0x6c, 0x74, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x22, 0x2a, 0x0a, 0x0e, 0x53, 0x67, 0x64, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, + 0x22, 0x31, 0x0a, 0x15, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x53, 0x67, 0x64, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x49, 0x64, 0x22, 0x14, 0x0a, 0x12, 0x41, 0x6c, 0x6c, 0x53, 0x67, 0x64, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x54, 0x0a, 0x10, 0x41, 0x6c, 0x6c, + 0x53, 0x67, 0x64, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, + 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, + 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, + 0xca, 0x06, 0x0a, 0x08, 0x53, 0x68, 0x61, 0x72, 0x65, 0x53, 0x67, 0x64, 0x12, 0x92, 0x01, 0x0a, + 0x13, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x53, 0x67, 0x64, 0x54, + 0x72, 0x61, 0x64, 0x65, 0x12, 0x2a, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x67, 0x64, 0x42, 0x6f, 0x74, 0x53, + 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x28, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, + 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x53, 0x67, 0x64, + 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x25, 0x82, 0xd3, 0xe4, 0x93, + 0x02, 0x1f, 0x3a, 0x01, 0x2a, 0x22, 0x1a, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, + 0x61, 0x72, 0x65, 0x73, 0x67, 0x64, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x6c, 0x69, 0x73, + 0x74, 0x12, 0x87, 0x01, 0x0a, 0x12, 0x53, 0x68, 0x61, 0x72, 0x65, 0x53, 0x67, 0x64, 0x50, 0x6c, + 0x61, 0x63, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x24, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x53, + 0x67, 0x64, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, + 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x53, 0x67, 0x64, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2c, 0x82, + 0xd3, 0xe4, 0x93, 0x02, 0x26, 0x3a, 0x01, 0x2a, 0x22, 0x21, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x73, 0x67, 0x64, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, + 0x70, 0x6c, 0x61, 0x63, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x8a, 0x01, 0x0a, 0x13, + 0x53, 0x68, 0x61, 0x72, 0x65, 0x53, 0x67, 0x64, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x12, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, + 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x67, 0x64, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x67, 0x64, 0x4f, + 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93, 0x02, + 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, + 0x72, 0x65, 0x73, 0x67, 0x64, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x75, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x83, 0x01, 0x0a, 0x10, 0x53, 0x68, 0x61, + 0x72, 0x65, 0x53, 0x67, 0x64, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x25, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, + 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x53, 0x67, 0x64, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x67, 0x64, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x29, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x23, 0x3a, 0x01, 0x2a, 0x22, 0x1e, + 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x73, 0x67, 0x64, 0x2f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x8a, + 0x01, 0x0a, 0x13, 0x53, 0x68, 0x61, 0x72, 0x65, 0x53, 0x67, 0x64, 0x41, 0x6c, 0x6c, 0x50, 0x6f, + 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x22, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, + 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x53, 0x67, 0x64, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x53, + 0x67, 0x64, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2d, 0x82, 0xd3, + 0xe4, 0x93, 0x02, 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x73, 0x67, 0x64, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x61, + 0x6c, 0x6c, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x7f, 0x0a, 0x0e, 0x53, + 0x68, 0x61, 0x72, 0x65, 0x53, 0x67, 0x64, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x12, 0x25, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, + 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x53, 0x67, 0x64, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x67, 0x64, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x27, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x21, 0x3a, 0x01, 0x2a, 0x22, 0x1c, + 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x73, 0x67, 0x64, 0x2f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x42, 0x2a, 0x5a, 0x28, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x73, 0x79, 0x73, 0x74, + 0x65, 0x6d, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_share_shareSgd_proto_rawDescOnce sync.Once + file_matchmaking_v1_share_shareSgd_proto_rawDescData = file_matchmaking_v1_share_shareSgd_proto_rawDesc +) + +func file_matchmaking_v1_share_shareSgd_proto_rawDescGZIP() []byte { + file_matchmaking_v1_share_shareSgd_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_share_shareSgd_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_share_shareSgd_proto_rawDescData) + }) + return file_matchmaking_v1_share_shareSgd_proto_rawDescData +} + +var file_matchmaking_v1_share_shareSgd_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_matchmaking_v1_share_shareSgd_proto_goTypes = []any{ + (*GetSgdBotStockTradeRequest)(nil), // 0: matchmaking.v1.GetSgdBotStockTradeRequest + (*GetBotStockSgdTradeReply)(nil), // 1: matchmaking.v1.GetBotStockSgdTradeReply + (*BotStockSgdTradeReply)(nil), // 2: matchmaking.v1.BotStockSgdTradeReply + (*BotStockSgdTrade)(nil), // 3: matchmaking.v1.BotStockSgdTrade + (*ShareSgdOrderRequest)(nil), // 4: matchmaking.v1.ShareSgdOrderRequest + (*UpdateSgdOrderRequest)(nil), // 5: matchmaking.v1.UpdateSgdOrderRequest + (*SgdOrderReply)(nil), // 6: matchmaking.v1.SgdOrderReply + (*SgdOrderResult)(nil), // 7: matchmaking.v1.SgdOrderResult + (*CancelSgdOrderRequest)(nil), // 8: matchmaking.v1.CancelSgdOrderRequest + (*AllSgdOrderRequest)(nil), // 9: matchmaking.v1.AllSgdOrderRequest + (*AllSgdOrderReply)(nil), // 10: matchmaking.v1.AllSgdOrderReply +} +var file_matchmaking_v1_share_shareSgd_proto_depIdxs = []int32{ + 2, // 0: matchmaking.v1.GetBotStockSgdTradeReply.data:type_name -> matchmaking.v1.BotStockSgdTradeReply + 3, // 1: matchmaking.v1.BotStockSgdTradeReply.data:type_name -> matchmaking.v1.BotStockSgdTrade + 7, // 2: matchmaking.v1.SgdOrderReply.data:type_name -> matchmaking.v1.SgdOrderResult + 0, // 3: matchmaking.v1.ShareSgd.GetBotStockSgdTrade:input_type -> matchmaking.v1.GetSgdBotStockTradeRequest + 4, // 4: matchmaking.v1.ShareSgd.ShareSgdPlaceOrder:input_type -> matchmaking.v1.ShareSgdOrderRequest + 5, // 5: matchmaking.v1.ShareSgd.ShareSgdUpdateOrder:input_type -> matchmaking.v1.UpdateSgdOrderRequest + 8, // 6: matchmaking.v1.ShareSgd.ShareSgdPosition:input_type -> matchmaking.v1.CancelSgdOrderRequest + 9, // 7: matchmaking.v1.ShareSgd.ShareSgdAllPosition:input_type -> matchmaking.v1.AllSgdOrderRequest + 8, // 8: matchmaking.v1.ShareSgd.ShareSgdCancel:input_type -> matchmaking.v1.CancelSgdOrderRequest + 1, // 9: matchmaking.v1.ShareSgd.GetBotStockSgdTrade:output_type -> matchmaking.v1.GetBotStockSgdTradeReply + 6, // 10: matchmaking.v1.ShareSgd.ShareSgdPlaceOrder:output_type -> matchmaking.v1.SgdOrderReply + 6, // 11: matchmaking.v1.ShareSgd.ShareSgdUpdateOrder:output_type -> matchmaking.v1.SgdOrderReply + 6, // 12: matchmaking.v1.ShareSgd.ShareSgdPosition:output_type -> matchmaking.v1.SgdOrderReply + 10, // 13: matchmaking.v1.ShareSgd.ShareSgdAllPosition:output_type -> matchmaking.v1.AllSgdOrderReply + 6, // 14: matchmaking.v1.ShareSgd.ShareSgdCancel:output_type -> matchmaking.v1.SgdOrderReply + 9, // [9:15] is the sub-list for method output_type + 3, // [3:9] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_share_shareSgd_proto_init() } +func file_matchmaking_v1_share_shareSgd_proto_init() { + if File_matchmaking_v1_share_shareSgd_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_matchmaking_v1_share_shareSgd_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*GetSgdBotStockTradeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareSgd_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*GetBotStockSgdTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareSgd_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*BotStockSgdTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareSgd_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*BotStockSgdTrade); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareSgd_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*ShareSgdOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareSgd_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*UpdateSgdOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareSgd_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*SgdOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareSgd_proto_msgTypes[7].Exporter = func(v any, i int) any { + switch v := v.(*SgdOrderResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareSgd_proto_msgTypes[8].Exporter = func(v any, i int) any { + switch v := v.(*CancelSgdOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareSgd_proto_msgTypes[9].Exporter = func(v any, i int) any { + switch v := v.(*AllSgdOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareSgd_proto_msgTypes[10].Exporter = func(v any, i int) any { + switch v := v.(*AllSgdOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_share_shareSgd_proto_rawDesc, + NumEnums: 0, + NumMessages: 11, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_matchmaking_v1_share_shareSgd_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_share_shareSgd_proto_depIdxs, + MessageInfos: file_matchmaking_v1_share_shareSgd_proto_msgTypes, + }.Build() + File_matchmaking_v1_share_shareSgd_proto = out.File + file_matchmaking_v1_share_shareSgd_proto_rawDesc = nil + file_matchmaking_v1_share_shareSgd_proto_goTypes = nil + file_matchmaking_v1_share_shareSgd_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/share/shareSgd.proto b/api/matchmaking/v1/share/shareSgd.proto new file mode 100644 index 0000000..60786c9 --- /dev/null +++ b/api/matchmaking/v1/share/shareSgd.proto @@ -0,0 +1,144 @@ +syntax = "proto3"; + +package matchmaking.v1; + +import "google/api/annotations.proto"; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +service ShareSgd { + // GetBotStockSgdTrade 新加坡股列表查询 + rpc GetBotStockSgdTrade(GetSgdBotStockTradeRequest)returns(GetBotStockSgdTradeReply){ + option (google.api.http) = { + post:"/order_sharesgd/share_list", + body:"*", + }; + } + // ShareSgdPlaceOrder 新加坡股下单 + rpc ShareSgdPlaceOrder(ShareSgdOrderRequest)returns(SgdOrderReply) { + option (google.api.http) = { + post: "/order_sharesgd/share_place_order", + body: "*", + }; + } + // ShareSgdUpdateOrder 新加坡股设置止盈止损 + rpc ShareSgdUpdateOrder(UpdateSgdOrderRequest)returns(SgdOrderReply){ + option (google.api.http) = { + post:"/order_sharesgd/share_update_order", + body:"*", + }; + } + // ShareSgdPosition 新加坡股平仓 + rpc ShareSgdPosition(CancelSgdOrderRequest)returns(SgdOrderReply){ + option (google.api.http) = { + post:"/order_sharesgd/share_position", + body:"*", + }; + } + // ShareSgdAllPosition 新加坡股一键平仓 + rpc ShareSgdAllPosition(AllSgdOrderRequest)returns(AllSgdOrderReply){ + option (google.api.http) = { + post:"/order_sharesgd/share_all_position", + body:"*", + }; + } + // ShareSgdCancel 新加坡股撤单 + rpc ShareSgdCancel(CancelSgdOrderRequest)returns(SgdOrderReply){ + option (google.api.http) = { + post:"/order_sharesgd/share_cancel", + body:"*", + }; + } +} + +message GetSgdBotStockTradeRequest{ + int64 status =1;// 状态码 + int64 pageSize =2; // 每页显示条数 + int64 pageCount =3;// 开始的位置 +} + +message GetBotStockSgdTradeReply{ + int64 code =1;// 状态码 + BotStockSgdTradeReply data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message BotStockSgdTradeReply{ + int64 pageSize =1; // 每页显示条数 + int64 pageCount =2;// 开始的位置 + repeated BotStockSgdTrade data =3;// 返回结果 + int64 totalCount =4;// 总数据 +} + +message BotStockSgdTrade{ + string orderId =1;// 订单ID + string stockId =2;// 股票代码 + int64 tradeType =3;// 交易类型 + int64 dealType =4;// 交易方式 + string limitPrice =5;// 限价 + string marketPrice =6;// 市价 + string dealPrice =7;// 开仓价 + string closingPrice =8;// 平仓价 + string orderNumber =9;// 订单数量 + int64 stopType =10;// 止盈止损 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string serviceCost =13;// 开仓手续费 + string marketMoney =14;// 订单金额 + string orderMoney =15;// 订单总金额 + int64 status =16;// 订单状态 + string createTime =17;// 订单创建时间 + string updateTime =18;// 订单更新时间 + string openTime =19;// 订单开仓时间 + string closingTime =20;// 订单平仓时间 + string closingCost =21;// 平仓手续费 + string faceValue =22;// 面值 + string pryNum =23;// 杠杆 + string keepDecimal =24;// 保留小数位 + string stockName =25;// 股票名称 +} + +message ShareSgdOrderRequest{ + string stockId =1;// 股票Code + int64 tradeType =2;// 交易类型:1买入,2卖出 + int64 dealType =3;// 委托方式:1限价,2市价 + string limitPrice =4;// 限价 + string marketPrice =5;// 市价 + string marketMoney =6;// 订单金额 + string orderNumber =7;// 订单数量 + string serviceCost =8;// 手续费 + int64 stopType =9;// 止损止盈设置:1无设置,2止损止盈 + string stopLossPrice =10;// 止损 + string stopWinPrice =11;// 止损 + string pryNum =12;// 杠杆 +} + +message UpdateSgdOrderRequest{ + string orderId =1;// 订单Id + int64 stopType =2;// 止盈止损 + string stopLossPrice =3;// 止损 + string stopWinPrice =4;// 止盈 +} + +message SgdOrderReply{ + int64 code =1;// 状态码 + SgdOrderResult data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message SgdOrderResult { + string orderId =1;// 订单Id +} + +message CancelSgdOrderRequest{ + string orderId =1;// 订单ID +} + +message AllSgdOrderRequest{ + +} +message AllSgdOrderReply{ + int64 code =1;// 状态码 + string data =2;// 返回结果 + string message =3;// 返回消息提示 +} \ No newline at end of file diff --git a/api/matchmaking/v1/share/shareSgd_grpc.pb.go b/api/matchmaking/v1/share/shareSgd_grpc.pb.go new file mode 100644 index 0000000..a6b021f --- /dev/null +++ b/api/matchmaking/v1/share/shareSgd_grpc.pb.go @@ -0,0 +1,312 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareSgd.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + ShareSgd_GetBotStockSgdTrade_FullMethodName = "/matchmaking.v1.ShareSgd/GetBotStockSgdTrade" + ShareSgd_ShareSgdPlaceOrder_FullMethodName = "/matchmaking.v1.ShareSgd/ShareSgdPlaceOrder" + ShareSgd_ShareSgdUpdateOrder_FullMethodName = "/matchmaking.v1.ShareSgd/ShareSgdUpdateOrder" + ShareSgd_ShareSgdPosition_FullMethodName = "/matchmaking.v1.ShareSgd/ShareSgdPosition" + ShareSgd_ShareSgdAllPosition_FullMethodName = "/matchmaking.v1.ShareSgd/ShareSgdAllPosition" + ShareSgd_ShareSgdCancel_FullMethodName = "/matchmaking.v1.ShareSgd/ShareSgdCancel" +) + +// ShareSgdClient is the client API for ShareSgd service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ShareSgdClient interface { + // GetBotStockSgdTrade 新加坡股列表查询 + GetBotStockSgdTrade(ctx context.Context, in *GetSgdBotStockTradeRequest, opts ...grpc.CallOption) (*GetBotStockSgdTradeReply, error) + // ShareSgdPlaceOrder 新加坡股下单 + ShareSgdPlaceOrder(ctx context.Context, in *ShareSgdOrderRequest, opts ...grpc.CallOption) (*SgdOrderReply, error) + // ShareSgdUpdateOrder 新加坡股设置止盈止损 + ShareSgdUpdateOrder(ctx context.Context, in *UpdateSgdOrderRequest, opts ...grpc.CallOption) (*SgdOrderReply, error) + // ShareSgdPosition 新加坡股平仓 + ShareSgdPosition(ctx context.Context, in *CancelSgdOrderRequest, opts ...grpc.CallOption) (*SgdOrderReply, error) + // ShareSgdAllPosition 新加坡股一键平仓 + ShareSgdAllPosition(ctx context.Context, in *AllSgdOrderRequest, opts ...grpc.CallOption) (*AllSgdOrderReply, error) + // ShareSgdCancel 新加坡股撤单 + ShareSgdCancel(ctx context.Context, in *CancelSgdOrderRequest, opts ...grpc.CallOption) (*SgdOrderReply, error) +} + +type shareSgdClient struct { + cc grpc.ClientConnInterface +} + +func NewShareSgdClient(cc grpc.ClientConnInterface) ShareSgdClient { + return &shareSgdClient{cc} +} + +func (c *shareSgdClient) GetBotStockSgdTrade(ctx context.Context, in *GetSgdBotStockTradeRequest, opts ...grpc.CallOption) (*GetBotStockSgdTradeReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetBotStockSgdTradeReply) + err := c.cc.Invoke(ctx, ShareSgd_GetBotStockSgdTrade_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareSgdClient) ShareSgdPlaceOrder(ctx context.Context, in *ShareSgdOrderRequest, opts ...grpc.CallOption) (*SgdOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(SgdOrderReply) + err := c.cc.Invoke(ctx, ShareSgd_ShareSgdPlaceOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareSgdClient) ShareSgdUpdateOrder(ctx context.Context, in *UpdateSgdOrderRequest, opts ...grpc.CallOption) (*SgdOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(SgdOrderReply) + err := c.cc.Invoke(ctx, ShareSgd_ShareSgdUpdateOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareSgdClient) ShareSgdPosition(ctx context.Context, in *CancelSgdOrderRequest, opts ...grpc.CallOption) (*SgdOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(SgdOrderReply) + err := c.cc.Invoke(ctx, ShareSgd_ShareSgdPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareSgdClient) ShareSgdAllPosition(ctx context.Context, in *AllSgdOrderRequest, opts ...grpc.CallOption) (*AllSgdOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AllSgdOrderReply) + err := c.cc.Invoke(ctx, ShareSgd_ShareSgdAllPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareSgdClient) ShareSgdCancel(ctx context.Context, in *CancelSgdOrderRequest, opts ...grpc.CallOption) (*SgdOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(SgdOrderReply) + err := c.cc.Invoke(ctx, ShareSgd_ShareSgdCancel_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ShareSgdServer is the server API for ShareSgd service. +// All implementations must embed UnimplementedShareSgdServer +// for forward compatibility +type ShareSgdServer interface { + // GetBotStockSgdTrade 新加坡股列表查询 + GetBotStockSgdTrade(context.Context, *GetSgdBotStockTradeRequest) (*GetBotStockSgdTradeReply, error) + // ShareSgdPlaceOrder 新加坡股下单 + ShareSgdPlaceOrder(context.Context, *ShareSgdOrderRequest) (*SgdOrderReply, error) + // ShareSgdUpdateOrder 新加坡股设置止盈止损 + ShareSgdUpdateOrder(context.Context, *UpdateSgdOrderRequest) (*SgdOrderReply, error) + // ShareSgdPosition 新加坡股平仓 + ShareSgdPosition(context.Context, *CancelSgdOrderRequest) (*SgdOrderReply, error) + // ShareSgdAllPosition 新加坡股一键平仓 + ShareSgdAllPosition(context.Context, *AllSgdOrderRequest) (*AllSgdOrderReply, error) + // ShareSgdCancel 新加坡股撤单 + ShareSgdCancel(context.Context, *CancelSgdOrderRequest) (*SgdOrderReply, error) + mustEmbedUnimplementedShareSgdServer() +} + +// UnimplementedShareSgdServer must be embedded to have forward compatible implementations. +type UnimplementedShareSgdServer struct { +} + +func (UnimplementedShareSgdServer) GetBotStockSgdTrade(context.Context, *GetSgdBotStockTradeRequest) (*GetBotStockSgdTradeReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBotStockSgdTrade not implemented") +} +func (UnimplementedShareSgdServer) ShareSgdPlaceOrder(context.Context, *ShareSgdOrderRequest) (*SgdOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareSgdPlaceOrder not implemented") +} +func (UnimplementedShareSgdServer) ShareSgdUpdateOrder(context.Context, *UpdateSgdOrderRequest) (*SgdOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareSgdUpdateOrder not implemented") +} +func (UnimplementedShareSgdServer) ShareSgdPosition(context.Context, *CancelSgdOrderRequest) (*SgdOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareSgdPosition not implemented") +} +func (UnimplementedShareSgdServer) ShareSgdAllPosition(context.Context, *AllSgdOrderRequest) (*AllSgdOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareSgdAllPosition not implemented") +} +func (UnimplementedShareSgdServer) ShareSgdCancel(context.Context, *CancelSgdOrderRequest) (*SgdOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareSgdCancel not implemented") +} +func (UnimplementedShareSgdServer) mustEmbedUnimplementedShareSgdServer() {} + +// UnsafeShareSgdServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ShareSgdServer will +// result in compilation errors. +type UnsafeShareSgdServer interface { + mustEmbedUnimplementedShareSgdServer() +} + +func RegisterShareSgdServer(s grpc.ServiceRegistrar, srv ShareSgdServer) { + s.RegisterService(&ShareSgd_ServiceDesc, srv) +} + +func _ShareSgd_GetBotStockSgdTrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetSgdBotStockTradeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareSgdServer).GetBotStockSgdTrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareSgd_GetBotStockSgdTrade_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareSgdServer).GetBotStockSgdTrade(ctx, req.(*GetSgdBotStockTradeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareSgd_ShareSgdPlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ShareSgdOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareSgdServer).ShareSgdPlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareSgd_ShareSgdPlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareSgdServer).ShareSgdPlaceOrder(ctx, req.(*ShareSgdOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareSgd_ShareSgdUpdateOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateSgdOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareSgdServer).ShareSgdUpdateOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareSgd_ShareSgdUpdateOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareSgdServer).ShareSgdUpdateOrder(ctx, req.(*UpdateSgdOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareSgd_ShareSgdPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelSgdOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareSgdServer).ShareSgdPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareSgd_ShareSgdPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareSgdServer).ShareSgdPosition(ctx, req.(*CancelSgdOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareSgd_ShareSgdAllPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AllSgdOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareSgdServer).ShareSgdAllPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareSgd_ShareSgdAllPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareSgdServer).ShareSgdAllPosition(ctx, req.(*AllSgdOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareSgd_ShareSgdCancel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelSgdOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareSgdServer).ShareSgdCancel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareSgd_ShareSgdCancel_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareSgdServer).ShareSgdCancel(ctx, req.(*CancelSgdOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// ShareSgd_ServiceDesc is the grpc.ServiceDesc for ShareSgd service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ShareSgd_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "matchmaking.v1.ShareSgd", + HandlerType: (*ShareSgdServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetBotStockSgdTrade", + Handler: _ShareSgd_GetBotStockSgdTrade_Handler, + }, + { + MethodName: "ShareSgdPlaceOrder", + Handler: _ShareSgd_ShareSgdPlaceOrder_Handler, + }, + { + MethodName: "ShareSgdUpdateOrder", + Handler: _ShareSgd_ShareSgdUpdateOrder_Handler, + }, + { + MethodName: "ShareSgdPosition", + Handler: _ShareSgd_ShareSgdPosition_Handler, + }, + { + MethodName: "ShareSgdAllPosition", + Handler: _ShareSgd_ShareSgdAllPosition_Handler, + }, + { + MethodName: "ShareSgdCancel", + Handler: _ShareSgd_ShareSgdCancel_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "matchmaking/v1/share/shareSgd.proto", +} diff --git a/api/matchmaking/v1/share/shareSgd_http.pb.go b/api/matchmaking/v1/share/shareSgd_http.pb.go new file mode 100644 index 0000000..789264b --- /dev/null +++ b/api/matchmaking/v1/share/shareSgd_http.pb.go @@ -0,0 +1,279 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.3 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareSgd.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationShareSgdGetBotStockSgdTrade = "/matchmaking.v1.ShareSgd/GetBotStockSgdTrade" +const OperationShareSgdShareSgdAllPosition = "/matchmaking.v1.ShareSgd/ShareSgdAllPosition" +const OperationShareSgdShareSgdCancel = "/matchmaking.v1.ShareSgd/ShareSgdCancel" +const OperationShareSgdShareSgdPlaceOrder = "/matchmaking.v1.ShareSgd/ShareSgdPlaceOrder" +const OperationShareSgdShareSgdPosition = "/matchmaking.v1.ShareSgd/ShareSgdPosition" +const OperationShareSgdShareSgdUpdateOrder = "/matchmaking.v1.ShareSgd/ShareSgdUpdateOrder" + +type ShareSgdHTTPServer interface { + // GetBotStockSgdTrade GetBotStockSgdTrade 新加坡股列表查询 + GetBotStockSgdTrade(context.Context, *GetSgdBotStockTradeRequest) (*GetBotStockSgdTradeReply, error) + // ShareSgdAllPosition ShareSgdAllPosition 新加坡股一键平仓 + ShareSgdAllPosition(context.Context, *AllSgdOrderRequest) (*AllSgdOrderReply, error) + // ShareSgdCancel ShareSgdCancel 新加坡股撤单 + ShareSgdCancel(context.Context, *CancelSgdOrderRequest) (*SgdOrderReply, error) + // ShareSgdPlaceOrder ShareSgdPlaceOrder 新加坡股下单 + ShareSgdPlaceOrder(context.Context, *ShareSgdOrderRequest) (*SgdOrderReply, error) + // ShareSgdPosition ShareSgdPosition 新加坡股平仓 + ShareSgdPosition(context.Context, *CancelSgdOrderRequest) (*SgdOrderReply, error) + // ShareSgdUpdateOrder ShareSgdUpdateOrder 新加坡股设置止盈止损 + ShareSgdUpdateOrder(context.Context, *UpdateSgdOrderRequest) (*SgdOrderReply, error) +} + +func RegisterShareSgdHTTPServer(s *http.Server, srv ShareSgdHTTPServer) { + r := s.Route("/") + r.POST("/order_sharesgd/share_list", _ShareSgd_GetBotStockSgdTrade0_HTTP_Handler(srv)) + r.POST("/order_sharesgd/share_place_order", _ShareSgd_ShareSgdPlaceOrder0_HTTP_Handler(srv)) + r.POST("/order_sharesgd/share_update_order", _ShareSgd_ShareSgdUpdateOrder0_HTTP_Handler(srv)) + r.POST("/order_sharesgd/share_position", _ShareSgd_ShareSgdPosition0_HTTP_Handler(srv)) + r.POST("/order_sharesgd/share_all_position", _ShareSgd_ShareSgdAllPosition0_HTTP_Handler(srv)) + r.POST("/order_sharesgd/share_cancel", _ShareSgd_ShareSgdCancel0_HTTP_Handler(srv)) +} + +func _ShareSgd_GetBotStockSgdTrade0_HTTP_Handler(srv ShareSgdHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetSgdBotStockTradeRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareSgdGetBotStockSgdTrade) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.GetBotStockSgdTrade(ctx, req.(*GetSgdBotStockTradeRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetBotStockSgdTradeReply) + return ctx.Result(200, reply) + } +} + +func _ShareSgd_ShareSgdPlaceOrder0_HTTP_Handler(srv ShareSgdHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in ShareSgdOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareSgdShareSgdPlaceOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareSgdPlaceOrder(ctx, req.(*ShareSgdOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*SgdOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareSgd_ShareSgdUpdateOrder0_HTTP_Handler(srv ShareSgdHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in UpdateSgdOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareSgdShareSgdUpdateOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareSgdUpdateOrder(ctx, req.(*UpdateSgdOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*SgdOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareSgd_ShareSgdPosition0_HTTP_Handler(srv ShareSgdHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelSgdOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareSgdShareSgdPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareSgdPosition(ctx, req.(*CancelSgdOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*SgdOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareSgd_ShareSgdAllPosition0_HTTP_Handler(srv ShareSgdHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in AllSgdOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareSgdShareSgdAllPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareSgdAllPosition(ctx, req.(*AllSgdOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*AllSgdOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareSgd_ShareSgdCancel0_HTTP_Handler(srv ShareSgdHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelSgdOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareSgdShareSgdCancel) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareSgdCancel(ctx, req.(*CancelSgdOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*SgdOrderReply) + return ctx.Result(200, reply) + } +} + +type ShareSgdHTTPClient interface { + GetBotStockSgdTrade(ctx context.Context, req *GetSgdBotStockTradeRequest, opts ...http.CallOption) (rsp *GetBotStockSgdTradeReply, err error) + ShareSgdAllPosition(ctx context.Context, req *AllSgdOrderRequest, opts ...http.CallOption) (rsp *AllSgdOrderReply, err error) + ShareSgdCancel(ctx context.Context, req *CancelSgdOrderRequest, opts ...http.CallOption) (rsp *SgdOrderReply, err error) + ShareSgdPlaceOrder(ctx context.Context, req *ShareSgdOrderRequest, opts ...http.CallOption) (rsp *SgdOrderReply, err error) + ShareSgdPosition(ctx context.Context, req *CancelSgdOrderRequest, opts ...http.CallOption) (rsp *SgdOrderReply, err error) + ShareSgdUpdateOrder(ctx context.Context, req *UpdateSgdOrderRequest, opts ...http.CallOption) (rsp *SgdOrderReply, err error) +} + +type ShareSgdHTTPClientImpl struct { + cc *http.Client +} + +func NewShareSgdHTTPClient(client *http.Client) ShareSgdHTTPClient { + return &ShareSgdHTTPClientImpl{client} +} + +func (c *ShareSgdHTTPClientImpl) GetBotStockSgdTrade(ctx context.Context, in *GetSgdBotStockTradeRequest, opts ...http.CallOption) (*GetBotStockSgdTradeReply, error) { + var out GetBotStockSgdTradeReply + pattern := "/order_sharesgd/share_list" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareSgdGetBotStockSgdTrade)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareSgdHTTPClientImpl) ShareSgdAllPosition(ctx context.Context, in *AllSgdOrderRequest, opts ...http.CallOption) (*AllSgdOrderReply, error) { + var out AllSgdOrderReply + pattern := "/order_sharesgd/share_all_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareSgdShareSgdAllPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareSgdHTTPClientImpl) ShareSgdCancel(ctx context.Context, in *CancelSgdOrderRequest, opts ...http.CallOption) (*SgdOrderReply, error) { + var out SgdOrderReply + pattern := "/order_sharesgd/share_cancel" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareSgdShareSgdCancel)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareSgdHTTPClientImpl) ShareSgdPlaceOrder(ctx context.Context, in *ShareSgdOrderRequest, opts ...http.CallOption) (*SgdOrderReply, error) { + var out SgdOrderReply + pattern := "/order_sharesgd/share_place_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareSgdShareSgdPlaceOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareSgdHTTPClientImpl) ShareSgdPosition(ctx context.Context, in *CancelSgdOrderRequest, opts ...http.CallOption) (*SgdOrderReply, error) { + var out SgdOrderReply + pattern := "/order_sharesgd/share_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareSgdShareSgdPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareSgdHTTPClientImpl) ShareSgdUpdateOrder(ctx context.Context, in *UpdateSgdOrderRequest, opts ...http.CallOption) (*SgdOrderReply, error) { + var out SgdOrderReply + pattern := "/order_sharesgd/share_update_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareSgdShareSgdUpdateOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/api/matchmaking/v1/share/shareTha.pb.go b/api/matchmaking/v1/share/shareTha.pb.go new file mode 100644 index 0000000..d9b1cba --- /dev/null +++ b/api/matchmaking/v1/share/shareTha.pb.go @@ -0,0 +1,1327 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/share/shareTha.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GetThaBotStockTradeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status int64 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` // 状态码 + PageSize int64 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,3,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 +} + +func (x *GetThaBotStockTradeRequest) Reset() { + *x = GetThaBotStockTradeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetThaBotStockTradeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetThaBotStockTradeRequest) ProtoMessage() {} + +func (x *GetThaBotStockTradeRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetThaBotStockTradeRequest.ProtoReflect.Descriptor instead. +func (*GetThaBotStockTradeRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareTha_proto_rawDescGZIP(), []int{0} +} + +func (x *GetThaBotStockTradeRequest) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *GetThaBotStockTradeRequest) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *GetThaBotStockTradeRequest) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +type GetBotStockThaTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *BotStockThaTradeData `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *GetBotStockThaTradeReply) Reset() { + *x = GetBotStockThaTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotStockThaTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotStockThaTradeReply) ProtoMessage() {} + +func (x *GetBotStockThaTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotStockThaTradeReply.ProtoReflect.Descriptor instead. +func (*GetBotStockThaTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareTha_proto_rawDescGZIP(), []int{1} +} + +func (x *GetBotStockThaTradeReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *GetBotStockThaTradeReply) GetData() *BotStockThaTradeData { + if x != nil { + return x.Data + } + return nil +} + +func (x *GetBotStockThaTradeReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type BotStockThaTradeData struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PageSize int64 `protobuf:"varint,1,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,2,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + Data []*BotStockThaTrade `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty"` // 返回结果 + TotalCount int64 `protobuf:"varint,4,opt,name=totalCount,proto3" json:"totalCount,omitempty"` // 总数据 +} + +func (x *BotStockThaTradeData) Reset() { + *x = BotStockThaTradeData{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockThaTradeData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockThaTradeData) ProtoMessage() {} + +func (x *BotStockThaTradeData) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockThaTradeData.ProtoReflect.Descriptor instead. +func (*BotStockThaTradeData) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareTha_proto_rawDescGZIP(), []int{2} +} + +func (x *BotStockThaTradeData) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *BotStockThaTradeData) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *BotStockThaTradeData) GetData() []*BotStockThaTrade { + if x != nil { + return x.Data + } + return nil +} + +func (x *BotStockThaTradeData) GetTotalCount() int64 { + if x != nil { + return x.TotalCount + } + return 0 +} + +type BotStockThaTrade struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID + StockId string `protobuf:"bytes,2,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票代码 + TradeType int64 `protobuf:"varint,3,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型 + DealType int64 `protobuf:"varint,4,opt,name=dealType,proto3" json:"dealType,omitempty"` // 交易方式 + LimitPrice string `protobuf:"bytes,5,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,6,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + DealPrice string `protobuf:"bytes,7,opt,name=dealPrice,proto3" json:"dealPrice,omitempty"` // 开仓价 + ClosingPrice string `protobuf:"bytes,8,opt,name=closingPrice,proto3" json:"closingPrice,omitempty"` // 平仓价 + OrderNumber string `protobuf:"bytes,9,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + ServiceCost string `protobuf:"bytes,13,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 开仓手续费 + MarketMoney string `protobuf:"bytes,14,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderMoney string `protobuf:"bytes,15,opt,name=orderMoney,proto3" json:"orderMoney,omitempty"` // 订单总金额 + Status int64 `protobuf:"varint,16,opt,name=status,proto3" json:"status,omitempty"` // 订单状态 + CreateTime string `protobuf:"bytes,17,opt,name=createTime,proto3" json:"createTime,omitempty"` // 订单创建时间 + UpdateTime string `protobuf:"bytes,18,opt,name=updateTime,proto3" json:"updateTime,omitempty"` // 订单更新时间 + OpenTime string `protobuf:"bytes,19,opt,name=openTime,proto3" json:"openTime,omitempty"` // 订单开仓时间 + ClosingTime string `protobuf:"bytes,20,opt,name=closingTime,proto3" json:"closingTime,omitempty"` // 订单平仓时间 + ClosingCost string `protobuf:"bytes,21,opt,name=closingCost,proto3" json:"closingCost,omitempty"` // 平仓手续费 + FaceValue string `protobuf:"bytes,22,opt,name=faceValue,proto3" json:"faceValue,omitempty"` // 面值 + PryNum string `protobuf:"bytes,23,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 + KeepDecimal string `protobuf:"bytes,24,opt,name=keepDecimal,proto3" json:"keepDecimal,omitempty"` // 保留小数位 + StockName string `protobuf:"bytes,25,opt,name=stockName,proto3" json:"stockName,omitempty"` // 股票名称 +} + +func (x *BotStockThaTrade) Reset() { + *x = BotStockThaTrade{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotStockThaTrade) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotStockThaTrade) ProtoMessage() {} + +func (x *BotStockThaTrade) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotStockThaTrade.ProtoReflect.Descriptor instead. +func (*BotStockThaTrade) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareTha_proto_rawDescGZIP(), []int{3} +} + +func (x *BotStockThaTrade) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *BotStockThaTrade) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *BotStockThaTrade) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *BotStockThaTrade) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *BotStockThaTrade) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *BotStockThaTrade) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *BotStockThaTrade) GetDealPrice() string { + if x != nil { + return x.DealPrice + } + return "" +} + +func (x *BotStockThaTrade) GetClosingPrice() string { + if x != nil { + return x.ClosingPrice + } + return "" +} + +func (x *BotStockThaTrade) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *BotStockThaTrade) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *BotStockThaTrade) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *BotStockThaTrade) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *BotStockThaTrade) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *BotStockThaTrade) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *BotStockThaTrade) GetOrderMoney() string { + if x != nil { + return x.OrderMoney + } + return "" +} + +func (x *BotStockThaTrade) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *BotStockThaTrade) GetCreateTime() string { + if x != nil { + return x.CreateTime + } + return "" +} + +func (x *BotStockThaTrade) GetUpdateTime() string { + if x != nil { + return x.UpdateTime + } + return "" +} + +func (x *BotStockThaTrade) GetOpenTime() string { + if x != nil { + return x.OpenTime + } + return "" +} + +func (x *BotStockThaTrade) GetClosingTime() string { + if x != nil { + return x.ClosingTime + } + return "" +} + +func (x *BotStockThaTrade) GetClosingCost() string { + if x != nil { + return x.ClosingCost + } + return "" +} + +func (x *BotStockThaTrade) GetFaceValue() string { + if x != nil { + return x.FaceValue + } + return "" +} + +func (x *BotStockThaTrade) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *BotStockThaTrade) GetKeepDecimal() string { + if x != nil { + return x.KeepDecimal + } + return "" +} + +func (x *BotStockThaTrade) GetStockName() string { + if x != nil { + return x.StockName + } + return "" +} + +type ShareThaOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + StockId string `protobuf:"bytes,1,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票Code + TradeType int64 `protobuf:"varint,2,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型:1买入,2卖出 + DealType int64 `protobuf:"varint,3,opt,name=dealType,proto3" json:"dealType,omitempty"` // 委托方式:1限价,2市价 + LimitPrice string `protobuf:"bytes,4,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,5,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + MarketMoney string `protobuf:"bytes,6,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderNumber string `protobuf:"bytes,7,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + ServiceCost string `protobuf:"bytes,8,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 手续费 + StopType int64 `protobuf:"varint,9,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止损止盈设置:1无设置,2止损止盈 + StopLossPrice string `protobuf:"bytes,10,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,11,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止损 + PryNum string `protobuf:"bytes,12,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 +} + +func (x *ShareThaOrderRequest) Reset() { + *x = ShareThaOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ShareThaOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ShareThaOrderRequest) ProtoMessage() {} + +func (x *ShareThaOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ShareThaOrderRequest.ProtoReflect.Descriptor instead. +func (*ShareThaOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareTha_proto_rawDescGZIP(), []int{4} +} + +func (x *ShareThaOrderRequest) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *ShareThaOrderRequest) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *ShareThaOrderRequest) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *ShareThaOrderRequest) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *ShareThaOrderRequest) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *ShareThaOrderRequest) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *ShareThaOrderRequest) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *ShareThaOrderRequest) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *ShareThaOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *ShareThaOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *ShareThaOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *ShareThaOrderRequest) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +type UpdateThaOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id + StopType int64 `protobuf:"varint,2,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,3,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,4,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 +} + +func (x *UpdateThaOrderRequest) Reset() { + *x = UpdateThaOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateThaOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateThaOrderRequest) ProtoMessage() {} + +func (x *UpdateThaOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateThaOrderRequest.ProtoReflect.Descriptor instead. +func (*UpdateThaOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareTha_proto_rawDescGZIP(), []int{5} +} + +func (x *UpdateThaOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *UpdateThaOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *UpdateThaOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *UpdateThaOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +type ThaOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *ThaOrderResult `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *ThaOrderReply) Reset() { + *x = ThaOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ThaOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ThaOrderReply) ProtoMessage() {} + +func (x *ThaOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ThaOrderReply.ProtoReflect.Descriptor instead. +func (*ThaOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareTha_proto_rawDescGZIP(), []int{6} +} + +func (x *ThaOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *ThaOrderReply) GetData() *ThaOrderResult { + if x != nil { + return x.Data + } + return nil +} + +func (x *ThaOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type ThaOrderResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id +} + +func (x *ThaOrderResult) Reset() { + *x = ThaOrderResult{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ThaOrderResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ThaOrderResult) ProtoMessage() {} + +func (x *ThaOrderResult) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ThaOrderResult.ProtoReflect.Descriptor instead. +func (*ThaOrderResult) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareTha_proto_rawDescGZIP(), []int{7} +} + +func (x *ThaOrderResult) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type CancelThaOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID +} + +func (x *CancelThaOrderRequest) Reset() { + *x = CancelThaOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CancelThaOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CancelThaOrderRequest) ProtoMessage() {} + +func (x *CancelThaOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CancelThaOrderRequest.ProtoReflect.Descriptor instead. +func (*CancelThaOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareTha_proto_rawDescGZIP(), []int{8} +} + +func (x *CancelThaOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type AllThaOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *AllThaOrderRequest) Reset() { + *x = AllThaOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllThaOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllThaOrderRequest) ProtoMessage() {} + +func (x *AllThaOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllThaOrderRequest.ProtoReflect.Descriptor instead. +func (*AllThaOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareTha_proto_rawDescGZIP(), []int{9} +} + +type AllThaOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *AllThaOrderReply) Reset() { + *x = AllThaOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllThaOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllThaOrderReply) ProtoMessage() {} + +func (x *AllThaOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareTha_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllThaOrderReply.ProtoReflect.Descriptor instead. +func (*AllThaOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareTha_proto_rawDescGZIP(), []int{10} +} + +func (x *AllThaOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *AllThaOrderReply) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +func (x *AllThaOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_matchmaking_v1_share_shareTha_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_share_shareTha_proto_rawDesc = []byte{ + 0x0a, 0x23, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x54, 0x68, 0x61, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0x6e, 0x0a, 0x1a, 0x47, 0x65, 0x74, 0x54, 0x68, 0x61, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, + 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, + 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x22, 0x82, 0x01, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, + 0x6f, 0x63, 0x6b, 0x54, 0x68, 0x61, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, + 0x63, 0x6f, 0x64, 0x65, 0x12, 0x38, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x68, 0x61, 0x54, + 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, + 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xa6, 0x01, 0x0a, 0x14, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x68, 0x61, 0x54, 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, + 0x61, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, + 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x34, 0x0a, 0x04, 0x64, + 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x6d, 0x61, 0x74, 0x63, + 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x53, 0x74, + 0x6f, 0x63, 0x6b, 0x54, 0x68, 0x61, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x04, 0x64, 0x61, 0x74, + 0x61, 0x12, 0x1e, 0x0a, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, + 0x74, 0x22, 0x9e, 0x06, 0x0a, 0x10, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x68, + 0x61, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, + 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, + 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, + 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, + 0x54, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, + 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, + 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x65, 0x61, 0x6c, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x64, 0x65, 0x61, 0x6c, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6c, 0x6f, 0x73, + 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, + 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, + 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, + 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, + 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, + 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0c, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, + 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, + 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, + 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, 0x6f, 0x6e, + 0x65, 0x79, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x10, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1e, 0x0a, 0x0a, + 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x11, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1e, 0x0a, 0x0a, + 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x12, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, + 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x13, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, + 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, + 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, + 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, + 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x15, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, + 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x16, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x72, + 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x17, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, 0x79, 0x4e, + 0x75, 0x6d, 0x12, 0x20, 0x0a, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, 0x6d, 0x61, + 0x6c, 0x18, 0x18, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, + 0x69, 0x6d, 0x61, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x4e, 0x61, 0x6d, + 0x65, 0x18, 0x19, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x4e, 0x61, + 0x6d, 0x65, 0x22, 0x90, 0x03, 0x0a, 0x14, 0x53, 0x68, 0x61, 0x72, 0x65, 0x54, 0x68, 0x61, 0x4f, + 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, + 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, + 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, + 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, + 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, + 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, + 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, + 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, + 0x6e, 0x65, 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, + 0x65, 0x72, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, + 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x43, 0x6f, 0x73, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, + 0x79, 0x70, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, + 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, 0x6f, 0x70, + 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x74, 0x6f, + 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x16, 0x0a, + 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, + 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x22, 0x97, 0x01, 0x0a, 0x15, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x54, 0x68, 0x61, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, + 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, + 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, + 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, + 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, + 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x22, + 0x71, 0x0a, 0x0d, 0x54, 0x68, 0x61, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, + 0x63, 0x6f, 0x64, 0x65, 0x12, 0x32, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x68, 0x61, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x73, 0x75, + 0x6c, 0x74, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x22, 0x2a, 0x0a, 0x0e, 0x54, 0x68, 0x61, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x73, 0x75, 0x6c, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x22, 0x31, + 0x0a, 0x15, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x54, 0x68, 0x61, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, + 0x64, 0x22, 0x14, 0x0a, 0x12, 0x41, 0x6c, 0x6c, 0x54, 0x68, 0x61, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x54, 0x0a, 0x10, 0x41, 0x6c, 0x6c, 0x54, 0x68, + 0x61, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, + 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, + 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, + 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0xca, 0x06, + 0x0a, 0x08, 0x53, 0x68, 0x61, 0x72, 0x65, 0x54, 0x68, 0x61, 0x12, 0x92, 0x01, 0x0a, 0x13, 0x47, + 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x68, 0x61, 0x54, 0x72, 0x61, + 0x64, 0x65, 0x12, 0x2a, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x54, 0x68, 0x61, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, + 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x28, + 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x68, 0x61, 0x54, 0x72, + 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x25, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1f, + 0x3a, 0x01, 0x2a, 0x22, 0x1a, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, + 0x65, 0x74, 0x68, 0x61, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x12, + 0x87, 0x01, 0x0a, 0x12, 0x53, 0x68, 0x61, 0x72, 0x65, 0x54, 0x68, 0x61, 0x50, 0x6c, 0x61, 0x63, + 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x24, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, + 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x54, 0x68, 0x61, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, + 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x68, + 0x61, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2c, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x26, 0x3a, 0x01, 0x2a, 0x22, 0x21, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, + 0x68, 0x61, 0x72, 0x65, 0x74, 0x68, 0x61, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x70, 0x6c, + 0x61, 0x63, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x8a, 0x01, 0x0a, 0x13, 0x53, 0x68, + 0x61, 0x72, 0x65, 0x54, 0x68, 0x61, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x12, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, + 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x68, 0x61, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x68, 0x61, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x27, 0x3a, + 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, + 0x74, 0x68, 0x61, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x83, 0x01, 0x0a, 0x10, 0x53, 0x68, 0x61, 0x72, 0x65, + 0x54, 0x68, 0x61, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x25, 0x2e, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x61, 0x6e, + 0x63, 0x65, 0x6c, 0x54, 0x68, 0x61, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x68, 0x61, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x22, 0x29, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x23, 0x3a, 0x01, 0x2a, 0x22, 0x1e, 0x2f, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x74, 0x68, 0x61, 0x2f, 0x73, 0x68, + 0x61, 0x72, 0x65, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x8a, 0x01, 0x0a, + 0x13, 0x53, 0x68, 0x61, 0x72, 0x65, 0x54, 0x68, 0x61, 0x41, 0x6c, 0x6c, 0x50, 0x6f, 0x73, 0x69, + 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x22, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x54, 0x68, 0x61, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x54, 0x68, 0x61, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93, + 0x02, 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, + 0x61, 0x72, 0x65, 0x74, 0x68, 0x61, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x61, 0x6c, 0x6c, + 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x7f, 0x0a, 0x0e, 0x53, 0x68, 0x61, + 0x72, 0x65, 0x54, 0x68, 0x61, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x12, 0x25, 0x2e, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x61, 0x6e, + 0x63, 0x65, 0x6c, 0x54, 0x68, 0x61, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x68, 0x61, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x22, 0x27, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x21, 0x3a, 0x01, 0x2a, 0x22, 0x1c, 0x2f, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x74, 0x68, 0x61, 0x2f, 0x73, 0x68, + 0x61, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x42, 0x2a, 0x5a, 0x28, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, + 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_share_shareTha_proto_rawDescOnce sync.Once + file_matchmaking_v1_share_shareTha_proto_rawDescData = file_matchmaking_v1_share_shareTha_proto_rawDesc +) + +func file_matchmaking_v1_share_shareTha_proto_rawDescGZIP() []byte { + file_matchmaking_v1_share_shareTha_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_share_shareTha_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_share_shareTha_proto_rawDescData) + }) + return file_matchmaking_v1_share_shareTha_proto_rawDescData +} + +var file_matchmaking_v1_share_shareTha_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_matchmaking_v1_share_shareTha_proto_goTypes = []any{ + (*GetThaBotStockTradeRequest)(nil), // 0: matchmaking.v1.GetThaBotStockTradeRequest + (*GetBotStockThaTradeReply)(nil), // 1: matchmaking.v1.GetBotStockThaTradeReply + (*BotStockThaTradeData)(nil), // 2: matchmaking.v1.BotStockThaTradeData + (*BotStockThaTrade)(nil), // 3: matchmaking.v1.BotStockThaTrade + (*ShareThaOrderRequest)(nil), // 4: matchmaking.v1.ShareThaOrderRequest + (*UpdateThaOrderRequest)(nil), // 5: matchmaking.v1.UpdateThaOrderRequest + (*ThaOrderReply)(nil), // 6: matchmaking.v1.ThaOrderReply + (*ThaOrderResult)(nil), // 7: matchmaking.v1.ThaOrderResult + (*CancelThaOrderRequest)(nil), // 8: matchmaking.v1.CancelThaOrderRequest + (*AllThaOrderRequest)(nil), // 9: matchmaking.v1.AllThaOrderRequest + (*AllThaOrderReply)(nil), // 10: matchmaking.v1.AllThaOrderReply +} +var file_matchmaking_v1_share_shareTha_proto_depIdxs = []int32{ + 2, // 0: matchmaking.v1.GetBotStockThaTradeReply.data:type_name -> matchmaking.v1.BotStockThaTradeData + 3, // 1: matchmaking.v1.BotStockThaTradeData.data:type_name -> matchmaking.v1.BotStockThaTrade + 7, // 2: matchmaking.v1.ThaOrderReply.data:type_name -> matchmaking.v1.ThaOrderResult + 0, // 3: matchmaking.v1.ShareTha.GetBotStockThaTrade:input_type -> matchmaking.v1.GetThaBotStockTradeRequest + 4, // 4: matchmaking.v1.ShareTha.ShareThaPlaceOrder:input_type -> matchmaking.v1.ShareThaOrderRequest + 5, // 5: matchmaking.v1.ShareTha.ShareThaUpdateOrder:input_type -> matchmaking.v1.UpdateThaOrderRequest + 8, // 6: matchmaking.v1.ShareTha.ShareThaPosition:input_type -> matchmaking.v1.CancelThaOrderRequest + 9, // 7: matchmaking.v1.ShareTha.ShareThaAllPosition:input_type -> matchmaking.v1.AllThaOrderRequest + 8, // 8: matchmaking.v1.ShareTha.ShareThaCancel:input_type -> matchmaking.v1.CancelThaOrderRequest + 1, // 9: matchmaking.v1.ShareTha.GetBotStockThaTrade:output_type -> matchmaking.v1.GetBotStockThaTradeReply + 6, // 10: matchmaking.v1.ShareTha.ShareThaPlaceOrder:output_type -> matchmaking.v1.ThaOrderReply + 6, // 11: matchmaking.v1.ShareTha.ShareThaUpdateOrder:output_type -> matchmaking.v1.ThaOrderReply + 6, // 12: matchmaking.v1.ShareTha.ShareThaPosition:output_type -> matchmaking.v1.ThaOrderReply + 10, // 13: matchmaking.v1.ShareTha.ShareThaAllPosition:output_type -> matchmaking.v1.AllThaOrderReply + 6, // 14: matchmaking.v1.ShareTha.ShareThaCancel:output_type -> matchmaking.v1.ThaOrderReply + 9, // [9:15] is the sub-list for method output_type + 3, // [3:9] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_share_shareTha_proto_init() } +func file_matchmaking_v1_share_shareTha_proto_init() { + if File_matchmaking_v1_share_shareTha_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_matchmaking_v1_share_shareTha_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*GetThaBotStockTradeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareTha_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*GetBotStockThaTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareTha_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*BotStockThaTradeData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareTha_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*BotStockThaTrade); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareTha_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*ShareThaOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareTha_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*UpdateThaOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareTha_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*ThaOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareTha_proto_msgTypes[7].Exporter = func(v any, i int) any { + switch v := v.(*ThaOrderResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareTha_proto_msgTypes[8].Exporter = func(v any, i int) any { + switch v := v.(*CancelThaOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareTha_proto_msgTypes[9].Exporter = func(v any, i int) any { + switch v := v.(*AllThaOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareTha_proto_msgTypes[10].Exporter = func(v any, i int) any { + switch v := v.(*AllThaOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_share_shareTha_proto_rawDesc, + NumEnums: 0, + NumMessages: 11, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_matchmaking_v1_share_shareTha_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_share_shareTha_proto_depIdxs, + MessageInfos: file_matchmaking_v1_share_shareTha_proto_msgTypes, + }.Build() + File_matchmaking_v1_share_shareTha_proto = out.File + file_matchmaking_v1_share_shareTha_proto_rawDesc = nil + file_matchmaking_v1_share_shareTha_proto_goTypes = nil + file_matchmaking_v1_share_shareTha_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/share/shareTha.proto b/api/matchmaking/v1/share/shareTha.proto new file mode 100644 index 0000000..6a30682 --- /dev/null +++ b/api/matchmaking/v1/share/shareTha.proto @@ -0,0 +1,144 @@ +syntax = "proto3"; + +package matchmaking.v1; + +import "google/api/annotations.proto"; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +service ShareTha { + // GetBotStockThaTrade 泰股列表查询 + rpc GetBotStockThaTrade(GetThaBotStockTradeRequest)returns(GetBotStockThaTradeReply){ + option (google.api.http) = { + post:"/order_sharetha/share_list", + body:"*", + }; + } + // ShareThaPlaceOrder 泰股下单 + rpc ShareThaPlaceOrder(ShareThaOrderRequest)returns(ThaOrderReply) { + option (google.api.http) = { + post: "/order_sharetha/share_place_order", + body: "*", + }; + } + // ShareThaUpdateOrder 泰股设置止盈止损 + rpc ShareThaUpdateOrder(UpdateThaOrderRequest)returns(ThaOrderReply){ + option (google.api.http) = { + post:"/order_sharetha/share_update_order", + body:"*", + }; + } + // ShareThaPosition 泰股平仓 + rpc ShareThaPosition(CancelThaOrderRequest)returns(ThaOrderReply){ + option (google.api.http) = { + post:"/order_sharetha/share_position", + body:"*", + }; + } + // ShareThaAllPosition 泰股一键平仓 + rpc ShareThaAllPosition(AllThaOrderRequest)returns(AllThaOrderReply){ + option (google.api.http) = { + post:"/order_sharetha/share_all_position", + body:"*", + }; + } + // ShareThaCancel 泰股撤单 + rpc ShareThaCancel(CancelThaOrderRequest)returns(ThaOrderReply){ + option (google.api.http) = { + post:"/order_sharetha/share_cancel", + body:"*", + }; + } +} + +message GetThaBotStockTradeRequest{ + int64 status =1;// 状态码 + int64 pageSize =2; // 每页显示条数 + int64 pageCount =3;// 开始的位置 +} + +message GetBotStockThaTradeReply{ + int64 code =1;// 状态码 + BotStockThaTradeData data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message BotStockThaTradeData{ + int64 pageSize =1; // 每页显示条数 + int64 pageCount =2;// 开始的位置 + repeated BotStockThaTrade data =3;// 返回结果 + int64 totalCount =4;// 总数据 +} + +message BotStockThaTrade{ + string orderId =1;// 订单ID + string stockId =2;// 股票代码 + int64 tradeType =3;// 交易类型 + int64 dealType =4;// 交易方式 + string limitPrice =5;// 限价 + string marketPrice =6;// 市价 + string dealPrice =7;// 开仓价 + string closingPrice =8;// 平仓价 + string orderNumber =9;// 订单数量 + int64 stopType =10;// 止盈止损 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string serviceCost =13;// 开仓手续费 + string marketMoney =14;// 订单金额 + string orderMoney =15;// 订单总金额 + int64 status =16;// 订单状态 + string createTime =17;// 订单创建时间 + string updateTime =18;// 订单更新时间 + string openTime =19;// 订单开仓时间 + string closingTime =20;// 订单平仓时间 + string closingCost =21;// 平仓手续费 + string faceValue =22;// 面值 + string pryNum =23;// 杠杆 + string keepDecimal =24;// 保留小数位 + string stockName =25;// 股票名称 +} + +message ShareThaOrderRequest{ + string stockId =1;// 股票Code + int64 tradeType =2;// 交易类型:1买入,2卖出 + int64 dealType =3;// 委托方式:1限价,2市价 + string limitPrice =4;// 限价 + string marketPrice =5;// 市价 + string marketMoney =6;// 订单金额 + string orderNumber =7;// 订单数量 + string serviceCost =8;// 手续费 + int64 stopType =9;// 止损止盈设置:1无设置,2止损止盈 + string stopLossPrice =10;// 止损 + string stopWinPrice =11;// 止损 + string pryNum =12;// 杠杆 +} + +message UpdateThaOrderRequest{ + string orderId =1;// 订单Id + int64 stopType =2;// 止盈止损 + string stopLossPrice =3;// 止损 + string stopWinPrice =4;// 止盈 +} + +message ThaOrderReply{ + int64 code =1;// 状态码 + ThaOrderResult data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message ThaOrderResult { + string orderId =1;// 订单Id +} + +message CancelThaOrderRequest{ + string orderId =1;// 订单ID +} + +message AllThaOrderRequest{ + +} +message AllThaOrderReply{ + int64 code =1;// 状态码 + string data =2;// 返回结果 + string message =3;// 返回消息提示 +} \ No newline at end of file diff --git a/api/matchmaking/v1/share/shareTha_grpc.pb.go b/api/matchmaking/v1/share/shareTha_grpc.pb.go new file mode 100644 index 0000000..454a94f --- /dev/null +++ b/api/matchmaking/v1/share/shareTha_grpc.pb.go @@ -0,0 +1,312 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareTha.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + ShareTha_GetBotStockThaTrade_FullMethodName = "/matchmaking.v1.ShareTha/GetBotStockThaTrade" + ShareTha_ShareThaPlaceOrder_FullMethodName = "/matchmaking.v1.ShareTha/ShareThaPlaceOrder" + ShareTha_ShareThaUpdateOrder_FullMethodName = "/matchmaking.v1.ShareTha/ShareThaUpdateOrder" + ShareTha_ShareThaPosition_FullMethodName = "/matchmaking.v1.ShareTha/ShareThaPosition" + ShareTha_ShareThaAllPosition_FullMethodName = "/matchmaking.v1.ShareTha/ShareThaAllPosition" + ShareTha_ShareThaCancel_FullMethodName = "/matchmaking.v1.ShareTha/ShareThaCancel" +) + +// ShareThaClient is the client API for ShareTha service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ShareThaClient interface { + // GetBotStockThaTrade 泰股列表查询 + GetBotStockThaTrade(ctx context.Context, in *GetThaBotStockTradeRequest, opts ...grpc.CallOption) (*GetBotStockThaTradeReply, error) + // ShareThaPlaceOrder 泰股下单 + ShareThaPlaceOrder(ctx context.Context, in *ShareThaOrderRequest, opts ...grpc.CallOption) (*ThaOrderReply, error) + // ShareThaUpdateOrder 泰股设置止盈止损 + ShareThaUpdateOrder(ctx context.Context, in *UpdateThaOrderRequest, opts ...grpc.CallOption) (*ThaOrderReply, error) + // ShareThaPosition 泰股平仓 + ShareThaPosition(ctx context.Context, in *CancelThaOrderRequest, opts ...grpc.CallOption) (*ThaOrderReply, error) + // ShareThaAllPosition 泰股一键平仓 + ShareThaAllPosition(ctx context.Context, in *AllThaOrderRequest, opts ...grpc.CallOption) (*AllThaOrderReply, error) + // ShareThaCancel 泰股撤单 + ShareThaCancel(ctx context.Context, in *CancelThaOrderRequest, opts ...grpc.CallOption) (*ThaOrderReply, error) +} + +type shareThaClient struct { + cc grpc.ClientConnInterface +} + +func NewShareThaClient(cc grpc.ClientConnInterface) ShareThaClient { + return &shareThaClient{cc} +} + +func (c *shareThaClient) GetBotStockThaTrade(ctx context.Context, in *GetThaBotStockTradeRequest, opts ...grpc.CallOption) (*GetBotStockThaTradeReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetBotStockThaTradeReply) + err := c.cc.Invoke(ctx, ShareTha_GetBotStockThaTrade_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareThaClient) ShareThaPlaceOrder(ctx context.Context, in *ShareThaOrderRequest, opts ...grpc.CallOption) (*ThaOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(ThaOrderReply) + err := c.cc.Invoke(ctx, ShareTha_ShareThaPlaceOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareThaClient) ShareThaUpdateOrder(ctx context.Context, in *UpdateThaOrderRequest, opts ...grpc.CallOption) (*ThaOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(ThaOrderReply) + err := c.cc.Invoke(ctx, ShareTha_ShareThaUpdateOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareThaClient) ShareThaPosition(ctx context.Context, in *CancelThaOrderRequest, opts ...grpc.CallOption) (*ThaOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(ThaOrderReply) + err := c.cc.Invoke(ctx, ShareTha_ShareThaPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareThaClient) ShareThaAllPosition(ctx context.Context, in *AllThaOrderRequest, opts ...grpc.CallOption) (*AllThaOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AllThaOrderReply) + err := c.cc.Invoke(ctx, ShareTha_ShareThaAllPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareThaClient) ShareThaCancel(ctx context.Context, in *CancelThaOrderRequest, opts ...grpc.CallOption) (*ThaOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(ThaOrderReply) + err := c.cc.Invoke(ctx, ShareTha_ShareThaCancel_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ShareThaServer is the server API for ShareTha service. +// All implementations must embed UnimplementedShareThaServer +// for forward compatibility +type ShareThaServer interface { + // GetBotStockThaTrade 泰股列表查询 + GetBotStockThaTrade(context.Context, *GetThaBotStockTradeRequest) (*GetBotStockThaTradeReply, error) + // ShareThaPlaceOrder 泰股下单 + ShareThaPlaceOrder(context.Context, *ShareThaOrderRequest) (*ThaOrderReply, error) + // ShareThaUpdateOrder 泰股设置止盈止损 + ShareThaUpdateOrder(context.Context, *UpdateThaOrderRequest) (*ThaOrderReply, error) + // ShareThaPosition 泰股平仓 + ShareThaPosition(context.Context, *CancelThaOrderRequest) (*ThaOrderReply, error) + // ShareThaAllPosition 泰股一键平仓 + ShareThaAllPosition(context.Context, *AllThaOrderRequest) (*AllThaOrderReply, error) + // ShareThaCancel 泰股撤单 + ShareThaCancel(context.Context, *CancelThaOrderRequest) (*ThaOrderReply, error) + mustEmbedUnimplementedShareThaServer() +} + +// UnimplementedShareThaServer must be embedded to have forward compatible implementations. +type UnimplementedShareThaServer struct { +} + +func (UnimplementedShareThaServer) GetBotStockThaTrade(context.Context, *GetThaBotStockTradeRequest) (*GetBotStockThaTradeReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBotStockThaTrade not implemented") +} +func (UnimplementedShareThaServer) ShareThaPlaceOrder(context.Context, *ShareThaOrderRequest) (*ThaOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareThaPlaceOrder not implemented") +} +func (UnimplementedShareThaServer) ShareThaUpdateOrder(context.Context, *UpdateThaOrderRequest) (*ThaOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareThaUpdateOrder not implemented") +} +func (UnimplementedShareThaServer) ShareThaPosition(context.Context, *CancelThaOrderRequest) (*ThaOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareThaPosition not implemented") +} +func (UnimplementedShareThaServer) ShareThaAllPosition(context.Context, *AllThaOrderRequest) (*AllThaOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareThaAllPosition not implemented") +} +func (UnimplementedShareThaServer) ShareThaCancel(context.Context, *CancelThaOrderRequest) (*ThaOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareThaCancel not implemented") +} +func (UnimplementedShareThaServer) mustEmbedUnimplementedShareThaServer() {} + +// UnsafeShareThaServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ShareThaServer will +// result in compilation errors. +type UnsafeShareThaServer interface { + mustEmbedUnimplementedShareThaServer() +} + +func RegisterShareThaServer(s grpc.ServiceRegistrar, srv ShareThaServer) { + s.RegisterService(&ShareTha_ServiceDesc, srv) +} + +func _ShareTha_GetBotStockThaTrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetThaBotStockTradeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareThaServer).GetBotStockThaTrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareTha_GetBotStockThaTrade_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareThaServer).GetBotStockThaTrade(ctx, req.(*GetThaBotStockTradeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareTha_ShareThaPlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ShareThaOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareThaServer).ShareThaPlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareTha_ShareThaPlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareThaServer).ShareThaPlaceOrder(ctx, req.(*ShareThaOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareTha_ShareThaUpdateOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateThaOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareThaServer).ShareThaUpdateOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareTha_ShareThaUpdateOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareThaServer).ShareThaUpdateOrder(ctx, req.(*UpdateThaOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareTha_ShareThaPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelThaOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareThaServer).ShareThaPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareTha_ShareThaPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareThaServer).ShareThaPosition(ctx, req.(*CancelThaOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareTha_ShareThaAllPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AllThaOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareThaServer).ShareThaAllPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareTha_ShareThaAllPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareThaServer).ShareThaAllPosition(ctx, req.(*AllThaOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareTha_ShareThaCancel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelThaOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareThaServer).ShareThaCancel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareTha_ShareThaCancel_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareThaServer).ShareThaCancel(ctx, req.(*CancelThaOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// ShareTha_ServiceDesc is the grpc.ServiceDesc for ShareTha service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ShareTha_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "matchmaking.v1.ShareTha", + HandlerType: (*ShareThaServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetBotStockThaTrade", + Handler: _ShareTha_GetBotStockThaTrade_Handler, + }, + { + MethodName: "ShareThaPlaceOrder", + Handler: _ShareTha_ShareThaPlaceOrder_Handler, + }, + { + MethodName: "ShareThaUpdateOrder", + Handler: _ShareTha_ShareThaUpdateOrder_Handler, + }, + { + MethodName: "ShareThaPosition", + Handler: _ShareTha_ShareThaPosition_Handler, + }, + { + MethodName: "ShareThaAllPosition", + Handler: _ShareTha_ShareThaAllPosition_Handler, + }, + { + MethodName: "ShareThaCancel", + Handler: _ShareTha_ShareThaCancel_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "matchmaking/v1/share/shareTha.proto", +} diff --git a/api/matchmaking/v1/share/shareTha_http.pb.go b/api/matchmaking/v1/share/shareTha_http.pb.go new file mode 100644 index 0000000..4dfc67b --- /dev/null +++ b/api/matchmaking/v1/share/shareTha_http.pb.go @@ -0,0 +1,279 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.3 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareTha.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationShareThaGetBotStockThaTrade = "/matchmaking.v1.ShareTha/GetBotStockThaTrade" +const OperationShareThaShareThaAllPosition = "/matchmaking.v1.ShareTha/ShareThaAllPosition" +const OperationShareThaShareThaCancel = "/matchmaking.v1.ShareTha/ShareThaCancel" +const OperationShareThaShareThaPlaceOrder = "/matchmaking.v1.ShareTha/ShareThaPlaceOrder" +const OperationShareThaShareThaPosition = "/matchmaking.v1.ShareTha/ShareThaPosition" +const OperationShareThaShareThaUpdateOrder = "/matchmaking.v1.ShareTha/ShareThaUpdateOrder" + +type ShareThaHTTPServer interface { + // GetBotStockThaTrade GetBotStockThaTrade 泰股列表查询 + GetBotStockThaTrade(context.Context, *GetThaBotStockTradeRequest) (*GetBotStockThaTradeReply, error) + // ShareThaAllPosition ShareThaAllPosition 泰股一键平仓 + ShareThaAllPosition(context.Context, *AllThaOrderRequest) (*AllThaOrderReply, error) + // ShareThaCancel ShareThaCancel 泰股撤单 + ShareThaCancel(context.Context, *CancelThaOrderRequest) (*ThaOrderReply, error) + // ShareThaPlaceOrder ShareThaPlaceOrder 泰股下单 + ShareThaPlaceOrder(context.Context, *ShareThaOrderRequest) (*ThaOrderReply, error) + // ShareThaPosition ShareThaPosition 泰股平仓 + ShareThaPosition(context.Context, *CancelThaOrderRequest) (*ThaOrderReply, error) + // ShareThaUpdateOrder ShareThaUpdateOrder 泰股设置止盈止损 + ShareThaUpdateOrder(context.Context, *UpdateThaOrderRequest) (*ThaOrderReply, error) +} + +func RegisterShareThaHTTPServer(s *http.Server, srv ShareThaHTTPServer) { + r := s.Route("/") + r.POST("/order_sharetha/share_list", _ShareTha_GetBotStockThaTrade0_HTTP_Handler(srv)) + r.POST("/order_sharetha/share_place_order", _ShareTha_ShareThaPlaceOrder0_HTTP_Handler(srv)) + r.POST("/order_sharetha/share_update_order", _ShareTha_ShareThaUpdateOrder0_HTTP_Handler(srv)) + r.POST("/order_sharetha/share_position", _ShareTha_ShareThaPosition0_HTTP_Handler(srv)) + r.POST("/order_sharetha/share_all_position", _ShareTha_ShareThaAllPosition0_HTTP_Handler(srv)) + r.POST("/order_sharetha/share_cancel", _ShareTha_ShareThaCancel0_HTTP_Handler(srv)) +} + +func _ShareTha_GetBotStockThaTrade0_HTTP_Handler(srv ShareThaHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetThaBotStockTradeRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareThaGetBotStockThaTrade) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.GetBotStockThaTrade(ctx, req.(*GetThaBotStockTradeRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetBotStockThaTradeReply) + return ctx.Result(200, reply) + } +} + +func _ShareTha_ShareThaPlaceOrder0_HTTP_Handler(srv ShareThaHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in ShareThaOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareThaShareThaPlaceOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareThaPlaceOrder(ctx, req.(*ShareThaOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*ThaOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareTha_ShareThaUpdateOrder0_HTTP_Handler(srv ShareThaHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in UpdateThaOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareThaShareThaUpdateOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareThaUpdateOrder(ctx, req.(*UpdateThaOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*ThaOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareTha_ShareThaPosition0_HTTP_Handler(srv ShareThaHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelThaOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareThaShareThaPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareThaPosition(ctx, req.(*CancelThaOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*ThaOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareTha_ShareThaAllPosition0_HTTP_Handler(srv ShareThaHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in AllThaOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareThaShareThaAllPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareThaAllPosition(ctx, req.(*AllThaOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*AllThaOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareTha_ShareThaCancel0_HTTP_Handler(srv ShareThaHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelThaOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareThaShareThaCancel) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareThaCancel(ctx, req.(*CancelThaOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*ThaOrderReply) + return ctx.Result(200, reply) + } +} + +type ShareThaHTTPClient interface { + GetBotStockThaTrade(ctx context.Context, req *GetThaBotStockTradeRequest, opts ...http.CallOption) (rsp *GetBotStockThaTradeReply, err error) + ShareThaAllPosition(ctx context.Context, req *AllThaOrderRequest, opts ...http.CallOption) (rsp *AllThaOrderReply, err error) + ShareThaCancel(ctx context.Context, req *CancelThaOrderRequest, opts ...http.CallOption) (rsp *ThaOrderReply, err error) + ShareThaPlaceOrder(ctx context.Context, req *ShareThaOrderRequest, opts ...http.CallOption) (rsp *ThaOrderReply, err error) + ShareThaPosition(ctx context.Context, req *CancelThaOrderRequest, opts ...http.CallOption) (rsp *ThaOrderReply, err error) + ShareThaUpdateOrder(ctx context.Context, req *UpdateThaOrderRequest, opts ...http.CallOption) (rsp *ThaOrderReply, err error) +} + +type ShareThaHTTPClientImpl struct { + cc *http.Client +} + +func NewShareThaHTTPClient(client *http.Client) ShareThaHTTPClient { + return &ShareThaHTTPClientImpl{client} +} + +func (c *ShareThaHTTPClientImpl) GetBotStockThaTrade(ctx context.Context, in *GetThaBotStockTradeRequest, opts ...http.CallOption) (*GetBotStockThaTradeReply, error) { + var out GetBotStockThaTradeReply + pattern := "/order_sharetha/share_list" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareThaGetBotStockThaTrade)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareThaHTTPClientImpl) ShareThaAllPosition(ctx context.Context, in *AllThaOrderRequest, opts ...http.CallOption) (*AllThaOrderReply, error) { + var out AllThaOrderReply + pattern := "/order_sharetha/share_all_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareThaShareThaAllPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareThaHTTPClientImpl) ShareThaCancel(ctx context.Context, in *CancelThaOrderRequest, opts ...http.CallOption) (*ThaOrderReply, error) { + var out ThaOrderReply + pattern := "/order_sharetha/share_cancel" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareThaShareThaCancel)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareThaHTTPClientImpl) ShareThaPlaceOrder(ctx context.Context, in *ShareThaOrderRequest, opts ...http.CallOption) (*ThaOrderReply, error) { + var out ThaOrderReply + pattern := "/order_sharetha/share_place_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareThaShareThaPlaceOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareThaHTTPClientImpl) ShareThaPosition(ctx context.Context, in *CancelThaOrderRequest, opts ...http.CallOption) (*ThaOrderReply, error) { + var out ThaOrderReply + pattern := "/order_sharetha/share_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareThaShareThaPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareThaHTTPClientImpl) ShareThaUpdateOrder(ctx context.Context, in *UpdateThaOrderRequest, opts ...http.CallOption) (*ThaOrderReply, error) { + var out ThaOrderReply + pattern := "/order_sharetha/share_update_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareThaShareThaUpdateOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/api/matchmaking/v1/share/shareUs.pb.go b/api/matchmaking/v1/share/shareUs.pb.go new file mode 100644 index 0000000..24da610 --- /dev/null +++ b/api/matchmaking/v1/share/shareUs.pb.go @@ -0,0 +1,1323 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/share/shareUs.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GetUsBotStockTradeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status int64 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` // 状态码 + PageSize int64 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,3,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 +} + +func (x *GetUsBotStockTradeRequest) Reset() { + *x = GetUsBotStockTradeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetUsBotStockTradeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetUsBotStockTradeRequest) ProtoMessage() {} + +func (x *GetUsBotStockTradeRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetUsBotStockTradeRequest.ProtoReflect.Descriptor instead. +func (*GetUsBotStockTradeRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareUs_proto_rawDescGZIP(), []int{0} +} + +func (x *GetUsBotStockTradeRequest) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *GetUsBotStockTradeRequest) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *GetUsBotStockTradeRequest) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +type GetUsBotStockTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *BotUsStockTradeData `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *GetUsBotStockTradeReply) Reset() { + *x = GetUsBotStockTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetUsBotStockTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetUsBotStockTradeReply) ProtoMessage() {} + +func (x *GetUsBotStockTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetUsBotStockTradeReply.ProtoReflect.Descriptor instead. +func (*GetUsBotStockTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareUs_proto_rawDescGZIP(), []int{1} +} + +func (x *GetUsBotStockTradeReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *GetUsBotStockTradeReply) GetData() *BotUsStockTradeData { + if x != nil { + return x.Data + } + return nil +} + +func (x *GetUsBotStockTradeReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type BotUsStockTradeData struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PageSize int64 `protobuf:"varint,1,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,2,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + Data []*BotUsOrderTrade `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty"` // 返回结果 + TotalCount int64 `protobuf:"varint,4,opt,name=totalCount,proto3" json:"totalCount,omitempty"` // 总数据 +} + +func (x *BotUsStockTradeData) Reset() { + *x = BotUsStockTradeData{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotUsStockTradeData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotUsStockTradeData) ProtoMessage() {} + +func (x *BotUsStockTradeData) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotUsStockTradeData.ProtoReflect.Descriptor instead. +func (*BotUsStockTradeData) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareUs_proto_rawDescGZIP(), []int{2} +} + +func (x *BotUsStockTradeData) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *BotUsStockTradeData) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *BotUsStockTradeData) GetData() []*BotUsOrderTrade { + if x != nil { + return x.Data + } + return nil +} + +func (x *BotUsStockTradeData) GetTotalCount() int64 { + if x != nil { + return x.TotalCount + } + return 0 +} + +type BotUsOrderTrade struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID + StockId string `protobuf:"bytes,2,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票代码 + TradeType int64 `protobuf:"varint,3,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型 + DealType int64 `protobuf:"varint,4,opt,name=dealType,proto3" json:"dealType,omitempty"` // 交易方式 + LimitPrice string `protobuf:"bytes,5,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,6,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + DealPrice string `protobuf:"bytes,7,opt,name=dealPrice,proto3" json:"dealPrice,omitempty"` // 开仓价 + ClosingPrice string `protobuf:"bytes,8,opt,name=closingPrice,proto3" json:"closingPrice,omitempty"` // 平仓价 + OrderNumber string `protobuf:"bytes,9,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损状态 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + ServiceCost string `protobuf:"bytes,13,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 开仓手续费 + MarketMoney string `protobuf:"bytes,14,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderMoney string `protobuf:"bytes,15,opt,name=orderMoney,proto3" json:"orderMoney,omitempty"` // 订单总金额 + Status int64 `protobuf:"varint,16,opt,name=status,proto3" json:"status,omitempty"` // 订单状态 + CreateTime string `protobuf:"bytes,17,opt,name=createTime,proto3" json:"createTime,omitempty"` // 订单创建时间 + UpdateTime string `protobuf:"bytes,18,opt,name=updateTime,proto3" json:"updateTime,omitempty"` // 订单更新时间 + OpenTime string `protobuf:"bytes,19,opt,name=openTime,proto3" json:"openTime,omitempty"` // 订单开仓时间 + ClosingTime string `protobuf:"bytes,20,opt,name=closingTime,proto3" json:"closingTime,omitempty"` // 订单平仓时间 + ClosingCost string `protobuf:"bytes,21,opt,name=closingCost,proto3" json:"closingCost,omitempty"` // 平仓手续费 + FaceValue string `protobuf:"bytes,22,opt,name=faceValue,proto3" json:"faceValue,omitempty"` // 面值 + PryNum string `protobuf:"bytes,23,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 + KeepDecimal string `protobuf:"bytes,24,opt,name=keepDecimal,proto3" json:"keepDecimal,omitempty"` // 保留小数位 + StockName string `protobuf:"bytes,25,opt,name=stockName,proto3" json:"stockName,omitempty"` // 股票名称 +} + +func (x *BotUsOrderTrade) Reset() { + *x = BotUsOrderTrade{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotUsOrderTrade) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotUsOrderTrade) ProtoMessage() {} + +func (x *BotUsOrderTrade) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotUsOrderTrade.ProtoReflect.Descriptor instead. +func (*BotUsOrderTrade) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareUs_proto_rawDescGZIP(), []int{3} +} + +func (x *BotUsOrderTrade) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *BotUsOrderTrade) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *BotUsOrderTrade) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *BotUsOrderTrade) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *BotUsOrderTrade) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *BotUsOrderTrade) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *BotUsOrderTrade) GetDealPrice() string { + if x != nil { + return x.DealPrice + } + return "" +} + +func (x *BotUsOrderTrade) GetClosingPrice() string { + if x != nil { + return x.ClosingPrice + } + return "" +} + +func (x *BotUsOrderTrade) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *BotUsOrderTrade) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *BotUsOrderTrade) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *BotUsOrderTrade) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *BotUsOrderTrade) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *BotUsOrderTrade) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *BotUsOrderTrade) GetOrderMoney() string { + if x != nil { + return x.OrderMoney + } + return "" +} + +func (x *BotUsOrderTrade) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *BotUsOrderTrade) GetCreateTime() string { + if x != nil { + return x.CreateTime + } + return "" +} + +func (x *BotUsOrderTrade) GetUpdateTime() string { + if x != nil { + return x.UpdateTime + } + return "" +} + +func (x *BotUsOrderTrade) GetOpenTime() string { + if x != nil { + return x.OpenTime + } + return "" +} + +func (x *BotUsOrderTrade) GetClosingTime() string { + if x != nil { + return x.ClosingTime + } + return "" +} + +func (x *BotUsOrderTrade) GetClosingCost() string { + if x != nil { + return x.ClosingCost + } + return "" +} + +func (x *BotUsOrderTrade) GetFaceValue() string { + if x != nil { + return x.FaceValue + } + return "" +} + +func (x *BotUsOrderTrade) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *BotUsOrderTrade) GetKeepDecimal() string { + if x != nil { + return x.KeepDecimal + } + return "" +} + +func (x *BotUsOrderTrade) GetStockName() string { + if x != nil { + return x.StockName + } + return "" +} + +type UsOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + StockId string `protobuf:"bytes,1,opt,name=stockId,proto3" json:"stockId,omitempty"` // 股票Code + TradeType int64 `protobuf:"varint,2,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型:1买入,2卖出 + DealType int64 `protobuf:"varint,3,opt,name=dealType,proto3" json:"dealType,omitempty"` // 委托方式:1限价,2市价 + LimitPrice string `protobuf:"bytes,4,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,5,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + MarketMoney string `protobuf:"bytes,6,opt,name=marketMoney,proto3" json:"marketMoney,omitempty"` // 订单金额 + OrderNumber string `protobuf:"bytes,7,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + ServiceCost string `protobuf:"bytes,8,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 手续费 + StopType int64 `protobuf:"varint,9,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止损止盈设置:1无设置,2止损止盈 + StopLossPrice string `protobuf:"bytes,10,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,11,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止损 + PryNum string `protobuf:"bytes,12,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆 +} + +func (x *UsOrderRequest) Reset() { + *x = UsOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UsOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UsOrderRequest) ProtoMessage() {} + +func (x *UsOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UsOrderRequest.ProtoReflect.Descriptor instead. +func (*UsOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareUs_proto_rawDescGZIP(), []int{4} +} + +func (x *UsOrderRequest) GetStockId() string { + if x != nil { + return x.StockId + } + return "" +} + +func (x *UsOrderRequest) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *UsOrderRequest) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *UsOrderRequest) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *UsOrderRequest) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *UsOrderRequest) GetMarketMoney() string { + if x != nil { + return x.MarketMoney + } + return "" +} + +func (x *UsOrderRequest) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *UsOrderRequest) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *UsOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *UsOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *UsOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *UsOrderRequest) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +type UpdateUsOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id + StopType int64 `protobuf:"varint,2,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,3,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,4,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 +} + +func (x *UpdateUsOrderRequest) Reset() { + *x = UpdateUsOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateUsOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateUsOrderRequest) ProtoMessage() {} + +func (x *UpdateUsOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateUsOrderRequest.ProtoReflect.Descriptor instead. +func (*UpdateUsOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareUs_proto_rawDescGZIP(), []int{5} +} + +func (x *UpdateUsOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *UpdateUsOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *UpdateUsOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *UpdateUsOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +type UsOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *UsOrderResult `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *UsOrderReply) Reset() { + *x = UsOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UsOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UsOrderReply) ProtoMessage() {} + +func (x *UsOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UsOrderReply.ProtoReflect.Descriptor instead. +func (*UsOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareUs_proto_rawDescGZIP(), []int{6} +} + +func (x *UsOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *UsOrderReply) GetData() *UsOrderResult { + if x != nil { + return x.Data + } + return nil +} + +func (x *UsOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type AllUsOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *AllUsOrderRequest) Reset() { + *x = AllUsOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllUsOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllUsOrderRequest) ProtoMessage() {} + +func (x *AllUsOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllUsOrderRequest.ProtoReflect.Descriptor instead. +func (*AllUsOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareUs_proto_rawDescGZIP(), []int{7} +} + +type CancelUsOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID +} + +func (x *CancelUsOrderRequest) Reset() { + *x = CancelUsOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CancelUsOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CancelUsOrderRequest) ProtoMessage() {} + +func (x *CancelUsOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CancelUsOrderRequest.ProtoReflect.Descriptor instead. +func (*CancelUsOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareUs_proto_rawDescGZIP(), []int{8} +} + +func (x *CancelUsOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type AllUsOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *AllUsOrderReply) Reset() { + *x = AllUsOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllUsOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllUsOrderReply) ProtoMessage() {} + +func (x *AllUsOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllUsOrderReply.ProtoReflect.Descriptor instead. +func (*AllUsOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareUs_proto_rawDescGZIP(), []int{9} +} + +func (x *AllUsOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *AllUsOrderReply) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +func (x *AllUsOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type UsOrderResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id +} + +func (x *UsOrderResult) Reset() { + *x = UsOrderResult{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UsOrderResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UsOrderResult) ProtoMessage() {} + +func (x *UsOrderResult) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_share_shareUs_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UsOrderResult.ProtoReflect.Descriptor instead. +func (*UsOrderResult) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_share_shareUs_proto_rawDescGZIP(), []int{10} +} + +func (x *UsOrderResult) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +var File_matchmaking_v1_share_shareUs_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_share_shareUs_proto_rawDesc = []byte{ + 0x0a, 0x22, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x55, 0x73, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, + 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, + 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x22, 0x6d, 0x0a, 0x19, 0x47, 0x65, 0x74, 0x55, 0x73, 0x42, 0x6f, 0x74, 0x53, 0x74, + 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, + 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, + 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, + 0x74, 0x22, 0x80, 0x01, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x55, 0x73, 0x42, 0x6f, 0x74, 0x53, 0x74, + 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, + 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, + 0x65, 0x12, 0x37, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x23, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, + 0x2e, 0x42, 0x6f, 0x74, 0x55, 0x73, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, + 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x22, 0xa4, 0x01, 0x0a, 0x13, 0x42, 0x6f, 0x74, 0x55, 0x73, 0x53, 0x74, + 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, 0x61, 0x12, 0x1a, 0x0a, 0x08, + 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, + 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, + 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, + 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x33, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x55, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x1e, 0x0a, 0x0a, 0x74, + 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x9d, 0x06, 0x0a, 0x0f, + 0x42, 0x6f, 0x74, 0x55, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, + 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, + 0x63, 0x6b, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x63, + 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, + 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, + 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, + 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, + 0x1c, 0x0a, 0x09, 0x64, 0x65, 0x61, 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x07, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x09, 0x64, 0x65, 0x61, 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, + 0x0c, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x08, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, + 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, + 0x62, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, + 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, + 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, + 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, + 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x6d, + 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x1e, 0x0a, + 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x0f, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x16, 0x0a, + 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x10, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, + 0x69, 0x6d, 0x65, 0x18, 0x11, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, + 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, + 0x69, 0x6d, 0x65, 0x18, 0x12, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, + 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, + 0x65, 0x18, 0x13, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, + 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, + 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, + 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, + 0x73, 0x74, 0x18, 0x15, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, + 0x67, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, + 0x75, 0x65, 0x18, 0x16, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, + 0x6c, 0x75, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x17, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x12, 0x20, 0x0a, 0x0b, 0x6b, + 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x18, 0x18, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x12, 0x1c, 0x0a, + 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x19, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x09, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x8a, 0x03, 0x0a, 0x0e, + 0x55, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, + 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, 0x61, 0x64, + 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x72, 0x61, + 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, + 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, + 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x4d, 0x6f, + 0x6e, 0x65, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, + 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, + 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, + 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, + 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, + 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, + 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, + 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x12, 0x16, 0x0a, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x22, 0x96, 0x01, 0x0a, 0x14, 0x55, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x55, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, + 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, + 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, + 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, + 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, + 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x22, 0x6f, 0x0a, 0x0c, 0x55, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x31, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, + 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x73, 0x75, + 0x6c, 0x74, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x22, 0x13, 0x0a, 0x11, 0x41, 0x6c, 0x6c, 0x55, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x30, 0x0a, 0x14, 0x43, 0x61, 0x6e, 0x63, 0x65, + 0x6c, 0x55, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x22, 0x53, 0x0a, 0x0f, 0x41, 0x6c, 0x6c, + 0x55, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, + 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, + 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, + 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x29, + 0x0a, 0x0d, 0x55, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, + 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x32, 0x9e, 0x06, 0x0a, 0x07, 0x53, 0x68, + 0x61, 0x72, 0x65, 0x55, 0x73, 0x12, 0x8c, 0x01, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, + 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x29, 0x2e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x55, + 0x73, 0x42, 0x6f, 0x74, 0x53, 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, + 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x55, 0x73, 0x42, 0x6f, 0x74, 0x53, + 0x74, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x24, + 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1e, 0x3a, 0x01, 0x2a, 0x22, 0x19, 0x2f, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x75, 0x73, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, + 0x6c, 0x69, 0x73, 0x74, 0x12, 0x7c, 0x0a, 0x0f, 0x53, 0x68, 0x61, 0x72, 0x65, 0x50, 0x6c, 0x61, + 0x63, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x1e, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, + 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, + 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2b, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x25, 0x3a, 0x01, 0x2a, + 0x22, 0x20, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x75, 0x73, + 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x5f, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x12, 0x84, 0x01, 0x0a, 0x10, 0x53, 0x68, 0x61, 0x72, 0x65, 0x55, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x24, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, + 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x55, + 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x55, + 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2c, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x26, 0x3a, 0x01, 0x2a, 0x22, 0x21, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, + 0x68, 0x61, 0x72, 0x65, 0x75, 0x73, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x75, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x7d, 0x0a, 0x0d, 0x53, 0x68, 0x61, + 0x72, 0x65, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x24, 0x2e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x61, 0x6e, 0x63, + 0x65, 0x6c, 0x55, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x1c, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, + 0x31, 0x2e, 0x55, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x28, + 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x22, 0x3a, 0x01, 0x2a, 0x22, 0x1d, 0x2f, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x75, 0x73, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, + 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x84, 0x01, 0x0a, 0x10, 0x53, 0x68, 0x61, + 0x72, 0x65, 0x41, 0x6c, 0x6c, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x21, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, + 0x6c, 0x6c, 0x55, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x1f, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, + 0x31, 0x2e, 0x41, 0x6c, 0x6c, 0x55, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x22, 0x2c, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x26, 0x3a, 0x01, 0x2a, 0x22, 0x21, 0x2f, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x75, 0x73, 0x2f, 0x73, 0x68, 0x61, + 0x72, 0x65, 0x5f, 0x61, 0x6c, 0x6c, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, + 0x79, 0x0a, 0x0b, 0x53, 0x68, 0x61, 0x72, 0x65, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x12, 0x24, + 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x55, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, + 0x6c, 0x79, 0x22, 0x26, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x20, 0x3a, 0x01, 0x2a, 0x22, 0x1b, 0x2f, + 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x75, 0x73, 0x2f, 0x73, 0x68, + 0x61, 0x72, 0x65, 0x5f, 0x63, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x42, 0x2a, 0x5a, 0x28, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, + 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_share_shareUs_proto_rawDescOnce sync.Once + file_matchmaking_v1_share_shareUs_proto_rawDescData = file_matchmaking_v1_share_shareUs_proto_rawDesc +) + +func file_matchmaking_v1_share_shareUs_proto_rawDescGZIP() []byte { + file_matchmaking_v1_share_shareUs_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_share_shareUs_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_share_shareUs_proto_rawDescData) + }) + return file_matchmaking_v1_share_shareUs_proto_rawDescData +} + +var file_matchmaking_v1_share_shareUs_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_matchmaking_v1_share_shareUs_proto_goTypes = []any{ + (*GetUsBotStockTradeRequest)(nil), // 0: matchmaking.v1.GetUsBotStockTradeRequest + (*GetUsBotStockTradeReply)(nil), // 1: matchmaking.v1.GetUsBotStockTradeReply + (*BotUsStockTradeData)(nil), // 2: matchmaking.v1.BotUsStockTradeData + (*BotUsOrderTrade)(nil), // 3: matchmaking.v1.BotUsOrderTrade + (*UsOrderRequest)(nil), // 4: matchmaking.v1.UsOrderRequest + (*UpdateUsOrderRequest)(nil), // 5: matchmaking.v1.UpdateUsOrderRequest + (*UsOrderReply)(nil), // 6: matchmaking.v1.UsOrderReply + (*AllUsOrderRequest)(nil), // 7: matchmaking.v1.AllUsOrderRequest + (*CancelUsOrderRequest)(nil), // 8: matchmaking.v1.CancelUsOrderRequest + (*AllUsOrderReply)(nil), // 9: matchmaking.v1.AllUsOrderReply + (*UsOrderResult)(nil), // 10: matchmaking.v1.UsOrderResult +} +var file_matchmaking_v1_share_shareUs_proto_depIdxs = []int32{ + 2, // 0: matchmaking.v1.GetUsBotStockTradeReply.data:type_name -> matchmaking.v1.BotUsStockTradeData + 3, // 1: matchmaking.v1.BotUsStockTradeData.data:type_name -> matchmaking.v1.BotUsOrderTrade + 10, // 2: matchmaking.v1.UsOrderReply.data:type_name -> matchmaking.v1.UsOrderResult + 0, // 3: matchmaking.v1.ShareUs.GetBotStockTrade:input_type -> matchmaking.v1.GetUsBotStockTradeRequest + 4, // 4: matchmaking.v1.ShareUs.SharePlaceOrder:input_type -> matchmaking.v1.UsOrderRequest + 5, // 5: matchmaking.v1.ShareUs.ShareUpdateOrder:input_type -> matchmaking.v1.UpdateUsOrderRequest + 8, // 6: matchmaking.v1.ShareUs.SharePosition:input_type -> matchmaking.v1.CancelUsOrderRequest + 7, // 7: matchmaking.v1.ShareUs.ShareAllPosition:input_type -> matchmaking.v1.AllUsOrderRequest + 8, // 8: matchmaking.v1.ShareUs.ShareCancel:input_type -> matchmaking.v1.CancelUsOrderRequest + 1, // 9: matchmaking.v1.ShareUs.GetBotStockTrade:output_type -> matchmaking.v1.GetUsBotStockTradeReply + 6, // 10: matchmaking.v1.ShareUs.SharePlaceOrder:output_type -> matchmaking.v1.UsOrderReply + 6, // 11: matchmaking.v1.ShareUs.ShareUpdateOrder:output_type -> matchmaking.v1.UsOrderReply + 6, // 12: matchmaking.v1.ShareUs.SharePosition:output_type -> matchmaking.v1.UsOrderReply + 9, // 13: matchmaking.v1.ShareUs.ShareAllPosition:output_type -> matchmaking.v1.AllUsOrderReply + 6, // 14: matchmaking.v1.ShareUs.ShareCancel:output_type -> matchmaking.v1.UsOrderReply + 9, // [9:15] is the sub-list for method output_type + 3, // [3:9] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_share_shareUs_proto_init() } +func file_matchmaking_v1_share_shareUs_proto_init() { + if File_matchmaking_v1_share_shareUs_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_matchmaking_v1_share_shareUs_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*GetUsBotStockTradeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareUs_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*GetUsBotStockTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareUs_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*BotUsStockTradeData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareUs_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*BotUsOrderTrade); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareUs_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*UsOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareUs_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*UpdateUsOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareUs_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*UsOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareUs_proto_msgTypes[7].Exporter = func(v any, i int) any { + switch v := v.(*AllUsOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareUs_proto_msgTypes[8].Exporter = func(v any, i int) any { + switch v := v.(*CancelUsOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareUs_proto_msgTypes[9].Exporter = func(v any, i int) any { + switch v := v.(*AllUsOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_share_shareUs_proto_msgTypes[10].Exporter = func(v any, i int) any { + switch v := v.(*UsOrderResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_share_shareUs_proto_rawDesc, + NumEnums: 0, + NumMessages: 11, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_matchmaking_v1_share_shareUs_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_share_shareUs_proto_depIdxs, + MessageInfos: file_matchmaking_v1_share_shareUs_proto_msgTypes, + }.Build() + File_matchmaking_v1_share_shareUs_proto = out.File + file_matchmaking_v1_share_shareUs_proto_rawDesc = nil + file_matchmaking_v1_share_shareUs_proto_goTypes = nil + file_matchmaking_v1_share_shareUs_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/share/shareUs.proto b/api/matchmaking/v1/share/shareUs.proto new file mode 100644 index 0000000..8a928d6 --- /dev/null +++ b/api/matchmaking/v1/share/shareUs.proto @@ -0,0 +1,145 @@ +syntax = "proto3"; + +package matchmaking.v1; + +import "google/api/annotations.proto"; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +service ShareUs { + // GetBotStockTrade 美股列表查询 + rpc GetBotStockTrade(GetUsBotStockTradeRequest)returns(GetUsBotStockTradeReply){ + option (google.api.http) = { + post:"/order_shareus/share_list", + body:"*", + }; + } + // SharePlaceOrder 美股下单 + rpc SharePlaceOrder(UsOrderRequest)returns(UsOrderReply) { + option (google.api.http) = { + post: "/order_shareus/share_place_order", + body: "*", + }; + } + // ShareUpdateOrder 美股设置止盈止损 + rpc ShareUpdateOrder(UpdateUsOrderRequest)returns(UsOrderReply){ + option (google.api.http) = { + post:"/order_shareus/share_update_order", + body:"*", + }; + } + // SharePosition 美股平仓 + rpc SharePosition(CancelUsOrderRequest)returns(UsOrderReply){ + option (google.api.http) = { + post:"/order_shareus/share_position", + body:"*", + }; + } + // ShareCancel 美股一键平仓 + rpc ShareAllPosition(AllUsOrderRequest)returns(AllUsOrderReply){ + option (google.api.http) = { + post:"/order_shareus/share_all_position", + body:"*", + }; + } + // ShareCancel 美股撤单 + rpc ShareCancel(CancelUsOrderRequest)returns(UsOrderReply){ + option (google.api.http) = { + post:"/order_shareus/share_cancel", + body:"*", + }; + } +} + +message GetUsBotStockTradeRequest{ + int64 status =1;// 状态码 + int64 pageSize =2; // 每页显示条数 + int64 pageCount =3;// 开始的位置 +} + +message GetUsBotStockTradeReply{ + int64 code =1;// 状态码 + BotUsStockTradeData data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message BotUsStockTradeData{ + int64 pageSize =1; // 每页显示条数 + int64 pageCount =2;// 开始的位置 + repeated BotUsOrderTrade data =3;// 返回结果 + int64 totalCount =4;// 总数据 +} + +message BotUsOrderTrade{ + string orderId =1;// 订单ID + string stockId =2;// 股票代码 + int64 tradeType =3;// 交易类型 + int64 dealType =4;// 交易方式 + string limitPrice =5;// 限价 + string marketPrice =6;// 市价 + string dealPrice =7;// 开仓价 + string closingPrice =8;// 平仓价 + string orderNumber =9;// 订单数量 + int64 stopType =10;// 止盈止损状态 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string serviceCost =13;// 开仓手续费 + string marketMoney =14;// 订单金额 + string orderMoney =15;// 订单总金额 + int64 status =16;// 订单状态 + string createTime =17;// 订单创建时间 + string updateTime =18;// 订单更新时间 + string openTime =19;// 订单开仓时间 + string closingTime =20;// 订单平仓时间 + string closingCost =21;// 平仓手续费 + string faceValue =22;// 面值 + string pryNum =23;// 杠杆 + string keepDecimal =24;// 保留小数位 + string stockName =25;// 股票名称 +} + +message UsOrderRequest{ + string stockId =1;// 股票Code + int64 tradeType =2;// 交易类型:1买入,2卖出 + int64 dealType =3;// 委托方式:1限价,2市价 + string limitPrice =4;// 限价 + string marketPrice =5;// 市价 + string marketMoney =6;// 订单金额 + string orderNumber =7;// 订单数量 + string serviceCost =8;// 手续费 + int64 stopType =9;// 止损止盈设置:1无设置,2止损止盈 + string stopLossPrice =10;// 止损 + string stopWinPrice =11;// 止损 + string pryNum =12;// 杠杆 +} + +message UpdateUsOrderRequest{ + string orderId =1;// 订单Id + int64 stopType =2;// 止盈止损 + string stopLossPrice =3;// 止损 + string stopWinPrice =4;// 止盈 +} + +message UsOrderReply{ + int64 code =1;// 状态码 + UsOrderResult data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message AllUsOrderRequest{ + +} + +message CancelUsOrderRequest{ + string orderId =1;// 订单ID +} + +message AllUsOrderReply{ + int64 code =1;// 状态码 + string data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message UsOrderResult { + string orderId =1;// 订单Id +} \ No newline at end of file diff --git a/api/matchmaking/v1/share/shareUs_grpc.pb.go b/api/matchmaking/v1/share/shareUs_grpc.pb.go new file mode 100644 index 0000000..229bdc5 --- /dev/null +++ b/api/matchmaking/v1/share/shareUs_grpc.pb.go @@ -0,0 +1,312 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareUs.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + ShareUs_GetBotStockTrade_FullMethodName = "/matchmaking.v1.ShareUs/GetBotStockTrade" + ShareUs_SharePlaceOrder_FullMethodName = "/matchmaking.v1.ShareUs/SharePlaceOrder" + ShareUs_ShareUpdateOrder_FullMethodName = "/matchmaking.v1.ShareUs/ShareUpdateOrder" + ShareUs_SharePosition_FullMethodName = "/matchmaking.v1.ShareUs/SharePosition" + ShareUs_ShareAllPosition_FullMethodName = "/matchmaking.v1.ShareUs/ShareAllPosition" + ShareUs_ShareCancel_FullMethodName = "/matchmaking.v1.ShareUs/ShareCancel" +) + +// ShareUsClient is the client API for ShareUs service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ShareUsClient interface { + // GetBotStockTrade 美股列表查询 + GetBotStockTrade(ctx context.Context, in *GetUsBotStockTradeRequest, opts ...grpc.CallOption) (*GetUsBotStockTradeReply, error) + // SharePlaceOrder 美股下单 + SharePlaceOrder(ctx context.Context, in *UsOrderRequest, opts ...grpc.CallOption) (*UsOrderReply, error) + // ShareUpdateOrder 美股设置止盈止损 + ShareUpdateOrder(ctx context.Context, in *UpdateUsOrderRequest, opts ...grpc.CallOption) (*UsOrderReply, error) + // SharePosition 美股平仓 + SharePosition(ctx context.Context, in *CancelUsOrderRequest, opts ...grpc.CallOption) (*UsOrderReply, error) + // ShareCancel 美股一键平仓 + ShareAllPosition(ctx context.Context, in *AllUsOrderRequest, opts ...grpc.CallOption) (*AllUsOrderReply, error) + // ShareCancel 美股撤单 + ShareCancel(ctx context.Context, in *CancelUsOrderRequest, opts ...grpc.CallOption) (*UsOrderReply, error) +} + +type shareUsClient struct { + cc grpc.ClientConnInterface +} + +func NewShareUsClient(cc grpc.ClientConnInterface) ShareUsClient { + return &shareUsClient{cc} +} + +func (c *shareUsClient) GetBotStockTrade(ctx context.Context, in *GetUsBotStockTradeRequest, opts ...grpc.CallOption) (*GetUsBotStockTradeReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetUsBotStockTradeReply) + err := c.cc.Invoke(ctx, ShareUs_GetBotStockTrade_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareUsClient) SharePlaceOrder(ctx context.Context, in *UsOrderRequest, opts ...grpc.CallOption) (*UsOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(UsOrderReply) + err := c.cc.Invoke(ctx, ShareUs_SharePlaceOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareUsClient) ShareUpdateOrder(ctx context.Context, in *UpdateUsOrderRequest, opts ...grpc.CallOption) (*UsOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(UsOrderReply) + err := c.cc.Invoke(ctx, ShareUs_ShareUpdateOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareUsClient) SharePosition(ctx context.Context, in *CancelUsOrderRequest, opts ...grpc.CallOption) (*UsOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(UsOrderReply) + err := c.cc.Invoke(ctx, ShareUs_SharePosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareUsClient) ShareAllPosition(ctx context.Context, in *AllUsOrderRequest, opts ...grpc.CallOption) (*AllUsOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AllUsOrderReply) + err := c.cc.Invoke(ctx, ShareUs_ShareAllPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *shareUsClient) ShareCancel(ctx context.Context, in *CancelUsOrderRequest, opts ...grpc.CallOption) (*UsOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(UsOrderReply) + err := c.cc.Invoke(ctx, ShareUs_ShareCancel_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ShareUsServer is the server API for ShareUs service. +// All implementations must embed UnimplementedShareUsServer +// for forward compatibility +type ShareUsServer interface { + // GetBotStockTrade 美股列表查询 + GetBotStockTrade(context.Context, *GetUsBotStockTradeRequest) (*GetUsBotStockTradeReply, error) + // SharePlaceOrder 美股下单 + SharePlaceOrder(context.Context, *UsOrderRequest) (*UsOrderReply, error) + // ShareUpdateOrder 美股设置止盈止损 + ShareUpdateOrder(context.Context, *UpdateUsOrderRequest) (*UsOrderReply, error) + // SharePosition 美股平仓 + SharePosition(context.Context, *CancelUsOrderRequest) (*UsOrderReply, error) + // ShareCancel 美股一键平仓 + ShareAllPosition(context.Context, *AllUsOrderRequest) (*AllUsOrderReply, error) + // ShareCancel 美股撤单 + ShareCancel(context.Context, *CancelUsOrderRequest) (*UsOrderReply, error) + mustEmbedUnimplementedShareUsServer() +} + +// UnimplementedShareUsServer must be embedded to have forward compatible implementations. +type UnimplementedShareUsServer struct { +} + +func (UnimplementedShareUsServer) GetBotStockTrade(context.Context, *GetUsBotStockTradeRequest) (*GetUsBotStockTradeReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBotStockTrade not implemented") +} +func (UnimplementedShareUsServer) SharePlaceOrder(context.Context, *UsOrderRequest) (*UsOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method SharePlaceOrder not implemented") +} +func (UnimplementedShareUsServer) ShareUpdateOrder(context.Context, *UpdateUsOrderRequest) (*UsOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareUpdateOrder not implemented") +} +func (UnimplementedShareUsServer) SharePosition(context.Context, *CancelUsOrderRequest) (*UsOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method SharePosition not implemented") +} +func (UnimplementedShareUsServer) ShareAllPosition(context.Context, *AllUsOrderRequest) (*AllUsOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareAllPosition not implemented") +} +func (UnimplementedShareUsServer) ShareCancel(context.Context, *CancelUsOrderRequest) (*UsOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ShareCancel not implemented") +} +func (UnimplementedShareUsServer) mustEmbedUnimplementedShareUsServer() {} + +// UnsafeShareUsServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ShareUsServer will +// result in compilation errors. +type UnsafeShareUsServer interface { + mustEmbedUnimplementedShareUsServer() +} + +func RegisterShareUsServer(s grpc.ServiceRegistrar, srv ShareUsServer) { + s.RegisterService(&ShareUs_ServiceDesc, srv) +} + +func _ShareUs_GetBotStockTrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetUsBotStockTradeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareUsServer).GetBotStockTrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareUs_GetBotStockTrade_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareUsServer).GetBotStockTrade(ctx, req.(*GetUsBotStockTradeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareUs_SharePlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UsOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareUsServer).SharePlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareUs_SharePlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareUsServer).SharePlaceOrder(ctx, req.(*UsOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareUs_ShareUpdateOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateUsOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareUsServer).ShareUpdateOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareUs_ShareUpdateOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareUsServer).ShareUpdateOrder(ctx, req.(*UpdateUsOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareUs_SharePosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelUsOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareUsServer).SharePosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareUs_SharePosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareUsServer).SharePosition(ctx, req.(*CancelUsOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareUs_ShareAllPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AllUsOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareUsServer).ShareAllPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareUs_ShareAllPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareUsServer).ShareAllPosition(ctx, req.(*AllUsOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ShareUs_ShareCancel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelUsOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShareUsServer).ShareCancel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShareUs_ShareCancel_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShareUsServer).ShareCancel(ctx, req.(*CancelUsOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// ShareUs_ServiceDesc is the grpc.ServiceDesc for ShareUs service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ShareUs_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "matchmaking.v1.ShareUs", + HandlerType: (*ShareUsServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetBotStockTrade", + Handler: _ShareUs_GetBotStockTrade_Handler, + }, + { + MethodName: "SharePlaceOrder", + Handler: _ShareUs_SharePlaceOrder_Handler, + }, + { + MethodName: "ShareUpdateOrder", + Handler: _ShareUs_ShareUpdateOrder_Handler, + }, + { + MethodName: "SharePosition", + Handler: _ShareUs_SharePosition_Handler, + }, + { + MethodName: "ShareAllPosition", + Handler: _ShareUs_ShareAllPosition_Handler, + }, + { + MethodName: "ShareCancel", + Handler: _ShareUs_ShareCancel_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "matchmaking/v1/share/shareUs.proto", +} diff --git a/api/matchmaking/v1/share/shareUs_http.pb.go b/api/matchmaking/v1/share/shareUs_http.pb.go new file mode 100644 index 0000000..a7c7f56 --- /dev/null +++ b/api/matchmaking/v1/share/shareUs_http.pb.go @@ -0,0 +1,279 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.3 +// - protoc v5.27.1 +// source: matchmaking/v1/share/shareUs.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationShareUsGetBotStockTrade = "/matchmaking.v1.ShareUs/GetBotStockTrade" +const OperationShareUsShareAllPosition = "/matchmaking.v1.ShareUs/ShareAllPosition" +const OperationShareUsShareCancel = "/matchmaking.v1.ShareUs/ShareCancel" +const OperationShareUsSharePlaceOrder = "/matchmaking.v1.ShareUs/SharePlaceOrder" +const OperationShareUsSharePosition = "/matchmaking.v1.ShareUs/SharePosition" +const OperationShareUsShareUpdateOrder = "/matchmaking.v1.ShareUs/ShareUpdateOrder" + +type ShareUsHTTPServer interface { + // GetBotStockTrade GetBotStockTrade 美股列表查询 + GetBotStockTrade(context.Context, *GetUsBotStockTradeRequest) (*GetUsBotStockTradeReply, error) + // ShareAllPosition ShareCancel 美股一键平仓 + ShareAllPosition(context.Context, *AllUsOrderRequest) (*AllUsOrderReply, error) + // ShareCancel ShareCancel 美股撤单 + ShareCancel(context.Context, *CancelUsOrderRequest) (*UsOrderReply, error) + // SharePlaceOrder SharePlaceOrder 美股下单 + SharePlaceOrder(context.Context, *UsOrderRequest) (*UsOrderReply, error) + // SharePosition SharePosition 美股平仓 + SharePosition(context.Context, *CancelUsOrderRequest) (*UsOrderReply, error) + // ShareUpdateOrder ShareUpdateOrder 美股设置止盈止损 + ShareUpdateOrder(context.Context, *UpdateUsOrderRequest) (*UsOrderReply, error) +} + +func RegisterShareUsHTTPServer(s *http.Server, srv ShareUsHTTPServer) { + r := s.Route("/") + r.POST("/order_shareus/share_list", _ShareUs_GetBotStockTrade0_HTTP_Handler(srv)) + r.POST("/order_shareus/share_place_order", _ShareUs_SharePlaceOrder0_HTTP_Handler(srv)) + r.POST("/order_shareus/share_update_order", _ShareUs_ShareUpdateOrder0_HTTP_Handler(srv)) + r.POST("/order_shareus/share_position", _ShareUs_SharePosition0_HTTP_Handler(srv)) + r.POST("/order_shareus/share_all_position", _ShareUs_ShareAllPosition0_HTTP_Handler(srv)) + r.POST("/order_shareus/share_cancel", _ShareUs_ShareCancel0_HTTP_Handler(srv)) +} + +func _ShareUs_GetBotStockTrade0_HTTP_Handler(srv ShareUsHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetUsBotStockTradeRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareUsGetBotStockTrade) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.GetBotStockTrade(ctx, req.(*GetUsBotStockTradeRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetUsBotStockTradeReply) + return ctx.Result(200, reply) + } +} + +func _ShareUs_SharePlaceOrder0_HTTP_Handler(srv ShareUsHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in UsOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareUsSharePlaceOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.SharePlaceOrder(ctx, req.(*UsOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*UsOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareUs_ShareUpdateOrder0_HTTP_Handler(srv ShareUsHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in UpdateUsOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareUsShareUpdateOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareUpdateOrder(ctx, req.(*UpdateUsOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*UsOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareUs_SharePosition0_HTTP_Handler(srv ShareUsHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelUsOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareUsSharePosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.SharePosition(ctx, req.(*CancelUsOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*UsOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareUs_ShareAllPosition0_HTTP_Handler(srv ShareUsHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in AllUsOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareUsShareAllPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareAllPosition(ctx, req.(*AllUsOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*AllUsOrderReply) + return ctx.Result(200, reply) + } +} + +func _ShareUs_ShareCancel0_HTTP_Handler(srv ShareUsHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelUsOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationShareUsShareCancel) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ShareCancel(ctx, req.(*CancelUsOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*UsOrderReply) + return ctx.Result(200, reply) + } +} + +type ShareUsHTTPClient interface { + GetBotStockTrade(ctx context.Context, req *GetUsBotStockTradeRequest, opts ...http.CallOption) (rsp *GetUsBotStockTradeReply, err error) + ShareAllPosition(ctx context.Context, req *AllUsOrderRequest, opts ...http.CallOption) (rsp *AllUsOrderReply, err error) + ShareCancel(ctx context.Context, req *CancelUsOrderRequest, opts ...http.CallOption) (rsp *UsOrderReply, err error) + SharePlaceOrder(ctx context.Context, req *UsOrderRequest, opts ...http.CallOption) (rsp *UsOrderReply, err error) + SharePosition(ctx context.Context, req *CancelUsOrderRequest, opts ...http.CallOption) (rsp *UsOrderReply, err error) + ShareUpdateOrder(ctx context.Context, req *UpdateUsOrderRequest, opts ...http.CallOption) (rsp *UsOrderReply, err error) +} + +type ShareUsHTTPClientImpl struct { + cc *http.Client +} + +func NewShareUsHTTPClient(client *http.Client) ShareUsHTTPClient { + return &ShareUsHTTPClientImpl{client} +} + +func (c *ShareUsHTTPClientImpl) GetBotStockTrade(ctx context.Context, in *GetUsBotStockTradeRequest, opts ...http.CallOption) (*GetUsBotStockTradeReply, error) { + var out GetUsBotStockTradeReply + pattern := "/order_shareus/share_list" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareUsGetBotStockTrade)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareUsHTTPClientImpl) ShareAllPosition(ctx context.Context, in *AllUsOrderRequest, opts ...http.CallOption) (*AllUsOrderReply, error) { + var out AllUsOrderReply + pattern := "/order_shareus/share_all_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareUsShareAllPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareUsHTTPClientImpl) ShareCancel(ctx context.Context, in *CancelUsOrderRequest, opts ...http.CallOption) (*UsOrderReply, error) { + var out UsOrderReply + pattern := "/order_shareus/share_cancel" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareUsShareCancel)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareUsHTTPClientImpl) SharePlaceOrder(ctx context.Context, in *UsOrderRequest, opts ...http.CallOption) (*UsOrderReply, error) { + var out UsOrderReply + pattern := "/order_shareus/share_place_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareUsSharePlaceOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareUsHTTPClientImpl) SharePosition(ctx context.Context, in *CancelUsOrderRequest, opts ...http.CallOption) (*UsOrderReply, error) { + var out UsOrderReply + pattern := "/order_shareus/share_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareUsSharePosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ShareUsHTTPClientImpl) ShareUpdateOrder(ctx context.Context, in *UpdateUsOrderRequest, opts ...http.CallOption) (*UsOrderReply, error) { + var out UsOrderReply + pattern := "/order_shareus/share_update_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationShareUsShareUpdateOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/api/matchmaking/v1/virtually/contract.pb.go b/api/matchmaking/v1/virtually/contract.pb.go new file mode 100644 index 0000000..84fb0d8 --- /dev/null +++ b/api/matchmaking/v1/virtually/contract.pb.go @@ -0,0 +1,1393 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/virtually/contract.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GetBotContractTradeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status int64 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` // 状态码 + PageSize int64 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,3,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + State int64 `protobuf:"varint,4,opt,name=state,proto3" json:"state,omitempty"` // 订单类型 +} + +func (x *GetBotContractTradeRequest) Reset() { + *x = GetBotContractTradeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotContractTradeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotContractTradeRequest) ProtoMessage() {} + +func (x *GetBotContractTradeRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotContractTradeRequest.ProtoReflect.Descriptor instead. +func (*GetBotContractTradeRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_contract_proto_rawDescGZIP(), []int{0} +} + +func (x *GetBotContractTradeRequest) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *GetBotContractTradeRequest) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *GetBotContractTradeRequest) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *GetBotContractTradeRequest) GetState() int64 { + if x != nil { + return x.State + } + return 0 +} + +type GetBotContractTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *BotContractTradeData `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *GetBotContractTradeReply) Reset() { + *x = GetBotContractTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotContractTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotContractTradeReply) ProtoMessage() {} + +func (x *GetBotContractTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotContractTradeReply.ProtoReflect.Descriptor instead. +func (*GetBotContractTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_contract_proto_rawDescGZIP(), []int{1} +} + +func (x *GetBotContractTradeReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *GetBotContractTradeReply) GetData() *BotContractTradeData { + if x != nil { + return x.Data + } + return nil +} + +func (x *GetBotContractTradeReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type BotContractTradeData struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PageSize int64 `protobuf:"varint,1,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,2,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + Data []*BotContractTrade `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty"` // 返回结果 + TotalCount int64 `protobuf:"varint,4,opt,name=totalCount,proto3" json:"totalCount,omitempty"` // 总数据 +} + +func (x *BotContractTradeData) Reset() { + *x = BotContractTradeData{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotContractTradeData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotContractTradeData) ProtoMessage() {} + +func (x *BotContractTradeData) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotContractTradeData.ProtoReflect.Descriptor instead. +func (*BotContractTradeData) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_contract_proto_rawDescGZIP(), []int{2} +} + +func (x *BotContractTradeData) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *BotContractTradeData) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *BotContractTradeData) GetData() []*BotContractTrade { + if x != nil { + return x.Data + } + return nil +} + +func (x *BotContractTradeData) GetTotalCount() int64 { + if x != nil { + return x.TotalCount + } + return 0 +} + +type BotContractTrade struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID + ContractId string `protobuf:"bytes,2,opt,name=contractId,proto3" json:"contractId,omitempty"` // 合约ID + TradeType int64 `protobuf:"varint,3,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型 + DealType int64 `protobuf:"varint,4,opt,name=dealType,proto3" json:"dealType,omitempty"` // 交易方式 + LimitPrice string `protobuf:"bytes,5,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,6,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + DealPrice string `protobuf:"bytes,7,opt,name=dealPrice,proto3" json:"dealPrice,omitempty"` // 开仓价 + ClosingPrice string `protobuf:"bytes,8,opt,name=closingPrice,proto3" json:"closingPrice,omitempty"` // 平仓价 + OrderNumber string `protobuf:"bytes,9,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损状态 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + ServiceCost string `protobuf:"bytes,13,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 开仓手续费 + EarnestMoney string `protobuf:"bytes,14,opt,name=earnestMoney,proto3" json:"earnestMoney,omitempty"` // 保证金 + OrderMoney string `protobuf:"bytes,15,opt,name=orderMoney,proto3" json:"orderMoney,omitempty"` // 订单总额 + Status int64 `protobuf:"varint,16,opt,name=status,proto3" json:"status,omitempty"` // 订单状态 + CreateTime *timestamppb.Timestamp `protobuf:"bytes,17,opt,name=createTime,proto3" json:"createTime,omitempty"` // 订单创建时间 + UpdateTime *timestamppb.Timestamp `protobuf:"bytes,18,opt,name=updateTime,proto3" json:"updateTime,omitempty"` // 订单更新时间 + OpenTime *timestamppb.Timestamp `protobuf:"bytes,19,opt,name=openTime,proto3" json:"openTime,omitempty"` // 订单开仓时间 + ClosingTime *timestamppb.Timestamp `protobuf:"bytes,20,opt,name=closingTime,proto3" json:"closingTime,omitempty"` // 订单平仓时间 + ClosingCost string `protobuf:"bytes,21,opt,name=closingCost,proto3" json:"closingCost,omitempty"` // 平仓手续费 + FaceValue string `protobuf:"bytes,22,opt,name=faceValue,proto3" json:"faceValue,omitempty"` // 面值 + OvernightCost string `protobuf:"bytes,23,opt,name=overnightCost,proto3" json:"overnightCost,omitempty"` // 过夜手续费 + PryNum string `protobuf:"bytes,24,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆值 + KeepDecimal string `protobuf:"bytes,25,opt,name=keepDecimal,proto3" json:"keepDecimal,omitempty"` // 保留小数位 + SecondTime string `protobuf:"bytes,26,opt,name=secondTime,proto3" json:"secondTime,omitempty"` // 秒合约时间 + State int64 `protobuf:"varint,27,opt,name=state,proto3" json:"state,omitempty"` // 订单类型 +} + +func (x *BotContractTrade) Reset() { + *x = BotContractTrade{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotContractTrade) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotContractTrade) ProtoMessage() {} + +func (x *BotContractTrade) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotContractTrade.ProtoReflect.Descriptor instead. +func (*BotContractTrade) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_contract_proto_rawDescGZIP(), []int{3} +} + +func (x *BotContractTrade) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *BotContractTrade) GetContractId() string { + if x != nil { + return x.ContractId + } + return "" +} + +func (x *BotContractTrade) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *BotContractTrade) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *BotContractTrade) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *BotContractTrade) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *BotContractTrade) GetDealPrice() string { + if x != nil { + return x.DealPrice + } + return "" +} + +func (x *BotContractTrade) GetClosingPrice() string { + if x != nil { + return x.ClosingPrice + } + return "" +} + +func (x *BotContractTrade) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *BotContractTrade) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *BotContractTrade) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *BotContractTrade) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *BotContractTrade) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *BotContractTrade) GetEarnestMoney() string { + if x != nil { + return x.EarnestMoney + } + return "" +} + +func (x *BotContractTrade) GetOrderMoney() string { + if x != nil { + return x.OrderMoney + } + return "" +} + +func (x *BotContractTrade) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *BotContractTrade) GetCreateTime() *timestamppb.Timestamp { + if x != nil { + return x.CreateTime + } + return nil +} + +func (x *BotContractTrade) GetUpdateTime() *timestamppb.Timestamp { + if x != nil { + return x.UpdateTime + } + return nil +} + +func (x *BotContractTrade) GetOpenTime() *timestamppb.Timestamp { + if x != nil { + return x.OpenTime + } + return nil +} + +func (x *BotContractTrade) GetClosingTime() *timestamppb.Timestamp { + if x != nil { + return x.ClosingTime + } + return nil +} + +func (x *BotContractTrade) GetClosingCost() string { + if x != nil { + return x.ClosingCost + } + return "" +} + +func (x *BotContractTrade) GetFaceValue() string { + if x != nil { + return x.FaceValue + } + return "" +} + +func (x *BotContractTrade) GetOvernightCost() string { + if x != nil { + return x.OvernightCost + } + return "" +} + +func (x *BotContractTrade) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *BotContractTrade) GetKeepDecimal() string { + if x != nil { + return x.KeepDecimal + } + return "" +} + +func (x *BotContractTrade) GetSecondTime() string { + if x != nil { + return x.SecondTime + } + return "" +} + +func (x *BotContractTrade) GetState() int64 { + if x != nil { + return x.State + } + return 0 +} + +type ContractRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ContractId string `protobuf:"bytes,1,opt,name=contractId,proto3" json:"contractId,omitempty"` // 交易对 + TradeType int64 `protobuf:"varint,2,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型:1买入,2卖出 + DealType int64 `protobuf:"varint,3,opt,name=dealType,proto3" json:"dealType,omitempty"` // 委托方式:1限价,2市价 + LimitPrice string `protobuf:"bytes,4,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,5,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + OrderAmount string `protobuf:"bytes,6,opt,name=orderAmount,proto3" json:"orderAmount,omitempty"` // 订单金额 + OrderNumber string `protobuf:"bytes,7,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + EarnestMoney string `protobuf:"bytes,8,opt,name=earnestMoney,proto3" json:"earnestMoney,omitempty"` // 保证金 + ServiceCost string `protobuf:"bytes,9,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 手续费 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止损止盈设置:0无设置,1止损止盈 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + PryNum string `protobuf:"bytes,13,opt,name=pryNum,proto3" json:"pryNum,omitempty"` //杠杆 + Time int64 `protobuf:"varint,14,opt,name=time,proto3" json:"time,omitempty"` // 秒合约时间 +} + +func (x *ContractRequest) Reset() { + *x = ContractRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ContractRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ContractRequest) ProtoMessage() {} + +func (x *ContractRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ContractRequest.ProtoReflect.Descriptor instead. +func (*ContractRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_contract_proto_rawDescGZIP(), []int{4} +} + +func (x *ContractRequest) GetContractId() string { + if x != nil { + return x.ContractId + } + return "" +} + +func (x *ContractRequest) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *ContractRequest) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *ContractRequest) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *ContractRequest) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *ContractRequest) GetOrderAmount() string { + if x != nil { + return x.OrderAmount + } + return "" +} + +func (x *ContractRequest) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *ContractRequest) GetEarnestMoney() string { + if x != nil { + return x.EarnestMoney + } + return "" +} + +func (x *ContractRequest) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *ContractRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *ContractRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *ContractRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *ContractRequest) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *ContractRequest) GetTime() int64 { + if x != nil { + return x.Time + } + return 0 +} + +type ContractReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *ContractResult `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *ContractReply) Reset() { + *x = ContractReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ContractReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ContractReply) ProtoMessage() {} + +func (x *ContractReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ContractReply.ProtoReflect.Descriptor instead. +func (*ContractReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_contract_proto_rawDescGZIP(), []int{5} +} + +func (x *ContractReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *ContractReply) GetData() *ContractResult { + if x != nil { + return x.Data + } + return nil +} + +func (x *ContractReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type ContractResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id +} + +func (x *ContractResult) Reset() { + *x = ContractResult{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ContractResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ContractResult) ProtoMessage() {} + +func (x *ContractResult) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ContractResult.ProtoReflect.Descriptor instead. +func (*ContractResult) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_contract_proto_rawDescGZIP(), []int{6} +} + +func (x *ContractResult) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type UpdateContractRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id + StopType int64 `protobuf:"varint,2,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损 + StopLossPrice string `protobuf:"bytes,3,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,4,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 +} + +func (x *UpdateContractRequest) Reset() { + *x = UpdateContractRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateContractRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateContractRequest) ProtoMessage() {} + +func (x *UpdateContractRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateContractRequest.ProtoReflect.Descriptor instead. +func (*UpdateContractRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_contract_proto_rawDescGZIP(), []int{7} +} + +func (x *UpdateContractRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *UpdateContractRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *UpdateContractRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *UpdateContractRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +type CancelContractRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID +} + +func (x *CancelContractRequest) Reset() { + *x = CancelContractRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CancelContractRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CancelContractRequest) ProtoMessage() {} + +func (x *CancelContractRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CancelContractRequest.ProtoReflect.Descriptor instead. +func (*CancelContractRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_contract_proto_rawDescGZIP(), []int{8} +} + +func (x *CancelContractRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type AllContractRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *AllContractRequest) Reset() { + *x = AllContractRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllContractRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllContractRequest) ProtoMessage() {} + +func (x *AllContractRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllContractRequest.ProtoReflect.Descriptor instead. +func (*AllContractRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_contract_proto_rawDescGZIP(), []int{9} +} + +type AllContractReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *AllContractReply) Reset() { + *x = AllContractReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AllContractReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AllContractReply) ProtoMessage() {} + +func (x *AllContractReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_contract_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AllContractReply.ProtoReflect.Descriptor instead. +func (*AllContractReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_contract_proto_rawDescGZIP(), []int{10} +} + +func (x *AllContractReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *AllContractReply) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +func (x *AllContractReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_matchmaking_v1_virtually_contract_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_virtually_contract_proto_rawDesc = []byte{ + 0x0a, 0x27, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x6c, 0x79, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, + 0x61, 0x63, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, + 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, + 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, + 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x84, 0x01, 0x0a, 0x1a, 0x47, 0x65, 0x74, + 0x42, 0x6f, 0x74, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x54, 0x72, 0x61, 0x64, 0x65, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, + 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, + 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, + 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, + 0x74, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, + 0x82, 0x01, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, + 0x63, 0x74, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, + 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, + 0x12, 0x38, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, + 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x42, 0x6f, 0x74, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x54, 0x72, 0x61, 0x64, 0x65, + 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x22, 0xa6, 0x01, 0x0a, 0x14, 0x42, 0x6f, 0x74, 0x43, 0x6f, 0x6e, 0x74, + 0x72, 0x61, 0x63, 0x74, 0x54, 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, 0x61, 0x12, 0x1a, 0x0a, + 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, + 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, + 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x34, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, + 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, + 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, + 0x63, 0x74, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x1e, 0x0a, + 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0xd4, 0x07, + 0x0a, 0x10, 0x42, 0x6f, 0x74, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x54, 0x72, 0x61, + 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1e, 0x0a, 0x0a, + 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, + 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, + 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, + 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, + 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, + 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x65, 0x61, 0x6c, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x64, 0x65, 0x61, + 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, + 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6c, + 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, + 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, + 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, + 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, + 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0c, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, + 0x74, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x43, 0x6f, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x0c, 0x65, 0x61, 0x72, 0x6e, 0x65, 0x73, 0x74, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x61, 0x72, 0x6e, + 0x65, 0x73, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, + 0x75, 0x73, 0x18, 0x10, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x12, 0x3a, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x11, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, + 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x3a, 0x0a, 0x0a, + 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x12, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x75, 0x70, + 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x36, 0x0a, 0x08, 0x6f, 0x70, 0x65, 0x6e, + 0x54, 0x69, 0x6d, 0x65, 0x18, 0x13, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, + 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, + 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x08, 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, + 0x12, 0x3c, 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x18, + 0x14, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, + 0x70, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, + 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x15, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, + 0x12, 0x1c, 0x0a, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x16, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x24, + 0x0a, 0x0d, 0x6f, 0x76, 0x65, 0x72, 0x6e, 0x69, 0x67, 0x68, 0x74, 0x43, 0x6f, 0x73, 0x74, 0x18, + 0x17, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x6f, 0x76, 0x65, 0x72, 0x6e, 0x69, 0x67, 0x68, 0x74, + 0x43, 0x6f, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x18, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x12, 0x20, 0x0a, 0x0b, + 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x18, 0x19, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x12, 0x1e, + 0x0a, 0x0a, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x1a, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x14, + 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x1b, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x73, + 0x74, 0x61, 0x74, 0x65, 0x22, 0xc9, 0x03, 0x0a, 0x0f, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, + 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x74, + 0x72, 0x61, 0x63, 0x74, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x6f, + 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, 0x61, 0x64, + 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x72, 0x61, + 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, + 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, + 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x41, 0x6d, 0x6f, + 0x75, 0x6e, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, + 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x22, 0x0a, 0x0c, 0x65, 0x61, 0x72, 0x6e, + 0x65, 0x73, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, + 0x65, 0x61, 0x72, 0x6e, 0x65, 0x73, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x20, 0x0a, 0x0b, + 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x09, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1a, + 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, + 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x0d, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x12, 0x12, 0x0a, 0x04, + 0x74, 0x69, 0x6d, 0x65, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x69, 0x6d, 0x65, + 0x22, 0x71, 0x0a, 0x0d, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x32, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, + 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x52, 0x65, 0x73, + 0x75, 0x6c, 0x74, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x22, 0x2a, 0x0a, 0x0e, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x52, + 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x22, + 0x97, 0x01, 0x0a, 0x15, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, + 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, + 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, + 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x22, 0x31, 0x0a, 0x15, 0x43, 0x61, 0x6e, + 0x63, 0x65, 0x6c, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x22, 0x14, 0x0a, 0x12, + 0x41, 0x6c, 0x6c, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x22, 0x54, 0x0a, 0x10, 0x41, 0x6c, 0x6c, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, + 0x74, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, + 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, + 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0xdd, 0x06, 0x0a, 0x08, 0x43, 0x6f, 0x6e, + 0x74, 0x72, 0x61, 0x63, 0x74, 0x12, 0x95, 0x01, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, + 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x2a, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, + 0x65, 0x74, 0x42, 0x6f, 0x74, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x54, 0x72, 0x61, + 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x28, 0x2e, 0x6d, 0x61, 0x74, 0x63, + 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6f, + 0x74, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x28, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x22, 0x3a, 0x01, 0x2a, 0x22, 0x1d, + 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x2f, + 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x12, 0x85, 0x01, + 0x0a, 0x12, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x50, 0x6c, 0x61, 0x63, 0x65, 0x4f, + 0x72, 0x64, 0x65, 0x72, 0x12, 0x1f, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, + 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, + 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x52, + 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2f, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x29, 0x3a, 0x01, 0x2a, 0x22, + 0x24, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, + 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x5f, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x5f, + 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x92, 0x01, 0x0a, 0x18, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, + 0x63, 0x74, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x6c, 0x61, 0x63, 0x65, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x12, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, + 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, + 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x72, + 0x61, 0x63, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x30, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x2a, + 0x3a, 0x01, 0x2a, 0x22, 0x25, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x63, 0x6f, 0x6e, 0x74, + 0x72, 0x61, 0x63, 0x74, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x5f, 0x75, 0x70, + 0x64, 0x61, 0x74, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x86, 0x01, 0x0a, 0x10, 0x43, + 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, + 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, + 0x2e, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, + 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, + 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2c, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x26, 0x3a, 0x01, 0x2a, + 0x22, 0x21, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, + 0x74, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, + 0x69, 0x6f, 0x6e, 0x12, 0x8d, 0x01, 0x0a, 0x13, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, + 0x41, 0x6c, 0x6c, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x22, 0x2e, 0x6d, 0x61, + 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6c, 0x6c, + 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x20, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, + 0x2e, 0x41, 0x6c, 0x6c, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x52, 0x65, 0x70, 0x6c, + 0x79, 0x22, 0x30, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x2a, 0x3a, 0x01, 0x2a, 0x22, 0x25, 0x2f, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x2f, 0x63, 0x6f, + 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x5f, 0x61, 0x6c, 0x6c, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, + 0x69, 0x6f, 0x6e, 0x12, 0x82, 0x01, 0x0a, 0x0e, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, + 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x12, 0x25, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, + 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x43, 0x6f, + 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, + 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2a, 0x82, 0xd3, + 0xe4, 0x93, 0x02, 0x24, 0x3a, 0x01, 0x2a, 0x22, 0x1f, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, + 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, + 0x74, 0x5f, 0x63, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x42, 0x2a, 0x5a, 0x28, 0x6d, 0x61, 0x74, 0x63, + 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2f, 0x61, + 0x70, 0x69, 0x2f, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, + 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_virtually_contract_proto_rawDescOnce sync.Once + file_matchmaking_v1_virtually_contract_proto_rawDescData = file_matchmaking_v1_virtually_contract_proto_rawDesc +) + +func file_matchmaking_v1_virtually_contract_proto_rawDescGZIP() []byte { + file_matchmaking_v1_virtually_contract_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_virtually_contract_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_virtually_contract_proto_rawDescData) + }) + return file_matchmaking_v1_virtually_contract_proto_rawDescData +} + +var file_matchmaking_v1_virtually_contract_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_matchmaking_v1_virtually_contract_proto_goTypes = []any{ + (*GetBotContractTradeRequest)(nil), // 0: matchmaking.v1.GetBotContractTradeRequest + (*GetBotContractTradeReply)(nil), // 1: matchmaking.v1.GetBotContractTradeReply + (*BotContractTradeData)(nil), // 2: matchmaking.v1.BotContractTradeData + (*BotContractTrade)(nil), // 3: matchmaking.v1.BotContractTrade + (*ContractRequest)(nil), // 4: matchmaking.v1.ContractRequest + (*ContractReply)(nil), // 5: matchmaking.v1.ContractReply + (*ContractResult)(nil), // 6: matchmaking.v1.ContractResult + (*UpdateContractRequest)(nil), // 7: matchmaking.v1.UpdateContractRequest + (*CancelContractRequest)(nil), // 8: matchmaking.v1.CancelContractRequest + (*AllContractRequest)(nil), // 9: matchmaking.v1.AllContractRequest + (*AllContractReply)(nil), // 10: matchmaking.v1.AllContractReply + (*timestamppb.Timestamp)(nil), // 11: google.protobuf.Timestamp +} +var file_matchmaking_v1_virtually_contract_proto_depIdxs = []int32{ + 2, // 0: matchmaking.v1.GetBotContractTradeReply.data:type_name -> matchmaking.v1.BotContractTradeData + 3, // 1: matchmaking.v1.BotContractTradeData.data:type_name -> matchmaking.v1.BotContractTrade + 11, // 2: matchmaking.v1.BotContractTrade.createTime:type_name -> google.protobuf.Timestamp + 11, // 3: matchmaking.v1.BotContractTrade.updateTime:type_name -> google.protobuf.Timestamp + 11, // 4: matchmaking.v1.BotContractTrade.openTime:type_name -> google.protobuf.Timestamp + 11, // 5: matchmaking.v1.BotContractTrade.closingTime:type_name -> google.protobuf.Timestamp + 6, // 6: matchmaking.v1.ContractReply.data:type_name -> matchmaking.v1.ContractResult + 0, // 7: matchmaking.v1.Contract.GetBotContractTrade:input_type -> matchmaking.v1.GetBotContractTradeRequest + 4, // 8: matchmaking.v1.Contract.ContractPlaceOrder:input_type -> matchmaking.v1.ContractRequest + 7, // 9: matchmaking.v1.Contract.ContractUpdatePlaceOrder:input_type -> matchmaking.v1.UpdateContractRequest + 8, // 10: matchmaking.v1.Contract.ContractPosition:input_type -> matchmaking.v1.CancelContractRequest + 9, // 11: matchmaking.v1.Contract.ContractAllPosition:input_type -> matchmaking.v1.AllContractRequest + 8, // 12: matchmaking.v1.Contract.ContractCancel:input_type -> matchmaking.v1.CancelContractRequest + 1, // 13: matchmaking.v1.Contract.GetBotContractTrade:output_type -> matchmaking.v1.GetBotContractTradeReply + 5, // 14: matchmaking.v1.Contract.ContractPlaceOrder:output_type -> matchmaking.v1.ContractReply + 5, // 15: matchmaking.v1.Contract.ContractUpdatePlaceOrder:output_type -> matchmaking.v1.ContractReply + 5, // 16: matchmaking.v1.Contract.ContractPosition:output_type -> matchmaking.v1.ContractReply + 10, // 17: matchmaking.v1.Contract.ContractAllPosition:output_type -> matchmaking.v1.AllContractReply + 5, // 18: matchmaking.v1.Contract.ContractCancel:output_type -> matchmaking.v1.ContractReply + 13, // [13:19] is the sub-list for method output_type + 7, // [7:13] is the sub-list for method input_type + 7, // [7:7] is the sub-list for extension type_name + 7, // [7:7] is the sub-list for extension extendee + 0, // [0:7] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_virtually_contract_proto_init() } +func file_matchmaking_v1_virtually_contract_proto_init() { + if File_matchmaking_v1_virtually_contract_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_matchmaking_v1_virtually_contract_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*GetBotContractTradeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_contract_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*GetBotContractTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_contract_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*BotContractTradeData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_contract_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*BotContractTrade); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_contract_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*ContractRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_contract_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*ContractReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_contract_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*ContractResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_contract_proto_msgTypes[7].Exporter = func(v any, i int) any { + switch v := v.(*UpdateContractRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_contract_proto_msgTypes[8].Exporter = func(v any, i int) any { + switch v := v.(*CancelContractRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_contract_proto_msgTypes[9].Exporter = func(v any, i int) any { + switch v := v.(*AllContractRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_contract_proto_msgTypes[10].Exporter = func(v any, i int) any { + switch v := v.(*AllContractReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_virtually_contract_proto_rawDesc, + NumEnums: 0, + NumMessages: 11, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_matchmaking_v1_virtually_contract_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_virtually_contract_proto_depIdxs, + MessageInfos: file_matchmaking_v1_virtually_contract_proto_msgTypes, + }.Build() + File_matchmaking_v1_virtually_contract_proto = out.File + file_matchmaking_v1_virtually_contract_proto_rawDesc = nil + file_matchmaking_v1_virtually_contract_proto_goTypes = nil + file_matchmaking_v1_virtually_contract_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/virtually/contract.proto b/api/matchmaking/v1/virtually/contract.proto new file mode 100644 index 0000000..d97da7b --- /dev/null +++ b/api/matchmaking/v1/virtually/contract.proto @@ -0,0 +1,151 @@ +syntax = "proto3"; + +package matchmaking.v1; + +import "google/api/annotations.proto"; +import "google/protobuf/timestamp.proto"; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +service Contract { + // GetBotContractTrade 合约列表查询 + rpc GetBotContractTrade(GetBotContractTradeRequest)returns(GetBotContractTradeReply){ + option (google.api.http) = { + post:"/order_contract/contract_list", + body:"*", + }; + } + // ContractPlaceOrder 合约下单 + rpc ContractPlaceOrder(ContractRequest)returns(ContractReply){ + option (google.api.http) = { + post: "/order_contract/contract_place_order", + body: "*", + }; + } + // ContractUpdatePlaceOrder 合约设置止盈止损 + rpc ContractUpdatePlaceOrder(UpdateContractRequest)returns(ContractReply){ + option (google.api.http) = { + post: "/order_contract/contract_update_order", + body: "*", + }; + } + // ContractPosition 合约平仓 + rpc ContractPosition(CancelContractRequest)returns(ContractReply){ + option (google.api.http) = { + post:"/order_contract/contract_position", + body:"*", + }; + } + // ContractAllPosition 合约一键平仓 + rpc ContractAllPosition(AllContractRequest)returns(AllContractReply){ + option (google.api.http) = { + post:"/order_contract/contract_all_position", + body:"*", + }; + } + // ContractCancel 合约撤单 + rpc ContractCancel(CancelContractRequest)returns(ContractReply){ + option (google.api.http) = { + post:"/order_contract/contract_cancel", + body:"*", + }; + } +} + +message GetBotContractTradeRequest{ + int64 status =1;// 状态码 + int64 pageSize =2; // 每页显示条数 + int64 pageCount =3;// 开始的位置 + int64 state = 4;// 订单类型 +} + +message GetBotContractTradeReply{ + int64 code =1;// 状态码 + BotContractTradeData data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message BotContractTradeData{ + int64 pageSize =1; // 每页显示条数 + int64 pageCount =2;// 开始的位置 + repeated BotContractTrade data =3;// 返回结果 + int64 totalCount =4;// 总数据 +} + +message BotContractTrade{ + string orderId =1;// 订单ID + string contractId =2;// 合约ID + int64 tradeType =3;// 交易类型 + int64 dealType =4;// 交易方式 + string limitPrice =5;// 限价 + string marketPrice =6;// 市价 + string dealPrice =7;// 开仓价 + string closingPrice =8;// 平仓价 + string orderNumber =9;// 订单数量 + int64 stopType =10;// 止盈止损状态 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string serviceCost =13;// 开仓手续费 + string earnestMoney =14;// 保证金 + string orderMoney =15;// 订单总额 + int64 status =16;// 订单状态 + google.protobuf.Timestamp createTime =17;// 订单创建时间 + google.protobuf.Timestamp updateTime =18;// 订单更新时间 + google.protobuf.Timestamp openTime =19;// 订单开仓时间 + google.protobuf.Timestamp closingTime =20;// 订单平仓时间 + string closingCost =21;// 平仓手续费 + string faceValue =22;// 面值 + string overnightCost =23;// 过夜手续费 + string pryNum =24;// 杠杆值 + string keepDecimal =25;// 保留小数位 + string secondTime = 26;// 秒合约时间 + int64 state = 27;// 订单类型 +} + +message ContractRequest{ + string contractId =1;// 交易对 + int64 tradeType =2;// 交易类型:1买入,2卖出 + int64 dealType =3;// 委托方式:1限价,2市价 + string limitPrice =4;// 限价 + string marketPrice =5;// 市价 + string orderAmount =6;// 订单金额 + string orderNumber =7;// 订单数量 + string earnestMoney =8;// 保证金 + string serviceCost =9;// 手续费 + int64 stopType =10;// 止损止盈设置:0无设置,1止损止盈 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string pryNum =13;//杠杆 + int64 time = 14;// 秒合约时间 +} + +message ContractReply{ + int64 code =1;// 状态码 + ContractResult data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message ContractResult { + string orderId =1;// 订单Id +} + +message UpdateContractRequest{ + string orderId =1;// 订单Id + int64 stopType =2;// 止盈止损 + string stopLossPrice =3;// 止损 + string stopWinPrice =4;// 止盈 +} + +message CancelContractRequest{ + string orderId =1;// 订单ID +} + +message AllContractRequest{ + +} + +message AllContractReply{ + int64 code =1;// 状态码 + string data =2;// 返回结果 + string message =3;// 返回消息提示 +} \ No newline at end of file diff --git a/api/matchmaking/v1/virtually/contract_grpc.pb.go b/api/matchmaking/v1/virtually/contract_grpc.pb.go new file mode 100644 index 0000000..5384a5c --- /dev/null +++ b/api/matchmaking/v1/virtually/contract_grpc.pb.go @@ -0,0 +1,312 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.1 +// source: matchmaking/v1/virtually/contract.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + Contract_GetBotContractTrade_FullMethodName = "/matchmaking.v1.Contract/GetBotContractTrade" + Contract_ContractPlaceOrder_FullMethodName = "/matchmaking.v1.Contract/ContractPlaceOrder" + Contract_ContractUpdatePlaceOrder_FullMethodName = "/matchmaking.v1.Contract/ContractUpdatePlaceOrder" + Contract_ContractPosition_FullMethodName = "/matchmaking.v1.Contract/ContractPosition" + Contract_ContractAllPosition_FullMethodName = "/matchmaking.v1.Contract/ContractAllPosition" + Contract_ContractCancel_FullMethodName = "/matchmaking.v1.Contract/ContractCancel" +) + +// ContractClient is the client API for Contract service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ContractClient interface { + // GetBotContractTrade 合约列表查询 + GetBotContractTrade(ctx context.Context, in *GetBotContractTradeRequest, opts ...grpc.CallOption) (*GetBotContractTradeReply, error) + // ContractPlaceOrder 合约下单 + ContractPlaceOrder(ctx context.Context, in *ContractRequest, opts ...grpc.CallOption) (*ContractReply, error) + // ContractUpdatePlaceOrder 合约设置止盈止损 + ContractUpdatePlaceOrder(ctx context.Context, in *UpdateContractRequest, opts ...grpc.CallOption) (*ContractReply, error) + // ContractPosition 合约平仓 + ContractPosition(ctx context.Context, in *CancelContractRequest, opts ...grpc.CallOption) (*ContractReply, error) + // ContractAllPosition 合约一键平仓 + ContractAllPosition(ctx context.Context, in *AllContractRequest, opts ...grpc.CallOption) (*AllContractReply, error) + // ContractCancel 合约撤单 + ContractCancel(ctx context.Context, in *CancelContractRequest, opts ...grpc.CallOption) (*ContractReply, error) +} + +type contractClient struct { + cc grpc.ClientConnInterface +} + +func NewContractClient(cc grpc.ClientConnInterface) ContractClient { + return &contractClient{cc} +} + +func (c *contractClient) GetBotContractTrade(ctx context.Context, in *GetBotContractTradeRequest, opts ...grpc.CallOption) (*GetBotContractTradeReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetBotContractTradeReply) + err := c.cc.Invoke(ctx, Contract_GetBotContractTrade_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *contractClient) ContractPlaceOrder(ctx context.Context, in *ContractRequest, opts ...grpc.CallOption) (*ContractReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(ContractReply) + err := c.cc.Invoke(ctx, Contract_ContractPlaceOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *contractClient) ContractUpdatePlaceOrder(ctx context.Context, in *UpdateContractRequest, opts ...grpc.CallOption) (*ContractReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(ContractReply) + err := c.cc.Invoke(ctx, Contract_ContractUpdatePlaceOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *contractClient) ContractPosition(ctx context.Context, in *CancelContractRequest, opts ...grpc.CallOption) (*ContractReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(ContractReply) + err := c.cc.Invoke(ctx, Contract_ContractPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *contractClient) ContractAllPosition(ctx context.Context, in *AllContractRequest, opts ...grpc.CallOption) (*AllContractReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AllContractReply) + err := c.cc.Invoke(ctx, Contract_ContractAllPosition_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *contractClient) ContractCancel(ctx context.Context, in *CancelContractRequest, opts ...grpc.CallOption) (*ContractReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(ContractReply) + err := c.cc.Invoke(ctx, Contract_ContractCancel_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ContractServer is the server API for Contract service. +// All implementations must embed UnimplementedContractServer +// for forward compatibility +type ContractServer interface { + // GetBotContractTrade 合约列表查询 + GetBotContractTrade(context.Context, *GetBotContractTradeRequest) (*GetBotContractTradeReply, error) + // ContractPlaceOrder 合约下单 + ContractPlaceOrder(context.Context, *ContractRequest) (*ContractReply, error) + // ContractUpdatePlaceOrder 合约设置止盈止损 + ContractUpdatePlaceOrder(context.Context, *UpdateContractRequest) (*ContractReply, error) + // ContractPosition 合约平仓 + ContractPosition(context.Context, *CancelContractRequest) (*ContractReply, error) + // ContractAllPosition 合约一键平仓 + ContractAllPosition(context.Context, *AllContractRequest) (*AllContractReply, error) + // ContractCancel 合约撤单 + ContractCancel(context.Context, *CancelContractRequest) (*ContractReply, error) + mustEmbedUnimplementedContractServer() +} + +// UnimplementedContractServer must be embedded to have forward compatible implementations. +type UnimplementedContractServer struct { +} + +func (UnimplementedContractServer) GetBotContractTrade(context.Context, *GetBotContractTradeRequest) (*GetBotContractTradeReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBotContractTrade not implemented") +} +func (UnimplementedContractServer) ContractPlaceOrder(context.Context, *ContractRequest) (*ContractReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ContractPlaceOrder not implemented") +} +func (UnimplementedContractServer) ContractUpdatePlaceOrder(context.Context, *UpdateContractRequest) (*ContractReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ContractUpdatePlaceOrder not implemented") +} +func (UnimplementedContractServer) ContractPosition(context.Context, *CancelContractRequest) (*ContractReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ContractPosition not implemented") +} +func (UnimplementedContractServer) ContractAllPosition(context.Context, *AllContractRequest) (*AllContractReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ContractAllPosition not implemented") +} +func (UnimplementedContractServer) ContractCancel(context.Context, *CancelContractRequest) (*ContractReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method ContractCancel not implemented") +} +func (UnimplementedContractServer) mustEmbedUnimplementedContractServer() {} + +// UnsafeContractServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ContractServer will +// result in compilation errors. +type UnsafeContractServer interface { + mustEmbedUnimplementedContractServer() +} + +func RegisterContractServer(s grpc.ServiceRegistrar, srv ContractServer) { + s.RegisterService(&Contract_ServiceDesc, srv) +} + +func _Contract_GetBotContractTrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetBotContractTradeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ContractServer).GetBotContractTrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Contract_GetBotContractTrade_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ContractServer).GetBotContractTrade(ctx, req.(*GetBotContractTradeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Contract_ContractPlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ContractRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ContractServer).ContractPlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Contract_ContractPlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ContractServer).ContractPlaceOrder(ctx, req.(*ContractRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Contract_ContractUpdatePlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateContractRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ContractServer).ContractUpdatePlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Contract_ContractUpdatePlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ContractServer).ContractUpdatePlaceOrder(ctx, req.(*UpdateContractRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Contract_ContractPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelContractRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ContractServer).ContractPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Contract_ContractPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ContractServer).ContractPosition(ctx, req.(*CancelContractRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Contract_ContractAllPosition_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AllContractRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ContractServer).ContractAllPosition(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Contract_ContractAllPosition_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ContractServer).ContractAllPosition(ctx, req.(*AllContractRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Contract_ContractCancel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelContractRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ContractServer).ContractCancel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Contract_ContractCancel_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ContractServer).ContractCancel(ctx, req.(*CancelContractRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Contract_ServiceDesc is the grpc.ServiceDesc for Contract service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Contract_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "matchmaking.v1.Contract", + HandlerType: (*ContractServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetBotContractTrade", + Handler: _Contract_GetBotContractTrade_Handler, + }, + { + MethodName: "ContractPlaceOrder", + Handler: _Contract_ContractPlaceOrder_Handler, + }, + { + MethodName: "ContractUpdatePlaceOrder", + Handler: _Contract_ContractUpdatePlaceOrder_Handler, + }, + { + MethodName: "ContractPosition", + Handler: _Contract_ContractPosition_Handler, + }, + { + MethodName: "ContractAllPosition", + Handler: _Contract_ContractAllPosition_Handler, + }, + { + MethodName: "ContractCancel", + Handler: _Contract_ContractCancel_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "matchmaking/v1/virtually/contract.proto", +} diff --git a/api/matchmaking/v1/virtually/contract_http.pb.go b/api/matchmaking/v1/virtually/contract_http.pb.go new file mode 100644 index 0000000..3bcfc0a --- /dev/null +++ b/api/matchmaking/v1/virtually/contract_http.pb.go @@ -0,0 +1,279 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.3 +// - protoc v5.27.1 +// source: matchmaking/v1/virtually/contract.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationContractContractAllPosition = "/matchmaking.v1.Contract/ContractAllPosition" +const OperationContractContractCancel = "/matchmaking.v1.Contract/ContractCancel" +const OperationContractContractPlaceOrder = "/matchmaking.v1.Contract/ContractPlaceOrder" +const OperationContractContractPosition = "/matchmaking.v1.Contract/ContractPosition" +const OperationContractContractUpdatePlaceOrder = "/matchmaking.v1.Contract/ContractUpdatePlaceOrder" +const OperationContractGetBotContractTrade = "/matchmaking.v1.Contract/GetBotContractTrade" + +type ContractHTTPServer interface { + // ContractAllPosition ContractAllPosition 合约一键平仓 + ContractAllPosition(context.Context, *AllContractRequest) (*AllContractReply, error) + // ContractCancel ContractCancel 合约撤单 + ContractCancel(context.Context, *CancelContractRequest) (*ContractReply, error) + // ContractPlaceOrder ContractPlaceOrder 合约下单 + ContractPlaceOrder(context.Context, *ContractRequest) (*ContractReply, error) + // ContractPosition ContractPosition 合约平仓 + ContractPosition(context.Context, *CancelContractRequest) (*ContractReply, error) + // ContractUpdatePlaceOrder ContractUpdatePlaceOrder 合约设置止盈止损 + ContractUpdatePlaceOrder(context.Context, *UpdateContractRequest) (*ContractReply, error) + // GetBotContractTrade GetBotContractTrade 合约列表查询 + GetBotContractTrade(context.Context, *GetBotContractTradeRequest) (*GetBotContractTradeReply, error) +} + +func RegisterContractHTTPServer(s *http.Server, srv ContractHTTPServer) { + r := s.Route("/") + r.POST("/order_contract/contract_list", _Contract_GetBotContractTrade0_HTTP_Handler(srv)) + r.POST("/order_contract/contract_place_order", _Contract_ContractPlaceOrder0_HTTP_Handler(srv)) + r.POST("/order_contract/contract_update_order", _Contract_ContractUpdatePlaceOrder0_HTTP_Handler(srv)) + r.POST("/order_contract/contract_position", _Contract_ContractPosition0_HTTP_Handler(srv)) + r.POST("/order_contract/contract_all_position", _Contract_ContractAllPosition0_HTTP_Handler(srv)) + r.POST("/order_contract/contract_cancel", _Contract_ContractCancel0_HTTP_Handler(srv)) +} + +func _Contract_GetBotContractTrade0_HTTP_Handler(srv ContractHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetBotContractTradeRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationContractGetBotContractTrade) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.GetBotContractTrade(ctx, req.(*GetBotContractTradeRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetBotContractTradeReply) + return ctx.Result(200, reply) + } +} + +func _Contract_ContractPlaceOrder0_HTTP_Handler(srv ContractHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in ContractRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationContractContractPlaceOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ContractPlaceOrder(ctx, req.(*ContractRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*ContractReply) + return ctx.Result(200, reply) + } +} + +func _Contract_ContractUpdatePlaceOrder0_HTTP_Handler(srv ContractHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in UpdateContractRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationContractContractUpdatePlaceOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ContractUpdatePlaceOrder(ctx, req.(*UpdateContractRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*ContractReply) + return ctx.Result(200, reply) + } +} + +func _Contract_ContractPosition0_HTTP_Handler(srv ContractHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelContractRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationContractContractPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ContractPosition(ctx, req.(*CancelContractRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*ContractReply) + return ctx.Result(200, reply) + } +} + +func _Contract_ContractAllPosition0_HTTP_Handler(srv ContractHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in AllContractRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationContractContractAllPosition) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ContractAllPosition(ctx, req.(*AllContractRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*AllContractReply) + return ctx.Result(200, reply) + } +} + +func _Contract_ContractCancel0_HTTP_Handler(srv ContractHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelContractRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationContractContractCancel) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.ContractCancel(ctx, req.(*CancelContractRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*ContractReply) + return ctx.Result(200, reply) + } +} + +type ContractHTTPClient interface { + ContractAllPosition(ctx context.Context, req *AllContractRequest, opts ...http.CallOption) (rsp *AllContractReply, err error) + ContractCancel(ctx context.Context, req *CancelContractRequest, opts ...http.CallOption) (rsp *ContractReply, err error) + ContractPlaceOrder(ctx context.Context, req *ContractRequest, opts ...http.CallOption) (rsp *ContractReply, err error) + ContractPosition(ctx context.Context, req *CancelContractRequest, opts ...http.CallOption) (rsp *ContractReply, err error) + ContractUpdatePlaceOrder(ctx context.Context, req *UpdateContractRequest, opts ...http.CallOption) (rsp *ContractReply, err error) + GetBotContractTrade(ctx context.Context, req *GetBotContractTradeRequest, opts ...http.CallOption) (rsp *GetBotContractTradeReply, err error) +} + +type ContractHTTPClientImpl struct { + cc *http.Client +} + +func NewContractHTTPClient(client *http.Client) ContractHTTPClient { + return &ContractHTTPClientImpl{client} +} + +func (c *ContractHTTPClientImpl) ContractAllPosition(ctx context.Context, in *AllContractRequest, opts ...http.CallOption) (*AllContractReply, error) { + var out AllContractReply + pattern := "/order_contract/contract_all_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationContractContractAllPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ContractHTTPClientImpl) ContractCancel(ctx context.Context, in *CancelContractRequest, opts ...http.CallOption) (*ContractReply, error) { + var out ContractReply + pattern := "/order_contract/contract_cancel" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationContractContractCancel)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ContractHTTPClientImpl) ContractPlaceOrder(ctx context.Context, in *ContractRequest, opts ...http.CallOption) (*ContractReply, error) { + var out ContractReply + pattern := "/order_contract/contract_place_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationContractContractPlaceOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ContractHTTPClientImpl) ContractPosition(ctx context.Context, in *CancelContractRequest, opts ...http.CallOption) (*ContractReply, error) { + var out ContractReply + pattern := "/order_contract/contract_position" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationContractContractPosition)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ContractHTTPClientImpl) ContractUpdatePlaceOrder(ctx context.Context, in *UpdateContractRequest, opts ...http.CallOption) (*ContractReply, error) { + var out ContractReply + pattern := "/order_contract/contract_update_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationContractContractUpdatePlaceOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *ContractHTTPClientImpl) GetBotContractTrade(ctx context.Context, in *GetBotContractTradeRequest, opts ...http.CallOption) (*GetBotContractTradeReply, error) { + var out GetBotContractTradeReply + pattern := "/order_contract/contract_list" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationContractGetBotContractTrade)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/api/matchmaking/v1/virtually/second.pb.go b/api/matchmaking/v1/virtually/second.pb.go new file mode 100644 index 0000000..a85de9a --- /dev/null +++ b/api/matchmaking/v1/virtually/second.pb.go @@ -0,0 +1,1078 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/virtually/second.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GetBotSecondTradeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status int64 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` // 状态码 + PageSize int64 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,3,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + State int64 `protobuf:"varint,4,opt,name=state,proto3" json:"state,omitempty"` // 订单类型 +} + +func (x *GetBotSecondTradeRequest) Reset() { + *x = GetBotSecondTradeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_second_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotSecondTradeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotSecondTradeRequest) ProtoMessage() {} + +func (x *GetBotSecondTradeRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_second_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotSecondTradeRequest.ProtoReflect.Descriptor instead. +func (*GetBotSecondTradeRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_second_proto_rawDescGZIP(), []int{0} +} + +func (x *GetBotSecondTradeRequest) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *GetBotSecondTradeRequest) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *GetBotSecondTradeRequest) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *GetBotSecondTradeRequest) GetState() int64 { + if x != nil { + return x.State + } + return 0 +} + +type GetBotSecondTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *BotSecondTradeData `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *GetBotSecondTradeReply) Reset() { + *x = GetBotSecondTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_second_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotSecondTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotSecondTradeReply) ProtoMessage() {} + +func (x *GetBotSecondTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_second_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotSecondTradeReply.ProtoReflect.Descriptor instead. +func (*GetBotSecondTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_second_proto_rawDescGZIP(), []int{1} +} + +func (x *GetBotSecondTradeReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *GetBotSecondTradeReply) GetData() *BotSecondTradeData { + if x != nil { + return x.Data + } + return nil +} + +func (x *GetBotSecondTradeReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type BotSecondTradeData struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PageSize int64 `protobuf:"varint,1,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,2,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + Data []*BotSecondTrade `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty"` // 返回结果 + TotalCount int64 `protobuf:"varint,4,opt,name=totalCount,proto3" json:"totalCount,omitempty"` // 总数据 +} + +func (x *BotSecondTradeData) Reset() { + *x = BotSecondTradeData{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_second_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotSecondTradeData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotSecondTradeData) ProtoMessage() {} + +func (x *BotSecondTradeData) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_second_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotSecondTradeData.ProtoReflect.Descriptor instead. +func (*BotSecondTradeData) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_second_proto_rawDescGZIP(), []int{2} +} + +func (x *BotSecondTradeData) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *BotSecondTradeData) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *BotSecondTradeData) GetData() []*BotSecondTrade { + if x != nil { + return x.Data + } + return nil +} + +func (x *BotSecondTradeData) GetTotalCount() int64 { + if x != nil { + return x.TotalCount + } + return 0 +} + +type BotSecondTrade struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID + ContractId string `protobuf:"bytes,2,opt,name=contractId,proto3" json:"contractId,omitempty"` // 合约ID + TradeType int64 `protobuf:"varint,3,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型 + DealType int64 `protobuf:"varint,4,opt,name=dealType,proto3" json:"dealType,omitempty"` // 交易方式 + LimitPrice string `protobuf:"bytes,5,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,6,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + DealPrice string `protobuf:"bytes,7,opt,name=dealPrice,proto3" json:"dealPrice,omitempty"` // 开仓价 + ClosingPrice string `protobuf:"bytes,8,opt,name=closingPrice,proto3" json:"closingPrice,omitempty"` // 平仓价 + OrderNumber string `protobuf:"bytes,9,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止盈止损状态 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + ServiceCost string `protobuf:"bytes,13,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 开仓手续费 + EarnestMoney string `protobuf:"bytes,14,opt,name=earnestMoney,proto3" json:"earnestMoney,omitempty"` // 保证金 + OrderMoney string `protobuf:"bytes,15,opt,name=orderMoney,proto3" json:"orderMoney,omitempty"` // 订单总额 + Status int64 `protobuf:"varint,16,opt,name=status,proto3" json:"status,omitempty"` // 订单状态 + CreateTime *timestamppb.Timestamp `protobuf:"bytes,17,opt,name=createTime,proto3" json:"createTime,omitempty"` // 订单创建时间 + UpdateTime *timestamppb.Timestamp `protobuf:"bytes,18,opt,name=updateTime,proto3" json:"updateTime,omitempty"` // 订单更新时间 + OpenTime *timestamppb.Timestamp `protobuf:"bytes,19,opt,name=openTime,proto3" json:"openTime,omitempty"` // 订单开仓时间 + ClosingTime *timestamppb.Timestamp `protobuf:"bytes,20,opt,name=closingTime,proto3" json:"closingTime,omitempty"` // 订单平仓时间 + ClosingCost string `protobuf:"bytes,21,opt,name=closingCost,proto3" json:"closingCost,omitempty"` // 平仓手续费 + FaceValue string `protobuf:"bytes,22,opt,name=faceValue,proto3" json:"faceValue,omitempty"` // 面值 + OvernightCost string `protobuf:"bytes,23,opt,name=overnightCost,proto3" json:"overnightCost,omitempty"` // 过夜手续费 + PryNum string `protobuf:"bytes,24,opt,name=pryNum,proto3" json:"pryNum,omitempty"` // 杠杆值 + KeepDecimal string `protobuf:"bytes,25,opt,name=keepDecimal,proto3" json:"keepDecimal,omitempty"` // 保留小数位 + SecondTime string `protobuf:"bytes,26,opt,name=secondTime,proto3" json:"secondTime,omitempty"` // 秒合约时间 + State int64 `protobuf:"varint,27,opt,name=state,proto3" json:"state,omitempty"` // 订单类型 + OrderStatus int64 `protobuf:"varint,28,opt,name=orderStatus,proto3" json:"orderStatus,omitempty"` // 订单盈亏状态 + OrderValue string `protobuf:"bytes,29,opt,name=orderValue,proto3" json:"orderValue,omitempty"` // 订单盈亏值 +} + +func (x *BotSecondTrade) Reset() { + *x = BotSecondTrade{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_second_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotSecondTrade) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotSecondTrade) ProtoMessage() {} + +func (x *BotSecondTrade) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_second_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotSecondTrade.ProtoReflect.Descriptor instead. +func (*BotSecondTrade) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_second_proto_rawDescGZIP(), []int{3} +} + +func (x *BotSecondTrade) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *BotSecondTrade) GetContractId() string { + if x != nil { + return x.ContractId + } + return "" +} + +func (x *BotSecondTrade) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *BotSecondTrade) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *BotSecondTrade) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *BotSecondTrade) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *BotSecondTrade) GetDealPrice() string { + if x != nil { + return x.DealPrice + } + return "" +} + +func (x *BotSecondTrade) GetClosingPrice() string { + if x != nil { + return x.ClosingPrice + } + return "" +} + +func (x *BotSecondTrade) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *BotSecondTrade) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *BotSecondTrade) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *BotSecondTrade) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *BotSecondTrade) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *BotSecondTrade) GetEarnestMoney() string { + if x != nil { + return x.EarnestMoney + } + return "" +} + +func (x *BotSecondTrade) GetOrderMoney() string { + if x != nil { + return x.OrderMoney + } + return "" +} + +func (x *BotSecondTrade) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *BotSecondTrade) GetCreateTime() *timestamppb.Timestamp { + if x != nil { + return x.CreateTime + } + return nil +} + +func (x *BotSecondTrade) GetUpdateTime() *timestamppb.Timestamp { + if x != nil { + return x.UpdateTime + } + return nil +} + +func (x *BotSecondTrade) GetOpenTime() *timestamppb.Timestamp { + if x != nil { + return x.OpenTime + } + return nil +} + +func (x *BotSecondTrade) GetClosingTime() *timestamppb.Timestamp { + if x != nil { + return x.ClosingTime + } + return nil +} + +func (x *BotSecondTrade) GetClosingCost() string { + if x != nil { + return x.ClosingCost + } + return "" +} + +func (x *BotSecondTrade) GetFaceValue() string { + if x != nil { + return x.FaceValue + } + return "" +} + +func (x *BotSecondTrade) GetOvernightCost() string { + if x != nil { + return x.OvernightCost + } + return "" +} + +func (x *BotSecondTrade) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *BotSecondTrade) GetKeepDecimal() string { + if x != nil { + return x.KeepDecimal + } + return "" +} + +func (x *BotSecondTrade) GetSecondTime() string { + if x != nil { + return x.SecondTime + } + return "" +} + +func (x *BotSecondTrade) GetState() int64 { + if x != nil { + return x.State + } + return 0 +} + +func (x *BotSecondTrade) GetOrderStatus() int64 { + if x != nil { + return x.OrderStatus + } + return 0 +} + +func (x *BotSecondTrade) GetOrderValue() string { + if x != nil { + return x.OrderValue + } + return "" +} + +type SecondOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ContractId string `protobuf:"bytes,1,opt,name=contractId,proto3" json:"contractId,omitempty"` // 交易对 + TradeType int64 `protobuf:"varint,2,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型:1买入,2卖出 + DealType int64 `protobuf:"varint,3,opt,name=dealType,proto3" json:"dealType,omitempty"` // 委托方式:1限价,2市价 + LimitPrice string `protobuf:"bytes,4,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,5,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + OrderAmount string `protobuf:"bytes,6,opt,name=orderAmount,proto3" json:"orderAmount,omitempty"` // 订单金额 + OrderNumber string `protobuf:"bytes,7,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + EarnestMoney string `protobuf:"bytes,8,opt,name=earnestMoney,proto3" json:"earnestMoney,omitempty"` // 保证金 + ServiceCost string `protobuf:"bytes,9,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 手续费 + StopType int64 `protobuf:"varint,10,opt,name=stopType,proto3" json:"stopType,omitempty"` // 止损止盈设置:0无设置,1止损止盈 + StopLossPrice string `protobuf:"bytes,11,opt,name=stopLossPrice,proto3" json:"stopLossPrice,omitempty"` // 止损 + StopWinPrice string `protobuf:"bytes,12,opt,name=stopWinPrice,proto3" json:"stopWinPrice,omitempty"` // 止盈 + PryNum string `protobuf:"bytes,13,opt,name=pryNum,proto3" json:"pryNum,omitempty"` //杠杆 + Time int64 `protobuf:"varint,14,opt,name=time,proto3" json:"time,omitempty"` // 秒合约时间 +} + +func (x *SecondOrderRequest) Reset() { + *x = SecondOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_second_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SecondOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SecondOrderRequest) ProtoMessage() {} + +func (x *SecondOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_second_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SecondOrderRequest.ProtoReflect.Descriptor instead. +func (*SecondOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_second_proto_rawDescGZIP(), []int{4} +} + +func (x *SecondOrderRequest) GetContractId() string { + if x != nil { + return x.ContractId + } + return "" +} + +func (x *SecondOrderRequest) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *SecondOrderRequest) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *SecondOrderRequest) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *SecondOrderRequest) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *SecondOrderRequest) GetOrderAmount() string { + if x != nil { + return x.OrderAmount + } + return "" +} + +func (x *SecondOrderRequest) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *SecondOrderRequest) GetEarnestMoney() string { + if x != nil { + return x.EarnestMoney + } + return "" +} + +func (x *SecondOrderRequest) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *SecondOrderRequest) GetStopType() int64 { + if x != nil { + return x.StopType + } + return 0 +} + +func (x *SecondOrderRequest) GetStopLossPrice() string { + if x != nil { + return x.StopLossPrice + } + return "" +} + +func (x *SecondOrderRequest) GetStopWinPrice() string { + if x != nil { + return x.StopWinPrice + } + return "" +} + +func (x *SecondOrderRequest) GetPryNum() string { + if x != nil { + return x.PryNum + } + return "" +} + +func (x *SecondOrderRequest) GetTime() int64 { + if x != nil { + return x.Time + } + return 0 +} + +type SecondOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *SecondResult `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *SecondOrderReply) Reset() { + *x = SecondOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_second_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SecondOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SecondOrderReply) ProtoMessage() {} + +func (x *SecondOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_second_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SecondOrderReply.ProtoReflect.Descriptor instead. +func (*SecondOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_second_proto_rawDescGZIP(), []int{5} +} + +func (x *SecondOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *SecondOrderReply) GetData() *SecondResult { + if x != nil { + return x.Data + } + return nil +} + +func (x *SecondOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type SecondResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id +} + +func (x *SecondResult) Reset() { + *x = SecondResult{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_second_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SecondResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SecondResult) ProtoMessage() {} + +func (x *SecondResult) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_second_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SecondResult.ProtoReflect.Descriptor instead. +func (*SecondResult) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_second_proto_rawDescGZIP(), []int{6} +} + +func (x *SecondResult) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +var File_matchmaking_v1_virtually_second_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_virtually_second_proto_rawDesc = []byte{ + 0x0a, 0x25, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x6c, 0x79, 0x2f, 0x73, 0x65, 0x63, 0x6f, 0x6e, + 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, + 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, + 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x82, 0x01, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x42, 0x6f, + 0x74, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x70, + 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, + 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, + 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, + 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0x7e, 0x0a, 0x16, 0x47, + 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x54, 0x72, 0x61, 0x64, 0x65, + 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x36, 0x0a, 0x04, 0x64, 0x61, 0x74, + 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, + 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x53, 0x65, 0x63, 0x6f, + 0x6e, 0x64, 0x54, 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, + 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xa2, 0x01, 0x0a, 0x12, + 0x42, 0x6f, 0x74, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x54, 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, + 0x74, 0x61, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, + 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x32, 0x0a, 0x04, + 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x6d, 0x61, 0x74, + 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x53, + 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, + 0x12, 0x1e, 0x0a, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, 0x74, + 0x22, 0x94, 0x08, 0x0a, 0x0e, 0x42, 0x6f, 0x74, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x54, 0x72, + 0x61, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1e, 0x0a, + 0x0a, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x49, 0x64, 0x12, 0x1c, 0x0a, + 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, + 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, + 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, + 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, + 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, + 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x65, 0x61, + 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x64, 0x65, + 0x61, 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6c, 0x6f, 0x73, 0x69, + 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, + 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x1a, 0x0a, + 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, + 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, + 0x22, 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, + 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, + 0x73, 0x74, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x0c, 0x65, 0x61, 0x72, 0x6e, 0x65, 0x73, 0x74, + 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x61, 0x72, + 0x6e, 0x65, 0x73, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, + 0x74, 0x75, 0x73, 0x18, 0x10, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x12, 0x3a, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, + 0x11, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, + 0x70, 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x3a, 0x0a, + 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x12, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x75, + 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x36, 0x0a, 0x08, 0x6f, 0x70, 0x65, + 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x13, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, + 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x08, 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, + 0x65, 0x12, 0x3c, 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, + 0x18, 0x14, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, + 0x6d, 0x70, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x12, + 0x20, 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x15, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, + 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x16, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x66, 0x61, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, + 0x24, 0x0a, 0x0d, 0x6f, 0x76, 0x65, 0x72, 0x6e, 0x69, 0x67, 0x68, 0x74, 0x43, 0x6f, 0x73, 0x74, + 0x18, 0x17, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x6f, 0x76, 0x65, 0x72, 0x6e, 0x69, 0x67, 0x68, + 0x74, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x18, + 0x18, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, 0x79, 0x4e, 0x75, 0x6d, 0x12, 0x20, 0x0a, + 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x18, 0x19, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x12, + 0x1e, 0x0a, 0x0a, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x1a, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x12, + 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x1b, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, + 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x53, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x18, 0x1c, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x56, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x1d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x22, 0xcc, 0x03, 0x0a, 0x12, 0x53, 0x65, 0x63, 0x6f, + 0x6e, 0x64, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1e, + 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x49, 0x64, 0x12, 0x1c, + 0x0a, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x09, 0x74, 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, + 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, + 0x64, 0x65, 0x61, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, + 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, + 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, + 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, + 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x20, 0x0a, 0x0b, + 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x07, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x22, + 0x0a, 0x0c, 0x65, 0x61, 0x72, 0x6e, 0x65, 0x73, 0x74, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x08, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x61, 0x72, 0x6e, 0x65, 0x73, 0x74, 0x4d, 0x6f, 0x6e, + 0x65, 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, + 0x74, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, + 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x74, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, + 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, 0x73, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x74, 0x6f, 0x70, 0x4c, 0x6f, 0x73, + 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x74, 0x6f, 0x70, 0x57, 0x69, + 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x74, + 0x6f, 0x70, 0x57, 0x69, 0x6e, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x72, + 0x79, 0x4e, 0x75, 0x6d, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, 0x79, 0x4e, + 0x75, 0x6d, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x22, 0x72, 0x0a, 0x10, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, + 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x30, + 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x6d, + 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, + 0x63, 0x6f, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, + 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x28, 0x0a, 0x0c, 0x53, 0x65, + 0x63, 0x6f, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, + 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x49, 0x64, 0x32, 0xa4, 0x02, 0x0a, 0x06, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x12, + 0x93, 0x01, 0x0a, 0x19, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, + 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x54, 0x72, 0x61, 0x64, 0x65, 0x12, 0x28, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, + 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x54, 0x72, 0x61, 0x64, 0x65, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x26, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, + 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x53, + 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, + 0x24, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1e, 0x3a, 0x01, 0x2a, 0x22, 0x19, 0x2f, 0x6f, 0x72, 0x64, + 0x65, 0x72, 0x5f, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x2f, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, + 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x12, 0x83, 0x01, 0x0a, 0x0b, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x22, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, + 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x6d, 0x61, 0x74, 0x63, + 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x63, 0x6f, 0x6e, + 0x64, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x2e, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x28, 0x3a, 0x01, 0x2a, 0x22, 0x23, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, + 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x5f, 0x73, + 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x42, 0x2a, 0x5a, 0x28, 0x6d, + 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2d, 0x73, 0x79, 0x73, 0x74, 0x65, + 0x6d, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, + 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_virtually_second_proto_rawDescOnce sync.Once + file_matchmaking_v1_virtually_second_proto_rawDescData = file_matchmaking_v1_virtually_second_proto_rawDesc +) + +func file_matchmaking_v1_virtually_second_proto_rawDescGZIP() []byte { + file_matchmaking_v1_virtually_second_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_virtually_second_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_virtually_second_proto_rawDescData) + }) + return file_matchmaking_v1_virtually_second_proto_rawDescData +} + +var file_matchmaking_v1_virtually_second_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_matchmaking_v1_virtually_second_proto_goTypes = []any{ + (*GetBotSecondTradeRequest)(nil), // 0: matchmaking.v1.GetBotSecondTradeRequest + (*GetBotSecondTradeReply)(nil), // 1: matchmaking.v1.GetBotSecondTradeReply + (*BotSecondTradeData)(nil), // 2: matchmaking.v1.BotSecondTradeData + (*BotSecondTrade)(nil), // 3: matchmaking.v1.BotSecondTrade + (*SecondOrderRequest)(nil), // 4: matchmaking.v1.SecondOrderRequest + (*SecondOrderReply)(nil), // 5: matchmaking.v1.SecondOrderReply + (*SecondResult)(nil), // 6: matchmaking.v1.SecondResult + (*timestamppb.Timestamp)(nil), // 7: google.protobuf.Timestamp +} +var file_matchmaking_v1_virtually_second_proto_depIdxs = []int32{ + 2, // 0: matchmaking.v1.GetBotSecondTradeReply.data:type_name -> matchmaking.v1.BotSecondTradeData + 3, // 1: matchmaking.v1.BotSecondTradeData.data:type_name -> matchmaking.v1.BotSecondTrade + 7, // 2: matchmaking.v1.BotSecondTrade.createTime:type_name -> google.protobuf.Timestamp + 7, // 3: matchmaking.v1.BotSecondTrade.updateTime:type_name -> google.protobuf.Timestamp + 7, // 4: matchmaking.v1.BotSecondTrade.openTime:type_name -> google.protobuf.Timestamp + 7, // 5: matchmaking.v1.BotSecondTrade.closingTime:type_name -> google.protobuf.Timestamp + 6, // 6: matchmaking.v1.SecondOrderReply.data:type_name -> matchmaking.v1.SecondResult + 0, // 7: matchmaking.v1.Second.SecondGetBotContractTrade:input_type -> matchmaking.v1.GetBotSecondTradeRequest + 4, // 8: matchmaking.v1.Second.SecondOrder:input_type -> matchmaking.v1.SecondOrderRequest + 1, // 9: matchmaking.v1.Second.SecondGetBotContractTrade:output_type -> matchmaking.v1.GetBotSecondTradeReply + 5, // 10: matchmaking.v1.Second.SecondOrder:output_type -> matchmaking.v1.SecondOrderReply + 9, // [9:11] is the sub-list for method output_type + 7, // [7:9] is the sub-list for method input_type + 7, // [7:7] is the sub-list for extension type_name + 7, // [7:7] is the sub-list for extension extendee + 0, // [0:7] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_virtually_second_proto_init() } +func file_matchmaking_v1_virtually_second_proto_init() { + if File_matchmaking_v1_virtually_second_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_matchmaking_v1_virtually_second_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*GetBotSecondTradeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_second_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*GetBotSecondTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_second_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*BotSecondTradeData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_second_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*BotSecondTrade); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_second_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*SecondOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_second_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*SecondOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_second_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*SecondResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_virtually_second_proto_rawDesc, + NumEnums: 0, + NumMessages: 7, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_matchmaking_v1_virtually_second_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_virtually_second_proto_depIdxs, + MessageInfos: file_matchmaking_v1_virtually_second_proto_msgTypes, + }.Build() + File_matchmaking_v1_virtually_second_proto = out.File + file_matchmaking_v1_virtually_second_proto_rawDesc = nil + file_matchmaking_v1_virtually_second_proto_goTypes = nil + file_matchmaking_v1_virtually_second_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/virtually/second.proto b/api/matchmaking/v1/virtually/second.proto new file mode 100644 index 0000000..8645d15 --- /dev/null +++ b/api/matchmaking/v1/virtually/second.proto @@ -0,0 +1,104 @@ +syntax = "proto3"; + +package matchmaking.v1; + +import "google/api/annotations.proto"; +import "google/protobuf/timestamp.proto"; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +service Second { + // SecondGetBotContractTrade 合约列表查询 + rpc SecondGetBotContractTrade(GetBotSecondTradeRequest)returns(GetBotSecondTradeReply){ + option (google.api.http) = { + post:"/order_second/second_list", + body:"*", + }; + } + // SecondOrder 秒合约下单 + rpc SecondOrder(SecondOrderRequest)returns(SecondOrderReply){ + option (google.api.http) = { + post: "/order_second/contract_second_order", + body: "*", + }; + } +} + +message GetBotSecondTradeRequest{ + int64 status =1;// 状态码 + int64 pageSize =2; // 每页显示条数 + int64 pageCount =3;// 开始的位置 + int64 state = 4;// 订单类型 +} + +message GetBotSecondTradeReply{ + int64 code =1;// 状态码 + BotSecondTradeData data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message BotSecondTradeData{ + int64 pageSize =1; // 每页显示条数 + int64 pageCount =2;// 开始的位置 + repeated BotSecondTrade data =3;// 返回结果 + int64 totalCount =4;// 总数据 +} + +message BotSecondTrade{ + string orderId =1;// 订单ID + string contractId =2;// 合约ID + int64 tradeType =3;// 交易类型 + int64 dealType =4;// 交易方式 + string limitPrice =5;// 限价 + string marketPrice =6;// 市价 + string dealPrice =7;// 开仓价 + string closingPrice =8;// 平仓价 + string orderNumber =9;// 订单数量 + int64 stopType =10;// 止盈止损状态 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string serviceCost =13;// 开仓手续费 + string earnestMoney =14;// 保证金 + string orderMoney =15;// 订单总额 + int64 status =16;// 订单状态 + google.protobuf.Timestamp createTime =17;// 订单创建时间 + google.protobuf.Timestamp updateTime =18;// 订单更新时间 + google.protobuf.Timestamp openTime =19;// 订单开仓时间 + google.protobuf.Timestamp closingTime =20;// 订单平仓时间 + string closingCost =21;// 平仓手续费 + string faceValue =22;// 面值 + string overnightCost =23;// 过夜手续费 + string pryNum =24;// 杠杆值 + string keepDecimal =25;// 保留小数位 + string secondTime = 26;// 秒合约时间 + int64 state = 27;// 订单类型 + int64 orderStatus = 28;// 订单盈亏状态 + string orderValue = 29;// 订单盈亏值 +} + +message SecondOrderRequest{ + string contractId =1;// 交易对 + int64 tradeType =2;// 交易类型:1买入,2卖出 + int64 dealType =3;// 委托方式:1限价,2市价 + string limitPrice =4;// 限价 + string marketPrice =5;// 市价 + string orderAmount =6;// 订单金额 + string orderNumber =7;// 订单数量 + string earnestMoney =8;// 保证金 + string serviceCost =9;// 手续费 + int64 stopType =10;// 止损止盈设置:0无设置,1止损止盈 + string stopLossPrice =11;// 止损 + string stopWinPrice =12;// 止盈 + string pryNum =13;//杠杆 + int64 time = 14;// 秒合约时间 +} + +message SecondOrderReply{ + int64 code =1;// 状态码 + SecondResult data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message SecondResult { + string orderId =1;// 订单Id +} \ No newline at end of file diff --git a/api/matchmaking/v1/virtually/second_grpc.pb.go b/api/matchmaking/v1/virtually/second_grpc.pb.go new file mode 100644 index 0000000..c5b60f3 --- /dev/null +++ b/api/matchmaking/v1/virtually/second_grpc.pb.go @@ -0,0 +1,152 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.1 +// source: matchmaking/v1/virtually/second.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + Second_SecondGetBotContractTrade_FullMethodName = "/matchmaking.v1.Second/SecondGetBotContractTrade" + Second_SecondOrder_FullMethodName = "/matchmaking.v1.Second/SecondOrder" +) + +// SecondClient is the client API for Second service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type SecondClient interface { + // SecondGetBotContractTrade 合约列表查询 + SecondGetBotContractTrade(ctx context.Context, in *GetBotSecondTradeRequest, opts ...grpc.CallOption) (*GetBotSecondTradeReply, error) + // SecondOrder 秒合约下单 + SecondOrder(ctx context.Context, in *SecondOrderRequest, opts ...grpc.CallOption) (*SecondOrderReply, error) +} + +type secondClient struct { + cc grpc.ClientConnInterface +} + +func NewSecondClient(cc grpc.ClientConnInterface) SecondClient { + return &secondClient{cc} +} + +func (c *secondClient) SecondGetBotContractTrade(ctx context.Context, in *GetBotSecondTradeRequest, opts ...grpc.CallOption) (*GetBotSecondTradeReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetBotSecondTradeReply) + err := c.cc.Invoke(ctx, Second_SecondGetBotContractTrade_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *secondClient) SecondOrder(ctx context.Context, in *SecondOrderRequest, opts ...grpc.CallOption) (*SecondOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(SecondOrderReply) + err := c.cc.Invoke(ctx, Second_SecondOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// SecondServer is the server API for Second service. +// All implementations must embed UnimplementedSecondServer +// for forward compatibility +type SecondServer interface { + // SecondGetBotContractTrade 合约列表查询 + SecondGetBotContractTrade(context.Context, *GetBotSecondTradeRequest) (*GetBotSecondTradeReply, error) + // SecondOrder 秒合约下单 + SecondOrder(context.Context, *SecondOrderRequest) (*SecondOrderReply, error) + mustEmbedUnimplementedSecondServer() +} + +// UnimplementedSecondServer must be embedded to have forward compatible implementations. +type UnimplementedSecondServer struct { +} + +func (UnimplementedSecondServer) SecondGetBotContractTrade(context.Context, *GetBotSecondTradeRequest) (*GetBotSecondTradeReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method SecondGetBotContractTrade not implemented") +} +func (UnimplementedSecondServer) SecondOrder(context.Context, *SecondOrderRequest) (*SecondOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method SecondOrder not implemented") +} +func (UnimplementedSecondServer) mustEmbedUnimplementedSecondServer() {} + +// UnsafeSecondServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to SecondServer will +// result in compilation errors. +type UnsafeSecondServer interface { + mustEmbedUnimplementedSecondServer() +} + +func RegisterSecondServer(s grpc.ServiceRegistrar, srv SecondServer) { + s.RegisterService(&Second_ServiceDesc, srv) +} + +func _Second_SecondGetBotContractTrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetBotSecondTradeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SecondServer).SecondGetBotContractTrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Second_SecondGetBotContractTrade_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SecondServer).SecondGetBotContractTrade(ctx, req.(*GetBotSecondTradeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Second_SecondOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SecondOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SecondServer).SecondOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Second_SecondOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SecondServer).SecondOrder(ctx, req.(*SecondOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Second_ServiceDesc is the grpc.ServiceDesc for Second service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Second_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "matchmaking.v1.Second", + HandlerType: (*SecondServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "SecondGetBotContractTrade", + Handler: _Second_SecondGetBotContractTrade_Handler, + }, + { + MethodName: "SecondOrder", + Handler: _Second_SecondOrder_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "matchmaking/v1/virtually/second.proto", +} diff --git a/api/matchmaking/v1/virtually/second_http.pb.go b/api/matchmaking/v1/virtually/second_http.pb.go new file mode 100644 index 0000000..cf4ae38 --- /dev/null +++ b/api/matchmaking/v1/virtually/second_http.pb.go @@ -0,0 +1,119 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.3 +// - protoc v5.27.1 +// source: matchmaking/v1/virtually/second.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationSecondSecondGetBotContractTrade = "/matchmaking.v1.Second/SecondGetBotContractTrade" +const OperationSecondSecondOrder = "/matchmaking.v1.Second/SecondOrder" + +type SecondHTTPServer interface { + // SecondGetBotContractTrade SecondGetBotContractTrade 合约列表查询 + SecondGetBotContractTrade(context.Context, *GetBotSecondTradeRequest) (*GetBotSecondTradeReply, error) + // SecondOrder SecondOrder 秒合约下单 + SecondOrder(context.Context, *SecondOrderRequest) (*SecondOrderReply, error) +} + +func RegisterSecondHTTPServer(s *http.Server, srv SecondHTTPServer) { + r := s.Route("/") + r.POST("/order_second/second_list", _Second_SecondGetBotContractTrade0_HTTP_Handler(srv)) + r.POST("/order_second/contract_second_order", _Second_SecondOrder0_HTTP_Handler(srv)) +} + +func _Second_SecondGetBotContractTrade0_HTTP_Handler(srv SecondHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetBotSecondTradeRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationSecondSecondGetBotContractTrade) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.SecondGetBotContractTrade(ctx, req.(*GetBotSecondTradeRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetBotSecondTradeReply) + return ctx.Result(200, reply) + } +} + +func _Second_SecondOrder0_HTTP_Handler(srv SecondHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in SecondOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationSecondSecondOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.SecondOrder(ctx, req.(*SecondOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*SecondOrderReply) + return ctx.Result(200, reply) + } +} + +type SecondHTTPClient interface { + SecondGetBotContractTrade(ctx context.Context, req *GetBotSecondTradeRequest, opts ...http.CallOption) (rsp *GetBotSecondTradeReply, err error) + SecondOrder(ctx context.Context, req *SecondOrderRequest, opts ...http.CallOption) (rsp *SecondOrderReply, err error) +} + +type SecondHTTPClientImpl struct { + cc *http.Client +} + +func NewSecondHTTPClient(client *http.Client) SecondHTTPClient { + return &SecondHTTPClientImpl{client} +} + +func (c *SecondHTTPClientImpl) SecondGetBotContractTrade(ctx context.Context, in *GetBotSecondTradeRequest, opts ...http.CallOption) (*GetBotSecondTradeReply, error) { + var out GetBotSecondTradeReply + pattern := "/order_second/second_list" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationSecondSecondGetBotContractTrade)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *SecondHTTPClientImpl) SecondOrder(ctx context.Context, in *SecondOrderRequest, opts ...http.CallOption) (*SecondOrderReply, error) { + var out SecondOrderReply + pattern := "/order_second/contract_second_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationSecondSecondOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/api/matchmaking/v1/virtually/spots.pb.go b/api/matchmaking/v1/virtually/spots.pb.go new file mode 100644 index 0000000..be8d5cf --- /dev/null +++ b/api/matchmaking/v1/virtually/spots.pb.go @@ -0,0 +1,1004 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: matchmaking/v1/virtually/spots.proto + +package v1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GetBotDigitalTradeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status int64 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` // 状态码 + PageSize int64 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,3,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 +} + +func (x *GetBotDigitalTradeRequest) Reset() { + *x = GetBotDigitalTradeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_spots_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotDigitalTradeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotDigitalTradeRequest) ProtoMessage() {} + +func (x *GetBotDigitalTradeRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_spots_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotDigitalTradeRequest.ProtoReflect.Descriptor instead. +func (*GetBotDigitalTradeRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_spots_proto_rawDescGZIP(), []int{0} +} + +func (x *GetBotDigitalTradeRequest) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *GetBotDigitalTradeRequest) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *GetBotDigitalTradeRequest) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +type GetBotDigitalTradeReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *BotDigitalTradeData `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *GetBotDigitalTradeReply) Reset() { + *x = GetBotDigitalTradeReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_spots_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBotDigitalTradeReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBotDigitalTradeReply) ProtoMessage() {} + +func (x *GetBotDigitalTradeReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_spots_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBotDigitalTradeReply.ProtoReflect.Descriptor instead. +func (*GetBotDigitalTradeReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_spots_proto_rawDescGZIP(), []int{1} +} + +func (x *GetBotDigitalTradeReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *GetBotDigitalTradeReply) GetData() *BotDigitalTradeData { + if x != nil { + return x.Data + } + return nil +} + +func (x *GetBotDigitalTradeReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type BotDigitalTradeData struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PageSize int64 `protobuf:"varint,1,opt,name=pageSize,proto3" json:"pageSize,omitempty"` // 每页显示条数 + PageCount int64 `protobuf:"varint,2,opt,name=pageCount,proto3" json:"pageCount,omitempty"` // 开始的位置 + Data []*BotDigitalTrade `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty"` // 返回结果 + TotalCount int64 `protobuf:"varint,4,opt,name=totalCount,proto3" json:"totalCount,omitempty"` // 总数据 +} + +func (x *BotDigitalTradeData) Reset() { + *x = BotDigitalTradeData{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_spots_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotDigitalTradeData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotDigitalTradeData) ProtoMessage() {} + +func (x *BotDigitalTradeData) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_spots_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotDigitalTradeData.ProtoReflect.Descriptor instead. +func (*BotDigitalTradeData) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_spots_proto_rawDescGZIP(), []int{2} +} + +func (x *BotDigitalTradeData) GetPageSize() int64 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *BotDigitalTradeData) GetPageCount() int64 { + if x != nil { + return x.PageCount + } + return 0 +} + +func (x *BotDigitalTradeData) GetData() []*BotDigitalTrade { + if x != nil { + return x.Data + } + return nil +} + +func (x *BotDigitalTradeData) GetTotalCount() int64 { + if x != nil { + return x.TotalCount + } + return 0 +} + +type BotDigitalTrade struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID + DigitalId string `protobuf:"bytes,2,opt,name=digitalId,proto3" json:"digitalId,omitempty"` // 现货交易对 + TradeType int64 `protobuf:"varint,3,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型 + DealType int64 `protobuf:"varint,4,opt,name=dealType,proto3" json:"dealType,omitempty"` // 交易方式 + DealPrice string `protobuf:"bytes,7,opt,name=dealPrice,proto3" json:"dealPrice,omitempty"` // 开仓价 + ClosingPrice string `protobuf:"bytes,8,opt,name=closingPrice,proto3" json:"closingPrice,omitempty"` // 平仓价格 + LimitPrice string `protobuf:"bytes,5,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,6,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + OrderNumber string `protobuf:"bytes,9,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + ServiceCost string `protobuf:"bytes,10,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 开仓手续费 + OrderMoney string `protobuf:"bytes,11,opt,name=orderMoney,proto3" json:"orderMoney,omitempty"` // 订单金额 + TotalMoney string `protobuf:"bytes,12,opt,name=totalMoney,proto3" json:"totalMoney,omitempty"` // 订单总金额 + Status int64 `protobuf:"varint,13,opt,name=status,proto3" json:"status,omitempty"` // 订单状态 + CreateTime *timestamppb.Timestamp `protobuf:"bytes,14,opt,name=createTime,proto3" json:"createTime,omitempty"` // 订单创建时间 + UpdateTime *timestamppb.Timestamp `protobuf:"bytes,15,opt,name=updateTime,proto3" json:"updateTime,omitempty"` // 订单更新时间 + OpenTime *timestamppb.Timestamp `protobuf:"bytes,16,opt,name=openTime,proto3" json:"openTime,omitempty"` // 订单开仓时间 + ClosingTime *timestamppb.Timestamp `protobuf:"bytes,17,opt,name=closingTime,proto3" json:"closingTime,omitempty"` // 订单平仓时间 + ClosingCost string `protobuf:"bytes,18,opt,name=closingCost,proto3" json:"closingCost,omitempty"` // 平仓手续费 + KeepDecimal string `protobuf:"bytes,19,opt,name=keepDecimal,proto3" json:"keepDecimal,omitempty"` // 保留小数位 +} + +func (x *BotDigitalTrade) Reset() { + *x = BotDigitalTrade{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_spots_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BotDigitalTrade) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BotDigitalTrade) ProtoMessage() {} + +func (x *BotDigitalTrade) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_spots_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BotDigitalTrade.ProtoReflect.Descriptor instead. +func (*BotDigitalTrade) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_spots_proto_rawDescGZIP(), []int{3} +} + +func (x *BotDigitalTrade) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +func (x *BotDigitalTrade) GetDigitalId() string { + if x != nil { + return x.DigitalId + } + return "" +} + +func (x *BotDigitalTrade) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *BotDigitalTrade) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *BotDigitalTrade) GetDealPrice() string { + if x != nil { + return x.DealPrice + } + return "" +} + +func (x *BotDigitalTrade) GetClosingPrice() string { + if x != nil { + return x.ClosingPrice + } + return "" +} + +func (x *BotDigitalTrade) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *BotDigitalTrade) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *BotDigitalTrade) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *BotDigitalTrade) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +func (x *BotDigitalTrade) GetOrderMoney() string { + if x != nil { + return x.OrderMoney + } + return "" +} + +func (x *BotDigitalTrade) GetTotalMoney() string { + if x != nil { + return x.TotalMoney + } + return "" +} + +func (x *BotDigitalTrade) GetStatus() int64 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *BotDigitalTrade) GetCreateTime() *timestamppb.Timestamp { + if x != nil { + return x.CreateTime + } + return nil +} + +func (x *BotDigitalTrade) GetUpdateTime() *timestamppb.Timestamp { + if x != nil { + return x.UpdateTime + } + return nil +} + +func (x *BotDigitalTrade) GetOpenTime() *timestamppb.Timestamp { + if x != nil { + return x.OpenTime + } + return nil +} + +func (x *BotDigitalTrade) GetClosingTime() *timestamppb.Timestamp { + if x != nil { + return x.ClosingTime + } + return nil +} + +func (x *BotDigitalTrade) GetClosingCost() string { + if x != nil { + return x.ClosingCost + } + return "" +} + +func (x *BotDigitalTrade) GetKeepDecimal() string { + if x != nil { + return x.KeepDecimal + } + return "" +} + +type SpotsOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + DigitalId string `protobuf:"bytes,1,opt,name=digitalId,proto3" json:"digitalId,omitempty"` // 交易对 + TradeType int64 `protobuf:"varint,2,opt,name=tradeType,proto3" json:"tradeType,omitempty"` // 交易类型:1买入,2卖出 + DealType int64 `protobuf:"varint,3,opt,name=dealType,proto3" json:"dealType,omitempty"` // 委托方式:1限价,2市价 + LimitPrice string `protobuf:"bytes,4,opt,name=limitPrice,proto3" json:"limitPrice,omitempty"` // 限价 + MarketPrice string `protobuf:"bytes,5,opt,name=marketPrice,proto3" json:"marketPrice,omitempty"` // 市价 + DealPrice string `protobuf:"bytes,6,opt,name=dealPrice,proto3" json:"dealPrice,omitempty"` // 订单价格 + OrderNumber string `protobuf:"bytes,7,opt,name=orderNumber,proto3" json:"orderNumber,omitempty"` // 订单数量 + OrderMoney string `protobuf:"bytes,8,opt,name=orderMoney,proto3" json:"orderMoney,omitempty"` // 订单金额 + ServiceCost string `protobuf:"bytes,9,opt,name=serviceCost,proto3" json:"serviceCost,omitempty"` // 手续费 +} + +func (x *SpotsOrderRequest) Reset() { + *x = SpotsOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_spots_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SpotsOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SpotsOrderRequest) ProtoMessage() {} + +func (x *SpotsOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_spots_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SpotsOrderRequest.ProtoReflect.Descriptor instead. +func (*SpotsOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_spots_proto_rawDescGZIP(), []int{4} +} + +func (x *SpotsOrderRequest) GetDigitalId() string { + if x != nil { + return x.DigitalId + } + return "" +} + +func (x *SpotsOrderRequest) GetTradeType() int64 { + if x != nil { + return x.TradeType + } + return 0 +} + +func (x *SpotsOrderRequest) GetDealType() int64 { + if x != nil { + return x.DealType + } + return 0 +} + +func (x *SpotsOrderRequest) GetLimitPrice() string { + if x != nil { + return x.LimitPrice + } + return "" +} + +func (x *SpotsOrderRequest) GetMarketPrice() string { + if x != nil { + return x.MarketPrice + } + return "" +} + +func (x *SpotsOrderRequest) GetDealPrice() string { + if x != nil { + return x.DealPrice + } + return "" +} + +func (x *SpotsOrderRequest) GetOrderNumber() string { + if x != nil { + return x.OrderNumber + } + return "" +} + +func (x *SpotsOrderRequest) GetOrderMoney() string { + if x != nil { + return x.OrderMoney + } + return "" +} + +func (x *SpotsOrderRequest) GetServiceCost() string { + if x != nil { + return x.ServiceCost + } + return "" +} + +type CancelSpotsOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单ID +} + +func (x *CancelSpotsOrderRequest) Reset() { + *x = CancelSpotsOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_spots_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CancelSpotsOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CancelSpotsOrderRequest) ProtoMessage() {} + +func (x *CancelSpotsOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_spots_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CancelSpotsOrderRequest.ProtoReflect.Descriptor instead. +func (*CancelSpotsOrderRequest) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_spots_proto_rawDescGZIP(), []int{5} +} + +func (x *CancelSpotsOrderRequest) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +type SpotsOrderReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码 + Data *SpotsOrderResult `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 返回结果 + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` // 返回消息提示 +} + +func (x *SpotsOrderReply) Reset() { + *x = SpotsOrderReply{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_spots_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SpotsOrderReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SpotsOrderReply) ProtoMessage() {} + +func (x *SpotsOrderReply) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_spots_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SpotsOrderReply.ProtoReflect.Descriptor instead. +func (*SpotsOrderReply) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_spots_proto_rawDescGZIP(), []int{6} +} + +func (x *SpotsOrderReply) GetCode() int64 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *SpotsOrderReply) GetData() *SpotsOrderResult { + if x != nil { + return x.Data + } + return nil +} + +func (x *SpotsOrderReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type SpotsOrderResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OrderId string `protobuf:"bytes,1,opt,name=orderId,proto3" json:"orderId,omitempty"` // 订单Id +} + +func (x *SpotsOrderResult) Reset() { + *x = SpotsOrderResult{} + if protoimpl.UnsafeEnabled { + mi := &file_matchmaking_v1_virtually_spots_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SpotsOrderResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SpotsOrderResult) ProtoMessage() {} + +func (x *SpotsOrderResult) ProtoReflect() protoreflect.Message { + mi := &file_matchmaking_v1_virtually_spots_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SpotsOrderResult.ProtoReflect.Descriptor instead. +func (*SpotsOrderResult) Descriptor() ([]byte, []int) { + return file_matchmaking_v1_virtually_spots_proto_rawDescGZIP(), []int{7} +} + +func (x *SpotsOrderResult) GetOrderId() string { + if x != nil { + return x.OrderId + } + return "" +} + +var File_matchmaking_v1_virtually_spots_proto protoreflect.FileDescriptor + +var file_matchmaking_v1_virtually_spots_proto_rawDesc = []byte{ + 0x0a, 0x24, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, + 0x2f, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x6c, 0x79, 0x2f, 0x73, 0x70, 0x6f, 0x74, 0x73, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, + 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, + 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x6d, 0x0a, 0x19, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x44, + 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, + 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, + 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, + 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x70, 0x61, 0x67, 0x65, 0x43, + 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x80, 0x01, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x44, + 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, + 0x63, 0x6f, 0x64, 0x65, 0x12, 0x37, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x44, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x54, 0x72, + 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, + 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xa4, 0x01, 0x0a, 0x13, 0x42, 0x6f, 0x74, 0x44, + 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x54, 0x72, 0x61, 0x64, 0x65, 0x44, 0x61, 0x74, 0x61, 0x12, + 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x70, + 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, + 0x70, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x33, 0x0a, 0x04, 0x64, 0x61, 0x74, + 0x61, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, + 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x74, 0x44, 0x69, 0x67, 0x69, + 0x74, 0x61, 0x6c, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x1e, + 0x0a, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0xd5, + 0x05, 0x0a, 0x0f, 0x42, 0x6f, 0x74, 0x44, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x54, 0x72, 0x61, + 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, + 0x64, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x09, 0x64, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, + 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, + 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, + 0x54, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, + 0x54, 0x79, 0x70, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x65, 0x61, 0x6c, 0x50, 0x72, 0x69, 0x63, + 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x64, 0x65, 0x61, 0x6c, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, + 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, + 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, + 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, + 0x6b, 0x65, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, + 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x12, 0x1e, 0x0a, 0x0a, + 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, + 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, + 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x12, 0x3a, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, + 0x6d, 0x65, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, + 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, + 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, + 0x12, 0x3a, 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x0f, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, + 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x36, 0x0a, 0x08, + 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x10, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, + 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x08, 0x6f, 0x70, 0x65, 0x6e, + 0x54, 0x69, 0x6d, 0x65, 0x12, 0x3c, 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, + 0x69, 0x6d, 0x65, 0x18, 0x11, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, + 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x69, + 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x73, + 0x74, 0x18, 0x12, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, + 0x43, 0x6f, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, 0x65, 0x63, 0x69, + 0x6d, 0x61, 0x6c, 0x18, 0x13, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6b, 0x65, 0x65, 0x70, 0x44, + 0x65, 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x22, 0xaf, 0x02, 0x0a, 0x11, 0x53, 0x70, 0x6f, 0x74, 0x73, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, + 0x64, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x09, 0x64, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, + 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, + 0x72, 0x61, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x6c, + 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x6c, + 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x69, + 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x74, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x61, 0x72, 0x6b, 0x65, + 0x74, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x65, 0x61, 0x6c, 0x50, 0x72, + 0x69, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x64, 0x65, 0x61, 0x6c, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x75, 0x6d, + 0x62, 0x65, 0x72, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x1e, 0x0a, 0x0a, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4d, + 0x6f, 0x6e, 0x65, 0x79, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x43, 0x6f, 0x73, 0x74, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x73, 0x74, 0x22, 0x33, 0x0a, 0x17, 0x43, 0x61, 0x6e, 0x63, + 0x65, 0x6c, 0x53, 0x70, 0x6f, 0x74, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x22, 0x75, 0x0a, + 0x0f, 0x53, 0x70, 0x6f, 0x74, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, + 0x63, 0x6f, 0x64, 0x65, 0x12, 0x34, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x70, 0x6f, 0x74, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x73, 0x75, 0x6c, 0x74, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x22, 0x2c, 0x0a, 0x10, 0x53, 0x70, 0x6f, 0x74, 0x73, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x49, 0x64, 0x32, 0xac, 0x04, 0x0a, 0x05, 0x53, 0x70, 0x6f, 0x74, 0x73, 0x12, 0x8c, 0x01, 0x0a, + 0x12, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x44, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x54, 0x72, + 0x61, 0x64, 0x65, 0x12, 0x29, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, + 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x44, 0x69, 0x67, 0x69, 0x74, + 0x61, 0x6c, 0x54, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, + 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x47, 0x65, 0x74, 0x42, 0x6f, 0x74, 0x44, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x54, 0x72, 0x61, + 0x64, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x22, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1c, 0x3a, + 0x01, 0x2a, 0x22, 0x17, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x70, 0x6f, 0x74, 0x73, + 0x2f, 0x73, 0x70, 0x6f, 0x74, 0x73, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x12, 0x80, 0x01, 0x0a, 0x0f, + 0x53, 0x70, 0x6f, 0x74, 0x73, 0x50, 0x6c, 0x61, 0x63, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, + 0x21, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, + 0x2e, 0x53, 0x70, 0x6f, 0x74, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x70, 0x6f, 0x74, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x29, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x23, 0x3a, 0x01, 0x2a, 0x22, 0x1e, + 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x70, 0x6f, 0x74, 0x73, 0x2f, 0x73, 0x70, 0x6f, + 0x74, 0x73, 0x5f, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x7d, + 0x0a, 0x0b, 0x53, 0x70, 0x6f, 0x74, 0x73, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x12, 0x27, 0x2e, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, + 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x53, 0x70, 0x6f, 0x74, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, + 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x70, 0x6f, 0x74, 0x73, 0x4f, 0x72, 0x64, + 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x24, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1e, 0x3a, + 0x01, 0x2a, 0x22, 0x19, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x70, 0x6f, 0x74, 0x73, + 0x2f, 0x73, 0x70, 0x6f, 0x74, 0x73, 0x5f, 0x63, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x12, 0x91, 0x01, + 0x0a, 0x17, 0x53, 0x70, 0x6f, 0x74, 0x73, 0x4f, 0x6e, 0x65, 0x43, 0x6c, 0x69, 0x63, 0x6b, 0x52, + 0x65, 0x64, 0x65, 0x6d, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x21, 0x2e, 0x6d, 0x61, 0x74, 0x63, + 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x70, 0x6f, 0x74, 0x73, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x6d, + 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x70, + 0x6f, 0x74, 0x73, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x32, 0x82, + 0xd3, 0xe4, 0x93, 0x02, 0x2c, 0x3a, 0x01, 0x2a, 0x22, 0x27, 0x2f, 0x6f, 0x72, 0x64, 0x65, 0x72, + 0x5f, 0x73, 0x70, 0x6f, 0x74, 0x73, 0x2f, 0x73, 0x70, 0x6f, 0x74, 0x73, 0x5f, 0x6f, 0x6e, 0x65, + 0x5f, 0x63, 0x6c, 0x69, 0x63, 0x6b, 0x5f, 0x72, 0x65, 0x64, 0x65, 0x6d, 0x70, 0x74, 0x69, 0x6f, + 0x6e, 0x42, 0x2a, 0x5a, 0x28, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, + 0x2d, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x61, 0x74, 0x63, + 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_matchmaking_v1_virtually_spots_proto_rawDescOnce sync.Once + file_matchmaking_v1_virtually_spots_proto_rawDescData = file_matchmaking_v1_virtually_spots_proto_rawDesc +) + +func file_matchmaking_v1_virtually_spots_proto_rawDescGZIP() []byte { + file_matchmaking_v1_virtually_spots_proto_rawDescOnce.Do(func() { + file_matchmaking_v1_virtually_spots_proto_rawDescData = protoimpl.X.CompressGZIP(file_matchmaking_v1_virtually_spots_proto_rawDescData) + }) + return file_matchmaking_v1_virtually_spots_proto_rawDescData +} + +var file_matchmaking_v1_virtually_spots_proto_msgTypes = make([]protoimpl.MessageInfo, 8) +var file_matchmaking_v1_virtually_spots_proto_goTypes = []any{ + (*GetBotDigitalTradeRequest)(nil), // 0: matchmaking.v1.GetBotDigitalTradeRequest + (*GetBotDigitalTradeReply)(nil), // 1: matchmaking.v1.GetBotDigitalTradeReply + (*BotDigitalTradeData)(nil), // 2: matchmaking.v1.BotDigitalTradeData + (*BotDigitalTrade)(nil), // 3: matchmaking.v1.BotDigitalTrade + (*SpotsOrderRequest)(nil), // 4: matchmaking.v1.SpotsOrderRequest + (*CancelSpotsOrderRequest)(nil), // 5: matchmaking.v1.CancelSpotsOrderRequest + (*SpotsOrderReply)(nil), // 6: matchmaking.v1.SpotsOrderReply + (*SpotsOrderResult)(nil), // 7: matchmaking.v1.SpotsOrderResult + (*timestamppb.Timestamp)(nil), // 8: google.protobuf.Timestamp +} +var file_matchmaking_v1_virtually_spots_proto_depIdxs = []int32{ + 2, // 0: matchmaking.v1.GetBotDigitalTradeReply.data:type_name -> matchmaking.v1.BotDigitalTradeData + 3, // 1: matchmaking.v1.BotDigitalTradeData.data:type_name -> matchmaking.v1.BotDigitalTrade + 8, // 2: matchmaking.v1.BotDigitalTrade.createTime:type_name -> google.protobuf.Timestamp + 8, // 3: matchmaking.v1.BotDigitalTrade.updateTime:type_name -> google.protobuf.Timestamp + 8, // 4: matchmaking.v1.BotDigitalTrade.openTime:type_name -> google.protobuf.Timestamp + 8, // 5: matchmaking.v1.BotDigitalTrade.closingTime:type_name -> google.protobuf.Timestamp + 7, // 6: matchmaking.v1.SpotsOrderReply.data:type_name -> matchmaking.v1.SpotsOrderResult + 0, // 7: matchmaking.v1.Spots.GetBotDigitalTrade:input_type -> matchmaking.v1.GetBotDigitalTradeRequest + 4, // 8: matchmaking.v1.Spots.SpotsPlaceOrder:input_type -> matchmaking.v1.SpotsOrderRequest + 5, // 9: matchmaking.v1.Spots.SpotsCancel:input_type -> matchmaking.v1.CancelSpotsOrderRequest + 4, // 10: matchmaking.v1.Spots.SpotsOneClickRedemption:input_type -> matchmaking.v1.SpotsOrderRequest + 1, // 11: matchmaking.v1.Spots.GetBotDigitalTrade:output_type -> matchmaking.v1.GetBotDigitalTradeReply + 6, // 12: matchmaking.v1.Spots.SpotsPlaceOrder:output_type -> matchmaking.v1.SpotsOrderReply + 6, // 13: matchmaking.v1.Spots.SpotsCancel:output_type -> matchmaking.v1.SpotsOrderReply + 6, // 14: matchmaking.v1.Spots.SpotsOneClickRedemption:output_type -> matchmaking.v1.SpotsOrderReply + 11, // [11:15] is the sub-list for method output_type + 7, // [7:11] is the sub-list for method input_type + 7, // [7:7] is the sub-list for extension type_name + 7, // [7:7] is the sub-list for extension extendee + 0, // [0:7] is the sub-list for field type_name +} + +func init() { file_matchmaking_v1_virtually_spots_proto_init() } +func file_matchmaking_v1_virtually_spots_proto_init() { + if File_matchmaking_v1_virtually_spots_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_matchmaking_v1_virtually_spots_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*GetBotDigitalTradeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_spots_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*GetBotDigitalTradeReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_spots_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*BotDigitalTradeData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_spots_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*BotDigitalTrade); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_spots_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*SpotsOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_spots_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*CancelSpotsOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_spots_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*SpotsOrderReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_matchmaking_v1_virtually_spots_proto_msgTypes[7].Exporter = func(v any, i int) any { + switch v := v.(*SpotsOrderResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_matchmaking_v1_virtually_spots_proto_rawDesc, + NumEnums: 0, + NumMessages: 8, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_matchmaking_v1_virtually_spots_proto_goTypes, + DependencyIndexes: file_matchmaking_v1_virtually_spots_proto_depIdxs, + MessageInfos: file_matchmaking_v1_virtually_spots_proto_msgTypes, + }.Build() + File_matchmaking_v1_virtually_spots_proto = out.File + file_matchmaking_v1_virtually_spots_proto_rawDesc = nil + file_matchmaking_v1_virtually_spots_proto_goTypes = nil + file_matchmaking_v1_virtually_spots_proto_depIdxs = nil +} diff --git a/api/matchmaking/v1/virtually/spots.proto b/api/matchmaking/v1/virtually/spots.proto new file mode 100644 index 0000000..d7d6241 --- /dev/null +++ b/api/matchmaking/v1/virtually/spots.proto @@ -0,0 +1,106 @@ +syntax = "proto3"; + +package matchmaking.v1; + +import "google/api/annotations.proto"; +import "google/protobuf/timestamp.proto"; + +option go_package = "matchmaking-system/api/matchmaking/v1;v1"; + +service Spots { + // GetBotDigitalTrade 现货列表查询 + rpc GetBotDigitalTrade(GetBotDigitalTradeRequest)returns(GetBotDigitalTradeReply){ + option (google.api.http) = { + post:"/order_spots/spots_list", + body:"*", + }; + } + // SpotsPlaceOrder 现货下单 + rpc SpotsPlaceOrder(SpotsOrderRequest)returns(SpotsOrderReply) { + option (google.api.http) = { + post: "/order_spots/spots_place_order", + body: "*", + }; + } + // SpotsCancel 现货撤单 + rpc SpotsCancel(CancelSpotsOrderRequest)returns(SpotsOrderReply) { + option (google.api.http) = { + post: "/order_spots/spots_cancel", + body: "*", + }; + } + // SpotsOneClickRedemption 现货一键兑换 + rpc SpotsOneClickRedemption(SpotsOrderRequest)returns(SpotsOrderReply){ + option (google.api.http) = { + post: "/order_spots/spots_one_click_redemption", + body: "*", + }; + } +} + +message GetBotDigitalTradeRequest{ + int64 status =1;// 状态码 + int64 pageSize =2; // 每页显示条数 + int64 pageCount =3;// 开始的位置 +} + +message GetBotDigitalTradeReply{ + int64 code =1;// 状态码 + BotDigitalTradeData data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message BotDigitalTradeData{ + int64 pageSize =1; // 每页显示条数 + int64 pageCount =2;// 开始的位置 + repeated BotDigitalTrade data =3;// 返回结果 + int64 totalCount =4;// 总数据 +} + +message BotDigitalTrade{ + string orderId =1;// 订单ID + string digitalId =2;// 现货交易对 + int64 tradeType =3;// 交易类型 + int64 dealType =4;// 交易方式 + string dealPrice =7;// 开仓价 + string closingPrice =8;// 平仓价格 + string limitPrice =5;// 限价 + string marketPrice =6;// 市价 + string orderNumber =9;// 订单数量 + string serviceCost =10;// 开仓手续费 + string orderMoney =11;// 订单金额 + string totalMoney =12;// 订单总金额 + int64 status =13;// 订单状态 + google.protobuf.Timestamp createTime =14;// 订单创建时间 + google.protobuf.Timestamp updateTime =15;// 订单更新时间 + google.protobuf.Timestamp openTime =16;// 订单开仓时间 + google.protobuf.Timestamp closingTime =17;// 订单平仓时间 + string closingCost =18;// 平仓手续费 + string keepDecimal =19;// 保留小数位 +} + +message SpotsOrderRequest{ + string digitalId =1;// 交易对 + int64 tradeType =2;// 交易类型:1买入,2卖出 + int64 dealType =3;// 委托方式:1限价,2市价 + string limitPrice =4;// 限价 + string marketPrice =5;// 市价 + string dealPrice =6;// 订单价格 + string orderNumber =7;// 订单数量 + string orderMoney =8;// 订单金额 + string serviceCost =9;// 手续费 +} + +message CancelSpotsOrderRequest{ + string orderId =1;// 订单ID +} + +message SpotsOrderReply{ + int64 code =1;// 状态码 + SpotsOrderResult data =2;// 返回结果 + string message =3;// 返回消息提示 +} + +message SpotsOrderResult { + string orderId =1;// 订单Id +} \ No newline at end of file diff --git a/api/matchmaking/v1/virtually/spots_grpc.pb.go b/api/matchmaking/v1/virtually/spots_grpc.pb.go new file mode 100644 index 0000000..4b722d4 --- /dev/null +++ b/api/matchmaking/v1/virtually/spots_grpc.pb.go @@ -0,0 +1,232 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.1 +// source: matchmaking/v1/virtually/spots.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + Spots_GetBotDigitalTrade_FullMethodName = "/matchmaking.v1.Spots/GetBotDigitalTrade" + Spots_SpotsPlaceOrder_FullMethodName = "/matchmaking.v1.Spots/SpotsPlaceOrder" + Spots_SpotsCancel_FullMethodName = "/matchmaking.v1.Spots/SpotsCancel" + Spots_SpotsOneClickRedemption_FullMethodName = "/matchmaking.v1.Spots/SpotsOneClickRedemption" +) + +// SpotsClient is the client API for Spots service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type SpotsClient interface { + // GetBotDigitalTrade 现货列表查询 + GetBotDigitalTrade(ctx context.Context, in *GetBotDigitalTradeRequest, opts ...grpc.CallOption) (*GetBotDigitalTradeReply, error) + // SpotsPlaceOrder 现货下单 + SpotsPlaceOrder(ctx context.Context, in *SpotsOrderRequest, opts ...grpc.CallOption) (*SpotsOrderReply, error) + // SpotsCancel 现货撤单 + SpotsCancel(ctx context.Context, in *CancelSpotsOrderRequest, opts ...grpc.CallOption) (*SpotsOrderReply, error) + // SpotsOneClickRedemption 现货一键兑换 + SpotsOneClickRedemption(ctx context.Context, in *SpotsOrderRequest, opts ...grpc.CallOption) (*SpotsOrderReply, error) +} + +type spotsClient struct { + cc grpc.ClientConnInterface +} + +func NewSpotsClient(cc grpc.ClientConnInterface) SpotsClient { + return &spotsClient{cc} +} + +func (c *spotsClient) GetBotDigitalTrade(ctx context.Context, in *GetBotDigitalTradeRequest, opts ...grpc.CallOption) (*GetBotDigitalTradeReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetBotDigitalTradeReply) + err := c.cc.Invoke(ctx, Spots_GetBotDigitalTrade_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *spotsClient) SpotsPlaceOrder(ctx context.Context, in *SpotsOrderRequest, opts ...grpc.CallOption) (*SpotsOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(SpotsOrderReply) + err := c.cc.Invoke(ctx, Spots_SpotsPlaceOrder_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *spotsClient) SpotsCancel(ctx context.Context, in *CancelSpotsOrderRequest, opts ...grpc.CallOption) (*SpotsOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(SpotsOrderReply) + err := c.cc.Invoke(ctx, Spots_SpotsCancel_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *spotsClient) SpotsOneClickRedemption(ctx context.Context, in *SpotsOrderRequest, opts ...grpc.CallOption) (*SpotsOrderReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(SpotsOrderReply) + err := c.cc.Invoke(ctx, Spots_SpotsOneClickRedemption_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// SpotsServer is the server API for Spots service. +// All implementations must embed UnimplementedSpotsServer +// for forward compatibility +type SpotsServer interface { + // GetBotDigitalTrade 现货列表查询 + GetBotDigitalTrade(context.Context, *GetBotDigitalTradeRequest) (*GetBotDigitalTradeReply, error) + // SpotsPlaceOrder 现货下单 + SpotsPlaceOrder(context.Context, *SpotsOrderRequest) (*SpotsOrderReply, error) + // SpotsCancel 现货撤单 + SpotsCancel(context.Context, *CancelSpotsOrderRequest) (*SpotsOrderReply, error) + // SpotsOneClickRedemption 现货一键兑换 + SpotsOneClickRedemption(context.Context, *SpotsOrderRequest) (*SpotsOrderReply, error) + mustEmbedUnimplementedSpotsServer() +} + +// UnimplementedSpotsServer must be embedded to have forward compatible implementations. +type UnimplementedSpotsServer struct { +} + +func (UnimplementedSpotsServer) GetBotDigitalTrade(context.Context, *GetBotDigitalTradeRequest) (*GetBotDigitalTradeReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBotDigitalTrade not implemented") +} +func (UnimplementedSpotsServer) SpotsPlaceOrder(context.Context, *SpotsOrderRequest) (*SpotsOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method SpotsPlaceOrder not implemented") +} +func (UnimplementedSpotsServer) SpotsCancel(context.Context, *CancelSpotsOrderRequest) (*SpotsOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method SpotsCancel not implemented") +} +func (UnimplementedSpotsServer) SpotsOneClickRedemption(context.Context, *SpotsOrderRequest) (*SpotsOrderReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method SpotsOneClickRedemption not implemented") +} +func (UnimplementedSpotsServer) mustEmbedUnimplementedSpotsServer() {} + +// UnsafeSpotsServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to SpotsServer will +// result in compilation errors. +type UnsafeSpotsServer interface { + mustEmbedUnimplementedSpotsServer() +} + +func RegisterSpotsServer(s grpc.ServiceRegistrar, srv SpotsServer) { + s.RegisterService(&Spots_ServiceDesc, srv) +} + +func _Spots_GetBotDigitalTrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetBotDigitalTradeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SpotsServer).GetBotDigitalTrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Spots_GetBotDigitalTrade_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SpotsServer).GetBotDigitalTrade(ctx, req.(*GetBotDigitalTradeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Spots_SpotsPlaceOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SpotsOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SpotsServer).SpotsPlaceOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Spots_SpotsPlaceOrder_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SpotsServer).SpotsPlaceOrder(ctx, req.(*SpotsOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Spots_SpotsCancel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CancelSpotsOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SpotsServer).SpotsCancel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Spots_SpotsCancel_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SpotsServer).SpotsCancel(ctx, req.(*CancelSpotsOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Spots_SpotsOneClickRedemption_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SpotsOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SpotsServer).SpotsOneClickRedemption(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Spots_SpotsOneClickRedemption_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SpotsServer).SpotsOneClickRedemption(ctx, req.(*SpotsOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Spots_ServiceDesc is the grpc.ServiceDesc for Spots service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Spots_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "matchmaking.v1.Spots", + HandlerType: (*SpotsServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetBotDigitalTrade", + Handler: _Spots_GetBotDigitalTrade_Handler, + }, + { + MethodName: "SpotsPlaceOrder", + Handler: _Spots_SpotsPlaceOrder_Handler, + }, + { + MethodName: "SpotsCancel", + Handler: _Spots_SpotsCancel_Handler, + }, + { + MethodName: "SpotsOneClickRedemption", + Handler: _Spots_SpotsOneClickRedemption_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "matchmaking/v1/virtually/spots.proto", +} diff --git a/api/matchmaking/v1/virtually/spots_http.pb.go b/api/matchmaking/v1/virtually/spots_http.pb.go new file mode 100644 index 0000000..d54967c --- /dev/null +++ b/api/matchmaking/v1/virtually/spots_http.pb.go @@ -0,0 +1,199 @@ +// Code generated by protoc-gen-go-http. DO NOT EDIT. +// versions: +// - protoc-gen-go-http v2.7.3 +// - protoc v5.27.1 +// source: matchmaking/v1/virtually/spots.proto + +package v1 + +import ( + context "context" + http "github.com/go-kratos/kratos/v2/transport/http" + binding "github.com/go-kratos/kratos/v2/transport/http/binding" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the kratos package it is being compiled against. +var _ = new(context.Context) +var _ = binding.EncodeURL + +const _ = http.SupportPackageIsVersion1 + +const OperationSpotsGetBotDigitalTrade = "/matchmaking.v1.Spots/GetBotDigitalTrade" +const OperationSpotsSpotsCancel = "/matchmaking.v1.Spots/SpotsCancel" +const OperationSpotsSpotsOneClickRedemption = "/matchmaking.v1.Spots/SpotsOneClickRedemption" +const OperationSpotsSpotsPlaceOrder = "/matchmaking.v1.Spots/SpotsPlaceOrder" + +type SpotsHTTPServer interface { + // GetBotDigitalTrade GetBotDigitalTrade 现货列表查询 + GetBotDigitalTrade(context.Context, *GetBotDigitalTradeRequest) (*GetBotDigitalTradeReply, error) + // SpotsCancel SpotsCancel 现货撤单 + SpotsCancel(context.Context, *CancelSpotsOrderRequest) (*SpotsOrderReply, error) + // SpotsOneClickRedemption SpotsOneClickRedemption 现货一键兑换 + SpotsOneClickRedemption(context.Context, *SpotsOrderRequest) (*SpotsOrderReply, error) + // SpotsPlaceOrder SpotsPlaceOrder 现货下单 + SpotsPlaceOrder(context.Context, *SpotsOrderRequest) (*SpotsOrderReply, error) +} + +func RegisterSpotsHTTPServer(s *http.Server, srv SpotsHTTPServer) { + r := s.Route("/") + r.POST("/order_spots/spots_list", _Spots_GetBotDigitalTrade0_HTTP_Handler(srv)) + r.POST("/order_spots/spots_place_order", _Spots_SpotsPlaceOrder0_HTTP_Handler(srv)) + r.POST("/order_spots/spots_cancel", _Spots_SpotsCancel0_HTTP_Handler(srv)) + r.POST("/order_spots/spots_one_click_redemption", _Spots_SpotsOneClickRedemption0_HTTP_Handler(srv)) +} + +func _Spots_GetBotDigitalTrade0_HTTP_Handler(srv SpotsHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in GetBotDigitalTradeRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationSpotsGetBotDigitalTrade) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.GetBotDigitalTrade(ctx, req.(*GetBotDigitalTradeRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*GetBotDigitalTradeReply) + return ctx.Result(200, reply) + } +} + +func _Spots_SpotsPlaceOrder0_HTTP_Handler(srv SpotsHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in SpotsOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationSpotsSpotsPlaceOrder) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.SpotsPlaceOrder(ctx, req.(*SpotsOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*SpotsOrderReply) + return ctx.Result(200, reply) + } +} + +func _Spots_SpotsCancel0_HTTP_Handler(srv SpotsHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in CancelSpotsOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationSpotsSpotsCancel) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.SpotsCancel(ctx, req.(*CancelSpotsOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*SpotsOrderReply) + return ctx.Result(200, reply) + } +} + +func _Spots_SpotsOneClickRedemption0_HTTP_Handler(srv SpotsHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in SpotsOrderRequest + if err := ctx.Bind(&in); err != nil { + return err + } + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, OperationSpotsSpotsOneClickRedemption) + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.SpotsOneClickRedemption(ctx, req.(*SpotsOrderRequest)) + }) + out, err := h(ctx, &in) + if err != nil { + return err + } + reply := out.(*SpotsOrderReply) + return ctx.Result(200, reply) + } +} + +type SpotsHTTPClient interface { + GetBotDigitalTrade(ctx context.Context, req *GetBotDigitalTradeRequest, opts ...http.CallOption) (rsp *GetBotDigitalTradeReply, err error) + SpotsCancel(ctx context.Context, req *CancelSpotsOrderRequest, opts ...http.CallOption) (rsp *SpotsOrderReply, err error) + SpotsOneClickRedemption(ctx context.Context, req *SpotsOrderRequest, opts ...http.CallOption) (rsp *SpotsOrderReply, err error) + SpotsPlaceOrder(ctx context.Context, req *SpotsOrderRequest, opts ...http.CallOption) (rsp *SpotsOrderReply, err error) +} + +type SpotsHTTPClientImpl struct { + cc *http.Client +} + +func NewSpotsHTTPClient(client *http.Client) SpotsHTTPClient { + return &SpotsHTTPClientImpl{client} +} + +func (c *SpotsHTTPClientImpl) GetBotDigitalTrade(ctx context.Context, in *GetBotDigitalTradeRequest, opts ...http.CallOption) (*GetBotDigitalTradeReply, error) { + var out GetBotDigitalTradeReply + pattern := "/order_spots/spots_list" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationSpotsGetBotDigitalTrade)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *SpotsHTTPClientImpl) SpotsCancel(ctx context.Context, in *CancelSpotsOrderRequest, opts ...http.CallOption) (*SpotsOrderReply, error) { + var out SpotsOrderReply + pattern := "/order_spots/spots_cancel" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationSpotsSpotsCancel)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *SpotsHTTPClientImpl) SpotsOneClickRedemption(ctx context.Context, in *SpotsOrderRequest, opts ...http.CallOption) (*SpotsOrderReply, error) { + var out SpotsOrderReply + pattern := "/order_spots/spots_one_click_redemption" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationSpotsSpotsOneClickRedemption)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} + +func (c *SpotsHTTPClientImpl) SpotsPlaceOrder(ctx context.Context, in *SpotsOrderRequest, opts ...http.CallOption) (*SpotsOrderReply, error) { + var out SpotsOrderReply + pattern := "/order_spots/spots_place_order" + path := binding.EncodeURL(pattern, in, false) + opts = append(opts, http.Operation(OperationSpotsSpotsPlaceOrder)) + opts = append(opts, http.PathTemplate(pattern)) + err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/cmd/matchmaking-system/main.go b/cmd/matchmaking-system/main.go new file mode 100644 index 0000000..344451e --- /dev/null +++ b/cmd/matchmaking-system/main.go @@ -0,0 +1,102 @@ +package main + +import ( + "flag" + "github.com/go-kratos/kratos/v2" + "github.com/go-kratos/kratos/v2/log" + "github.com/go-kratos/kratos/v2/middleware/tracing" + "github.com/go-kratos/kratos/v2/transport/grpc" + "github.com/go-kratos/kratos/v2/transport/http" + _ "go.uber.org/automaxprocs" + "gopkg.in/yaml.v2" + "io/ioutil" + "matchmaking-system/internal/conf" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "os" +) + +// go build -ldflags "-X main.Version=x.y.z" +var ( + // Name is the name of the compiled software. + Name string + // Version is the version of the compiled software. + Version string + // flagConfig is the config flag. + flagConfig string + // Select subscription type + check string + // network + network string + + id, err = os.Hostname() +) + +func init() { + flag.StringVar(&flagConfig, "conf", "../../configs/money.yaml", "config path, eg: -conf config.yaml") + flag.StringVar(&check, "check", "money", "check content, eg: -check sport|contract|share-|admin-|") + flag.StringVar(&network, "network", "test", "network content, eg: -check test|onLine") +} + +func newApp(logger log.Logger, gs *grpc.Server, hs *http.Server) *kratos.App { + return kratos.New( + kratos.Name(Name), + kratos.Version(Version), + kratos.Metadata(map[string]string{}), + kratos.Logger(logger), + kratos.Server( + gs, + hs, + ), + ) +} + +func main() { + flag.Parse() + logger := log.With(log.NewStdLogger(os.Stdout), + "ts", log.DefaultTimestamp, + "caller", log.DefaultCaller, + "service.id", id, + "service.name", Name, + "service.version", Version, + "trace.id", tracing.TraceID(), + "span.id", tracing.SpanID(), + ) + + // yaml ReadFile config + yamlFile, err := ioutil.ReadFile(flagConfig) + if err != nil { + panic(err) + } + + // Bootstrap parsing + var bc conf.Bootstrap + err = yaml.Unmarshal(yamlFile, &bc) + if err != nil { + panic(err) + } + + // System environment variables + flags.CheckEnvironment = check + flags.CheckNetwork = network + flags.CheckAdminService = bc.Server.GetCheck() + switch network { + case flags.CheckOnLine: + flags.CheckSetting = true + case flags.CheckTest: + flags.CheckSetting = false + } + applogger.Info("methods:%v ,network:%v,adminService:%v", check, network, flags.CheckAdminService) + + // load wire app data + app, cleanup, err := wireApp(bc.Server, bc.Data, logger) + if err != nil { + panic(err) + } + defer cleanup() + + // start and wait for stop signal + if err = app.Run(); err != nil { + panic(err) + } +} diff --git a/cmd/matchmaking-system/wire.go b/cmd/matchmaking-system/wire.go new file mode 100644 index 0000000..495950c --- /dev/null +++ b/cmd/matchmaking-system/wire.go @@ -0,0 +1,22 @@ +//go:build wireinject +// +build wireinject + +// The build tag makes sure the stub is not built in the final build. + +package main + +import ( + "github.com/go-kratos/kratos/v2" + "github.com/go-kratos/kratos/v2/log" + "github.com/google/wire" + "matchmaking-system/internal/biz" + "matchmaking-system/internal/conf" + "matchmaking-system/internal/data" + "matchmaking-system/internal/server" + "matchmaking-system/internal/service" +) + +// wireApp init kratos application. +func wireApp(*conf.Server, *conf.Data, log.Logger) (*kratos.App, func(), error) { + panic(wire.Build(server.ProviderSet, data.ProviderSet, biz.ProviderSet, service.ProviderSet, newApp)) +} diff --git a/cmd/matchmaking-system/wire_gen.go b/cmd/matchmaking-system/wire_gen.go new file mode 100644 index 0000000..caf0d37 --- /dev/null +++ b/cmd/matchmaking-system/wire_gen.go @@ -0,0 +1,89 @@ +// Code generated by Wire. DO NOT EDIT. + +//go:generate go run -mod=mod github.com/google/wire/cmd/wire +//go:build !wireinject +// +build !wireinject + +package main + +import ( + "github.com/go-kratos/kratos/v2" + "github.com/go-kratos/kratos/v2/log" + "matchmaking-system/internal/biz" + "matchmaking-system/internal/conf" + "matchmaking-system/internal/data" + "matchmaking-system/internal/data/cache" + "matchmaking-system/internal/data/mysql" + "matchmaking-system/internal/data/redis" + "matchmaking-system/internal/data/sms" + "matchmaking-system/internal/server" + "matchmaking-system/internal/service" +) + +import ( + _ "go.uber.org/automaxprocs" +) + +// Injectors from wire.go: + +// wireApp init kratos application. +func wireApp(confServer *conf.Server, confData *conf.Data, logger log.Logger) (*kratos.App, func(), error) { + engineGroup := mysql.NewMySql(confData) + client := redis.NewRedis(confData) + cacheCache := cache.NewCacheDB(confData) + dataData, cleanup, err2 := data.NewData(confData, logger, engineGroup, client, cacheCache) + if err2 != nil { + return nil, nil, err + } + aLiYunRepo := data.NewALiYunRepo(dataData, logger) + aLiYunCase := sms.NewMsgSend(aLiYunRepo, logger) + userOrderRepo := data.NewUserOrderRepo(dataData, logger) + userOrder := biz.NewUserOrderRepo(userOrderRepo, logger) + userSecondOrderRepo := data.NewUserSecondRepo(dataData, logger) + userSecondOrder := biz.NewUserSecondOrderRepo(userSecondOrderRepo, logger) + userSpotsOrderRepo := data.NewUserSpotsRepo(dataData, logger) + userSpotsOrder := biz.NewUserSpotsOrderRepo(userSpotsOrderRepo, logger) + userContractOrderRepo := data.NewUserContractRepo(dataData, logger) + userContractOrder := biz.NewUserContractOrderRepo(userContractOrderRepo, logger) + userForexOrderRepo := data.NewUserForexRepo(dataData, logger) + userForexOrder := biz.NewUserForexOrderRepo(userForexOrderRepo, logger) + userMoneyOrderRepo := data.NewUserMoneyRepo(dataData, logger) + userMoneyOrder := biz.NewUserMoneyOrderRepo(userMoneyOrderRepo, logger) + userShareUsOrderRepo := data.NewUserShareUsRepo(dataData, logger) + userShareUsOrder := biz.NewUserShareUsOrderRepo(userShareUsOrderRepo, logger) + userShareThaOrderRepo := data.NewUserShareThaRepo(dataData, logger) + userShareThaOrder := biz.NewUserShareThaOrderRepo(userShareThaOrderRepo, logger) + userShareIdnOrderRepo := data.NewUserShareIdnRepo(dataData, logger) + userShareIdnOrder := biz.NewUserShareIdnOrderRepo(userShareIdnOrderRepo, logger) + userShareInrOrderRepo := data.NewUserShareInrRepo(dataData, logger) + userShareInrOrder := biz.NewUserShareInrOrderRepo(userShareInrOrderRepo, logger) + userShareMysOrderRepo := data.NewUserShareMysRepo(dataData, logger) + userShareMysOrder := biz.NewUserShareMysOrderRepo(userShareMysOrderRepo, logger) + userShareSgdOrderRepo := data.NewUserShareSgdRepo(dataData, logger) + userShareSgdOrder := biz.NewUserShareSgdOrderRepo(userShareSgdOrderRepo, logger) + userShareHkdOrderRepo := data.NewUserShareHkdRepo(dataData, logger) + userShareHkdOrder := biz.NewUserShareHkdOrderRepo(userShareHkdOrderRepo, logger) + userShareGbxOrderRepo := data.NewUserShareGbxRepo(dataData, logger) + userShareGbxOrder := biz.NewUserShareGbxOrderRepo(userShareGbxOrderRepo, logger) + userShareEurOrderRepo := data.NewUserShareEurRepo(dataData, logger) + userShareEurOrder := biz.NewUserShareEurOrderRepo(userShareEurOrderRepo, logger) + userShareFurOrderRepo := data.NewUserShareFurRepo(dataData, logger) + userShareFurOrder := biz.NewUserShareFurOrderRepo(userShareFurOrderRepo, logger) + userShareJpyOrderRepo := data.NewUserShareJpyRepo(dataData, logger) + userShareJpyOrder := biz.NewUserShareJpyOrderRepo(userShareJpyOrderRepo, logger) + userShareBrlOrderRepo := data.NewUserShareBrlRepo(dataData, logger) + userShareBrlOrder := biz.NewUserShareBrlOrderRepo(userShareBrlOrderRepo, logger) + userShareBlockOrderRepo := data.NewUserShareBlkRepo(dataData, logger) + userShareBlockOrder := biz.NewUserShareBlockOrderRepo(userShareHkdOrderRepo, userShareIdnOrderRepo, userShareInrOrderRepo, userShareMysOrderRepo, userShareSgdOrderRepo, userShareThaOrderRepo, userShareUsOrderRepo, userShareGbxOrderRepo, userShareFurOrderRepo, userShareEurOrderRepo, userShareBrlOrderRepo, userShareJpyOrderRepo, userShareBlockOrderRepo, logger) + userOptionInrOrderRepo := data.NewUserOptionInrRepo(dataData, logger) + userOptionInrOrder := biz.NewUserOptionInrOrderRepo(userOptionInrOrderRepo, logger) + userBackendRepo := data.NewUserBackendRepo(dataData, logger) + userBackend := biz.NewUserBackendRepo(userBackendRepo, logger) + conduitService := service.NewConduitService(aLiYunCase, userOrder, userSecondOrder, userSpotsOrder, userContractOrder, userForexOrder, userMoneyOrder, userShareUsOrder, userShareThaOrder, userShareIdnOrder, userShareInrOrder, userShareMysOrder, userShareSgdOrder, userShareHkdOrder, userShareGbxOrder, userShareEurOrder, userShareFurOrder, userShareJpyOrder, userShareBrlOrder, userShareBlockOrder, userOptionInrOrder, userBackend, logger) + grpcServer := server.NewGRPCServer(confServer, conduitService, logger) + httpServer := server.NewHTTPServer(confServer, conduitService, logger) + app := newApp(logger, grpcServer, httpServer) + return app, func() { + cleanup() + }, nil +} diff --git a/configs/README.md b/configs/README.md new file mode 100644 index 0000000..36ff76c --- /dev/null +++ b/configs/README.md @@ -0,0 +1,72 @@ +# 项目部署说明 + +## 服务域名规划 + +### git 分支管理 +``` + 1、主分支-main + 2、项目分支-p1_main、p2_main...... +``` + +### (测试(谷歌云)-新加坡交易所|股票)测试环境[虚拟币-(合约|秒合约|现货)、股票-(美股|泰股|马股|印尼股|印度股|新加坡股|港股|英股)、期权-(印度股)、新股申购(美股|泰股|马股|印尼股|印度股|新加坡股|港股|英股)、大宗交易(美股|泰股|马股|印尼股|印度股|新加坡股|港股|英股)]: +``` + 1、PC端:https://stockpc-india2.testjd.cc + 2、H5端:https://stockh5-india2.testjd.cc + 3、后台:https://stockmg-india2.testjd.cc +``` + +### (project01(谷歌云)-正式环境[美股、印度股、新股申购、大宗交易]: +``` + 1、交易订单域名: https://trade.lazardinvestgroup.net + 2、交易订单Wss: wss://trade.lazardinvestgroup.net +``` + +### (project02(谷歌云)-正式环境[美股、马股、泰股、港股、印度股、新加坡股、新股申购]: +``` + 1、交易订单域名: https://trade.troweinvestgroup.com + 2、交易订单Wss: wss://trade.troweinvestgroup.com +``` + +### (project04(谷歌云)-正式环境[美股、印度股、新股申购、大宗交易]: +``` + 1、交易订单域名: https://trade.voceangcp.com + 2、交易订单Wss: wss://trade.voceangcp.com +``` + +### (project05(谷歌云)-正式环境[美股、印度股、新股申购、大宗交易、期权(印度)]: +``` + 1、交易订单域名: https://trade.abglobalfund.com + 2、交易订单Wss: wss://trade.abglobalfund.com +``` + +### (project06(谷歌云)-正式环境[美股、英股、新股申购]: +``` + 1、交易订单域名: https://trade.twinim.com + 2、交易订单Wss: wss://trade.twinim.com +``` + +### (project07(谷歌云)-正式环境[美股、新股申购]: +``` + 1、交易订单域名: https://trade.sysdev8.cc + 2、交易订单Wss: wss://trade.sysdev8.cc +``` + +### (project08(谷歌云)-测试环境[现货、合约、秒合约]: +``` + 1、交易订单域名: https://trade.chdh.me + 2、交易订单Wss: wss://trade.chdh.me +``` + +### 服务环境和服务部署 +``` + 服务环境: + 1>数据库DB(mysql) + 2>数据缓存(redis) + 3>数据存储(mongodb) + 4>代理服务(nginx) + 5>进程管理器(supervisor) + 6>消息队列(RabbitMQ)--等待接入 + 服务部署: + 1>服务编译(make api | make config | make wire | make error | make win_build[windows编译]),参见项目:Makefile + 2>服务配置文件(上传到服务器:/home/ubuntu/service/config),参见项目:configs +``` \ No newline at end of file diff --git a/configs/admin.yaml b/configs/admin.yaml new file mode 100644 index 0000000..09a15e3 --- /dev/null +++ b/configs/admin.yaml @@ -0,0 +1,26 @@ +server: + http: + addr: 0.0.0.0:8000 + grpc: + addr: 0.0.0.0:9000 + check: second,contract,forex,shareUs,shareJpy + #check: second,contract,forex,shareUs,shareTha,shareIdn,shareInr,shareMys,shareSgd,shareHkd,shareGbx,shareFur,shareEur,shareJpy,shareBrl,optionInr +data: + database: + driver: mysql + source: root:Meetingyou0))@tcp(172.26.45.216:3306)/bourse?charset=utf8 + redis: + addr: 172.26.45.216:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 172.26.45.214:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "" + entrust: "" + start: True diff --git a/configs/adminBlk.yaml b/configs/adminBlk.yaml new file mode 100644 index 0000000..365e38b --- /dev/null +++ b/configs/adminBlk.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8014 + grpc: + addr: 0.0.0.0:9014 + check: +data: + database: + driver: mysql + source: bourse:A+#s$cQDVgMiop@tcp(rm-gs58762uh007sjwm78o.mysql.singapore.rds.aliyuncs.com:3306)/bourse?charset=utf8 + redis: + addr: r-gs5vsfhcyimqceug2kpd.redis.singapore.rds.aliyuncs.com:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 34.143.254.142:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "" + entrust: "" + start: True diff --git a/configs/backend.yaml b/configs/backend.yaml new file mode 100644 index 0000000..ef9ceb6 --- /dev/null +++ b/configs/backend.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8022 + grpc: + addr: 0.0.0.0:9022 + check: +data: + database: + driver: mysql + source: root:Meetingyou0))@tcp(172.26.45.216:3306)/bourse?charset=utf8 + redis: + addr: 172.26.45.216:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 172.26.45.214:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "backendPosition" + entrust: "backendEntrust" + start: True diff --git a/configs/contract.yaml b/configs/contract.yaml new file mode 100644 index 0000000..0b7daf2 --- /dev/null +++ b/configs/contract.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8002 + grpc: + addr: 0.0.0.0:9002 + check: +data: + database: + driver: mysql + source: root:Meetingyou0))@tcp(172.26.45.216:3306)/bourse?charset=utf8 + redis: + addr: 172.26.45.216:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 172.26.45.214:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "contractPosition" + entrust: "contractEntrust" + start: True diff --git a/configs/forex.yaml b/configs/forex.yaml new file mode 100644 index 0000000..db332eb --- /dev/null +++ b/configs/forex.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8020 + grpc: + addr: 0.0.0.0:9020 + check: +data: + database: + driver: mysql + source: root:Meetingyou0))@tcp(172.26.45.216:3306)/bourse?charset=utf8 + redis: + addr: 172.26.45.216:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 172.26.45.214:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "forexPosition" + entrust: "forexEntrust" + start: True diff --git a/configs/money.yaml b/configs/money.yaml new file mode 100644 index 0000000..ff3f31c --- /dev/null +++ b/configs/money.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8021 + grpc: + addr: 0.0.0.0:9021 + check: +data: + database: + driver: mysql + source: root:Meetingyou0))@tcp(172.26.45.216:3306)/bourse?charset=utf8 + redis: + addr: 172.26.45.216:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 172.26.45.214:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "moneyPosition" + entrust: "moneyEntrust" + start: True diff --git a/configs/optionInr.yaml b/configs/optionInr.yaml new file mode 100644 index 0000000..aff1dfe --- /dev/null +++ b/configs/optionInr.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8012 + grpc: + addr: 0.0.0.0:9012 + check: +data: + database: + driver: mysql + source: bourse:A+#s$cQDVgMiop@tcp(rm-gs58762uh007sjwm78o.mysql.singapore.rds.aliyuncs.com:3306)/bourse?charset=utf8 + redis: + addr: r-gs5vsfhcyimqceug2kpd.redis.singapore.rds.aliyuncs.com:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 34.143.254.142:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "optionInrPosition" + entrust: "optionInrEntrust" + start: True \ No newline at end of file diff --git a/configs/second.yaml b/configs/second.yaml new file mode 100644 index 0000000..5874dd7 --- /dev/null +++ b/configs/second.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8009 + grpc: + addr: 0.0.0.0:9009 + check: +data: + database: + driver: mysql + source: root:Meetingyou0))@tcp(172.26.45.216:3306)/bourse?charset=utf8 + redis: + addr: 172.26.45.216:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 172.26.45.214:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "contractSecondPosition" + entrust: "contractSecondEntrust" + start: True diff --git a/configs/shareBlk.yaml b/configs/shareBlk.yaml new file mode 100644 index 0000000..4326562 --- /dev/null +++ b/configs/shareBlk.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8013 + grpc: + addr: 0.0.0.0:9013 + check: +data: + database: + driver: mysql + source: bourse:A+#s$cQDVgMiop@tcp(rm-gs58762uh007sjwm78o.mysql.singapore.rds.aliyuncs.com:3306)/bourse?charset=utf8 + redis: + addr: r-gs5vsfhcyimqceug2kpd.redis.singapore.rds.aliyuncs.com:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 34.143.254.142:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "shareBlkPosition" + entrust: "shareBlkEntrust" + start: True diff --git a/configs/shareBrl.yaml b/configs/shareBrl.yaml new file mode 100644 index 0000000..0f0349b --- /dev/null +++ b/configs/shareBrl.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8018 + grpc: + addr: 0.0.0.0:9018 + check: +data: + database: + driver: mysql + source: bourse:A+#s$cQDVgMiop@tcp(rm-gs58762uh007sjwm78o.mysql.singapore.rds.aliyuncs.com:3306)/bourse?charset=utf8 + redis: + addr: r-gs5vsfhcyimqceug2kpd.redis.singapore.rds.aliyuncs.com:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 34.143.254.142:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "shareBrlPosition" + entrust: "shareBrlEntrust" + start: True \ No newline at end of file diff --git a/configs/shareCache.yaml b/configs/shareCache.yaml new file mode 100644 index 0000000..e79653d --- /dev/null +++ b/configs/shareCache.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8015 + grpc: + addr: 0.0.0.0:9015 + check: +data: + database: + driver: mysql + source: bourse:A+#s$cQDVgMiop@tcp(rm-gs58762uh007sjwm78o.mysql.singapore.rds.aliyuncs.com:3306)/bourse?charset=utf8 + redis: + addr: r-gs5vsfhcyimqceug2kpd.redis.singapore.rds.aliyuncs.com:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 34.143.254.142:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "shareInrPosition" + entrust: "shareInrEntrust" + start: True \ No newline at end of file diff --git a/configs/shareEur.yaml b/configs/shareEur.yaml new file mode 100644 index 0000000..a29f42b --- /dev/null +++ b/configs/shareEur.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8016 + grpc: + addr: 0.0.0.0:9016 + check: +data: + database: + driver: mysql + source: bourse:A+#s$cQDVgMiop@tcp(rm-gs58762uh007sjwm78o.mysql.singapore.rds.aliyuncs.com:3306)/bourse?charset=utf8 + redis: + addr: r-gs5vsfhcyimqceug2kpd.redis.singapore.rds.aliyuncs.com:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 34.143.254.142:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "shareEurPosition" + entrust: "shareEurEntrust" + start: True \ No newline at end of file diff --git a/configs/shareFur.yaml b/configs/shareFur.yaml new file mode 100644 index 0000000..c91ffae --- /dev/null +++ b/configs/shareFur.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8017 + grpc: + addr: 0.0.0.0:9017 + check: +data: + database: + driver: mysql + source: bourse:A+#s$cQDVgMiop@tcp(rm-gs58762uh007sjwm78o.mysql.singapore.rds.aliyuncs.com:3306)/bourse?charset=utf8 + redis: + addr: r-gs5vsfhcyimqceug2kpd.redis.singapore.rds.aliyuncs.com:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 34.143.254.142:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "shareFurPosition" + entrust: "shareFurEntrust" + start: True \ No newline at end of file diff --git a/configs/shareGbx.yaml b/configs/shareGbx.yaml new file mode 100644 index 0000000..ddec202 --- /dev/null +++ b/configs/shareGbx.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8015 + grpc: + addr: 0.0.0.0:9015 + check: +data: + database: + driver: mysql + source: bourse:A+#s$cQDVgMiop@tcp(rm-gs58762uh007sjwm78o.mysql.singapore.rds.aliyuncs.com:3306)/bourse?charset=utf8 + redis: + addr: r-gs5vsfhcyimqceug2kpd.redis.singapore.rds.aliyuncs.com:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 34.143.254.142:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "shareGbxPosition" + entrust: "shareGbxEntrust" + start: True \ No newline at end of file diff --git a/configs/shareHkd.yaml b/configs/shareHkd.yaml new file mode 100644 index 0000000..7b0bd0c --- /dev/null +++ b/configs/shareHkd.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8011 + grpc: + addr: 0.0.0.0:9011 + check: +data: + database: + driver: mysql + source: bourse:A+#s$cQDVgMiop@tcp(rm-gs58762uh007sjwm78o.mysql.singapore.rds.aliyuncs.com:3306)/bourse?charset=utf8 + redis: + addr: r-gs5vsfhcyimqceug2kpd.redis.singapore.rds.aliyuncs.com:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 34.143.254.142:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "shareHkdPosition" + entrust: "shareHkdEntrust" + start: True \ No newline at end of file diff --git a/configs/shareIdn.yaml b/configs/shareIdn.yaml new file mode 100644 index 0000000..dfaf1fd --- /dev/null +++ b/configs/shareIdn.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8006 + grpc: + addr: 0.0.0.0:9006 + check: +data: + database: + driver: mysql + source: bourse:A+#s$cQDVgMiop@tcp(rm-gs58762uh007sjwm78o.mysql.singapore.rds.aliyuncs.com:3306)/bourse?charset=utf8 + redis: + addr: r-gs5vsfhcyimqceug2kpd.redis.singapore.rds.aliyuncs.com:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 34.143.254.142:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "shareIdnPosition" + entrust: "shareIdnEntrust" + start: True diff --git a/configs/shareInit.yaml b/configs/shareInit.yaml new file mode 100644 index 0000000..466b8f7 --- /dev/null +++ b/configs/shareInit.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8009 + grpc: + addr: 0.0.0.0:9009 + check: +data: + database: + driver: mysql + source: bourse:A+#s$cQDVgMiop@tcp(rm-gs58762uh007sjwm78o.mysql.singapore.rds.aliyuncs.com:3306)/bourse?charset=utf8 + redis: + addr: r-gs5vsfhcyimqceug2kpd.redis.singapore.rds.aliyuncs.com:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 34.143.254.142:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "shareInrPosition" + entrust: "shareInrEntrust" + start: True \ No newline at end of file diff --git a/configs/shareInr.yaml b/configs/shareInr.yaml new file mode 100644 index 0000000..f33b033 --- /dev/null +++ b/configs/shareInr.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8008 + grpc: + addr: 0.0.0.0:9008 + check: +data: + database: + driver: mysql + source: bourse:A+#s$cQDVgMiop@tcp(rm-gs58762uh007sjwm78o.mysql.singapore.rds.aliyuncs.com:3306)/bourse?charset=utf8 + redis: + addr: r-gs5vsfhcyimqceug2kpd.redis.singapore.rds.aliyuncs.com:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 34.143.254.142:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "shareInrPosition" + entrust: "shareInrEntrust" + start: True \ No newline at end of file diff --git a/configs/shareJpy.yaml b/configs/shareJpy.yaml new file mode 100644 index 0000000..822a5f3 --- /dev/null +++ b/configs/shareJpy.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8019 + grpc: + addr: 0.0.0.0:9019 + check: +data: + database: + driver: mysql + source: bourse:A+#s$cQDVgMiop@tcp(rm-gs58762uh007sjwm78o.mysql.singapore.rds.aliyuncs.com:3306)/bourse?charset=utf8 + redis: + addr: r-gs5vsfhcyimqceug2kpd.redis.singapore.rds.aliyuncs.com:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 34.143.254.142:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "shareJpyPosition" + entrust: "shareJpyEntrust" + start: True \ No newline at end of file diff --git a/configs/shareMys.yaml b/configs/shareMys.yaml new file mode 100644 index 0000000..5773afb --- /dev/null +++ b/configs/shareMys.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8004 + grpc: + addr: 0.0.0.0:9004 + check: +data: + database: + driver: mysql + source: bourse:A+#s$cQDVgMiop@tcp(rm-gs58762uh007sjwm78o.mysql.singapore.rds.aliyuncs.com:3306)/bourse?charset=utf8 + redis: + addr: r-gs5vsfhcyimqceug2kpd.redis.singapore.rds.aliyuncs.com:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 34.143.254.142:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "shareMysPosition" + entrust: "shareMysEntrust" + start: True \ No newline at end of file diff --git a/configs/shareSgd.yaml b/configs/shareSgd.yaml new file mode 100644 index 0000000..7fc4cf7 --- /dev/null +++ b/configs/shareSgd.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8010 + grpc: + addr: 0.0.0.0:9010 + check: +data: + database: + driver: mysql + source: bourse:A+#s$cQDVgMiop@tcp(rm-gs58762uh007sjwm78o.mysql.singapore.rds.aliyuncs.com:3306)/bourse?charset=utf8 + redis: + addr: r-gs5vsfhcyimqceug2kpd.redis.singapore.rds.aliyuncs.com:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 34.143.254.142:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "shareSgdPosition" + entrust: "shareSgdEntrust" + start: True \ No newline at end of file diff --git a/configs/shareTha.yaml b/configs/shareTha.yaml new file mode 100644 index 0000000..edf46c1 --- /dev/null +++ b/configs/shareTha.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8005 + grpc: + addr: 0.0.0.0:9005 + check: +data: + database: + driver: mysql + source: bourse:A+#s$cQDVgMiop@tcp(rm-gs58762uh007sjwm78o.mysql.singapore.rds.aliyuncs.com:3306)/bourse?charset=utf8 + redis: + addr: r-gs5vsfhcyimqceug2kpd.redis.singapore.rds.aliyuncs.com:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 34.143.254.142:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "shareThaPosition" + entrust: "shareThaEntrust" + start: True \ No newline at end of file diff --git a/configs/shareUs.yaml b/configs/shareUs.yaml new file mode 100644 index 0000000..bddb78a --- /dev/null +++ b/configs/shareUs.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8003 + grpc: + addr: 0.0.0.0:9003 + check: +data: + database: + driver: mysql + source: bourse:A+#s$cQDVgMiop@tcp(rm-gs58762uh007sjwm78o.mysql.singapore.rds.aliyuncs.com:3306)/bourse?charset=utf8 + redis: + addr: r-gs523wj7gcnshp3d1fpd.redis.singapore.rds.aliyuncs.com:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 34.143.254.142:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "shareUsPosition" + entrust: "shareUsEntrust" + start: True \ No newline at end of file diff --git a/configs/spots.yaml b/configs/spots.yaml new file mode 100644 index 0000000..1674a71 --- /dev/null +++ b/configs/spots.yaml @@ -0,0 +1,25 @@ +server: + http: + addr: 0.0.0.0:8001 + grpc: + addr: 0.0.0.0:9001 + check: +data: + database: + driver: mysql + source: root:Meetingyou0))@tcp(172.26.45.216:3306)/bourse?charset=utf8 + redis: + addr: 172.26.45.216:6379 + db: 0 + password: MRrfvtyujnb&hg56 + mongodb: + addr: 172.26.45.214:27085 + user: pqRRVamndJ + password: 35LlW3pXF76&WD!OOlnI + db: bourse + mq: + address: "amqp://admin:admin@127.0.0.1:5672/" + type: "direct" + position: "spotsPosition" + entrust: "spotsEntrust" + start: True diff --git a/deploy/environment/docker-compose.yaml b/deploy/environment/docker-compose.yaml new file mode 100644 index 0000000..aa0d4b9 --- /dev/null +++ b/deploy/environment/docker-compose.yaml @@ -0,0 +1,38 @@ +version: "3" +services: + + redis: + image: redis + container_name: redis3 + ports: + - "63121:6379" + volumes: + - ./data/redis/database:/data/db + command: redis-service --requirepass rfvtyujnbhg56 + restart: always + networks: + - default + stdin_open: true + tty: true + + mongo: + image: mongo + container_name: mongodb3 + ports: + - "27085:27017" + volumes: + - ./data/mongodb/database:/data/db + environment: + - MONGO_INITDB_ROOT_USERNAME=pqRRVamndJ + - MONGO_INITDB_ROOT_PASSWORD=35LlW3pXF76&WD!OOlnI + restart: always + networks: + - default + stdin_open: true + tty: true + +networks: + default: + driver: bridge + ipam: + driver: default \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..36d5784 --- /dev/null +++ b/go.mod @@ -0,0 +1,81 @@ +module matchmaking-system + +go 1.23 + +require ( + github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.4 + github.com/alibabacloud-go/dysmsapi-20180501/v2 v2.0.0 + github.com/alibabacloud-go/tea v1.2.0 + github.com/alibabacloud-go/tea-utils/v2 v2.0.2 + github.com/allegro/bigcache v1.2.1 + github.com/davecgh/go-spew v1.1.1 + github.com/go-kratos/kratos/v2 v2.7.1 + github.com/go-sql-driver/mysql v1.7.1 + github.com/go-xorm/xorm v0.7.9 + github.com/golang-jwt/jwt/v4 v4.5.0 + github.com/google/wire v0.5.0 + github.com/gorilla/handlers v1.5.1 + github.com/gorilla/mux v1.8.0 + github.com/gorilla/websocket v1.5.0 + github.com/patrickmn/go-cache v2.1.0+incompatible + github.com/redis/go-redis/v9 v9.3.0 + github.com/satori/go.uuid v1.2.0 + github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24 + github.com/streadway/amqp v1.1.0 + go.mongodb.org/mongo-driver v1.12.0 + go.uber.org/automaxprocs v1.5.1 + go.uber.org/zap v1.24.0 + google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 + google.golang.org/grpc v1.64.0 + google.golang.org/protobuf v1.34.2 + gopkg.in/yaml.v2 v2.2.8 +) + +require ( + cloud.google.com/go v0.110.8 // indirect + github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4 // indirect + github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 // indirect + github.com/alibabacloud-go/endpoint-util v1.1.0 // indirect + github.com/alibabacloud-go/openapi-util v0.0.11 // indirect + github.com/alibabacloud-go/tea-utils v1.3.1 // indirect + github.com/alibabacloud-go/tea-xml v1.1.2 // indirect + github.com/aliyun/credentials-go v1.1.2 // indirect + github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/clbanning/mxj/v2 v2.5.5 // indirect + github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect + github.com/felixge/httpsnoop v1.0.1 // indirect + github.com/go-kratos/aegis v0.2.0 // indirect + github.com/go-logr/logr v1.3.0 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-playground/form/v4 v4.2.1 // indirect + github.com/golang/snappy v0.0.4 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/compress v1.16.6 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect + github.com/tjfoc/gmsm v1.3.2 // indirect + github.com/xdg-go/pbkdf2 v1.0.0 // indirect + github.com/xdg-go/scram v1.1.2 // indirect + github.com/xdg-go/stringprep v1.0.4 // indirect + github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect + go.opentelemetry.io/otel v1.19.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect + go.opentelemetry.io/otel/sdk v1.19.0 // indirect + go.opentelemetry.io/otel/trace v1.19.0 // indirect + go.uber.org/atomic v1.7.0 // indirect + go.uber.org/goleak v1.2.1 // indirect + go.uber.org/multierr v1.6.0 // indirect + golang.org/x/crypto v0.24.0 // indirect + golang.org/x/net v0.26.0 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/sys v0.21.0 // indirect + golang.org/x/text v0.16.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240617180043-68d350f18fd4 // indirect + gopkg.in/ini.v1 v1.56.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect + xorm.io/builder v0.3.6 // indirect + xorm.io/core v0.7.2-0.20190928055935-90aeac8d08eb // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..53c6306 --- /dev/null +++ b/go.sum @@ -0,0 +1,399 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.37.4/go.mod h1:NHPJ89PdicEuT9hdPXMROBD91xc5uRDxsMtSB16k7hw= +cloud.google.com/go v0.110.8 h1:tyNdfIxjzaWctIiLYOTalaLKZ17SI44SKFW26QbOhME= +cloud.google.com/go v0.110.8/go.mod h1:Iz8AkXJf1qmxC3Oxoep8R1T36w8B92yU29PcBhHO5fk= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= +github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4 h1:iC9YFYKDGEy3n/FtqJnOkZsene9olVspKmkX5A2YBEo= +github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4/go.mod h1:sCavSAvdzOjul4cEqeVtvlSaSScfNsTQ+46HwlTL1hc= +github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.0/go.mod h1:5JHVmnHvGzR2wNdgaW1zDLQG8kOC4Uec8ubkMogW7OQ= +github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.4 h1:7Q2FEyqxeZeIkwYMwRC3uphxV4i7O2eV4ETe21d6lS4= +github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.4/go.mod h1:5JHVmnHvGzR2wNdgaW1zDLQG8kOC4Uec8ubkMogW7OQ= +github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 h1:NqugFkGxx1TXSh/pBcU00Y6bljgDPaFdh5MUSeJ7e50= +github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68/go.mod h1:6pb/Qy8c+lqua8cFpEy7g39NRRqOWc3rOwAy8m5Y2BY= +github.com/alibabacloud-go/dysmsapi-20180501/v2 v2.0.0 h1:5Y6ShlrRBQRvud6ldvwjkA84wt1logkqU6VDQ7vj6zM= +github.com/alibabacloud-go/dysmsapi-20180501/v2 v2.0.0/go.mod h1:/XnpFzAD8BwKHtA48Sdiv6aWcUE3QTbs/gFeHUgSmi0= +github.com/alibabacloud-go/endpoint-util v1.1.0 h1:r/4D3VSw888XGaeNpP994zDUaxdgTSHBbVfZlzf6b5Q= +github.com/alibabacloud-go/endpoint-util v1.1.0/go.mod h1:O5FuCALmCKs2Ff7JFJMudHs0I5EBgecXXxZRyswlEjE= +github.com/alibabacloud-go/openapi-util v0.0.11 h1:iYnqOPR5hyEEnNZmebGyRMkkEJRWUEjDiiaOHZ5aNhA= +github.com/alibabacloud-go/openapi-util v0.0.11/go.mod h1:sQuElr4ywwFRlCCberQwKRFhRzIyG4QTP/P4y1CJ6Ws= +github.com/alibabacloud-go/tea v1.1.0/go.mod h1:IkGyUSX4Ba1V+k4pCtJUc6jDpZLFph9QMy2VUPTwukg= +github.com/alibabacloud-go/tea v1.1.7/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4= +github.com/alibabacloud-go/tea v1.1.8/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4= +github.com/alibabacloud-go/tea v1.1.17/go.mod h1:nXxjm6CIFkBhwW4FQkNrolwbfon8Svy6cujmKFUq98A= +github.com/alibabacloud-go/tea v1.1.19/go.mod h1:nXxjm6CIFkBhwW4FQkNrolwbfon8Svy6cujmKFUq98A= +github.com/alibabacloud-go/tea v1.2.0 h1:UTe0AVhJTdSv0c2eIZN3dM2BgtXx4dLxd8yLG8Jw3lk= +github.com/alibabacloud-go/tea v1.2.0/go.mod h1:ojRksXLcgqz1usnR6nIkbVf3PtWzjb9ze3dkwqj5zcg= +github.com/alibabacloud-go/tea-utils v1.3.1 h1:iWQeRzRheqCMuiF3+XkfybB3kTgUXkXX+JMrqfLeB2I= +github.com/alibabacloud-go/tea-utils v1.3.1/go.mod h1:EI/o33aBfj3hETm4RLiAxF/ThQdSngxrpF8rKUDJjPE= +github.com/alibabacloud-go/tea-utils/v2 v2.0.0/go.mod h1:U5MTY10WwlquGPS34DOeomUGBB0gXbLueiq5Trwu0C4= +github.com/alibabacloud-go/tea-utils/v2 v2.0.2 h1:kNd2dtfNLGXHjZYE/kPGRCZ/AiZFlz4HUloO6lNpzJk= +github.com/alibabacloud-go/tea-utils/v2 v2.0.2/go.mod h1:sj1PbjPodAVTqGTA3olprfeeqqmwD0A5OQz94o9EuXQ= +github.com/alibabacloud-go/tea-xml v1.1.2 h1:oLxa7JUXm2EDFzMg+7oRsYc+kutgCVwm+bZlhhmvW5M= +github.com/alibabacloud-go/tea-xml v1.1.2/go.mod h1:Rq08vgCcCAjHyRi/M7xlHKUykZCEtyBy9+DPF6GgEu8= +github.com/aliyun/credentials-go v1.1.2 h1:qU1vwGIBb3UJ8BwunHDRFtAhS6jnQLnde/yk0+Ih2GY= +github.com/aliyun/credentials-go v1.1.2/go.mod h1:ozcZaMR5kLM7pwtCMEpVmQ242suV6qTJya2bDq4X1Tw= +github.com/allegro/bigcache v1.2.1 h1:hg1sY1raCwic3Vnsvje6TT7/pnZba83LeFck5NrFKSc= +github.com/allegro/bigcache v1.2.1/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= +github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= +github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= +github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= +github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= +github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= +github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= +github.com/census-instrumentation/opencensus-proto v0.4.1 h1:iKLQ0xPNFxR/2hzXZMrBo8f1j86j5WHzznCCQxV/b8g= +github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw= +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/clbanning/mxj/v2 v2.5.5 h1:oT81vUeEiQQ/DcHbzSytRngP6Ky9O+L+0Bw0zSJag9E= +github.com/clbanning/mxj/v2 v2.5.5/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/xds/go v0.0.0-20240318125728-8a4994d93e50 h1:DBmgJDC9dTfkVyGgipamEh2BpGYxScCH1TOF1LL1cXc= +github.com/cncf/xds/go v0.0.0-20240318125728-8a4994d93e50/go.mod h1:5e1+Vvlzido69INQaVO6d87Qn543Xr6nooe9Kz7oBFM= +github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4 h1:YcpmyvADGYw5LqMnHqSkyIELsHCGF6PkrmM31V8rF7o= +github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= +github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= +github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= +github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= +github.com/envoyproxy/go-control-plane v0.12.0 h1:4X+VP1GHd1Mhj6IB5mMeGbLCleqxjletLK6K0rbxyZI= +github.com/envoyproxy/go-control-plane v0.12.0/go.mod h1:ZBTaoJ23lqITozF0M6G4/IragXCQKCnYbmlmtHvwRG0= +github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU4zdyUgIUNhlgg0A= +github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZH4Blx/1gTIZ2UKVY1M+Yew= +github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ= +github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kratos/aegis v0.2.0 h1:dObzCDWn3XVjUkgxyBp6ZeWtx/do0DPZ7LY3yNSJLUQ= +github.com/go-kratos/aegis v0.2.0/go.mod h1:v0R2m73WgEEYB3XYu6aE2WcMwsZkJ/Rzuf5eVccm7bI= +github.com/go-kratos/kratos/v2 v2.7.1 h1:PNMUaWxS5ZGDp1EyID5ZosJb1OA/YiHnBxB0yUmocnc= +github.com/go-kratos/kratos/v2 v2.7.1/go.mod h1:CPn82O93OLHjtnbuyOKhAG5TkSvw+mFnL32c4lZFDwU= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= +github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= +github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/form/v4 v4.2.1 h1:HjdRDKO0fftVMU5epjPW2SOREcZ6/wLUzEobqUGJuPw= +github.com/go-playground/form/v4 v4.2.1/go.mod h1:q1a2BY+AQUUzhl6xA/6hBetay6dEIhMHjgvJiGo6K7U= +github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= +github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= +github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:9wScpmSP5A3Bk8V3XHWUcJmYTh+ZnlHVyc+A4oZYS3Y= +github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:56xuuqnHyryaerycW3BfssRdxQstACi0Epw/yC5E2xM= +github.com/go-xorm/xorm v0.7.9 h1:LZze6n1UvRmM5gpL9/U9Gucwqo6aWlFVlfcHKH10qA0= +github.com/go-xorm/xorm v0.7.9/go.mod h1:XiVxrMMIhFkwSkh96BW7PACl7UhLtx2iJIHMdmjh5sQ= +github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= +github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/subcommands v1.0.1/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/wire v0.5.0 h1:I7ELFeVBr3yfPIcc8+MWvrjk+3VjbcSzoXm3JVa+jD8= +github.com/google/wire v0.5.0/go.mod h1:ngWDr9Qvq3yZA10YrxfyGELY/AFWGVpy9c1LTRi1EoU= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 h1:l5lAOZEym3oK3SQ2HBHWsJUfbNBiTXJDeW2QDxw9AQ0= +github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= +github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4= +github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q= +github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= +github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= +github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/jackc/fake v0.0.0-20150926172116-812a484cc733/go.mod h1:WrMFNQdiFJ80sQsxDoMokWK1W5TQtxBFNpzWTD84ibQ= +github.com/jackc/pgx v3.6.0+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I= +github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= +github.com/klauspost/compress v1.16.6 h1:91SKEy4K37vkp255cJ8QesJhjyRO0hn9i9G0GoUwLsk= +github.com/klauspost/compress v1.16.6/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A= +github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o= +github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= +github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= +github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= +github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g= +github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= +github.com/redis/go-redis/v9 v9.3.0 h1:RiVDjmig62jIWp7Kk4XVLs0hzV6pI3PyTnnL0cnn0u0= +github.com/redis/go-redis/v9 v9.3.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= +github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= +github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24 h1:pntxY8Ary0t43dCZ5dqY4YTJCObLY1kIXl0uzMv+7DE= +github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/assertions v1.1.0 h1:MkTeG1DMwsrdH7QtLXy5W+fUxWq+vmb6cLmyJ7aRtF0= +github.com/smartystreets/assertions v1.1.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= +github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/streadway/amqp v1.1.0 h1:py12iX8XSyI7aN/3dUT8DFIDJazNJsVJdxNVEpnQTZM= +github.com/streadway/amqp v1.1.0/go.mod h1:WYSrTEYHOXHd0nwFeUXAe2G2hRnQT+deZJJf88uS9Bg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/tjfoc/gmsm v1.3.2 h1:7JVkAn5bvUJ7HtU08iW6UiD+UTmJTIToHCfeFzkcCxM= +github.com/tjfoc/gmsm v1.3.2/go.mod h1:HaUcFuY0auTiaHB9MHFGCPx5IaLhTUd2atbCFBQXn9w= +github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= +github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= +github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= +github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= +github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= +github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= +github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA= +github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.30/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs= +github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0= +go.mongodb.org/mongo-driver v1.12.0 h1:aPx33jmn/rQuJXPQLZQ8NtfPQG8CaqgLThFtqRb0PiE= +go.mongodb.org/mongo-driver v1.12.0/go.mod h1:AZkxhPnFJUoH7kZlFkVKucV20K387miPfm7oimrSmK0= +go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= +go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs= +go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY= +go.opentelemetry.io/otel/metric v1.19.0 h1:aTzpGtV0ar9wlV4Sna9sdJyII5jTVJEvKETPiOKwvpE= +go.opentelemetry.io/otel/metric v1.19.0/go.mod h1:L5rUsV9kM1IxCj1MmSdS+JQAcVm319EUrDVLrt7jqt8= +go.opentelemetry.io/otel/sdk v1.19.0 h1:6USY6zH+L8uMH8L3t1enZPR3WFEmSTADlqldyHtJi3o= +go.opentelemetry.io/otel/sdk v1.19.0/go.mod h1:NedEbbS4w3C6zElbLdPJKOpJQOrGUJ+GfzpjUvI0v1A= +go.opentelemetry.io/otel/trace v1.19.0 h1:DFVQmlVbfVeOuBRrwdtaehRrWiL1JoVs9CPIQ1Dzxpg= +go.opentelemetry.io/otel/trace v1.19.0/go.mod h1:mfaSyvGyEJEI0nyV2I4qhNQnbBOUUmYZpYojqMnX2vo= +go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/automaxprocs v1.5.1 h1:e1YG66Lrk73dn4qhg8WFSvhF0JuFQF0ERIp4rpuV8Qk= +go.uber.org/automaxprocs v1.5.1/go.mod h1:BF4eumQw0P9GtnuxxovUd06vwm1o18oMzFtK66vU6XU= +go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= +go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= +go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= +go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= +go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= +go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191219195013-becbf705a915/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= +golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= +golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= +golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200509044756-6aff5f38e54f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190404172233-64821d5d2107/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 h1:RFiFrvy37/mpSpdySBDrUdipW/dHwsRwh3J3+A9VgT4= +google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237/go.mod h1:Z5Iiy3jtmioajWHDGFk7CeugTyHtPvMHA4UTmUkyalE= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240617180043-68d350f18fd4 h1:Di6ANFilr+S60a4S61ZM00vLdw0IrQOSMS2/6mrnOU0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240617180043-68d350f18fd4/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= +google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= +google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/ini.v1 v1.56.0 h1:DPMeDvGTM54DXbPkVIZsp19fp/I2K7zwA/itHYHKo8Y= +gopkg.in/ini.v1 v1.56.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +xorm.io/builder v0.3.6 h1:ha28mQ2M+TFx96Hxo+iq6tQgnkC9IZkM6D8w9sKHHF8= +xorm.io/builder v0.3.6/go.mod h1:LEFAPISnRzG+zxaxj2vPicRwz67BdhFreKg8yv8/TgU= +xorm.io/core v0.7.2-0.20190928055935-90aeac8d08eb h1:msX3zG3BPl8Ti+LDzP33/9K7BzO/WqFXk610K1kYKfo= +xorm.io/core v0.7.2-0.20190928055935-90aeac8d08eb/go.mod h1:jJfd0UAEzZ4t87nbQYtVjmqpIODugN6PD2D9E+dJvdM= diff --git a/internal/biz/README.md b/internal/biz/README.md new file mode 100644 index 0000000..63215db --- /dev/null +++ b/internal/biz/README.md @@ -0,0 +1,16 @@ +# 一、Biz 模块功能 +### 功能块: 数字币(合约|现货|秒合约)、股票(美股|泰股|马股|印尼股|印度股|新加坡股|港股)、新股申购(美股|泰股|马股|印尼股|印度股|新加坡股|港股)、大宗交易(美股|泰股|马股|印尼股|印度股|新加坡股|港股)、期权(印度)) +``` + 1、自动监控服务功能 + 1>初始化代码列表 + 2>监控代码价格(行情|设置)缓存 + 3>监控挂单 + 4>监控持仓 + 2、调用服务功能(详细逻辑-->见相关功能设计文档) + 1>下单 + 2>止盈止损 + 3>撤单 + 4>平仓 + 5>一键平仓 + 3、相关调用文档(http://g.jd66.cc:3001/project/56/interface/api) +``` \ No newline at end of file diff --git a/internal/biz/backend.go b/internal/biz/backend.go new file mode 100644 index 0000000..506868d --- /dev/null +++ b/internal/biz/backend.go @@ -0,0 +1,70 @@ +package biz + +import ( + "context" + "github.com/go-kratos/kratos/v2/log" + "matchmaking-system/internal/pkg/flags" +) + +// UserOrder +// @Description: +type UserBackend struct { + ud UserBackendRepo + + log *log.Helper +} + +// UserBackendRepo +// @Description: +type UserBackendRepo interface { + // 检查用户(Token|UserID) + CheckToken(ctx context.Context) (int, error) + UpdateBotUsersByIsReal(ctx context.Context, userId int64) error +} + +// NewUserBackendRepo +// +// @Description: +// @param logger +// @return *UserOrder +func NewUserBackendRepo(uo UserBackendRepo, logger log.Logger) *UserBackend { + return &UserBackend{ud: uo, log: log.NewHelper(logger)} +} + +// GetUserIdByToken +// +// @Description: 通过token获取用户Id +// @receiver uo +// @param ctx +// @return int64 +// @return error +func (uo *UserBackend) GetUserIdByToken(ctx context.Context) (int64, bool, error) { + userId, err := uo.ud.CheckToken(ctx) + if err != nil { + return 0, false, flags.ErrTokenMessage + } + + return int64(userId), true, nil +} + +// SharePreTrade 新股申购交易下单-开盘服务(美股|印尼股|马股|泰股|印度股|新加坡股|港股|英股) +// +// @Description: +// @receiver uo +// @param ctx +// @param id +// @param code +// @param stock +// @return error +func (uo *UserBackend) UpdateBotUsersByIsReal(ctx context.Context) error { + userId, token, err := uo.GetUserIdByToken(ctx) + if userId == 0 || err != nil || !token { + return flags.ErrTokenMessage + } + + if err = uo.ud.UpdateBotUsersByIsReal(ctx, userId); err != nil { + return err + } + + return nil +} diff --git a/internal/biz/biz.go b/internal/biz/biz.go new file mode 100644 index 0000000..cc7aa44 --- /dev/null +++ b/internal/biz/biz.go @@ -0,0 +1,33 @@ +package biz + +import ( + "github.com/google/wire" + + "matchmaking-system/internal/data/sms" +) + +// ProviderSet is biz providers. +var ProviderSet = wire.NewSet( + sms.NewMsgSend, // user message + NewUserOrderRepo, // user order + NewUserSpotsOrderRepo, // user spots + NewUserSecondOrderRepo, // user second + NewUserContractOrderRepo, // user contract + NewUserForexOrderRepo, // user forex + NewUserShareUsOrderRepo, // user shareUs + NewUserShareThaOrderRepo, // user shareTha + NewUserShareIdnOrderRepo, // user shareIdn + NewUserShareInrOrderRepo, // user shareInr + NewUserShareMysOrderRepo, // user shareMys + NewUserShareSgdOrderRepo, // user shareSgd + NewUserShareGbxOrderRepo, // user shareGbx + NewUserOptionInrOrderRepo, // user optionInr + NewUserShareHkdOrderRepo, // user shareHkd + NewUserShareBlockOrderRepo, // user shareBlk + NewUserShareEurOrderRepo, // user shareEur + NewUserShareFurOrderRepo, // user shareFur + NewUserShareBrlOrderRepo, // user shareBrl + NewUserShareJpyOrderRepo, // user shareJpy + NewUserMoneyOrderRepo, // user shareMoney + NewUserBackendRepo, // user shareBackend +) diff --git a/internal/biz/forex.go b/internal/biz/forex.go new file mode 100644 index 0000000..f3accb0 --- /dev/null +++ b/internal/biz/forex.go @@ -0,0 +1,188 @@ +package biz + +import ( + "context" + "github.com/go-kratos/kratos/v2/log" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + + models "matchmaking-system/internal/pkg/model" +) + +// UserForexOrder +// @Description: +type UserForexOrder struct { + ud UserForexOrderRepo + + log *log.Helper +} + +// UserForexOrderRepo +// @Description: 操作订单(订单列表|下单|设置止损止盈|撤单|平仓|一键平仓) +type UserForexOrderRepo interface { + CheckToken(ctx context.Context) (int, error) + GetBotForexTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotForexTrade, int64, error) + CreateBotForexTrade(ctx context.Context, userId int64, order structure.ForexOrder) (string, error) + UpdateBotForexStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) + UpdateBotForexCancelByOrderId(ctx context.Context, orderId string) (bool, error) + UpdateBotForexClosingByOrderId(ctx context.Context, orderId string) (bool, error) + UpdateBotForexClosingAllByOrderId(ctx context.Context, userId int64) error +} + +// NewUserForexOrderRepo +// +// @Description: +// @param uo +// @param logger +// @return *UserSecondOrder +func NewUserForexOrderRepo(uo UserForexOrderRepo, logger log.Logger) *UserForexOrder { + return &UserForexOrder{ud: uo, log: log.NewHelper(logger)} +} + +// GetUserIdByToken +// +// @Description: 通过token获取用户Id +// @receiver uo +// @param ctx +// @return int64 +// @return error +func (uo *UserForexOrder) GetUserIdByToken(ctx context.Context) (int64, bool, error) { + userId, err := uo.ud.CheckToken(ctx) + if err != nil { + return 0, false, flags.ErrTokenMessage + } + + return int64(userId), true, nil +} + +// BotForexTradeList +// +// @Description: 订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param status +// @return []*models.BotForexTrade +// @return int64 +// @return error +func (uo *UserForexOrder) BotForexTradeList(ctx context.Context, pageSize, pageCount, status int64) ([]*models.BotForexTrade, int64, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if userId == 0 || err != nil || !token { + return nil, 0, flags.ErrTokenMessage + } + + contractList, totalCount, err := uo.ud.GetBotForexTradeList(ctx, pageSize, pageCount-1, userId, status) + if err != nil { + return nil, 0, err + } + + return contractList, totalCount, nil +} + +// ForexPlaceOrder +// +// @Description: 委托订单 +// @receiver uo +// @param ctx +// @param order +// @return string +// @return error +func (uo *UserForexOrder) ForexPlaceOrder(ctx context.Context, order structure.ForexOrder) (string, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.SetNull, flags.ErrTokenMessage + } + + orderId, err := uo.ud.CreateBotForexTrade(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + + return orderId, nil +} + +// ForexUpdatePlaceOrder +// +// @Description: 设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *UserForexOrder) ForexUpdatePlaceOrder(ctx context.Context, order structure.StopOrder) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + check, err := uo.ud.UpdateBotForexStopByOrderId(ctx, order) + if err != nil { + return false, err + } + + return check, nil +} + +// ForexCancel +// +// @Description: 撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserForexOrder) ForexCancel(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + check, err := uo.ud.UpdateBotForexCancelByOrderId(ctx, orderId) + if err != nil { + return false, err + } + + return check, nil +} + +// ForexPosition +// +// @Description: 平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserForexOrder) ForexPosition(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + check, err := uo.ud.UpdateBotForexClosingByOrderId(ctx, orderId) + if err != nil { + return false, err + } + + return check, nil +} + +// ForexAllPosition +// +// @Description: 一键平仓 +// @receiver uo +// @param ctx +// @return error +func (uo *UserForexOrder) ForexAllPosition(ctx context.Context) error { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.ErrTokenMessage + } + + if err = uo.ud.UpdateBotForexClosingAllByOrderId(ctx, userId); err != nil { + return err + } + + return nil +} diff --git a/internal/biz/money.go b/internal/biz/money.go new file mode 100644 index 0000000..bd24df4 --- /dev/null +++ b/internal/biz/money.go @@ -0,0 +1,210 @@ +package biz + +import ( + "context" + "github.com/go-kratos/kratos/v2/log" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + models "matchmaking-system/internal/pkg/model" +) + +// UserMoneyOrder +// @Description: +type UserMoneyOrder struct { + ud UserMoneyOrderRepo + + log *log.Helper +} + +// UserMoneyOrderRepo +// @Description: 操作订单(订单列表|下单|设置止损止盈|撤单|平仓|一键平仓) +type UserMoneyOrderRepo interface { + CheckToken(ctx context.Context) (int, error) + GetBotMoneyTradeList(ctx context.Context, pageSize, pageCount, userId, status, marketType int64) ([]*models.BotMoneyTrade, int64, error) + CreateBotMoneyTrade(ctx context.Context, userId int64, order structure.MoneyOrder) (string, error) + UpdateBotMoneyStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) + UpdateBotMoneyCancelByOrderId(ctx context.Context, orderId string) (bool, error) + UpdateBotMoneyClosingByOrderId(ctx context.Context, orderId string) (bool, error) + UpdateBotMoneyClosingAllByOrderId(ctx context.Context, userId int64) error + MoneyCreateOneClickRedemption(ctx context.Context, userId int64, order structure.MoneyOrder) (string, error) +} + +// NewUserMoneyOrderRepo +// +// @Description: +// @param uo +// @param logger +// @return *UserSecondOrder +func NewUserMoneyOrderRepo(uo UserMoneyOrderRepo, logger log.Logger) *UserMoneyOrder { + return &UserMoneyOrder{ud: uo, log: log.NewHelper(logger)} +} + +// GetUserIdByToken +// +// @Description: 通过token获取用户Id +// @receiver uo +// @param ctx +// @return int64 +// @return error +func (uo *UserMoneyOrder) GetUserIdByToken(ctx context.Context) (int64, bool, error) { + userId, err := uo.ud.CheckToken(ctx) + if err != nil { + return 0, false, flags.ErrTokenMessage + } + + return int64(userId), true, nil +} + +// BotMoneyTradeList +// +// @Description: 订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param status +// @return []*models.BotMoneyTrade +// @return int64 +// @return error +func (uo *UserMoneyOrder) BotMoneyTradeList(ctx context.Context, pageSize, pageCount, status, marketType int64) ([]*models.BotMoneyTrade, int64, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if userId == 0 || err != nil || !token { + return nil, 0, flags.ErrTokenMessage + } + + contractList, totalCount, err := uo.ud.GetBotMoneyTradeList(ctx, pageSize, pageCount-1, userId, status, marketType) + if err != nil { + return nil, 0, err + } + + return contractList, totalCount, nil +} + +// MoneyPlaceOrder +// +// @Description: 委托订单 +// @receiver uo +// @param ctx +// @param order +// @return string +// @return error +func (uo *UserMoneyOrder) MoneyPlaceOrder(ctx context.Context, order structure.MoneyOrder) (string, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.SetNull, flags.ErrTokenMessage + } + + orderId, err := uo.ud.CreateBotMoneyTrade(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + + return orderId, nil +} + +// MoneyUpdatePlaceOrder +// +// @Description: 设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *UserMoneyOrder) MoneyUpdatePlaceOrder(ctx context.Context, order structure.StopOrder) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + check, err := uo.ud.UpdateBotMoneyStopByOrderId(ctx, order) + if err != nil { + return false, err + } + + return check, nil +} + +// MoneyCancel +// +// @Description: 撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserMoneyOrder) MoneyCancel(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + check, err := uo.ud.UpdateBotMoneyCancelByOrderId(ctx, orderId) + if err != nil { + return false, err + } + + return check, nil +} + +// MoneyPosition +// +// @Description: 平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserMoneyOrder) MoneyPosition(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + check, err := uo.ud.UpdateBotMoneyClosingByOrderId(ctx, orderId) + if err != nil { + return false, err + } + + return check, nil +} + +// MoneyAllPosition +// +// @Description: 一键平仓 +// @receiver uo +// @param ctx +// @return error +func (uo *UserMoneyOrder) MoneyAllPosition(ctx context.Context) error { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.ErrTokenMessage + } + + if err = uo.ud.UpdateBotMoneyClosingAllByOrderId(ctx, userId); err != nil { + return err + } + + return nil +} + +// MoneyOneClickRedemption +// +// @Description: 一键兑换 +// @receiver uo +// @param ctx +// @param order +// @return string +// @return error +func (uo *UserMoneyOrder) MoneyOneClickRedemption(ctx context.Context, order structure.MoneyOrder) (string, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.SetNull, flags.ErrTokenMessage + } + + orderId, err := uo.ud.MoneyCreateOneClickRedemption(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + + return orderId, nil +} diff --git a/internal/biz/option_inr.go b/internal/biz/option_inr.go new file mode 100644 index 0000000..aa31ddf --- /dev/null +++ b/internal/biz/option_inr.go @@ -0,0 +1,211 @@ +package biz + +import ( + "context" + + "github.com/go-kratos/kratos/v2/log" + + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + + models "matchmaking-system/internal/pkg/model" +) + +// UserOptionInrOrder +// @Description: +type UserOptionInrOrder struct { + ud UserOptionInrOrderRepo + + log *log.Helper +} + +// UserOptionInrOrderRepo +// @Description: 订单操作(订单列表|下单|设置止盈止损|撤单|平仓|一键平仓) +type UserOptionInrOrderRepo interface { + CheckToken(ctx context.Context) (int, error) + GetBotUserIsRealByUserId(ctx context.Context, userId int) bool + GetBotStockOptionInrTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockOptionInrTrade, int64, error) + PlacingStockOptionInrOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) + UpdateBotStockOptionInrCancelByOrderId(ctx context.Context, orderId string) (bool, error) + UpdateBotStockOptionInrStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) + UpdateBotStockOptionInrClosingByOrderId(ctx context.Context, orderId string) (bool, error) + UpdateBotStockOptionInrAllClosingByOrderId(ctx context.Context, userId int64) error +} + +// NewUserOptionInrOrderRepo +// +// @Description: +// @param uo +// @param logger +// @return *UserOptionInrOrderRepo +func NewUserOptionInrOrderRepo(uo UserOptionInrOrderRepo, logger log.Logger) *UserOptionInrOrder { + return &UserOptionInrOrder{ud: uo, log: log.NewHelper(logger)} +} + +// GetUserIdByToken +// +// @Description: 通过token获取用户Id +// @receiver uo +// @param ctx +// @return int64 +// @return error +func (uo *UserOptionInrOrder) GetUserIdByToken(ctx context.Context) (int64, bool, error) { + userId, err := uo.ud.CheckToken(ctx) + if err != nil { + return 0, false, flags.ErrTokenMessage + } + + return int64(userId), true, nil +} + +// BotStockOptionInrTradeList +// +// @Description: 列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param status +// @return []*models.BotStockIdnTrade +// @return int64 +// @return error +func (uo *UserOptionInrOrder) BotStockOptionInrTradeList(ctx context.Context, pageSize, pageCount, status int64) ([]*models.BotStockOptionInrTrade, int64, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return nil, 0, flags.ErrTokenMessage + } + + stockList, totalCount, err := uo.ud.GetBotStockOptionInrTradeList(ctx, pageSize, pageCount-1, userId, status) + if err != nil { + return nil, 0, err + } + + return stockList, totalCount, nil +} + +// OptionInrPlaceOrder +// +// @Description: 下单 +// @receiver uo +// @param ctx +// @param order +// @return string +// @return error +func (uo *UserOptionInrOrder) OptionInrPlaceOrder(ctx context.Context, order structure.ShareOrder) (string, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.SetNull, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.SetNull, flags.ErrIsReal + } + + orderId, err := uo.ud.PlacingStockOptionInrOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + + return orderId, nil +} + +// OptionInrUpdateOrder +// +// @Description: 止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *UserOptionInrOrder) OptionInrUpdateOrder(ctx context.Context, order structure.StopOrder) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockOptionInrStopByOrderId(ctx, order) + if err != nil { + return false, err + } + + return check, nil +} + +// OptionInrCancel +// +// @Description: 撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserOptionInrOrder) OptionInrCancel(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockOptionInrCancelByOrderId(ctx, orderId) + if err != nil { + return false, err + } + + return check, nil +} + +// OptionInrPosition +// +// @Description: 平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserOptionInrOrder) OptionInrPosition(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockOptionInrClosingByOrderId(ctx, orderId) + if err != nil { + return false, err + } + + return check, nil +} + +// OptionInrAllPosition +// +// @Description: 一键平仓 +// @receiver uo +// @param ctx +// @return error +func (uo *UserOptionInrOrder) OptionInrAllPosition(ctx context.Context) error { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.ErrIsReal + } + + if err = uo.ud.UpdateBotStockOptionInrAllClosingByOrderId(ctx, userId); err != nil { + return err + } + + return nil +} diff --git a/internal/biz/order.go b/internal/biz/order.go new file mode 100644 index 0000000..3a21bbf --- /dev/null +++ b/internal/biz/order.go @@ -0,0 +1,1387 @@ +package biz + +import ( + "context" + "github.com/go-kratos/kratos/v2/log" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "strconv" + "strings" + + models "matchmaking-system/internal/pkg/model" +) + +// UserOrder +// @Description: +type UserOrder struct { + ud UserOrderRepo + + log *log.Helper +} + +// UserOrderRepo +// @Description: +type UserOrderRepo interface { + // 检查用户(Token|UserID) + CheckToken(ctx context.Context) (int, error) + // 新股申购交易下单-开盘服务(美股|泰股|马股|印尼股|印度股|新加坡股|港股|英股|法股|德股|巴西股) + GetBotUserUsPreStockOrder(ctx context.Context, id string) ([]models.BotUserUsPreStockOrder, error) + GetBotUserThaPreStockOrder(ctx context.Context, id string) ([]models.BotUserThaPreStockOrder, error) + GetBotUserMysPreStockOrder(ctx context.Context, id string) ([]models.BotUserMysPreStockOrder, error) + GetBotUserIdnPreStockOrder(ctx context.Context, id string) ([]models.BotUserIdnPreStockOrder, error) + GetBotUserInPreStockOrder(ctx context.Context, id string) ([]models.BotUserInPreStockOrder, error) + GetBotUserSgdPreStockOrder(ctx context.Context, id string) ([]models.BotUserSgdPreStockOrder, error) + GetBotUserHkdPreStockOrder(ctx context.Context, id string) ([]models.BotUserHkdPreStockOrder, error) + GetBotUserGbxPreStockOrder(ctx context.Context, id string) ([]models.BotUserGbxPreStockOrder, error) + GetBotUserEurPreStockOrder(ctx context.Context, id string) ([]models.BotUserEurPreStockOrder, error) + GetBotUserFurPreStockOrder(ctx context.Context, id string) ([]models.BotUserFurPreStockOrder, error) + GetBotUserBrlPreStockOrder(ctx context.Context, id string) ([]models.BotUserBrlPreStockOrder, error) + GetBotUserJpyPreStockOrder(ctx context.Context, id string) ([]models.BotUserJpPreStockOrder, error) + // 新股申购交易下单-开盘服务OrderNo(美股|泰股|马股|印尼股|印度股|新加坡股|港股|英股|法股|德股|巴西股) + GetBotUserUsPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserUsPreStockOrder, error) + GetBotUserThaPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserThaPreStockOrder, error) + GetBotUserMysPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserMysPreStockOrder, error) + GetBotUserIdnPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserIdnPreStockOrder, error) + GetBotUserInPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserInPreStockOrder, error) + GetBotUserSgdPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserSgdPreStockOrder, error) + GetBotUserHkdPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserHkdPreStockOrder, error) + GetBotUserGbxPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserGbxPreStockOrder, error) + GetBotUserEurPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserEurPreStockOrder, error) + GetBotUserFurPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserFurPreStockOrder, error) + GetBotUserBrlPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserBrlPreStockOrder, error) + GetBotUserJpyPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserJpPreStockOrder, error) + // 股票赠送交易下单-开盘服务(美股|泰股|马股|印尼股|印度股|新加坡股|港股|英股|法股|德股|巴西股) + GetBotUserUsGiveStockOrder(ctx context.Context, id string) ([]models.BotUserUsGiveStockOrder, error) + GetBotUserThaGiveStockOrders(ctx context.Context, id string) ([]models.BotUserThaGiveStockOrder, error) + GetBotUserMysGiveStockOrders(ctx context.Context, id string) ([]models.BotUserMysGiveStockOrder, error) + GetBotUserIdnGiveStockOrders(ctx context.Context, id string) ([]models.BotUserIdnGiveStockOrder, error) + GetBotUserInGiveStockOrders(ctx context.Context, id string) ([]models.BotUserInGiveStockOrder, error) + GetBotUserSgdGiveStockOrders(ctx context.Context, id string) ([]models.BotUserSgdGiveStockOrder, error) + GetBotUserHkdGiveStockOrders(ctx context.Context, id string) ([]models.BotUserHkdGiveStockOrder, error) + GetBotUserGbxGiveStockOrders(ctx context.Context, id string) ([]models.BotUserGbxGiveStockOrder, error) + GetBotUserEurGiveStockOrders(ctx context.Context, id string) ([]models.BotUserEurGiveStockOrder, error) + GetBotUserFurGiveStockOrders(ctx context.Context, id string) ([]models.BotUserFurGiveStockOrder, error) + GetBotUserBrlGiveStockOrders(ctx context.Context, id string) ([]models.BotUserBrlGiveStockOrder, error) + GetBotUserJpyGiveStockOrders(ctx context.Context, id string) ([]models.BotUserJpGiveStockOrder, error) + // 更新全局股票代码:[交易所名称:股票代码(BSE:AHINDCOPPER)](美股|泰股|马股|印尼股|印度股|新加坡股|港股|英股|法股|德股|巴西股) + GetBotStockList(ctx context.Context) ([]models.BotStockList, error) + GetBotStockMysList(ctx context.Context) ([]models.BotStockMysList, error) + GetBotStockThaList(ctx context.Context) ([]models.BotStockThaList, error) + GetBotStockIdnList(ctx context.Context) ([]models.BotStockIdnList, error) + GetBotStockInList(ctx context.Context) ([]models.BotStockInList, error) + GetBotStockSgdList(ctx context.Context) ([]models.BotStockSgdList, error) + GetBotStockHkdList(ctx context.Context) ([]models.BotStockHkdList, error) + GetBotStockGbxList(ctx context.Context) ([]models.BotStockGbxList, error) + GetBotStockEurList(ctx context.Context) ([]models.BotStockEurList, error) + GetBotStockFurList(ctx context.Context) ([]models.BotStockFurList, error) + GetBotStockBrlList(ctx context.Context) ([]models.BotStockBrlList, error) + GetBotStockJpyList(ctx context.Context) ([]models.BotStockJpList, error) + // 新股申购交易下单-创建持仓订单(美股|泰股|马股|印尼股|印度股|新加坡股|港股|英股|法股|德股|巴西股) + CreateBotUserUsPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error + CreateBotUserThaPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error + CreateBotUserMysPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error + CreateBotUserIdnPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error + CreateBotUserInPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error + CreateBotUserSgdPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error + CreateBotUserHkdPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error + CreateBotUserGbxPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error + CreateBotUserEurPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error + CreateBotUserFurPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error + CreateBotUserBrlPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error + CreateBotUserJpyPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error + // 新股申购-更新股票stockId(美股|泰股|马股|印尼股|印度股|新加坡股|港股|英股|法股|德股|巴西股) + UpdateShareUsTradeStockId(ctx context.Context, code, codeOld string) error + UpdateShareThaTradeStockId(ctx context.Context, code, codeOld string) error + UpdateShareMysTradeStockId(ctx context.Context, code, codeOld string) error + UpdateShareIdnTradeStockId(ctx context.Context, code, codeOld string) error + UpdateShareInTradeStockId(ctx context.Context, code, codeOld string) error + UpdateShareSgdTradeStockId(ctx context.Context, code, codeOld string) error + UpdateShareHkdTradeStockId(ctx context.Context, code, codeOld string) error + UpdateShareGbxTradeStockId(ctx context.Context, code, codeOld string) error + UpdateShareEurTradeStockId(ctx context.Context, code, codeOld string) error + UpdateShareFurTradeStockId(ctx context.Context, code, codeOld string) error + UpdateShareBrlTradeStockId(ctx context.Context, code, codeOld string) error + UpdateShareJpyTradeStockId(ctx context.Context, code, codeOld string) error +} + +// NewUserOrderRepo +// +// @Description: +// @param logger +// @return *UserOrder +func NewUserOrderRepo(uo UserOrderRepo, logger log.Logger) *UserOrder { + return &UserOrder{ud: uo, log: log.NewHelper(logger)} +} + +// GetUserIdByToken +// +// @Description: 通过token获取用户Id +// @receiver uo +// @param ctx +// @return int64 +// @return error +func (uo *UserOrder) GetUserIdByToken(ctx context.Context) (int64, bool, error) { + userId, err := uo.ud.CheckToken(ctx) + if err != nil { + return 0, false, flags.ErrTokenMessage + } + + return int64(userId), true, nil +} + +// SharePreTrade 新股申购交易下单-开盘服务(美股|印尼股|马股|泰股|印度股|新加坡股|港股|英股) +// +// @Description: +// @receiver uo +// @param ctx +// @param id +// @param code +// @param stock +// @return error +func (uo *UserOrder) SharePreTrade(ctx context.Context, id, code string, stock int32) error { + switch stock { + case flags.ShareUsMarketType: // 美股市场 + return uo.ShareUsMarket(ctx, id, code) + case flags.ShareThaMarketType: // 泰股市场 + return uo.ShareThaMarket(ctx, id, code) + case flags.ShareMysMarketType: // 马股市场 + return uo.ShareMysMarket(ctx, id, code) + case flags.ShareIdnMarketType: // 印尼市场 + return uo.ShareIdnMarket(ctx, id, code) + case flags.ShareInrMarketType: // 印度股市场 + return uo.ShareInrMarket(ctx, id, code) + case flags.ShareSgdMarketType: // 新加坡股市场 + return uo.ShareSgdMarket(ctx, id, code) + case flags.ShareHkdMarketType: // 港股市场 + return uo.ShareHkdMarket(ctx, id, code) + case flags.ShareGbxMarketType: // 英股市场 + return uo.ShareGbxMarket(ctx, id, code) + case flags.ShareEurMarketType: // 德股市场 + return uo.ShareEurMarket(ctx, id, code) + case flags.ShareFurMarketType: // 法股市场 + return uo.ShareFurMarket(ctx, id, code) + case flags.ShareBrlMarketType: // 巴西股市场 + return uo.ShareBrlMarket(ctx, id, code) + case flags.ShareJpyMarketType: // 日本股市场 + return uo.ShareJpyMarket(ctx, id, code) + default: + return flags.ErrOrderTow + } +} + +// SharePreTradeByOrderOn +// +// @Description: 新股申购交易下单-开盘服务(订单号)(美股|印尼股|马股|泰股|印度股|新加坡股|港股|英股) +// @receiver uo +// @param ctx +// @param id +// @param code +// @param stock +// @return error +func (uo *UserOrder) SharePreTradeByOrderOn(ctx context.Context, id, code string, stock int32) error { + switch stock { + case flags.ShareUsMarketType: // 美股市场 + return uo.ShareUsByOrderNoMarket(ctx, id, code) + case flags.ShareThaMarketType: // 泰股市场 + return uo.ShareThaOrderNoMarket(ctx, id, code) + case flags.ShareMysMarketType: // 马股市场 + return uo.ShareMysOrderNoMarket(ctx, id, code) + case flags.ShareIdnMarketType: // 印尼市场 + return uo.ShareIdnOrderNoMarket(ctx, id, code) + case flags.ShareInrMarketType: // 印度股市场 + return uo.ShareInrOrderNoMarket(ctx, id, code) + case flags.ShareSgdMarketType: // 新加坡股市场 + return uo.ShareSgdOrderNoMarket(ctx, id, code) + case flags.ShareHkdMarketType: // 港股市场 + return uo.ShareHkdOrderNoMarket(ctx, id, code) + case flags.ShareGbxMarketType: // 英股市场 + return uo.ShareGbxOrderNoMarket(ctx, id, code) + case flags.ShareEurMarketType: // 德股市场 + return uo.ShareEurOrderNoMarket(ctx, id, code) + case flags.ShareFurMarketType: // 法股市场 + return uo.ShareFurOrderNoMarket(ctx, id, code) + case flags.ShareBrlMarketType: // 巴西股市场 + return uo.ShareBrlOrderNoMarket(ctx, id, code) + case flags.ShareJpyMarketType: // 日本股市场 + return uo.ShareJpyOrderNoMarket(ctx, id, code) + default: + return flags.ErrOrderTow + } +} + +// UpdateShareTradeStockId +// +// @Description: 更新-新股申购股票stockId +// @receiver uo +// @param ctx +// @param code 新code +// @param codeOld 旧code标识 +// @param stock 市场标识 +// @return error +func (uo *UserOrder) UpdateShareTradeStockId(ctx context.Context, code, codeOld string, stock int64) error { + switch stock { + case flags.ShareUsMarketType: // 美股市场 + return uo.ud.UpdateShareUsTradeStockId(ctx, code, codeOld) + case flags.ShareThaMarketType: // 泰股市场 + return uo.ud.UpdateShareThaTradeStockId(ctx, code, codeOld) + case flags.ShareMysMarketType: // 马股市场 + return uo.ud.UpdateShareMysTradeStockId(ctx, code, codeOld) + case flags.ShareIdnMarketType: // 印尼市场 + return uo.ud.UpdateShareIdnTradeStockId(ctx, code, codeOld) + case flags.ShareInrMarketType: // 印度股市场 + return uo.ud.UpdateShareInTradeStockId(ctx, code, codeOld) + case flags.ShareSgdMarketType: // 新加坡股市场 + return uo.ud.UpdateShareSgdTradeStockId(ctx, code, codeOld) + case flags.ShareHkdMarketType: // 港股市场 + return uo.ud.UpdateShareHkdTradeStockId(ctx, code, codeOld) + case flags.ShareGbxMarketType: // 英股市场 + return uo.ud.UpdateShareGbxTradeStockId(ctx, code, codeOld) + case flags.ShareEurMarketType: // 德股市场 + return uo.ud.UpdateShareEurTradeStockId(ctx, code, codeOld) + case flags.ShareFurMarketType: // 法股市场 + return uo.ud.UpdateShareFurTradeStockId(ctx, code, codeOld) + case flags.ShareBrlMarketType: // 巴西股市场 + return uo.ud.UpdateShareBrlTradeStockId(ctx, code, codeOld) + case flags.ShareJpyMarketType: // 日本股市场 + return uo.ud.UpdateShareJpyTradeStockId(ctx, code, codeOld) + default: + return flags.ErrOrderTow + } +} + +// ShareGiveaways +// +// @Description: 赠送股票生成持仓订单 +// @receiver uo +// @param ctx +// @param id +// @param code +// @param stock +// @return error +func (uo *UserOrder) ShareGiveaways(ctx context.Context, id, code string, stock int32) error { + switch stock { + case flags.ShareUsMarketType: // 美股市场 + return uo.ShareUsMarketGiveaways(ctx, id, code) + case flags.ShareThaMarketType: // 泰股市场 + return uo.ShareThaMarketGiveaways(ctx, id, code) + case flags.ShareMysMarketType: // 马股市场 + return uo.ShareMysMarketGiveaways(ctx, id, code) + case flags.ShareIdnMarketType: // 印尼市场 + return uo.ShareIdnMarketGiveaways(ctx, id, code) + case flags.ShareInrMarketType: // 印度股市场 + return uo.ShareInrMarketGiveaways(ctx, id, code) + case flags.ShareSgdMarketType: // 新加坡股市场 + return uo.ShareSgdMarketGiveaways(ctx, id, code) + case flags.ShareHkdMarketType: // 港股市场 + return uo.ShareHkdMarketGiveaways(ctx, id, code) + case flags.ShareGbxMarketType: // 英股市场 + return uo.ShareGbxMarketGiveaways(ctx, id, code) + case flags.ShareEurMarketType: // 德股市场 + return uo.ShareEurMarketGiveaways(ctx, id, code) + case flags.ShareFurMarketType: // 法股市场 + return uo.ShareFurMarketGiveaways(ctx, id, code) + case flags.ShareBrlMarketType: // 巴西股市场 + return uo.ShareBrlMarketGiveaways(ctx, id, code) + case flags.ShareJpyMarketType: // 日本股市场 + return uo.ShareJpyMarketGiveaways(ctx, id, code) + default: + return flags.ErrOrderTow + } +} + +// UpdateShareTradeStockIdByList +// +// @Description: 更新-全局股票订单StockId标识 +// @receiver uo +// @param ctx +// @return error +func (uo *UserOrder) UpdateShareTradeStockIdByList(ctx context.Context) error { + // 美股StockId更新 + shareUs, _ := uo.ud.GetBotStockList(ctx) + for _, value := range shareUs { + code := value.StockCode + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + _ = uo.ud.UpdateShareUsTradeStockId(ctx, code, codeOld) + } + } + + // 泰股StockId更新 + shareTha, _ := uo.ud.GetBotStockThaList(ctx) + for _, value := range shareTha { + code := value.StockCode + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + _ = uo.ud.UpdateShareThaTradeStockId(ctx, code, codeOld) + } + } + + // 马股StockId更新 + shareMys, _ := uo.ud.GetBotStockMysList(ctx) + for _, value := range shareMys { + code := value.StockCode + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + _ = uo.ud.UpdateShareMysTradeStockId(ctx, code, codeOld) + } + } + + // 印尼股StockId更新 + shareIdn, _ := uo.ud.GetBotStockIdnList(ctx) + for _, value := range shareIdn { + code := value.StockCode + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + _ = uo.ud.UpdateShareIdnTradeStockId(ctx, code, codeOld) + } + } + + // 印度股StockId更新 + shareIn, _ := uo.ud.GetBotStockInList(ctx) + for _, value := range shareIn { + code := value.StockCode + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + _ = uo.ud.UpdateShareInTradeStockId(ctx, code, codeOld) + } + } + + // 新加坡股StockId更新 + shareSgd, _ := uo.ud.GetBotStockSgdList(ctx) + for _, value := range shareSgd { + code := value.StockCode + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + _ = uo.ud.UpdateShareSgdTradeStockId(ctx, code, codeOld) + } + } + + // 港股StockId更新 + shareHkd, _ := uo.ud.GetBotStockHkdList(ctx) + for _, value := range shareHkd { + code := value.StockCode + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + _ = uo.ud.UpdateShareHkdTradeStockId(ctx, code, codeOld) + } + } + + // 英股StockId更新 + shareGbx, _ := uo.ud.GetBotStockGbxList(ctx) + for _, value := range shareGbx { + code := value.StockCode + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + _ = uo.ud.UpdateShareGbxTradeStockId(ctx, code, codeOld) + } + } + + // 法股StockId更新 + shareFur, _ := uo.ud.GetBotStockFurList(ctx) + for _, value := range shareFur { + code := value.StockCode + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + _ = uo.ud.UpdateShareFurTradeStockId(ctx, code, codeOld) + } + } + + // 德股StockId更新 + shareEur, _ := uo.ud.GetBotStockEurList(ctx) + for _, value := range shareEur { + code := value.StockCode + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + _ = uo.ud.UpdateShareEurTradeStockId(ctx, code, codeOld) + } + } + + return nil +} + +// ShareUsMarket +// +// @Description: 美股市场 +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareUsMarket(ctx context.Context, id, code string) error { + usOrder, err := uo.ud.GetBotUserUsPreStockOrder(ctx, id) + if err != nil || usOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range usOrder { + if value.GetNum <= 0 { + applogger.Error("%v SharePreTrade.GetBotUserUsPreStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserUsPreStockOrder(ctx, code, order) +} + +// ShareUsByOrderNoMarket +// +// @Description: 美股市场-->OrderNo +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareUsByOrderNoMarket(ctx context.Context, id, code string) error { + orderNoArray := strings.Split(id, ",") + usOrder, err := uo.ud.GetBotUserUsPreStockOrderByOrderNo(ctx, orderNoArray) + if err != nil || usOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range usOrder { + if value.GetNum <= 0 { + applogger.Error("%v SharePreTrade.GetBotUserUsPreStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserUsPreStockOrder(ctx, code, order) +} + +// ShareUsMarketGiveaways +// +// @Description: 美股市场赠送 +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareUsMarketGiveaways(ctx context.Context, id, code string) error { + usOrder, err := uo.ud.GetBotUserUsGiveStockOrder(ctx, id) + if err != nil || usOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range usOrder { + if value.Num <= 0 { + applogger.Error("%v ShareGiveaways.GetBotUserUsGiveStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, flags.SetZero, value.Num, value.UserId)) + } + + return uo.ud.CreateBotUserUsPreStockOrder(ctx, code, order) +} + +// ShareThaMarket +// +// @Description: 泰股市场 +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareThaMarket(ctx context.Context, id, code string) error { + thaOrder, err := uo.ud.GetBotUserThaPreStockOrder(ctx, id) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.GetNum <= 0 { + applogger.Error("%v SharePreTrade.GetBotUserThaPreStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserThaPreStockOrder(ctx, code, order) +} + +// ShareThaOrderNoMarket +// +// @Description: 泰股市场-->OrderNo +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareThaOrderNoMarket(ctx context.Context, id, code string) error { + orderNoArray := strings.Split(id, ",") + thaOrder, err := uo.ud.GetBotUserThaPreStockOrderByOrderNo(ctx, orderNoArray) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.GetNum <= 0 { + applogger.Error("%v SharePreTrade.GetBotUserThaPreStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserThaPreStockOrder(ctx, code, order) +} + +// ShareThaMarketGiveaways +// +// @Description: 泰股市场赠送 +// @receiver uo +// @param ctx +// @param id +// @param +func (uo *UserOrder) ShareThaMarketGiveaways(ctx context.Context, id, code string) error { + thaOrder, err := uo.ud.GetBotUserThaGiveStockOrders(ctx, id) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.Num <= 0 { + applogger.Error("%v ShareGiveaways.GetBotUserThaGiveStockOrders:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, flags.SetZero, value.Num, value.UserId)) + } + + return uo.ud.CreateBotUserThaPreStockOrder(ctx, code, order) +} + +// ShareJpyMarket +// +// @Description: 日股市场 +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareJpyMarket(ctx context.Context, id, code string) error { + thaOrder, err := uo.ud.GetBotUserJpyPreStockOrder(ctx, id) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.GetNum <= 0 { + applogger.Error("%v SharePreTrade.GetBotUserJpyPreStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserJpyPreStockOrder(ctx, code, order) +} + +// ShareJpyOrderNoMarket +// +// @Description: 日股市场-->OrderNo +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareJpyOrderNoMarket(ctx context.Context, id, code string) error { + orderNoArray := strings.Split(id, ",") + thaOrder, err := uo.ud.GetBotUserJpyPreStockOrderByOrderNo(ctx, orderNoArray) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.GetNum <= 0 { + applogger.Error("%v SharePreTrade.GetBotUserJpyPreStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserJpyPreStockOrder(ctx, code, order) +} + +// ShareJpyMarketGiveaways +// +// @Description: 日股市场赠送 +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareJpyMarketGiveaways(ctx context.Context, id, code string) error { + thaOrder, err := uo.ud.GetBotUserJpyGiveStockOrders(ctx, id) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.Num <= 0 { + applogger.Error("%v ShareGiveaways.GetBotUserJpyGiveStockOrders:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, flags.SetZero, value.Num, value.UserId)) + } + + return uo.ud.CreateBotUserJpyPreStockOrder(ctx, code, order) +} + +// ShareBrlMarket +// +// @Description: 巴西股市场 +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareBrlMarket(ctx context.Context, id, code string) error { + thaOrder, err := uo.ud.GetBotUserBrlPreStockOrder(ctx, id) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.GetNum <= 0 { + applogger.Error("%v SharePreTrade.GetBotUserBrlPreStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserBrlPreStockOrder(ctx, code, order) +} + +// ShareBrlOrderNoMarket +// +// @Description: 巴西股市场-->OrderNo +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareBrlOrderNoMarket(ctx context.Context, id, code string) error { + orderNoArray := strings.Split(id, ",") + thaOrder, err := uo.ud.GetBotUserBrlPreStockOrderByOrderNo(ctx, orderNoArray) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.GetNum <= 0 { + applogger.Error("%v SharePreTrade.GetBotUserBrlPreStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserBrlPreStockOrder(ctx, code, order) +} + +// ShareBrlMarketGiveaways +// +// @Description: 巴西股市场赠送 +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareBrlMarketGiveaways(ctx context.Context, id, code string) error { + thaOrder, err := uo.ud.GetBotUserBrlGiveStockOrders(ctx, id) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.Num <= 0 { + applogger.Error("%v ShareGiveaways.GetBotUserBrlGiveStockOrders:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, flags.SetZero, value.Num, value.UserId)) + } + + return uo.ud.CreateBotUserBrlPreStockOrder(ctx, code, order) +} + +// ShareMysMarket +// +// @Description: 马股市场 +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareMysMarket(ctx context.Context, id, code string) error { + mysOrder, err := uo.ud.GetBotUserMysPreStockOrder(ctx, id) + if err != nil || mysOrder == nil { + return err + + } + var order []structure.ShareOrder + for _, value := range mysOrder { + if value.GetNum <= 0 { + applogger.Error("%v SharePreTrade.GetBotUserMysPreStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserMysPreStockOrder(ctx, code, order) +} + +// ShareMysOrderNoMarket +// +// @Description: 马股市场-->OrderNo +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareMysOrderNoMarket(ctx context.Context, id, code string) error { + orderNoArray := strings.Split(id, ",") + mysOrder, err := uo.ud.GetBotUserMysPreStockOrderByOrderNo(ctx, orderNoArray) + if err != nil || mysOrder == nil { + return err + + } + var order []structure.ShareOrder + for _, value := range mysOrder { + if value.GetNum <= 0 { + applogger.Error("%v SharePreTrade.GetBotUserMysPreStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserMysPreStockOrder(ctx, code, order) +} + +// ShareMysMarketGiveaways +// +// @Description: 马股市场赠送 +// @receiver uo +// @param ctx +// @param id +// @param code +func (uo *UserOrder) ShareMysMarketGiveaways(ctx context.Context, id, code string) error { + mysOrder, err := uo.ud.GetBotUserMysGiveStockOrders(ctx, id) + if err != nil || mysOrder == nil { + return err + + } + var order []structure.ShareOrder + for _, value := range mysOrder { + if value.Num <= 0 { + applogger.Error("%v ShareGiveaways.GetBotUserMysGiveStockOrders:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, flags.SetZero, value.Num, value.UserId)) + } + + return uo.ud.CreateBotUserMysPreStockOrder(ctx, code, order) +} + +// ShareIdnMarket +// +// @Description: 印尼市场 +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareIdnMarket(ctx context.Context, id, code string) error { + idnOrder, err := uo.ud.GetBotUserIdnPreStockOrder(ctx, id) + if err != nil || idnOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range idnOrder { + if value.GetNum <= 0 { + applogger.Error("%v SharePreTrade.GetBotUserIdnPreStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserIdnPreStockOrder(ctx, code, order) +} + +// ShareIdnOrderNoMarket +// +// @Description: 印尼市场-->OrderNo +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareIdnOrderNoMarket(ctx context.Context, id, code string) error { + orderNoArray := strings.Split(id, ",") + idnOrder, err := uo.ud.GetBotUserIdnPreStockOrderByOrderNo(ctx, orderNoArray) + if err != nil || idnOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range idnOrder { + if value.GetNum <= 0 { + applogger.Error("%v SharePreTrade.GetBotUserIdnPreStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserIdnPreStockOrder(ctx, code, order) +} + +// ShareIdnMarketGiveaways +// +// @Description: 印尼市场赠送 +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareIdnMarketGiveaways(ctx context.Context, id, code string) error { + idnOrder, err := uo.ud.GetBotUserIdnGiveStockOrders(ctx, id) + if err != nil || idnOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range idnOrder { + if value.Num <= 0 { + applogger.Error("%v ShareGiveaways.GetBotUserIdnGiveStockOrders:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, flags.SetZero, value.Num, value.UserId)) + } + + return uo.ud.CreateBotUserIdnPreStockOrder(ctx, code, order) +} + +// ShareInrMarket +// +// @Description: 印度股市场 +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareInrMarket(ctx context.Context, id, code string) error { + thaOrder, err := uo.ud.GetBotUserInPreStockOrder(ctx, id) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.GetNum <= 0 { + applogger.Error("%v SharePreTrade.GetBotUserInPreStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserInPreStockOrder(ctx, code, order) +} + +// ShareInrOrderNoMarket +// +// @Description: 印度股市场-->OrderNo +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareInrOrderNoMarket(ctx context.Context, id, code string) error { + orderNoArray := strings.Split(id, ",") + thaOrder, err := uo.ud.GetBotUserInPreStockOrderByOrderNo(ctx, orderNoArray) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.GetNum <= 0 { + applogger.Error("%v SharePreTrade.GetBotUserInPreStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserInPreStockOrder(ctx, code, order) +} + +// ShareInrMarketGiveaways +// +// @Description: 印度股市场赠送 +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareInrMarketGiveaways(ctx context.Context, id, code string) error { + thaOrder, err := uo.ud.GetBotUserInGiveStockOrders(ctx, id) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.Num <= 0 { + applogger.Error("%v ShareGiveaways.GetBotUserInGiveStockOrders:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, flags.SetZero, value.Num, value.UserId)) + } + + return uo.ud.CreateBotUserInPreStockOrder(ctx, code, order) +} + +// ShareSgdMarket +// +// @Description: 新加坡股市场 +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareSgdMarket(ctx context.Context, id, code string) error { + thaOrder, err := uo.ud.GetBotUserSgdPreStockOrder(ctx, id) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.GetNum <= 0 { + applogger.Error("%v SharePreTrade.GetBotUserInPreStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserSgdPreStockOrder(ctx, code, order) +} + +// ShareSgdOrderNoMarket +// +// @Description: 新加坡股市场-->OrderNo +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareSgdOrderNoMarket(ctx context.Context, id, code string) error { + orderNoArray := strings.Split(id, ",") + thaOrder, err := uo.ud.GetBotUserSgdPreStockOrderByOrderNo(ctx, orderNoArray) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.GetNum <= 0 { + applogger.Error("%v SharePreTrade.GetBotUserInPreStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserSgdPreStockOrder(ctx, code, order) +} + +// ShareSgdMarketGiveaways +// +// @Description: 新加坡股市场赠送 +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareSgdMarketGiveaways(ctx context.Context, id, code string) error { + thaOrder, err := uo.ud.GetBotUserSgdGiveStockOrders(ctx, id) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.Num <= 0 { + applogger.Error("%v ShareGiveaways.GetBotUserSgdGiveStockOrders:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, flags.SetZero, value.Num, value.UserId)) + } + + return uo.ud.CreateBotUserSgdPreStockOrder(ctx, code, order) +} + +// ShareGbxMarket +// +// @Description: 英股市场 +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareGbxMarket(ctx context.Context, id, code string) error { + thaOrder, err := uo.ud.GetBotUserGbxPreStockOrder(ctx, id) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.GetNum <= 0 { + applogger.Error("%v ShareGbxMarket.GetBotUserInPreStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserGbxPreStockOrder(ctx, code, order) +} + +// ShareGbxOrderNoMarket +// +// @Description: 英股市场-->OrderNo +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareGbxOrderNoMarket(ctx context.Context, id, code string) error { + orderNoArray := strings.Split(id, ",") + thaOrder, err := uo.ud.GetBotUserGbxPreStockOrderByOrderNo(ctx, orderNoArray) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.GetNum <= 0 { + applogger.Error("%v ShareGbxOrderNoMarket.GetBotUserGbxPreStockOrderByOrderNo:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserGbxPreStockOrder(ctx, code, order) +} + +// ShareGbxMarketGiveaways +// +// @Description: 英股市场赠送 +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareGbxMarketGiveaways(ctx context.Context, id, code string) error { + thaOrder, err := uo.ud.GetBotUserGbxGiveStockOrders(ctx, id) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.Num <= 0 { + applogger.Error("%v ShareGiveaways.GetBotUserSgdGiveStockOrders:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, flags.SetZero, value.Num, value.UserId)) + } + + return uo.ud.CreateBotUserGbxPreStockOrder(ctx, code, order) +} + +// ShareEurMarket +// +// @Description: 德股市场 +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareEurMarket(ctx context.Context, id, code string) error { + thaOrder, err := uo.ud.GetBotUserEurPreStockOrder(ctx, id) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.GetNum <= 0 { + applogger.Error("%v ShareEurMarket.GetBotUserInPreStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserEurPreStockOrder(ctx, code, order) +} + +// ShareEurOrderNoMarket +// +// @Description: 德股市场-->OrderNo +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareEurOrderNoMarket(ctx context.Context, id, code string) error { + orderNoArray := strings.Split(id, ",") + thaOrder, err := uo.ud.GetBotUserEurPreStockOrderByOrderNo(ctx, orderNoArray) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.GetNum <= 0 { + applogger.Error("%v ShareEurOrderNoMarket.GetBotUserEurPreStockOrderByOrderNo:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserEurPreStockOrder(ctx, code, order) +} + +// ShareEurMarketGiveaways +// +// @Description: 德股市场赠送 +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareEurMarketGiveaways(ctx context.Context, id, code string) error { + thaOrder, err := uo.ud.GetBotUserEurGiveStockOrders(ctx, id) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.Num <= 0 { + applogger.Error("%v ShareEurMarketGiveaways.GetBotUserEurGiveStockOrders:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, flags.SetZero, value.Num, value.UserId)) + } + + return uo.ud.CreateBotUserEurPreStockOrder(ctx, code, order) +} + +// ShareFurMarket +// +// @Description: 法股市场 +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareFurMarket(ctx context.Context, id, code string) error { + thaOrder, err := uo.ud.GetBotUserFurPreStockOrder(ctx, id) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.GetNum <= 0 { + applogger.Error("%v ShareFurMarket.GetBotUserFurPreStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserFurPreStockOrder(ctx, code, order) +} + +// ShareFurOrderNoMarket +// +// @Description: 法股市场-->OrderNo +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareFurOrderNoMarket(ctx context.Context, id, code string) error { + orderNoArray := strings.Split(id, ",") + thaOrder, err := uo.ud.GetBotUserFurPreStockOrderByOrderNo(ctx, orderNoArray) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.GetNum <= 0 { + applogger.Error("%v ShareFurOrderNoMarket.GetBotUserFurPreStockOrderByOrderNo:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserFurPreStockOrder(ctx, code, order) +} + +// ShareFurMarketGiveaways +// +// @Description: 法股市场赠送 +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareFurMarketGiveaways(ctx context.Context, id, code string) error { + thaOrder, err := uo.ud.GetBotUserFurGiveStockOrders(ctx, id) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.Num <= 0 { + applogger.Error("%v ShareFurMarketGiveaways.GetBotUserFurGiveStockOrders:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, flags.SetZero, value.Num, value.UserId)) + } + + return uo.ud.CreateBotUserFurPreStockOrder(ctx, code, order) +} + +// ShareHkdMarket +// +// @Description: 港股市场 +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareHkdMarket(ctx context.Context, id, code string) error { + thaOrder, err := uo.ud.GetBotUserHkdPreStockOrder(ctx, id) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.GetNum <= 0 { + applogger.Error("%v ShareHkdMarket.GetBotUserHkdPreStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserHkdPreStockOrder(ctx, code, order) +} + +// ShareHkdOrderNoMarket +// +// @Description: 港股市场-->OrderNo +// @receiver uo +// @param ctx +// @param id +// @param code +// @return error +func (uo *UserOrder) ShareHkdOrderNoMarket(ctx context.Context, id, code string) error { + orderNoArray := strings.Split(id, ",") + thaOrder, err := uo.ud.GetBotUserHkdPreStockOrderByOrderNo(ctx, orderNoArray) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.GetNum <= 0 { + applogger.Error("%v ShareHkdMarket.GetBotUserHkdPreStockOrder:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, value.GetAmount, value.GetNum, value.UserId)) + } + + return uo.ud.CreateBotUserHkdPreStockOrder(ctx, code, order) +} + +// ShareHkdMarketGiveaways +// +// @Description: 港股市场赠送 +// @receiver uo +// @param ctx +// @param id +// @param code +func (uo *UserOrder) ShareHkdMarketGiveaways(ctx context.Context, id, code string) error { + thaOrder, err := uo.ud.GetBotUserHkdGiveStockOrders(ctx, id) + if err != nil || thaOrder == nil { + return err + } + + var order []structure.ShareOrder + for _, value := range thaOrder { + if value.Num <= 0 { + applogger.Error("%v ShareGiveaways.GetBotUserHkdGiveStockOrders:%v", value.OrderNo, common.ErrSharePre) + continue + } + order = append(order, uo.ParameterConstruction(code, value.OrderNo, value.Price, flags.SetZero, value.Num, value.UserId)) + } + + return uo.ud.CreateBotUserHkdPreStockOrder(ctx, code, order) +} + +// ParameterConstruction +// +// @Description: 新股申购下单参数构造 +// @receiver uo +// @param ctx +// @param code +// @param price +// @param amount +// @param num +// @param userId +// @return structure.ShareOrder +func (uo *UserOrder) ParameterConstruction(code, orderNo string, price, amount string, num, userId int) structure.ShareOrder { + return structure.ShareOrder{ + UserId: userId, // 用户ID + StockId: code, // 股票代码 + TradeType: flags.TradeTypeBuy, // 买涨 + DealType: flags.DealTypeLimited, // 限价 + LimitPrice: price, // 申购价格--->开仓价格 + MarketPrice: flags.SetZero, // 市价 + MarketMoney: amount, // 订单金额 + OrderNumber: strconv.Itoa(num), // 订单数量 + ServiceCost: flags.SetZero, // 开仓手续费 + StopType: flags.StopTypeNone, // 止盈止损设置 + StopLossPrice: flags.SetNull, // 止损设置 + StopWinPrice: flags.SetNull, // 止盈设置 + PryNum: flags.SetOne, // 杠杆默认值 + OrderNo: orderNo, // IPO订单号 + } +} diff --git a/internal/biz/share_blk.go b/internal/biz/share_blk.go new file mode 100644 index 0000000..c7dbc49 --- /dev/null +++ b/internal/biz/share_blk.go @@ -0,0 +1,466 @@ +package biz + +import ( + "context" + "github.com/go-kratos/kratos/v2/log" + + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + + models "matchmaking-system/internal/pkg/model" +) + +// UserShareBlockOrder +// @Description: +type UserShareBlockOrder struct { + uHkd UserShareHkdOrderRepo // 港股 + uIdn UserShareIdnOrderRepo // 印尼股 + uInr UserShareInrOrderRepo // 印度股 + uMys UserShareMysOrderRepo // 马股 + uSgd UserShareSgdOrderRepo // 新加坡股 + uTha UserShareThaOrderRepo // 泰股 + uUs UserShareUsOrderRepo // 美股 + uGbx UserShareGbxOrderRepo // 英股 + uFur UserShareFurOrderRepo // 法股 + uEur UserShareEurOrderRepo // 德股 + uBrl UserShareBrlOrderRepo // 巴西股 + uJpy UserShareJpyOrderRepo // 日股 + uBlk UserShareBlockOrderRepo // 大宗交易股 + + log *log.Helper +} + +// UserShareBlockOrderRepo +// @Description: 订单操作(订单列表|下单|设置止损止盈|撤单|平仓|一键平仓) +type UserShareBlockOrderRepo interface { + CheckToken(ctx context.Context) (int, error) + GetBotUserIsRealByUserId(ctx context.Context, userId int) bool + GetBotStockBlockTradeList(ctx context.Context, pageSize, pageCount, userId, typeStatus, status int64) ([]*models.BotStockBlockTrade, int64, error) +} + +// NewUserShareBlockOrderRepo +// +// @Description: +// @param uo +// @param logger +// @return *UserShareBlockOrder +func NewUserShareBlockOrderRepo( + uHkd UserShareHkdOrderRepo, + uIdn UserShareIdnOrderRepo, + uInr UserShareInrOrderRepo, + uMys UserShareMysOrderRepo, + uSgd UserShareSgdOrderRepo, + uTha UserShareThaOrderRepo, + uUs UserShareUsOrderRepo, + uGbx UserShareGbxOrderRepo, + uFur UserShareFurOrderRepo, + uEur UserShareEurOrderRepo, + uBrl UserShareBrlOrderRepo, + uJpy UserShareJpyOrderRepo, + uBlk UserShareBlockOrderRepo, + logger log.Logger) *UserShareBlockOrder { + return &UserShareBlockOrder{ + uHkd: uHkd, + uIdn: uIdn, + uInr: uInr, + uMys: uMys, + uSgd: uSgd, + uTha: uTha, + uUs: uUs, + uGbx: uGbx, + uFur: uFur, + uEur: uEur, + uBrl: uBrl, + uJpy: uJpy, + uBlk: uBlk, + log: log.NewHelper(logger)} +} + +// GetUserIdByToken +// +// @Description: 通过token获取用户Id +// @receiver uo +// @param ctx +// @return int64 +// @return error +func (uo *UserShareBlockOrder) GetUserIdByToken(ctx context.Context) (int64, bool, error) { + userId, err := uo.uBlk.CheckToken(ctx) + if err != nil { + return 0, false, flags.ErrTokenMessage + } + + return int64(userId), true, nil +} + +// BotStockBlockTradeList +// +// @Description: 大宗交易订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param status +// @return []*models.BotStockBlockTrade +// @return int64 +// @return error +func (uo *UserShareBlockOrder) BotStockBlockTradeList(ctx context.Context, pageSize, pageCount, typeStatus, status int64) ([]*models.BotStockBlockTrade, int64, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return nil, 0, flags.ErrTokenMessage + } + + stockList, totalCount, err := uo.uBlk.GetBotStockBlockTradeList(ctx, pageSize, pageCount-1, userId, typeStatus, status) + if err != nil { + return nil, 0, err + } + + return stockList, totalCount, nil +} + +// ShareBlockPlaceOrder +// +// @Description: 下单 +// @receiver uo +// @param ctx +// @param order +// @return string +// @return error +func (uo *UserShareBlockOrder) ShareBlockPlaceOrder(ctx context.Context, order structure.ShareOrder) (string, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.SetNull, flags.ErrTokenMessage + } + + if !uo.uBlk.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.SetNull, flags.ErrIsReal + } + + var orderId string + switch order.Type { + case flags.ShareUsMarketType: // 美股 + orderId, err = uo.uUs.PlacingStockOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + case flags.ShareThaMarketType: // 泰股 + orderId, err = uo.uTha.PlacingStockThaOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + case flags.ShareMysMarketType: // 马股 + orderId, err = uo.uMys.PlacingStockMysOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + case flags.ShareIdnMarketType: // 印尼股 + orderId, err = uo.uIdn.PlacingStockIdnOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + case flags.ShareInrMarketType: // 印度股 + orderId, err = uo.uInr.PlacingStockInOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + case flags.ShareSgdMarketType: // 新加坡股 + orderId, err = uo.uSgd.PlacingStockSgdOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + case flags.ShareHkdMarketType: // 港股股 + orderId, err = uo.uHkd.PlacingStockHkdOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + case flags.ShareGbxMarketType: // 英股 + orderId, err = uo.uGbx.PlacingStockGbxOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + case flags.ShareFurMarketType: // 法股 + orderId, err = uo.uFur.PlacingStockFurOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + case flags.ShareEurMarketType: // 德股 + orderId, err = uo.uEur.PlacingStockEurOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + case flags.ShareBrlMarketType: // 巴西股 + orderId, err = uo.uBrl.PlacingStockBrlOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + case flags.ShareJpyMarketType: // 日本股 + orderId, err = uo.uJpy.PlacingStockJpyOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + default: + return flags.SetNull, flags.ErrPublicSix + } + + return orderId, nil +} + +// ShareBlockUpdateOrder +// +// @Description: 设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *UserShareBlockOrder) ShareBlockUpdateOrder(ctx context.Context, order structure.StopOrder) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.uBlk.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + var check bool + switch order.Type { + case flags.ShareUsMarketType: // 美股 + check, err = uo.uUs.UpdateBotStockStopByOrderId(ctx, order) + if err != nil { + return false, err + } + case flags.ShareThaMarketType: // 泰股 + check, err = uo.uTha.UpdateBotStockThaStopByOrderId(ctx, order) + if err != nil { + return false, err + } + case flags.ShareMysMarketType: // 马股 + check, err = uo.uMys.UpdateBotStockMysStopByOrderId(ctx, order) + if err != nil { + return false, err + } + case flags.ShareIdnMarketType: // 印尼股 + check, err = uo.uIdn.UpdateBotStockIdnStopByOrderId(ctx, order) + if err != nil { + return false, err + } + case flags.ShareInrMarketType: // 印度股 + check, err = uo.uInr.UpdateBotStockInStopByOrderId(ctx, order) + if err != nil { + return false, err + } + case flags.ShareSgdMarketType: // 新加坡股 + check, err = uo.uSgd.UpdateBotStockSgdStopByOrderId(ctx, order) + if err != nil { + return false, err + } + case flags.ShareHkdMarketType: // 港股 + check, err = uo.uHkd.UpdateBotStockHkdStopByOrderId(ctx, order) + if err != nil { + return false, err + } + case flags.ShareGbxMarketType: // 英股 + check, err = uo.uGbx.UpdateBotStockGbxStopByOrderId(ctx, order) + if err != nil { + return false, err + } + case flags.ShareFurMarketType: // 法股 + check, err = uo.uFur.UpdateBotStockFurStopByOrderId(ctx, order) + if err != nil { + return false, err + } + case flags.ShareEurMarketType: // 德股 + check, err = uo.uEur.UpdateBotStockEurStopByOrderId(ctx, order) + if err != nil { + return false, err + } + case flags.ShareBrlMarketType: // 巴西股 + check, err = uo.uBrl.UpdateBotStockBrlStopByOrderId(ctx, order) + if err != nil { + return false, err + } + case flags.ShareJpyMarketType: // 日本股 + check, err = uo.uJpy.UpdateBotStockJpyStopByOrderId(ctx, order) + if err != nil { + return false, err + } + default: + return false, flags.ErrPublicSix + } + + return check, nil +} + +// ShareBlockCancel +// +// @Description: 撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareBlockOrder) ShareBlockCancel(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.uBlk.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + var check bool + switch typeStatus { + case flags.ShareUsMarketType: // 美股 + check, err = uo.uUs.UpdateBotStockCancelByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareThaMarketType: // 泰股 + check, err = uo.uTha.UpdateBotStockThaCancelByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareMysMarketType: // 马股 + check, err = uo.uMys.UpdateBotStockMysCancelByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareIdnMarketType: // 印尼股 + check, err = uo.uIdn.UpdateBotStockIdnCancelByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareInrMarketType: // 印度股 + check, err = uo.uInr.UpdateBotStockInCancelByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareSgdMarketType: // 新加坡股 + check, err = uo.uSgd.UpdateBotStockSgdCancelByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareHkdMarketType: // 港股 + check, err = uo.uHkd.UpdateBotStockHkdCancelByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareGbxMarketType: // 英股 + check, err = uo.uGbx.UpdateBotStockGbxCancelByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareFurMarketType: // 法股 + check, err = uo.uFur.UpdateBotStockFurCancelByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareEurMarketType: // 德股 + check, err = uo.uEur.UpdateBotStockEurCancelByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareBrlMarketType: // 巴西股 + check, err = uo.uBrl.UpdateBotStockBrlCancelByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareJpyMarketType: // 日本股 + check, err = uo.uJpy.UpdateBotStockJpyCancelByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + default: + return false, flags.ErrPublicSix + } + + return check, nil +} + +// ShareBlockPosition +// +// @Description: 平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareBlockOrder) ShareBlockPosition(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.uBlk.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + var check bool + switch typeStatus { + case flags.ShareUsMarketType: // 美股 + check, err = uo.uUs.UpdateBotStockClosingByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareThaMarketType: // 泰股 + check, err = uo.uTha.UpdateBotStockThaClosingByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareMysMarketType: // 马股 + check, err = uo.uMys.UpdateBotStockMysClosingByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareIdnMarketType: // 印尼股 + check, err = uo.uIdn.UpdateBotStockIdnClosingByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareInrMarketType: // 印度股 + check, err = uo.uInr.UpdateBotStockInClosingByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareSgdMarketType: // 新加坡股 + check, err = uo.uSgd.UpdateBotStockSgdClosingByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareHkdMarketType: // 港股 + check, err = uo.uHkd.UpdateBotStockHkdClosingByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareGbxMarketType: // 英股 + check, err = uo.uGbx.UpdateBotStockGbxClosingByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareFurMarketType: // 法股 + check, err = uo.uFur.UpdateBotStockFurClosingByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareEurMarketType: // 德股 + check, err = uo.uEur.UpdateBotStockEurClosingByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareBrlMarketType: // 巴西股 + check, err = uo.uBrl.UpdateBotStockBrlClosingByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + case flags.ShareJpyMarketType: // 日本股 + check, err = uo.uJpy.UpdateBotStockJpyClosingByOrderId(ctx, orderId, typeStatus) + if err != nil { + return false, err + } + default: + return false, flags.ErrPublicSix + } + + return check, nil +} diff --git a/internal/biz/share_brl.go b/internal/biz/share_brl.go new file mode 100644 index 0000000..22f6d8d --- /dev/null +++ b/internal/biz/share_brl.go @@ -0,0 +1,211 @@ +package biz + +import ( + "context" + + "github.com/go-kratos/kratos/v2/log" + + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + + models "matchmaking-system/internal/pkg/model" +) + +// UserShareBrlOrder +// @Description: +type UserShareBrlOrder struct { + ud UserShareBrlOrderRepo + + log *log.Helper +} + +// UserShareBrlOrderRepo +// @Description: 订单操作(订单列表|下单|设置止盈止损|撤单|平仓|一键平仓) +type UserShareBrlOrderRepo interface { + CheckToken(ctx context.Context) (int, error) + GetBotUserIsRealByUserId(ctx context.Context, userId int) bool + GetBotStockBrlTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockBrlTrade, int64, error) + PlacingStockBrlOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) + UpdateBotStockBrlStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) + UpdateBotStockBrlCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockBrlClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockBrlAllClosingByOrderId(ctx context.Context, userId int64) error +} + +// NewUserShareBrlOrderRepo +// +// @Description: +// @param uo +// @param logger +// @return *UserShareBrlOrder +func NewUserShareBrlOrderRepo(uo UserShareBrlOrderRepo, logger log.Logger) *UserShareBrlOrder { + return &UserShareBrlOrder{ud: uo, log: log.NewHelper(logger)} +} + +// GetUserIdByToken +// +// @Description: 通过token获取用户Id +// @receiver uo +// @param ctx +// @return int64 +// @return error +func (uo *UserShareBrlOrder) GetUserIdByToken(ctx context.Context) (int64, bool, error) { + userId, err := uo.ud.CheckToken(ctx) + if err != nil { + return 0, false, flags.ErrTokenMessage + } + + return int64(userId), true, nil +} + +// BotStockBrlTradeList +// +// @Description: 订单列表 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param status +// @return []*models.BotStockBrlTrade +// @return int64 +// @return error +func (uo *UserShareBrlOrder) BotStockBrlTradeList(ctx context.Context, pageSize, pageCount, status int64) ([]*models.BotStockBrlTrade, int64, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return nil, 0, flags.ErrTokenMessage + } + + stockList, totalCount, err := uo.ud.GetBotStockBrlTradeList(ctx, pageSize, pageCount-1, userId, status) + if err != nil { + return nil, 0, err + } + + return stockList, totalCount, nil +} + +// ShareBrlPlaceOrder +// +// @Description: 下单 +// @receiver uo +// @param ctx +// @param order +// @return string +// @return error +func (uo *UserShareBrlOrder) ShareBrlPlaceOrder(ctx context.Context, order structure.ShareOrder) (string, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.SetNull, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.SetNull, flags.ErrIsReal + } + + orderId, err := uo.ud.PlacingStockBrlOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + + return orderId, nil +} + +// ShareBrlUpdateOrder +// +// @Description: 设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *UserShareBrlOrder) ShareBrlUpdateOrder(ctx context.Context, order structure.StopOrder) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockBrlStopByOrderId(ctx, order) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareBrlCancel +// +// @Description: 撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareBrlOrder) ShareBrlCancel(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockBrlCancelByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareBrlPosition +// +// @Description: 平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareBrlOrder) ShareBrlPosition(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockBrlClosingByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareBrlAllPosition +// +// @Description: 一键平仓 +// @receiver uo +// @param ctx +// @return error +func (uo *UserShareBrlOrder) ShareBrlAllPosition(ctx context.Context) error { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.ErrIsReal + } + + if err = uo.ud.UpdateBotStockBrlAllClosingByOrderId(ctx, userId); err != nil { + return err + } + + return nil +} diff --git a/internal/biz/share_eur.go b/internal/biz/share_eur.go new file mode 100644 index 0000000..59d299c --- /dev/null +++ b/internal/biz/share_eur.go @@ -0,0 +1,211 @@ +package biz + +import ( + "context" + + "github.com/go-kratos/kratos/v2/log" + + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + + models "matchmaking-system/internal/pkg/model" +) + +// UserShareEurOrder +// @Description: +type UserShareEurOrder struct { + ud UserShareEurOrderRepo + + log *log.Helper +} + +// UserShareEurOrderRepo +// @Description: 订单操作(订单列表|下单|设置止盈止损|撤单|平仓|一键平仓) +type UserShareEurOrderRepo interface { + CheckToken(ctx context.Context) (int, error) + GetBotUserIsRealByUserId(ctx context.Context, userId int) bool + GetBotStockEurTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockEurTrade, int64, error) + PlacingStockEurOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) + UpdateBotStockEurStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) + UpdateBotStockEurCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockEurClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockEurAllClosingByOrderId(ctx context.Context, userId int64) error +} + +// NewUserShareEurOrderRepo +// +// @Description: +// @param uo +// @param logger +// @return *UserShareEurOrder +func NewUserShareEurOrderRepo(uo UserShareEurOrderRepo, logger log.Logger) *UserShareEurOrder { + return &UserShareEurOrder{ud: uo, log: log.NewHelper(logger)} +} + +// GetUserIdByToken +// +// @Description: 通过token获取用户Id +// @receiver uo +// @param ctx +// @return int64 +// @return error +func (uo *UserShareEurOrder) GetUserIdByToken(ctx context.Context) (int64, bool, error) { + userId, err := uo.ud.CheckToken(ctx) + if err != nil { + return 0, false, flags.ErrTokenMessage + } + + return int64(userId), true, nil +} + +// BotStockEurTradeList +// +// @Description: 订单列表 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param status +// @return []*models.BotStockEurTrade +// @return int64 +// @return error +func (uo *UserShareEurOrder) BotStockEurTradeList(ctx context.Context, pageSize, pageCount, status int64) ([]*models.BotStockEurTrade, int64, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return nil, 0, flags.ErrTokenMessage + } + + stockList, totalCount, err := uo.ud.GetBotStockEurTradeList(ctx, pageSize, pageCount-1, userId, status) + if err != nil { + return nil, 0, err + } + + return stockList, totalCount, nil +} + +// ShareEurPlaceOrder +// +// @Description: 下单 +// @receiver uo +// @param ctx +// @param order +// @return string +// @return error +func (uo *UserShareEurOrder) ShareEurPlaceOrder(ctx context.Context, order structure.ShareOrder) (string, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.SetNull, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.SetNull, flags.ErrIsReal + } + + orderId, err := uo.ud.PlacingStockEurOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + + return orderId, nil +} + +// ShareEurUpdateOrder +// +// @Description: 设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *UserShareEurOrder) ShareEurUpdateOrder(ctx context.Context, order structure.StopOrder) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockEurStopByOrderId(ctx, order) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareEurCancel +// +// @Description: 撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareEurOrder) ShareEurCancel(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockEurCancelByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareEurPosition +// +// @Description: 平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareEurOrder) ShareEurPosition(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockEurClosingByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareEurAllPosition +// +// @Description: 一键平仓 +// @receiver uo +// @param ctx +// @return error +func (uo *UserShareEurOrder) ShareEurAllPosition(ctx context.Context) error { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.ErrIsReal + } + + if err = uo.ud.UpdateBotStockEurAllClosingByOrderId(ctx, userId); err != nil { + return err + } + + return nil +} diff --git a/internal/biz/share_fur.go b/internal/biz/share_fur.go new file mode 100644 index 0000000..f422382 --- /dev/null +++ b/internal/biz/share_fur.go @@ -0,0 +1,211 @@ +package biz + +import ( + "context" + + "github.com/go-kratos/kratos/v2/log" + + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + + models "matchmaking-system/internal/pkg/model" +) + +// UserShareFurOrder +// @Description: +type UserShareFurOrder struct { + ud UserShareFurOrderRepo + + log *log.Helper +} + +// UserShareFurOrderRepo +// @Description: 订单操作(订单列表|下单|设置止盈止损|撤单|平仓|一键平仓) +type UserShareFurOrderRepo interface { + CheckToken(ctx context.Context) (int, error) + GetBotUserIsRealByUserId(ctx context.Context, userId int) bool + GetBotStockFurTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockFurTrade, int64, error) + PlacingStockFurOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) + UpdateBotStockFurStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) + UpdateBotStockFurCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockFurClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockFurAllClosingByOrderId(ctx context.Context, userId int64) error +} + +// NewUserShareFurOrderRepo +// +// @Description: +// @param uo +// @param logger +// @return *UserShareFurOrder +func NewUserShareFurOrderRepo(uo UserShareFurOrderRepo, logger log.Logger) *UserShareFurOrder { + return &UserShareFurOrder{ud: uo, log: log.NewHelper(logger)} +} + +// GetUserIdByToken +// +// @Description: 通过token获取用户Id +// @receiver uo +// @param ctx +// @return int64 +// @return error +func (uo *UserShareFurOrder) GetUserIdByToken(ctx context.Context) (int64, bool, error) { + userId, err := uo.ud.CheckToken(ctx) + if err != nil { + return 0, false, flags.ErrTokenMessage + } + + return int64(userId), true, nil +} + +// BotStockFurTradeList +// +// @Description: 订单列表 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param status +// @return []*models.BotStockFurTrade +// @return int64 +// @return error +func (uo *UserShareFurOrder) BotStockFurTradeList(ctx context.Context, pageSize, pageCount, status int64) ([]*models.BotStockFurTrade, int64, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return nil, 0, flags.ErrTokenMessage + } + + stockList, totalCount, err := uo.ud.GetBotStockFurTradeList(ctx, pageSize, pageCount-1, userId, status) + if err != nil { + return nil, 0, err + } + + return stockList, totalCount, nil +} + +// ShareFurPlaceOrder +// +// @Description: 下单 +// @receiver uo +// @param ctx +// @param order +// @return string +// @return error +func (uo *UserShareFurOrder) ShareFurPlaceOrder(ctx context.Context, order structure.ShareOrder) (string, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.SetNull, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.SetNull, flags.ErrIsReal + } + + orderId, err := uo.ud.PlacingStockFurOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + + return orderId, nil +} + +// ShareFurUpdateOrder +// +// @Description: 设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *UserShareFurOrder) ShareFurUpdateOrder(ctx context.Context, order structure.StopOrder) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockFurStopByOrderId(ctx, order) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareFurCancel +// +// @Description: 撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareFurOrder) ShareFurCancel(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockFurCancelByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareFurPosition +// +// @Description: 平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareFurOrder) ShareFurPosition(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockFurClosingByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareFurAllPosition +// +// @Description: 一键平仓 +// @receiver uo +// @param ctx +// @return error +func (uo *UserShareFurOrder) ShareFurAllPosition(ctx context.Context) error { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.ErrIsReal + } + + if err = uo.ud.UpdateBotStockFurAllClosingByOrderId(ctx, userId); err != nil { + return err + } + + return nil +} diff --git a/internal/biz/share_gbx.go b/internal/biz/share_gbx.go new file mode 100644 index 0000000..8a4c750 --- /dev/null +++ b/internal/biz/share_gbx.go @@ -0,0 +1,211 @@ +package biz + +import ( + "context" + + "github.com/go-kratos/kratos/v2/log" + + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + + models "matchmaking-system/internal/pkg/model" +) + +// UserShareGbxOrder +// @Description: +type UserShareGbxOrder struct { + ud UserShareGbxOrderRepo + + log *log.Helper +} + +// UserShareGbxOrderRepo +// @Description: 订单操作(订单列表|下单|设置止盈止损|撤单|平仓|一键平仓) +type UserShareGbxOrderRepo interface { + CheckToken(ctx context.Context) (int, error) + GetBotUserIsRealByUserId(ctx context.Context, userId int) bool + GetBotStockGbxTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockGbxTrade, int64, error) + PlacingStockGbxOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) + UpdateBotStockGbxCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockGbxStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) + UpdateBotStockGbxClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockGbxAllClosingByOrderId(ctx context.Context, userId int64) error +} + +// NewUserShareGbxOrderRepo +// +// @Description: +// @param uo +// @param logger +// @return *UserShareGbxOrder +func NewUserShareGbxOrderRepo(uo UserShareGbxOrderRepo, logger log.Logger) *UserShareGbxOrder { + return &UserShareGbxOrder{ud: uo, log: log.NewHelper(logger)} +} + +// GetUserIdByToken +// +// @Description: 通过token获取用户Id +// @receiver uo +// @param ctx +// @return int64 +// @return error +func (uo *UserShareGbxOrder) GetUserIdByToken(ctx context.Context) (int64, bool, error) { + userId, err := uo.ud.CheckToken(ctx) + if err != nil { + return 0, false, flags.ErrTokenMessage + } + + return int64(userId), true, nil +} + +// BotStockGbxTradeList +// +// @Description: 列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param status +// @return []*models.BotStockInTrade +// @return int64 +// @return error +func (uo *UserShareGbxOrder) BotStockGbxTradeList(ctx context.Context, pageSize, pageCount, status int64) ([]*models.BotStockGbxTrade, int64, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return nil, 0, flags.ErrTokenMessage + } + + stockList, totalCount, err := uo.ud.GetBotStockGbxTradeList(ctx, pageSize, pageCount-1, userId, status) + if err != nil { + return nil, 0, err + } + + return stockList, totalCount, nil +} + +// ShareGbxPlaceOrder +// +// @Description: 下单 +// @receiver uo +// @param ctx +// @param order +// @return string +// @return error +func (uo *UserShareGbxOrder) ShareGbxPlaceOrder(ctx context.Context, order structure.ShareOrder) (string, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.SetNull, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.SetNull, flags.ErrIsReal + } + + orderId, err := uo.ud.PlacingStockGbxOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + + return orderId, nil +} + +// ShareGbxUpdateOrder +// +// @Description: 止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *UserShareGbxOrder) ShareGbxUpdateOrder(ctx context.Context, order structure.StopOrder) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockGbxStopByOrderId(ctx, order) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareGbxCancel +// +// @Description: 撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareGbxOrder) ShareGbxCancel(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockGbxCancelByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareGbxPosition +// +// @Description: 平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareGbxOrder) ShareGbxPosition(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockGbxClosingByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareGbxAllPosition +// +// @Description: 一键平仓 +// @receiver uo +// @param ctx +// @return error +func (uo *UserShareGbxOrder) ShareGbxAllPosition(ctx context.Context) error { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.ErrIsReal + } + + if err = uo.ud.UpdateBotStockGbxAllClosingByOrderId(ctx, userId); err != nil { + return err + } + + return nil +} diff --git a/internal/biz/share_hkd.go b/internal/biz/share_hkd.go new file mode 100644 index 0000000..1cbffad --- /dev/null +++ b/internal/biz/share_hkd.go @@ -0,0 +1,212 @@ +package biz + +import ( + "context" + + "github.com/go-kratos/kratos/v2/log" + + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + + models "matchmaking-system/internal/pkg/model" +) + +// UserShareHkdOrder +// @Description: +type UserShareHkdOrder struct { + ud UserShareHkdOrderRepo + + log *log.Helper +} + +// UserShareHkdOrderRepo +// @Description: 订单操作(订单列表|下单|设置止损止盈|撤单|平仓|一键平仓) +type UserShareHkdOrderRepo interface { + CheckToken(ctx context.Context) (int, error) + GetBotUserIsRealByUserId(ctx context.Context, userId int) bool + GetBotStockHkdTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockHkdTrade, int64, error) + PlacingStockHkdOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) + UpdateBotStockHkdStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) + UpdateBotStockHkdCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockHkdClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockHkdAllClosingByOrderId(ctx context.Context, userId int64) error +} + +// NewUserShareHkdOrderRepo +// +// @Description: +// @param uo +// @param logger +// @return *UserShareHkdOrder +func NewUserShareHkdOrderRepo(uo UserShareHkdOrderRepo, logger log.Logger) *UserShareHkdOrder { + return &UserShareHkdOrder{ud: uo, log: log.NewHelper(logger)} +} + +// GetUserIdByToken +// +// @Description: 通过token获取用户Id +// @receiver uo +// @param ctx +// @return int64 +// @return error +func (uo *UserShareHkdOrder) GetUserIdByToken(ctx context.Context) (int64, bool, error) { + userId, err := uo.ud.CheckToken(ctx) + if err != nil { + return 0, false, flags.ErrTokenMessage + } + + return int64(userId), true, nil +} + +// BotStockHkdTradeList +// +// @Description: 订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param status +// @return []*models.BotStockHkdTrade +// @return int64 +// @return error +func (uo *UserShareHkdOrder) BotStockHkdTradeList(ctx context.Context, pageSize, pageCount, status int64) ([]*models.BotStockHkdTrade, int64, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return nil, 0, flags.ErrTokenMessage + } + + stockList, totalCount, err := uo.ud.GetBotStockHkdTradeList(ctx, pageSize, pageCount-1, userId, status) + if err != nil { + return nil, 0, err + } + + return stockList, totalCount, nil +} + +// ShareHkdPlaceOrder +// +// @Description: 下单 +// @receiver uo +// @param ctx +// @param order +// @return string +// @return error +func (uo *UserShareHkdOrder) ShareHkdPlaceOrder(ctx context.Context, order structure.ShareOrder) (string, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.SetNull, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.SetNull, flags.ErrIsReal + } + + // add BotStockHkdTrade + orderId, err := uo.ud.PlacingStockHkdOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + + return orderId, nil +} + +// ShareHkdUpdateOrder +// +// @Description: 设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *UserShareHkdOrder) ShareHkdUpdateOrder(ctx context.Context, order structure.StopOrder) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockHkdStopByOrderId(ctx, order) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareHkdCancel +// +// @Description: 撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareHkdOrder) ShareHkdCancel(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockHkdCancelByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareHkdPosition +// +// @Description: 平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareHkdOrder) ShareHkdPosition(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockHkdClosingByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareHkdAllPosition +// +// @Description: 一键平仓 +// @receiver uo +// @param ctx +// @return error +func (uo *UserShareHkdOrder) ShareHkdAllPosition(ctx context.Context) error { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.ErrIsReal + } + + if err = uo.ud.UpdateBotStockHkdAllClosingByOrderId(ctx, userId); err != nil { + return err + } + + return nil +} diff --git a/internal/biz/share_idn.go b/internal/biz/share_idn.go new file mode 100644 index 0000000..666df8d --- /dev/null +++ b/internal/biz/share_idn.go @@ -0,0 +1,211 @@ +package biz + +import ( + "context" + + "github.com/go-kratos/kratos/v2/log" + + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + + models "matchmaking-system/internal/pkg/model" +) + +// UserShareIdnOrder +// @Description: +type UserShareIdnOrder struct { + ud UserShareIdnOrderRepo + + log *log.Helper +} + +// UserShareIdnOrderRepo +// @Description: 订单操作(订单列表|下单|设置止盈止损|撤单|平仓|一键平仓) +type UserShareIdnOrderRepo interface { + CheckToken(ctx context.Context) (int, error) + GetBotUserIsRealByUserId(ctx context.Context, userId int) bool + GetBotStockIdnTradeList(pageSize, pageCount, userId, status int64) ([]*models.BotStockIdnTrade, int64, error) + PlacingStockIdnOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) + UpdateBotStockIdnStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) + UpdateBotStockIdnCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockIdnClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockIdnAllClosingByOrderId(ctx context.Context, userId int64) error +} + +// NewUserShareIdnOrderRepo +// +// @Description: +// @param uo +// @param logger +// @return *UserSecondOrder +func NewUserShareIdnOrderRepo(uo UserShareIdnOrderRepo, logger log.Logger) *UserShareIdnOrder { + return &UserShareIdnOrder{ud: uo, log: log.NewHelper(logger)} +} + +// GetUserIdByToken +// +// @Description: 通过token获取用户Id +// @receiver uo +// @param ctx +// @return int64 +// @return error +func (uo *UserShareIdnOrder) GetUserIdByToken(ctx context.Context) (int64, bool, error) { + userId, err := uo.ud.CheckToken(ctx) + if err != nil { + return 0, false, flags.ErrTokenMessage + } + + return int64(userId), true, nil +} + +// BotStockIdnTradeList +// +// @Description: 订单列表 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param status +// @return []*models.BotStockIdnTrade +// @return int64 +// @return error +func (uo *UserShareIdnOrder) BotStockIdnTradeList(ctx context.Context, pageSize, pageCount, status int64) ([]*models.BotStockIdnTrade, int64, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return nil, 0, flags.ErrTokenMessage + } + + stockList, totalCount, err := uo.ud.GetBotStockIdnTradeList(pageSize, pageCount-1, userId, status) + if err != nil { + return nil, 0, err + } + + return stockList, totalCount, nil +} + +// ShareIdnPlaceOrder +// +// @Description: 下单 +// @receiver uo +// @param ctx +// @param order +// @return string +// @return error +func (uo *UserShareIdnOrder) ShareIdnPlaceOrder(ctx context.Context, order structure.ShareOrder) (string, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.SetNull, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.SetNull, flags.ErrIsReal + } + + orderId, err := uo.ud.PlacingStockIdnOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + + return orderId, nil +} + +// ShareIdnUpdateOrder +// +// @Description: 设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *UserShareIdnOrder) ShareIdnUpdateOrder(ctx context.Context, order structure.StopOrder) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockIdnStopByOrderId(ctx, order) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareIdnCancel +// +// @Description: 撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareIdnOrder) ShareIdnCancel(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockIdnCancelByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareIdnPosition +// +// @Description: 平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareIdnOrder) ShareIdnPosition(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockIdnClosingByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareIdnAllPosition +// +// @Description: 一键平仓 +// @receiver uo +// @param ctx +// @return error +func (uo *UserShareIdnOrder) ShareIdnAllPosition(ctx context.Context) error { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.ErrIsReal + } + + if err = uo.ud.UpdateBotStockIdnAllClosingByOrderId(ctx, userId); err != nil { + return err + } + + return nil +} diff --git a/internal/biz/share_inr.go b/internal/biz/share_inr.go new file mode 100644 index 0000000..6a141d0 --- /dev/null +++ b/internal/biz/share_inr.go @@ -0,0 +1,211 @@ +package biz + +import ( + "context" + + "github.com/go-kratos/kratos/v2/log" + + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + + models "matchmaking-system/internal/pkg/model" +) + +// UserShareInrOrder +// @Description: +type UserShareInrOrder struct { + ud UserShareInrOrderRepo + + log *log.Helper +} + +// UserShareInrOrderRepo +// @Description: 订单操作(订单列表|下单|设置止盈止损|撤单|平仓|一键平仓) +type UserShareInrOrderRepo interface { + CheckToken(ctx context.Context) (int, error) + GetBotUserIsRealByUserId(ctx context.Context, userId int) bool + GetBotStockInTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockInTrade, int64, error) + PlacingStockInOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) + UpdateBotStockInCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockInStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) + UpdateBotStockInClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockInAllClosingByOrderId(ctx context.Context, userId int64) error +} + +// NewUserShareInrOrderRepo +// +// @Description: +// @param uo +// @param logger +// @return *UserSecondOrder +func NewUserShareInrOrderRepo(uo UserShareInrOrderRepo, logger log.Logger) *UserShareInrOrder { + return &UserShareInrOrder{ud: uo, log: log.NewHelper(logger)} +} + +// GetUserIdByToken +// +// @Description: 通过token获取用户Id +// @receiver uo +// @param ctx +// @return int64 +// @return error +func (uo *UserShareInrOrder) GetUserIdByToken(ctx context.Context) (int64, bool, error) { + userId, err := uo.ud.CheckToken(ctx) + if err != nil { + return 0, false, flags.ErrTokenMessage + } + + return int64(userId), true, nil +} + +// BotStockInrTradeList +// +// @Description: 列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param status +// @return []*models.BotStockIdnTrade +// @return int64 +// @return error +func (uo *UserShareInrOrder) BotStockInrTradeList(ctx context.Context, pageSize, pageCount, status int64) ([]*models.BotStockInTrade, int64, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return nil, 0, flags.ErrTokenMessage + } + + stockList, totalCount, err := uo.ud.GetBotStockInTradeList(ctx, pageSize, pageCount-1, userId, status) + if err != nil { + return nil, 0, err + } + + return stockList, totalCount, nil +} + +// ShareInrPlaceOrder +// +// @Description: 下单 +// @receiver uo +// @param ctx +// @param order +// @return string +// @return error +func (uo *UserShareInrOrder) ShareInrPlaceOrder(ctx context.Context, order structure.ShareOrder) (string, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.SetNull, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.SetNull, flags.ErrIsReal + } + + orderId, err := uo.ud.PlacingStockInOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + + return orderId, nil +} + +// ShareInrUpdateOrder +// +// @Description: 止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *UserShareInrOrder) ShareInrUpdateOrder(ctx context.Context, order structure.StopOrder) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockInStopByOrderId(ctx, order) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareInrCancel +// +// @Description: 撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareInrOrder) ShareInrCancel(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockInCancelByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareInrPosition +// +// @Description: 平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareInrOrder) ShareInrPosition(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockInClosingByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareInrAllPosition +// +// @Description: 一键平仓 +// @receiver uo +// @param ctx +// @return error +func (uo *UserShareInrOrder) ShareInrAllPosition(ctx context.Context) error { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.ErrIsReal + } + + if err = uo.ud.UpdateBotStockInAllClosingByOrderId(ctx, userId); err != nil { + return err + } + + return nil +} diff --git a/internal/biz/share_jpy.go b/internal/biz/share_jpy.go new file mode 100644 index 0000000..2a8d521 --- /dev/null +++ b/internal/biz/share_jpy.go @@ -0,0 +1,211 @@ +package biz + +import ( + "context" + + "github.com/go-kratos/kratos/v2/log" + + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + + models "matchmaking-system/internal/pkg/model" +) + +// UserShareJpyOrder +// @Description: +type UserShareJpyOrder struct { + ud UserShareJpyOrderRepo + + log *log.Helper +} + +// UserShareJpyOrderRepo +// @Description: 订单操作(订单列表|下单|设置止盈止损|撤单|平仓|一键平仓) +type UserShareJpyOrderRepo interface { + CheckToken(ctx context.Context) (int, error) + GetBotUserIsRealByUserId(ctx context.Context, userId int) bool + GetBotStockJpyTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockJpTrade, int64, error) + PlacingStockJpyOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) + UpdateBotStockJpyStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) + UpdateBotStockJpyCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockJpyClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockJpyAllClosingByOrderId(ctx context.Context, userId int64) error +} + +// NewUserShareJpyOrderRepo +// +// @Description: +// @param uo +// @param logger +// @return *UserShareJpyOrder +func NewUserShareJpyOrderRepo(uo UserShareJpyOrderRepo, logger log.Logger) *UserShareJpyOrder { + return &UserShareJpyOrder{ud: uo, log: log.NewHelper(logger)} +} + +// GetUserIdByToken +// +// @Description: 通过token获取用户Id +// @receiver uo +// @param ctx +// @return int64 +// @return error +func (uo *UserShareJpyOrder) GetUserIdByToken(ctx context.Context) (int64, bool, error) { + userId, err := uo.ud.CheckToken(ctx) + if err != nil { + return 0, false, flags.ErrTokenMessage + } + + return int64(userId), true, nil +} + +// BotStockJpyTradeList +// +// @Description: 订单列表 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param status +// @return []*models.BotStockJpyTrade +// @return int64 +// @return error +func (uo *UserShareJpyOrder) BotStockJpyTradeList(ctx context.Context, pageSize, pageCount, status int64) ([]*models.BotStockJpTrade, int64, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return nil, 0, flags.ErrTokenMessage + } + + stockList, totalCount, err := uo.ud.GetBotStockJpyTradeList(ctx, pageSize, pageCount-1, userId, status) + if err != nil { + return nil, 0, err + } + + return stockList, totalCount, nil +} + +// ShareJpyPlaceOrder +// +// @Description: 下单 +// @receiver uo +// @param ctx +// @param order +// @return string +// @return error +func (uo *UserShareJpyOrder) ShareJpyPlaceOrder(ctx context.Context, order structure.ShareOrder) (string, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.SetNull, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.SetNull, flags.ErrIsReal + } + + orderId, err := uo.ud.PlacingStockJpyOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + + return orderId, nil +} + +// ShareJpyUpdateOrder +// +// @Description: 设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *UserShareJpyOrder) ShareJpyUpdateOrder(ctx context.Context, order structure.StopOrder) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockJpyStopByOrderId(ctx, order) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareJpyCancel +// +// @Description: 撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareJpyOrder) ShareJpyCancel(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockJpyCancelByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareJpyPosition +// +// @Description: 平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareJpyOrder) ShareJpyPosition(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockJpyClosingByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareJpyAllPosition +// +// @Description: 一键平仓 +// @receiver uo +// @param ctx +// @return error +func (uo *UserShareJpyOrder) ShareJpyAllPosition(ctx context.Context) error { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.ErrIsReal + } + + if err = uo.ud.UpdateBotStockJpyAllClosingByOrderId(ctx, userId); err != nil { + return err + } + + return nil +} diff --git a/internal/biz/share_mys.go b/internal/biz/share_mys.go new file mode 100644 index 0000000..29f9a87 --- /dev/null +++ b/internal/biz/share_mys.go @@ -0,0 +1,211 @@ +package biz + +import ( + "context" + + "github.com/go-kratos/kratos/v2/log" + + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + + models "matchmaking-system/internal/pkg/model" +) + +// UserShareMysOrder +// @Description: +type UserShareMysOrder struct { + ud UserShareMysOrderRepo + + log *log.Helper +} + +// UserShareMysOrderRepo +// @Description: 订单操作(订单列表|下单|设置止盈止损|撤单|平仓|一键平仓) +type UserShareMysOrderRepo interface { + CheckToken(ctx context.Context) (int, error) + GetBotUserIsRealByUserId(ctx context.Context, userId int) bool + GetBotStockMysTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockMysTrade, int64, error) + PlacingStockMysOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) + UpdateBotStockMysStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) + UpdateBotStockMysCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockMysClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockMysAllClosingByOrderId(ctx context.Context, userId int64) error +} + +// NewUserShareMysOrderRepo +// +// @Description: +// @param uo +// @param logger +// @return *UserSecondOrder +func NewUserShareMysOrderRepo(uo UserShareMysOrderRepo, logger log.Logger) *UserShareMysOrder { + return &UserShareMysOrder{ud: uo, log: log.NewHelper(logger)} +} + +// GetUserIdByToken +// +// @Description: 通过token获取用户Id +// @receiver uo +// @param ctx +// @return int64 +// @return error +func (uo *UserShareMysOrder) GetUserIdByToken(ctx context.Context) (int64, bool, error) { + userId, err := uo.ud.CheckToken(ctx) + if err != nil { + return 0, false, flags.ErrTokenMessage + } + + return int64(userId), true, nil +} + +// BotStockMysTradeList +// +// @Description: 订单列表 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param status +// @return []*models.BotStockMysTrade +// @return int64 +// @return error +func (uo *UserShareMysOrder) BotStockMysTradeList(ctx context.Context, pageSize, pageCount, status int64) ([]*models.BotStockMysTrade, int64, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return nil, 0, flags.ErrTokenMessage + } + + stockList, totalCount, err := uo.ud.GetBotStockMysTradeList(ctx, pageSize, pageCount-1, userId, status) + if err != nil { + return nil, 0, err + } + + return stockList, totalCount, nil +} + +// ShareMysPlaceOrder +// +// @Description: 下单 +// @receiver uo +// @param ctx +// @param order +// @return string +// @return error +func (uo *UserShareMysOrder) ShareMysPlaceOrder(ctx context.Context, order structure.ShareOrder) (string, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.SetNull, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.SetNull, flags.ErrIsReal + } + + orderId, err := uo.ud.PlacingStockMysOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + + return orderId, nil +} + +// ShareMysUpdateOrder +// +// @Description: 设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *UserShareMysOrder) ShareMysUpdateOrder(ctx context.Context, order structure.StopOrder) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockMysStopByOrderId(ctx, order) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareMysCancel +// +// @Description: 撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareMysOrder) ShareMysCancel(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockMysCancelByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareMysPosition +// +// @Description: 平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareMysOrder) ShareMysPosition(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockMysClosingByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareMysAllPosition +// +// @Description: 一键平仓 +// @receiver uo +// @param ctx +// @return error +func (uo *UserShareMysOrder) ShareMysAllPosition(ctx context.Context) error { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.ErrIsReal + } + + if err = uo.ud.UpdateBotStockMysAllClosingByOrderId(ctx, userId); err != nil { + return err + } + + return nil +} diff --git a/internal/biz/share_sgd.go b/internal/biz/share_sgd.go new file mode 100644 index 0000000..7c09a5e --- /dev/null +++ b/internal/biz/share_sgd.go @@ -0,0 +1,211 @@ +package biz + +import ( + "context" + + "github.com/go-kratos/kratos/v2/log" + + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + + models "matchmaking-system/internal/pkg/model" +) + +// UserShareSgdOrder +// @Description: +type UserShareSgdOrder struct { + ud UserShareSgdOrderRepo + + log *log.Helper +} + +// UserShareSgdOrderRepo +// @Description: 订单操作(订单列表|下单|设置止盈止损|撤单|平仓|一键平仓) +type UserShareSgdOrderRepo interface { + CheckToken(ctx context.Context) (int, error) + GetBotUserIsRealByUserId(ctx context.Context, userId int) bool + GetBotStockSgdTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockSgdTrade, int64, error) + PlacingStockSgdOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) + UpdateBotStockSgdStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) + UpdateBotStockSgdCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockSgdClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockSgdAllClosingByOrderId(ctx context.Context, userId int64) error +} + +// NewUserShareSgdOrderRepo +// +// @Description: +// @param uo +// @param logger +// @return *UserSecondOrder +func NewUserShareSgdOrderRepo(uo UserShareSgdOrderRepo, logger log.Logger) *UserShareSgdOrder { + return &UserShareSgdOrder{ud: uo, log: log.NewHelper(logger)} +} + +// GetUserIdByToken +// +// @Description: 通过token获取用户Id +// @receiver uo +// @param ctx +// @return int64 +// @return error +func (uo *UserShareSgdOrder) GetUserIdByToken(ctx context.Context) (int64, bool, error) { + userId, err := uo.ud.CheckToken(ctx) + if err != nil { + return 0, false, flags.ErrTokenMessage + } + + return int64(userId), true, nil +} + +// BotStockSgdTradeList +// +// @Description: 订单列表 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param status +// @return []*models.BotStockSgdTrade +// @return int64 +// @return error +func (uo *UserShareSgdOrder) BotStockSgdTradeList(ctx context.Context, pageSize, pageCount, status int64) ([]*models.BotStockSgdTrade, int64, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return nil, 0, flags.ErrTokenMessage + } + + stockList, totalCount, err := uo.ud.GetBotStockSgdTradeList(ctx, pageSize, pageCount-1, userId, status) + if err != nil { + return nil, 0, err + } + + return stockList, totalCount, nil +} + +// ShareSgdPlaceOrder +// +// @Description: 下单 +// @receiver uo +// @param ctx +// @param order +// @return string +// @return error +func (uo *UserShareSgdOrder) ShareSgdPlaceOrder(ctx context.Context, order structure.ShareOrder) (string, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.SetNull, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.SetNull, flags.ErrIsReal + } + + orderId, err := uo.ud.PlacingStockSgdOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + + return orderId, nil +} + +// ShareSgdUpdateOrder +// +// @Description: 设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *UserShareSgdOrder) ShareSgdUpdateOrder(ctx context.Context, order structure.StopOrder) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockSgdStopByOrderId(ctx, order) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareSgdCancel +// +// @Description: 撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareSgdOrder) ShareSgdCancel(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockSgdCancelByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareSgdPosition +// +// @Description: 平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareSgdOrder) ShareSgdPosition(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockSgdClosingByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareSgdAllPosition +// +// @Description: 一键平仓 +// @receiver uo +// @param ctx +// @return error +func (uo *UserShareSgdOrder) ShareSgdAllPosition(ctx context.Context) error { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.ErrIsReal + } + + if err = uo.ud.UpdateBotStockSgdAllClosingByOrderId(ctx, userId); err != nil { + return err + } + + return nil +} diff --git a/internal/biz/share_tha.go b/internal/biz/share_tha.go new file mode 100644 index 0000000..c72efc5 --- /dev/null +++ b/internal/biz/share_tha.go @@ -0,0 +1,211 @@ +package biz + +import ( + "context" + + "github.com/go-kratos/kratos/v2/log" + + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + + models "matchmaking-system/internal/pkg/model" +) + +// UserShareThaOrder +// @Description: +type UserShareThaOrder struct { + ud UserShareThaOrderRepo + + log *log.Helper +} + +// UserShareThaOrderRepo +// @Description: 订单操作(订单列表|下单|设置止盈止损|撤单|平仓|一键平仓) +type UserShareThaOrderRepo interface { + CheckToken(ctx context.Context) (int, error) + GetBotUserIsRealByUserId(ctx context.Context, userId int) bool + GetBotStockThaTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockThaTrade, int64, error) + PlacingStockThaOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) + UpdateBotStockThaStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) + UpdateBotStockThaCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockThaClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockThaAllClosingByOrderId(ctx context.Context, userId int64) error +} + +// NewUserShareThaOrderRepo +// +// @Description: +// @param uo +// @param logger +// @return *UserSecondOrder +func NewUserShareThaOrderRepo(uo UserShareThaOrderRepo, logger log.Logger) *UserShareThaOrder { + return &UserShareThaOrder{ud: uo, log: log.NewHelper(logger)} +} + +// GetUserIdByToken +// +// @Description: 通过token获取用户Id +// @receiver uo +// @param ctx +// @return int64 +// @return error +func (uo *UserShareThaOrder) GetUserIdByToken(ctx context.Context) (int64, bool, error) { + userId, err := uo.ud.CheckToken(ctx) + if err != nil { + return 0, false, flags.ErrTokenMessage + } + + return int64(userId), true, nil +} + +// BotStockThaTradeList +// +// @Description: 订单列表 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param status +// @return []*models.BotStockThaTrade +// @return int64 +// @return error +func (uo *UserShareThaOrder) BotStockThaTradeList(ctx context.Context, pageSize, pageCount, status int64) ([]*models.BotStockThaTrade, int64, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return nil, 0, flags.ErrTokenMessage + } + + stockList, totalCount, err := uo.ud.GetBotStockThaTradeList(ctx, pageSize, pageCount-1, userId, status) + if err != nil { + return nil, 0, err + } + + return stockList, totalCount, nil +} + +// ShareThaPlaceOrder +// +// @Description: 下单 +// @receiver uo +// @param ctx +// @param order +// @return string +// @return error +func (uo *UserShareThaOrder) ShareThaPlaceOrder(ctx context.Context, order structure.ShareOrder) (string, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.SetNull, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.SetNull, flags.ErrIsReal + } + + orderId, err := uo.ud.PlacingStockThaOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + + return orderId, nil +} + +// ShareThaUpdateOrder +// +// @Description: 设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *UserShareThaOrder) ShareThaUpdateOrder(ctx context.Context, order structure.StopOrder) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockThaStopByOrderId(ctx, order) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareThaCancel +// +// @Description: 撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareThaOrder) ShareThaCancel(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockThaCancelByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareThaPosition +// +// @Description: 平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareThaOrder) ShareThaPosition(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockThaClosingByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareThaAllPosition +// +// @Description: 一键平仓 +// @receiver uo +// @param ctx +// @return error +func (uo *UserShareThaOrder) ShareThaAllPosition(ctx context.Context) error { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.ErrIsReal + } + + if err = uo.ud.UpdateBotStockThaAllClosingByOrderId(ctx, userId); err != nil { + return err + } + + return nil +} diff --git a/internal/biz/share_us.go b/internal/biz/share_us.go new file mode 100644 index 0000000..4c286f9 --- /dev/null +++ b/internal/biz/share_us.go @@ -0,0 +1,212 @@ +package biz + +import ( + "context" + + "github.com/go-kratos/kratos/v2/log" + + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + + models "matchmaking-system/internal/pkg/model" +) + +// UserShareUsOrder +// @Description: +type UserShareUsOrder struct { + ud UserShareUsOrderRepo + + log *log.Helper +} + +// UserShareUsOrderRepo +// @Description: 订单操作(订单列表|下单|设置止损止盈|撤单|平仓|一键平仓) +type UserShareUsOrderRepo interface { + CheckToken(ctx context.Context) (int, error) + GetBotUserIsRealByUserId(ctx context.Context, userId int) bool + GetBotStockTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockTrade, int64, error) + PlacingStockOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) + UpdateBotStockStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) + UpdateBotStockCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) + UpdateBotStockAllClosingByOrderId(ctx context.Context, userId int64) error +} + +// NewUserShareUsOrderRepo +// +// @Description: +// @param uo +// @param logger +// @return *UserSecondOrder +func NewUserShareUsOrderRepo(uo UserShareUsOrderRepo, logger log.Logger) *UserShareUsOrder { + return &UserShareUsOrder{ud: uo, log: log.NewHelper(logger)} +} + +// GetUserIdByToken +// +// @Description: 通过token获取用户Id +// @receiver uo +// @param ctx +// @return int64 +// @return error +func (uo *UserShareUsOrder) GetUserIdByToken(ctx context.Context) (int64, bool, error) { + userId, err := uo.ud.CheckToken(ctx) + if err != nil { + return 0, false, flags.ErrTokenMessage + } + + return int64(userId), true, nil +} + +// BotStockTradeList +// +// @Description: 订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param status +// @return []*models.BotStockTrade +// @return int64 +// @return error +func (uo *UserShareUsOrder) BotStockTradeList(ctx context.Context, pageSize, pageCount, status int64) ([]*models.BotStockTrade, int64, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return nil, 0, flags.ErrTokenMessage + } + + stockList, totalCount, err := uo.ud.GetBotStockTradeList(ctx, pageSize, pageCount-1, userId, status) + if err != nil { + return nil, 0, err + } + + return stockList, totalCount, nil +} + +// SharePlaceOrder +// +// @Description: 下单 +// @receiver uo +// @param ctx +// @param order +// @return string +// @return error +func (uo *UserShareUsOrder) SharePlaceOrder(ctx context.Context, order structure.ShareOrder) (string, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.SetNull, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.SetNull, flags.ErrIsReal + } + + // add BotStockTrade + orderId, err := uo.ud.PlacingStockOrders(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + + return orderId, nil +} + +// ShareUpdateOrder +// +// @Description: 设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *UserShareUsOrder) ShareUpdateOrder(ctx context.Context, order structure.StopOrder) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockStopByOrderId(ctx, order) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareCancel +// +// @Description: 撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareUsOrder) ShareCancel(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockCancelByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// SharePosition +// +// @Description: 平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserShareUsOrder) SharePosition(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return false, flags.ErrIsReal + } + + check, err := uo.ud.UpdateBotStockClosingByOrderId(ctx, orderId, 0) + if err != nil { + return false, err + } + + return check, nil +} + +// ShareAllPosition +// +// @Description: 一键平仓 +// @receiver uo +// @param ctx +// @return error +func (uo *UserShareUsOrder) ShareAllPosition(ctx context.Context) error { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.ErrTokenMessage + } + + if !uo.ud.GetBotUserIsRealByUserId(ctx, int(userId)) { + return flags.ErrIsReal + } + + if err = uo.ud.UpdateBotStockAllClosingByOrderId(ctx, userId); err != nil { + return err + } + + return nil +} diff --git a/internal/biz/structure/contract.go b/internal/biz/structure/contract.go new file mode 100644 index 0000000..445aa0e --- /dev/null +++ b/internal/biz/structure/contract.go @@ -0,0 +1,235 @@ +package structure + +// ContractDepth +// @Description: +type ContractDepth struct { + Ch string `json:"ch"` + Status string `json:"status"` + Tick struct { + Mrid int64 `json:"mrid"` + ID int `json:"id"` + Bids [][]float64 `json:"bids"` + Asks [][]float64 `json:"asks"` + Ts int64 `json:"ts"` + Version int `json:"version"` + Ch string `json:"ch"` + } `json:"tick"` + Ts int64 `json:"ts"` +} + +// ContractBbo +// @Description: +type ContractBbo struct { + Status string `json:"status"` + Ticks []struct { + TradePartition string `json:"trade_partition"` + BusinessType string `json:"business_type"` + ContractCode string `json:"contract_code"` + Ask []float64 `json:"ask"` + Bid []float64 `json:"bid"` + Mrid int64 `json:"mrid"` + Ts int64 `json:"ts"` + } `json:"ticks"` + Ts int64 `json:"ts"` +} + +// ContractHistoryKline +// @Description: +type ContractHistoryKline struct { + Ch string `json:"ch"` + Ts int64 `json:"ts"` + Status string `json:"status"` + Data []struct { + ID int `json:"id"` + Open float64 `json:"open"` + Close float64 `json:"close"` + High float64 `json:"high"` + Low float64 `json:"low"` + Amount float64 `json:"amount"` + Vol int `json:"vol"` + TradeTurnover float64 `json:"trade_turnover"` + Count int `json:"count"` + } `json:"data"` +} + +// ContractHistoryPriceKline +// @Description: +type ContractHistoryPriceKline struct { + Ch string `json:"ch"` + Data []struct { + Amount string `json:"amount"` + Close string `json:"close"` + Count string `json:"count"` + High string `json:"high"` + ID int `json:"id"` + Low string `json:"low"` + Open string `json:"open"` + TradeTurnover string `json:"trade_turnover"` + Vol string `json:"vol"` + } `json:"data"` + Status string `json:"status"` + Ts int64 `json:"ts"` +} + +// ContractMerged +// @Description: +type ContractMerged struct { + Ch string `json:"ch"` + Status string `json:"status"` + Tick struct { + Amount string `json:"amount"` + Ask []float64 `json:"ask"` + Bid []float64 `json:"bid"` + Close string `json:"close"` + Count int `json:"count"` + High string `json:"high"` + ID int `json:"id"` + Low string `json:"low"` + Open string `json:"open"` + TradeTurnover string `json:"trade_turnover"` + Ts int64 `json:"ts"` + Vol string `json:"vol"` + } `json:"tick"` + Ts int64 `json:"ts"` +} + +// ContractBatchMerged +// @Description: +type ContractBatchMerged struct { + Status string `json:"status"` + Ticks []struct { + ID int `json:"id"` + Ts int64 `json:"ts"` + Ask []float64 `json:"ask"` + Bid []float64 `json:"bid"` + Open string `json:"open"` + Close string `json:"close"` + Low string `json:"low"` + High string `json:"high"` + Amount string `json:"amount"` + Count int `json:"count"` + Vol string `json:"vol"` + ContractCode string `json:"contract_code"` + NumberOf string `json:"number_of"` + BusinessType string `json:"business_type"` + TradePartition string `json:"trade_partition"` + } `json:"ticks"` + Ts int64 `json:"ts"` +} + +// ContractTrade +// @Description: +type ContractTrade struct { + Ch string `json:"ch"` + Status string `json:"status"` + Tick struct { + Data []struct { + Amount string `json:"amount"` + Quantity string `json:"quantity"` + TradeTurnover string `json:"trade_turnover"` + Ts int64 `json:"ts"` + ID int64 `json:"id"` + Price string `json:"price"` + Direction string `json:"direction"` + ContractCode string `json:"contract_code"` + BusinessType string `json:"business_type"` + TradePartition string `json:"trade_partition"` + } `json:"data"` + ID int64 `json:"id"` + Ts int64 `json:"ts"` + } `json:"tick"` + Ts int64 `json:"ts"` +} + +// ContractHistoryTrade +// @Description: +type ContractHistoryTrade struct { + Ch string `json:"ch"` + Ts int64 `json:"ts"` + Status string `json:"status"` + Data []struct { + ID int64 `json:"id"` + Ts int64 `json:"ts"` + Data []struct { + Amount int `json:"amount"` + Quantity float64 `json:"quantity"` + TradeTurnover float64 `json:"trade_turnover"` + Ts int64 `json:"ts"` + ID int64 `json:"id"` + Price float64 `json:"price"` + Direction string `json:"direction"` + } `json:"data"` + } `json:"data"` +} + +// ContractsWapHisOpenInterest +// @Description: +type ContractsWapHisOpenInterest struct { + Status string `json:"status"` + Data struct { + Symbol string `json:"symbol"` + Tick []struct { + Volume float64 `json:"volume"` + AmountType int `json:"amount_type"` + Ts int64 `json:"ts"` + Value float64 `json:"value"` + } `json:"tick"` + ContractCode string `json:"contract_code"` + BusinessType string `json:"business_type"` + Pair string `json:"pair"` + ContractType string `json:"contract_type"` + TradePartition string `json:"trade_partition"` + } `json:"data"` + Ts int64 `json:"ts"` +} + +// ContractHistoryLinearSwapPremiumIndexKline +// @Description: +type ContractHistoryLinearSwapPremiumIndexKline struct { + Ch string `json:"ch"` + Data []struct { + Amount string `json:"amount"` + Close string `json:"close"` + Count string `json:"count"` + High string `json:"high"` + ID int `json:"id"` + Low string `json:"low"` + Open string `json:"open"` + Vol string `json:"vol"` + } `json:"data"` + Status string `json:"status"` + Ts int64 `json:"ts"` +} + +// ContractHistoryLinearSwapEstimatedRateKline +// @Description: +type ContractHistoryLinearSwapEstimatedRateKline struct { + Ch string `json:"ch"` + Data []struct { + Amount string `json:"amount"` + Close string `json:"close"` + Count string `json:"count"` + High string `json:"high"` + ID int `json:"id"` + Low string `json:"low"` + Open string `json:"open"` + Vol string `json:"vol"` + } `json:"data"` + Status string `json:"status"` + Ts int64 `json:"ts"` +} + +// ContractHistoryLinearSwapBasis +// @Description: +type ContractHistoryLinearSwapBasis struct { + Ch string `json:"ch"` + Data []struct { + Basis string `json:"basis"` + BasisRate string `json:"basis_rate"` + ContractPrice string `json:"contract_price"` + ID int `json:"id"` + IndexPrice string `json:"index_price"` + } `json:"data"` + Status string `json:"status"` + Ts int64 `json:"ts"` +} diff --git a/internal/biz/structure/model.go b/internal/biz/structure/model.go new file mode 100644 index 0000000..b5ab78a --- /dev/null +++ b/internal/biz/structure/model.go @@ -0,0 +1,421 @@ +package structure + +import "time" + +// InTraDay +// @Description: +type InTraDay struct { + Timestamp int `json:"timestamp"` + GmtOffset int `json:"gmtOffset"` + Datetime string `json:"datetime"` + Open float64 `json:"open"` + High float64 `json:"high"` + Low float64 `json:"low"` + Close float64 `json:"close"` + Volume int `json:"volume"` +} + +// Eod +// @Description: +type Eod struct { + Date string `json:"date"` + Open float64 `json:"open"` + High float64 `json:"high"` + Low float64 `json:"low"` + Close float64 `json:"close"` + AdjustedClose float64 `json:"adjusted_close"` + Volume int `json:"volume"` +} + +// Aggregates +// @Description: +type Aggregates struct { + Ticker string `json:"ticker"` + QueryCount int `json:"queryCount"` + ResultsCount int `json:"resultsCount"` + Adjusted bool `json:"adjusted"` + Results []struct { + V float64 `json:"v"` + Vw float64 `json:"vw"` + O float64 `json:"o"` + C float64 `json:"c"` + H float64 `json:"h"` + L float64 `json:"l"` + T int64 `json:"t"` + N int64 `json:"n"` + } `json:"results"` + Status string `json:"status"` + RequestID string `json:"request_id"` + Count int `json:"count"` +} + +// Grouped +// @Description: +type Grouped struct { + QueryCount int `json:"queryCount"` + ResultsCount int `json:"resultsCount"` + Adjusted bool `json:"adjusted"` + Results []struct { + T string `json:"T"` + V int `json:"v"` + Vw float64 `json:"vw,omitempty"` + O float64 `json:"o"` + C float64 `json:"c"` + H float64 `json:"h"` + L float64 `json:"l"` + T0 int64 `json:"t"` + N int `json:"n,omitempty"` + } `json:"results"` + Status string `json:"status"` + RequestID string `json:"request_id"` + Count int `json:"count"` +} + +// OpenClose +// @Description: +type OpenClose struct { + Status string `json:"status"` + From string `json:"from"` + Symbol string `json:"symbol"` + Open float64 `json:"open"` + High float64 `json:"high"` + Low float64 `json:"low"` + Close float64 `json:"close"` + Volume int `json:"volume"` + AfterHours float64 `json:"afterHours"` + PreMarket float64 `json:"preMarket"` +} + +// PreviousClose +// @Description: +type PreviousClose struct { + Ticker string `json:"ticker"` + QueryCount int `json:"queryCount"` + ResultsCount int `json:"resultsCount"` + Adjusted bool `json:"adjusted"` + Results []struct { + T string `json:"T"` + V int `json:"v"` + Vw float64 `json:"vw"` + O float64 `json:"o"` + C float64 `json:"c"` + H float64 `json:"h"` + L float64 `json:"l"` + T0 int64 `json:"t"` + N int `json:"n"` + } `json:"results"` + Status string `json:"status"` + RequestID string `json:"request_id"` + Count int `json:"count"` +} + +// Trades +// @Description: +type Trades struct { + Results []struct { + Conditions []int `json:"conditions"` + Exchange int `json:"exchange"` + ID string `json:"id"` + ParticipantTimestamp int64 `json:"participant_timestamp"` + Price float64 `json:"price"` + SequenceNumber int `json:"sequence_number"` + SipTimestamp int64 `json:"sip_timestamp"` + Size int `json:"size"` + Tape int `json:"tape"` + } `json:"results"` + Status string `json:"status"` + RequestID string `json:"request_id"` + NextURL string `json:"next_url"` +} + +// LastTrade +// @Description: +type LastTrade struct { + Results struct { + T string `json:"T"` + C []int `json:"c"` + I string `json:"i"` + P float64 `json:"p"` + Q int `json:"q"` + S int `json:"s"` + T0 int64 `json:"t"` + X int `json:"x"` + Y int64 `json:"y"` + Z int `json:"z"` + } `json:"results"` + Status string `json:"status"` + RequestID string `json:"request_id"` +} + +// Quotes +// @Description: +type Quotes struct { + Results []struct { + AskExchange int `json:"ask_exchange"` + AskPrice float64 `json:"ask_price"` + AskSize int `json:"ask_size"` + BidExchange int `json:"bid_exchange"` + BidPrice float64 `json:"bid_price"` + BidSize int `json:"bid_size"` + Indicators []int `json:"indicators"` + ParticipantTimestamp int64 `json:"participant_timestamp"` + SequenceNumber int `json:"sequence_number"` + SipTimestamp int64 `json:"sip_timestamp"` + Tape int `json:"tape"` + } `json:"results"` + Status string `json:"status"` + RequestID string `json:"request_id"` + NextURL string `json:"next_url"` +} + +// LastQuote +// @Description: +type LastQuote struct { + Results struct { + P float64 `json:"P"` + S int `json:"S"` + T string `json:"T"` + X int `json:"X"` + I []int `json:"i"` + P0 float64 `json:"p"` + Q int `json:"q"` + S0 int `json:"s"` + T0 int64 `json:"t"` + X0 int `json:"x"` + Y int64 `json:"y"` + Z int `json:"z"` + } `json:"results"` + Status string `json:"status"` + RequestID string `json:"request_id"` +} + +// SnapshotAllTickers +// @Description: +type SnapshotAllTickers struct { + Tickers []struct { + Ticker string `json:"ticker"` + TodaysChangePerc float64 `json:"todaysChangePerc"` + TodaysChange float64 `json:"todaysChange"` + Updated int64 `json:"updated"` + Day struct { + O int `json:"o"` + H int `json:"h"` + L int `json:"l"` + C int `json:"c"` + V int `json:"v"` + Vw int `json:"vw"` + } `json:"day"` + LastQuote struct { + P float64 `json:"P"` + S int `json:"S"` + P0 float64 `json:"p"` + S0 int `json:"s"` + T int64 `json:"t"` + } `json:"lastQuote"` + LastTrade struct { + C []int `json:"c"` + I string `json:"i"` + P float64 `json:"p"` + S int `json:"s"` + T int64 `json:"t"` + X int `json:"x"` + } `json:"lastTrade"` + Min struct { + Av int `json:"av"` + T int64 `json:"t"` + N int `json:"n"` + O float64 `json:"o"` + H float64 `json:"h"` + L float64 `json:"l"` + C float64 `json:"c"` + V int `json:"v"` + Vw float64 `json:"vw"` + } `json:"min"` + PrevDay struct { + O float64 `json:"o"` + H float64 `json:"h"` + L float64 `json:"l"` + C float64 `json:"c"` + V int `json:"v"` + Vw float64 `json:"vw"` + } `json:"prevDay"` + } `json:"tickers"` + Status string `json:"status"` + RequestID string `json:"request_id"` + Count int `json:"count"` +} + +// SnapshotGainersLosers +// @Description: +type SnapshotGainersLosers struct { + Tickers []struct { + Ticker string `json:"ticker"` + TodaysChangePerc float64 `json:"todaysChangePerc"` + TodaysChange float64 `json:"todaysChange"` + Updated int64 `json:"updated"` + Day struct { + O int `json:"o"` + H int `json:"h"` + L int `json:"l"` + C int `json:"c"` + V int `json:"v"` + Vw int `json:"vw"` + } `json:"day"` + LastQuote struct { + P float64 `json:"P"` + S int `json:"S"` + P0 float64 `json:"p"` + S0 int `json:"s"` + T int64 `json:"t"` + } `json:"lastQuote"` + LastTrade struct { + C []int `json:"c"` + I string `json:"i"` + P float64 `json:"p"` + S int `json:"s"` + T int64 `json:"t"` + X int `json:"x"` + } `json:"lastTrade"` + Min struct { + Av int `json:"av"` + T int64 `json:"t"` + N int `json:"n"` + O float64 `json:"o"` + H float64 `json:"h"` + L float64 `json:"l"` + C float64 `json:"c"` + V int `json:"v"` + Vw float64 `json:"vw"` + } `json:"min"` + PrevDay struct { + O float64 `json:"o"` + H float64 `json:"h"` + L float64 `json:"l"` + C float64 `json:"c"` + V int `json:"v"` + Vw float64 `json:"vw"` + } `json:"prevDay"` + } `json:"tickers"` + Status string `json:"status"` + RequestID string `json:"request_id"` +} + +// SnapshotOneTicker +// @Description: +type SnapshotOneTicker struct { + Ticker struct { + Ticker string `json:"ticker"` + TodaysChangePerc float64 `json:"todaysChangePerc"` + TodaysChange float64 `json:"todaysChange"` + Updated int64 `json:"updated"` + Day struct { + O int `json:"o"` + H int `json:"h"` + L int `json:"l"` + C int `json:"c"` + V int `json:"v"` + Vw int `json:"vw"` + } `json:"day"` + LastQuote struct { + P float64 `json:"P"` + S int `json:"S"` + P0 float64 `json:"p"` + S0 int `json:"s"` + T int64 `json:"t"` + } `json:"lastQuote"` + LastTrade struct { + C []int `json:"c"` + I string `json:"i"` + P float64 `json:"p"` + S int `json:"s"` + T int64 `json:"t"` + X int `json:"x"` + } `json:"lastTrade"` + Min struct { + Av int `json:"av"` + T int64 `json:"t"` + N int `json:"n"` + O float64 `json:"o"` + H float64 `json:"h"` + L float64 `json:"l"` + C float64 `json:"c"` + V int `json:"v"` + Vw float64 `json:"vw"` + } `json:"min"` + PrevDay struct { + O float64 `json:"o"` + H float64 `json:"h"` + L float64 `json:"l"` + C float64 `json:"c"` + V int `json:"v"` + Vw float64 `json:"vw"` + } `json:"prevDay"` + } `json:"ticker"` + Status string `json:"status"` + RequestID string `json:"request_id"` +} + +// ReferenceTicker +// @Description: +type ReferenceTicker struct { + Results []struct { + Ticker string `json:"ticker"` + Name string `json:"name"` + Market string `json:"market"` + Locale string `json:"locale"` + PrimaryExchange string `json:"primary_exchange,omitempty"` + Type string `json:"type"` + Active bool `json:"active"` + CurrencyName string `json:"currency_name"` + Cik string `json:"cik,omitempty"` + CompositeFigi string `json:"composite_figi,omitempty"` + ShareClassFigi string `json:"share_class_figi,omitempty"` + LastUpdatedUtc time.Time `json:"last_updated_utc"` + } `json:"results"` + Status string `json:"status"` + RequestID string `json:"request_id"` + Count int `json:"count"` + NextURL string `json:"next_url"` +} + +// ReferenceTickerDetails +// @Description: +type ReferenceTickerDetails struct { + RequestID string `json:"request_id"` + Results struct { + Ticker string `json:"ticker"` + Name string `json:"name"` + Market string `json:"market"` + Locale string `json:"locale"` + PrimaryExchange string `json:"primary_exchange"` + Type string `json:"type"` + Active bool `json:"active"` + CurrencyName string `json:"currency_name"` + Cik string `json:"cik"` + CompositeFigi string `json:"composite_figi"` + ShareClassFigi string `json:"share_class_figi"` + MarketCap int64 `json:"market_cap"` + PhoneNumber string `json:"phone_number"` + Address struct { + Address1 string `json:"address1"` + City string `json:"city"` + State string `json:"state"` + PostalCode string `json:"postal_code"` + } `json:"address"` + Description string `json:"description"` + SicCode string `json:"sic_code"` + SicDescription string `json:"sic_description"` + TickerRoot string `json:"ticker_root"` + HomepageURL string `json:"homepage_url"` + TotalEmployees int `json:"total_employees"` + ListDate string `json:"list_date"` + Branding struct { + LogoURL string `json:"logo_url"` + IconURL string `json:"icon_url"` + } `json:"branding"` + ShareClassSharesOutstanding int64 `json:"share_class_shares_outstanding"` + WeightedSharesOutstanding int64 `json:"weighted_shares_outstanding"` + RoundLot int `json:"round_lot"` + } `json:"results"` + Status string `json:"status"` +} diff --git a/internal/biz/structure/order.go b/internal/biz/structure/order.go new file mode 100644 index 0000000..f68ad99 --- /dev/null +++ b/internal/biz/structure/order.go @@ -0,0 +1,177 @@ +package structure + +import ( + "github.com/shopspring/decimal" + "time" +) + +// StopOrder +// @Description: +type StopOrder struct { + OrderId string `json:"order_id"` // 订单ID + StopType int64 `json:"stop_type"` // 止盈止损 + StopLossPrice string `json:"stop_loss_price"` // 止损 + StopWinPrice string `json:"stop_win_price"` // 止盈 + Type int64 `json:"type"` // 市场 +} + +// ShareOrder +// @Description: +type ShareOrder struct { + StockId string `json:"trading_pair"` // 股票类型 + TradeType int64 `json:"direction"` // 交易类型:1买入,2卖出 + DealType int64 `json:"order_price"` // 委托方式:1限价,2市价 + LimitPrice string `json:"order_quantity"` // 限价 + MarketPrice string `json:"transaction_fee"` // 市价 + MarketMoney string `json:"market_money"` // 订单金额 + OrderNumber string `json:"order_number"` // 订单数量 + ServiceCost string `json:"service_cost"` // 手续费 + StopType int64 `json:"stop_type"` // 止损止盈设置 + StopLossPrice string `json:"stop_loss_price"` // 止损 + StopWinPrice string `json:"stop_win_price"` // 止盈 + UserId int `json:"user_id"` // 用户ID + PryNum string `json:"pry_num"` // 杠杆 + System *ShareSystem `json:"system"` // 系统设置 + Type int64 `json:"type"` // 大宗交易标识 + StockCode string `json:"stock_code"` // 期权订单标识(stockId+到期时间+行权价+(CALLS-CE|PUTS-PE)) + TradingType int64 `json:"trading_type"` // 交易方式: 1-BUY,2-SELLS + StopTime string `json:"stop_time"` // 到期时间 + StrikePrice string `json:"strike_price"` // 期权-行权价 + Multiplier string `json:"multiplier"` // 期权乘数 + Ratio string `json:"ratio"` // 保证金比率 + Bid string `json:"bid"` // 期权买一价 + Ask string `json:"ask"` // 期权卖一价 + OrderNo string `json:"order_no"` // IPO订单ID +} + +// ShareSystem +// @Description: +type ShareSystem struct { + StrongFlatRatio string // 股票强平设置 + Status decimal.Decimal // 杠杠状态 + StockMin decimal.Decimal // 触发杠杆最小值 + LevelMin decimal.Decimal // 最小杠杆值 + LevelMax decimal.Decimal // 最大杠杆值 + UserStatus string // 用户是否开启杠杆权限 +} + +// SpotsOrder +// @Description: +type SpotsOrder struct { + DigitalId string `json:"digital_id"` //交易对 + TradeType int64 `json:"trade_type"` //交易类型:1买入,2卖出 + DealType int64 `json:"deal_type"` //委托方式:1限价,2市价 + DealPrice string `json:"deal_price"` //订单价格 + LimitPrice string `json:"limit_price"` //限价 + MarketPrice string `json:"market_price"` //市价 + OrderNumber string `json:"order_number"` //订单数量 + OrderMoney string `json:"order_money"` //订单金额 + ServiceCost string `json:"service_cost"` //手续费 +} + +// ContractOrder +// @Description: +type ContractOrder struct { + ContractId string `json:"contract_id"` // 交易对 + TradeType int64 `json:"trade_type"` // 交易类型:1买入,2卖出 + DealType int64 `json:"deal_type"` // 委托方式:1限价,2市价 + LimitPrice string `json:"limit_price"` // 限价 + MarketPrice string `json:"market_price"` // 市价 + OrderAmount string `json:"order_amount"` // 订单价格 + OrderNumber string `json:"order_number"` // 订单数量 + EarnestMoney string `json:"earnest_money"` // 保证金 + ServiceCost string `json:"service_cost"` // 手续费 + StopType int64 `json:"stop_type"` // 止损止盈设置:0无设置,1止损止盈 + StopLossPrice string `json:"stop_loss_price"` // 止损 + StopWinPrice string `json:"stop_win_price"` // 止盈 + PryNum string `json:"pry_num"` // 杠杆 + System *ContractSystem `json:"system"` // 合约下单设置 + Proportion map[int64]ProportionSystem `json:"proportion"` // 秒合约比例值 + Time int64 `json:"time"` // 秒合约 + StopTime time.Time `json:"stop_time"` // 秒合约-平仓时间 +} + +// ProportionSystem +// @Description: +type ProportionSystem struct { + Value string // 比例值 +} + +// ContractTimeSetting +// @Description: +type ContractTimeSetting struct { + TimeStep int64 `json:"time_step"` // 秒合约-时间设置 + EarningsNum int64 `json:"earnings_num"` // 秒合约-比例配置 +} + +// ForexOrder +// @Description: +type ForexOrder struct { + ForexId string `json:"forex_id"` // 交易对 + TradeType int64 `json:"trade_type"` // 交易类型:1买入,2卖出 + DealType int64 `json:"deal_type"` // 委托方式:1限价,2市价 + LimitPrice string `json:"limit_price"` // 限价 + MarketPrice string `json:"market_price"` // 市价 + OrderAmount string `json:"order_amount"` // 订单价格 + OrderNumber string `json:"order_number"` // 订单数量 + EarnestMoney string `json:"earnest_money"` // 保证金 + ServiceCost string `json:"service_cost"` // 手续费 + StopType int64 `json:"stop_type"` // 止损止盈设置:0无设置,1止损止盈 + StopLossPrice string `json:"stop_loss_price"` // 止损 + StopWinPrice string `json:"stop_win_price"` // 止盈 + PryNum string `json:"pry_num"` // 杠杆 + System *ForexSystem `json:"system"` // 合约下单设置 + Proportion map[int64]ProportionSystem `json:"proportion"` // 秒合约比例值 + Time int64 `json:"time"` // 秒合约 + StopTime time.Time `json:"stop_time"` // 秒合约-平仓时间 +} + +// ForexOrder +// @Description: +type MoneyOrder struct { + StockId string `json:"stock_id"` // 交易对 + TradeType int64 `json:"trade_type"` // 交易类型:1买入,2卖出 + DealType int64 `json:"deal_type"` // 委托方式:1限价,2市价 + LimitPrice string `json:"limit_price"` // 限价 + MarketPrice string `json:"market_price"` // 市价 + OrderAmount string `json:"order_amount"` // 订单价格 + OrderNumber string `json:"order_number"` // 订单数量 + EarnestMoney string `json:"earnest_money"` // 保证金 + ServiceCost string `json:"service_cost"` // 手续费 + StopType int64 `json:"stop_type"` // 止损止盈设置:0无设置,1止损止盈 + StopLossPrice string `json:"stop_loss_price"` // 止损 + StopWinPrice string `json:"stop_win_price"` // 止盈 + PryNum string `json:"pry_num"` // 杠杆 + System *ForexSystem `json:"system"` // 合约下单设置 + Proportion map[int64]ProportionSystem `json:"proportion"` // 秒合约比例值 + Time int64 `json:"time"` // 秒合约 + StopTime time.Time `json:"stop_time"` // 秒合约-平仓时间 + Type int64 `json:"type"` // 市场标识 +} + +// ContractSystem +// @Description: 合约系统设置 +type ContractSystem struct { + FaceValue decimal.Decimal // 合约面值 + CompelNum decimal.Decimal // 强平阈值 + MaxPry decimal.Decimal // 最大杠杆 + MinPry decimal.Decimal // 最小杠杆 +} + +// ForexSystem +// @Description: 外汇系统设置 +type ForexSystem struct { + FaceValue decimal.Decimal // 合约面值 + CompelNum decimal.Decimal // 强平阈值 + MaxPry decimal.Decimal // 最大杠杆 + MinPry decimal.Decimal // 最小杠杆 +} + +// MoneySystem +// @Description: 综合(现货|合约|外汇)系统设置 +type MoneySystem struct { + FaceValue decimal.Decimal // 合约面值 + CompelNum decimal.Decimal // 强平阈值 + MaxPry decimal.Decimal // 最大杠杆 + MinPry decimal.Decimal // 最小杠杆 +} diff --git a/internal/biz/structure/spots.go b/internal/biz/structure/spots.go new file mode 100644 index 0000000..2f3c12c --- /dev/null +++ b/internal/biz/structure/spots.go @@ -0,0 +1,134 @@ +package structure + +// SpotsKline +// @Description: +type SpotsKline struct { + Ch string `json:"ch"` + Status string `json:"status"` + Ts int64 `json:"ts"` + Data []struct { + ID int `json:"id"` + Open float64 `json:"open"` + Close float64 `json:"close"` + Low float64 `json:"low"` + High float64 `json:"high"` + Amount float64 `json:"amount"` + Vol float64 `json:"vol"` + Count int `json:"count"` + } `json:"data"` +} + +// SpotsMerged +// @Description: +type SpotsMerged struct { + Ch string `json:"ch"` + Status string `json:"status"` + Ts int64 `json:"ts"` + Tick struct { + ID int64 `json:"id"` + Version int64 `json:"version"` + Open float64 `json:"open"` + Close float64 `json:"close"` + Low float64 `json:"low"` + High float64 `json:"high"` + Amount float64 `json:"amount"` + Vol float64 `json:"vol"` + Count int `json:"count"` + Bid []float64 `json:"bid"` + Ask []float64 `json:"ask"` + } `json:"tick"` +} + +// SpotsTickers +// @Description: +type SpotsTickers struct { + Data []struct { + Symbol string `json:"symbol"` + Open float64 `json:"open"` + High float64 `json:"high"` + Low float64 `json:"low"` + Close float64 `json:"close"` + Amount float64 `json:"amount"` + Vol float64 `json:"vol"` + Count int `json:"count"` + Bid float64 `json:"bid"` + BidSize float64 `json:"bidSize"` + Ask float64 `json:"ask"` + AskSize float64 `json:"askSize"` + } `json:"data"` + Status string `json:"status"` + Ts int64 `json:"ts"` +} + +// SpotsDepth +// @Description: +type SpotsDepth struct { + Ch string `json:"ch"` + Status string `json:"status"` + Ts int64 `json:"ts"` + Tick struct { + Ts int64 `json:"ts"` + Version int64 `json:"version"` + Bids [][]float64 `json:"bids"` + Asks [][]float64 `json:"asks"` + } `json:"tick"` +} + +// SpotsTrade +// @Description: +type SpotsTrade struct { + Ch string `json:"ch"` + Status string `json:"status"` + Ts int64 `json:"ts"` + Tick struct { + ID int64 `json:"id"` + Ts int64 `json:"ts"` + Data []struct { + ID int64 `json:"id"` + Ts int64 `json:"ts"` + TradeID int64 `json:"trade_id"` + Amount float64 `json:"amount"` + Price float64 `json:"price"` + Direction string `json:"direction"` + } `json:"data"` + } `json:"tick"` +} + +// SpotsHistoryTrade +// @Description: +type SpotsHistoryTrade struct { + Ch string `json:"ch"` + Status string `json:"status"` + Ts int64 `json:"ts"` + Data []struct { + ID int64 `json:"id"` + Ts int64 `json:"ts"` + Data []struct { + ID int64 `json:"id"` + Ts int64 `json:"ts"` + TradeID int64 `json:"trade_id"` + Amount float64 `json:"amount"` + Price float64 `json:"price"` + Direction string `json:"direction"` + } `json:"data"` + } `json:"data"` +} + +// SpotsDetail +// @Description: +type SpotsDetail struct { + Ch string `json:"ch"` + Status string `json:"status"` + Ts int64 `json:"ts"` + Tick struct { + ID int64 `json:"id"` + Low float64 `json:"low"` + High float64 `json:"high"` + Open float64 `json:"open"` + Close float64 `json:"close"` + Vol float64 `json:"vol"` + Amount float64 `json:"amount"` + Version int64 `json:"version"` + Count int `json:"count"` + } `json:"tick"` +} diff --git a/internal/biz/virtual_contract.go b/internal/biz/virtual_contract.go new file mode 100644 index 0000000..78180dc --- /dev/null +++ b/internal/biz/virtual_contract.go @@ -0,0 +1,190 @@ +package biz + +import ( + "context" + + "github.com/go-kratos/kratos/v2/log" + + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + + models "matchmaking-system/internal/pkg/model" +) + +// UserContractOrder +// @Description: +type UserContractOrder struct { + ud UserContractOrderRepo + + log *log.Helper +} + +// UserContractOrderRepo +// @Description: 操作订单(订单列表|下单|设置止损止盈|撤单|平仓|一键平仓) +type UserContractOrderRepo interface { + CheckToken(ctx context.Context) (int, error) + GetBotContractTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotContractTrade, int64, error) + CreateBotContractTrade(ctx context.Context, userId int64, order structure.ContractOrder) (string, error) + UpdateBotContractStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) + UpdateBotContractCancelByOrderId(ctx context.Context, orderId string) (bool, error) + UpdateBotContractClosingByOrderId(ctx context.Context, orderId string) (bool, error) + UpdateBotContractClosingAllByOrderId(ctx context.Context, userId int64) error +} + +// NewUserContractOrderRepo +// +// @Description: +// @param uo +// @param logger +// @return *UserSecondOrder +func NewUserContractOrderRepo(uo UserContractOrderRepo, logger log.Logger) *UserContractOrder { + return &UserContractOrder{ud: uo, log: log.NewHelper(logger)} +} + +// GetUserIdByToken +// +// @Description: 通过token获取用户Id +// @receiver uo +// @param ctx +// @return int64 +// @return error +func (uo *UserContractOrder) GetUserIdByToken(ctx context.Context) (int64, bool, error) { + userId, err := uo.ud.CheckToken(ctx) + if err != nil { + return 0, false, flags.ErrTokenMessage + } + + return int64(userId), true, nil +} + +// BotContractTradeList +// +// @Description: 订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param status +// @return []*models.BotContractTrade +// @return int64 +// @return error +func (uo *UserContractOrder) BotContractTradeList(ctx context.Context, pageSize, pageCount, status int64) ([]*models.BotContractTrade, int64, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if userId == 0 || err != nil || !token { + return nil, 0, flags.ErrTokenMessage + } + + contractList, totalCount, err := uo.ud.GetBotContractTradeList(ctx, pageSize, pageCount-1, userId, status) + if err != nil { + return nil, 0, err + } + + return contractList, totalCount, nil +} + +// ContractPlaceOrder +// +// @Description: 委托订单 +// @receiver uo +// @param ctx +// @param order +// @return string +// @return error +func (uo *UserContractOrder) ContractPlaceOrder(ctx context.Context, order structure.ContractOrder) (string, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.SetNull, flags.ErrTokenMessage + } + + orderId, err := uo.ud.CreateBotContractTrade(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + + return orderId, nil +} + +// ContractUpdatePlaceOrder +// +// @Description: 设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *UserContractOrder) ContractUpdatePlaceOrder(ctx context.Context, order structure.StopOrder) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + check, err := uo.ud.UpdateBotContractStopByOrderId(ctx, order) + if err != nil { + return false, err + } + + return check, nil +} + +// ContractCancel +// +// @Description: 撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserContractOrder) ContractCancel(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + check, err := uo.ud.UpdateBotContractCancelByOrderId(ctx, orderId) + if err != nil { + return false, err + } + + return check, nil +} + +// ContractPosition +// +// @Description: 平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserContractOrder) ContractPosition(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + check, err := uo.ud.UpdateBotContractClosingByOrderId(ctx, orderId) + if err != nil { + return false, err + } + + return check, nil +} + +// ContractAllPosition +// +// @Description: 一键平仓 +// @receiver uo +// @param ctx +// @return error +func (uo *UserContractOrder) ContractAllPosition(ctx context.Context) error { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.ErrTokenMessage + } + + if err = uo.ud.UpdateBotContractClosingAllByOrderId(ctx, userId); err != nil { + return err + } + + return nil +} diff --git a/internal/biz/virtual_second.go b/internal/biz/virtual_second.go new file mode 100644 index 0000000..9cdcdd5 --- /dev/null +++ b/internal/biz/virtual_second.go @@ -0,0 +1,103 @@ +package biz + +import ( + "context" + + "github.com/go-kratos/kratos/v2/log" + + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + + models "matchmaking-system/internal/pkg/model" +) + +// UserSecondOrder +// @Description: +type UserSecondOrder struct { + ud UserSecondOrderRepo + + log *log.Helper +} + +// UserSecondOrderRepo +// @Description: 订单操作(订单列表|下单) +type UserSecondOrderRepo interface { + CheckToken(ctx context.Context) (int, error) + GetBotSecondTradeList(pageSize, pageCount, userId, status int64) ([]*models.BotContractSecTrade, int64, error) + CreateSecondBotContractTrade(ctx context.Context, userId int64, order structure.ContractOrder) (string, error) +} + +// NewUserSecondOrderRepo +// +// @Description: +// @param uo +// @param logger +// @return *UserSecondOrder +func NewUserSecondOrderRepo(uo UserSecondOrderRepo, logger log.Logger) *UserSecondOrder { + return &UserSecondOrder{ud: uo, log: log.NewHelper(logger)} +} + +// GetUserIdByToken +// +// @Description: 通过token获取用户Id +// @receiver uo +// @param ctx +// @return int64 +// @return bool +// @return error +func (uo *UserSecondOrder) GetUserIdByToken(ctx context.Context) (int64, bool, error) { + userId, err := uo.ud.CheckToken(ctx) + if err != nil { + return 0, false, flags.ErrTokenMessage + } + + return int64(userId), true, nil +} + +// SecondTradeList +// +// @Description: 订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param status +// @param state +// @return []*models.BotContractTrade +// @return int64 +// @return error +func (uo *UserSecondOrder) SecondTradeList(ctx context.Context, pageSize, pageCount, status int64) ([]*models.BotContractSecTrade, int64, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if userId == 0 || err != nil || !token { + return nil, 0, flags.ErrTokenMessage + } + + contractList, totalCount, err := uo.ud.GetBotSecondTradeList(pageSize, pageCount-1, userId, status) + if err != nil { + return nil, 0, err + } + + return contractList, totalCount, nil +} + +// SecondOrder +// +// @Description: 下单 +// @receiver uo +// @param ctx +// @param order +// @return string +// @return error +func (uo *UserSecondOrder) SecondOrder(ctx context.Context, order structure.ContractOrder) (string, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.SetNull, flags.ErrTokenMessage + } + + orderId, err := uo.ud.CreateSecondBotContractTrade(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + + return orderId, nil +} diff --git a/internal/biz/virtual_spots.go b/internal/biz/virtual_spots.go new file mode 100644 index 0000000..de5ecfe --- /dev/null +++ b/internal/biz/virtual_spots.go @@ -0,0 +1,150 @@ +package biz + +import ( + "context" + + "github.com/go-kratos/kratos/v2/log" + + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + + models "matchmaking-system/internal/pkg/model" +) + +// UserSpotsOrder +// @Description: +type UserSpotsOrder struct { + ud UserSpotsOrderRepo + + log *log.Helper +} + +// UserContractOrderRepo +// @Description: 操作(订单列表|下单|撤单) +type UserSpotsOrderRepo interface { + CheckToken(ctx context.Context) (int, error) + GetBotDigitalTradeList(pageSize, pageCount, userId, status int64) ([]*models.BotDigitalTrade, int64, error) + GetBotDigitalTradeByOrderId(orderId string) ([]models.BotDigitalTrade, error) + CreateBotDigitalTrade(ctx context.Context, userId int64, order structure.SpotsOrder) (string, error) + CreateOneClickRedemption(ctx context.Context, userId int64, order structure.SpotsOrder) (string, error) + UpdateBotDigitalCancelByOrderId(ctx context.Context, orderId string) (bool, error) +} + +// NewUserSpotsOrderRepo +// +// @Description: +// @param uo +// @param logger +// @return *UserSecondOrder +func NewUserSpotsOrderRepo(uo UserSpotsOrderRepo, logger log.Logger) *UserSpotsOrder { + return &UserSpotsOrder{ud: uo, log: log.NewHelper(logger)} +} + +// GetUserIdByToken +// +// @Description: 通过token获取用户Id +// @receiver uo +// @param ctx +// @return int64 +// @return error +func (uo *UserSpotsOrder) GetUserIdByToken(ctx context.Context) (int64, bool, error) { + userId, err := uo.ud.CheckToken(ctx) + if err != nil { + return 0, false, flags.ErrTokenMessage + } + + return int64(userId), true, nil +} + +// BotDigitalTradeList +// +// @Description: 订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param status +// @return []*models.BotDigitalTrade +// @return int64 +// @return error +func (uo *UserSpotsOrder) BotDigitalTradeList(ctx context.Context, pageSize, pageCount, status int64) ([]*models.BotDigitalTrade, int64, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if userId == 0 || err != nil || !token { + return nil, 0, flags.ErrTokenMessage + } + + digitalList, totalCount, err := uo.ud.GetBotDigitalTradeList(pageSize, pageCount-1, userId, status) + if err != nil { + return nil, 0, err + } + + return digitalList, totalCount, nil +} + +// SpotsPlaceOrder +// +// @Description: 委托订单 +// @receiver uo +// @param ctx +// @param order +// @return string +// @return error +func (uo *UserSpotsOrder) SpotsPlaceOrder(ctx context.Context, order structure.SpotsOrder) (string, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.SetNull, flags.ErrTokenMessage + } + + // create BotDigitalTrade + orderId, err := uo.ud.CreateBotDigitalTrade(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + + return orderId, nil +} + +// SpotsCancel +// +// @Description: 撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *UserSpotsOrder) SpotsCancel(ctx context.Context, orderId string) (bool, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return false, flags.ErrTokenMessage + } + + check, err := uo.ud.UpdateBotDigitalCancelByOrderId(ctx, orderId) + if err != nil { + return false, err + } + + return check, nil +} + +// SpotsOneClickRedemption +// +// @Description: 一键兑换 +// @receiver uo +// @param ctx +// @param order +// @return string +// @return error +func (uo *UserSpotsOrder) SpotsOneClickRedemption(ctx context.Context, order structure.SpotsOrder) (string, error) { + userId, token, err := uo.GetUserIdByToken(ctx) + if !token || err != nil || userId == 0 { + return flags.SetNull, flags.ErrTokenMessage + } + + // create BotDigitalTrade + orderId, err := uo.ud.CreateOneClickRedemption(ctx, userId, order) + if err != nil { + return flags.SetNull, err + } + + return orderId, nil +} diff --git a/internal/conf/conf.pb.go b/internal/conf/conf.pb.go new file mode 100644 index 0000000..5f4785f --- /dev/null +++ b/internal/conf/conf.pb.go @@ -0,0 +1,848 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: conf/conf.proto + +package conf + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type Bootstrap struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Server *Server `protobuf:"bytes,1,opt,name=server,proto3" json:"server,omitempty"` + Data *Data `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` +} + +func (x *Bootstrap) Reset() { + *x = Bootstrap{} + if protoimpl.UnsafeEnabled { + mi := &file_conf_conf_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Bootstrap) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Bootstrap) ProtoMessage() {} + +func (x *Bootstrap) ProtoReflect() protoreflect.Message { + mi := &file_conf_conf_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Bootstrap.ProtoReflect.Descriptor instead. +func (*Bootstrap) Descriptor() ([]byte, []int) { + return file_conf_conf_proto_rawDescGZIP(), []int{0} +} + +func (x *Bootstrap) GetServer() *Server { + if x != nil { + return x.Server + } + return nil +} + +func (x *Bootstrap) GetData() *Data { + if x != nil { + return x.Data + } + return nil +} + +type Server struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Http *Server_HTTP `protobuf:"bytes,1,opt,name=http,proto3" json:"http,omitempty"` + Grpc *Server_GRPC `protobuf:"bytes,2,opt,name=grpc,proto3" json:"grpc,omitempty"` + Check string `protobuf:"bytes,3,opt,name=check,proto3" json:"check,omitempty"` +} + +func (x *Server) Reset() { + *x = Server{} + if protoimpl.UnsafeEnabled { + mi := &file_conf_conf_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Server) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Server) ProtoMessage() {} + +func (x *Server) ProtoReflect() protoreflect.Message { + mi := &file_conf_conf_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Server.ProtoReflect.Descriptor instead. +func (*Server) Descriptor() ([]byte, []int) { + return file_conf_conf_proto_rawDescGZIP(), []int{1} +} + +func (x *Server) GetHttp() *Server_HTTP { + if x != nil { + return x.Http + } + return nil +} + +func (x *Server) GetGrpc() *Server_GRPC { + if x != nil { + return x.Grpc + } + return nil +} + +func (x *Server) GetCheck() string { + if x != nil { + return x.Check + } + return "" +} + +type Data struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Database *Data_Database `protobuf:"bytes,1,opt,name=database,proto3" json:"database,omitempty"` + Redis *Data_Redis `protobuf:"bytes,2,opt,name=redis,proto3" json:"redis,omitempty"` + Mongodb *Data_Mongodb `protobuf:"bytes,3,opt,name=mongodb,proto3" json:"mongodb,omitempty"` + Mq *Data_Mq `protobuf:"bytes,4,opt,name=mq,proto3" json:"mq,omitempty"` +} + +func (x *Data) Reset() { + *x = Data{} + if protoimpl.UnsafeEnabled { + mi := &file_conf_conf_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Data) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Data) ProtoMessage() {} + +func (x *Data) ProtoReflect() protoreflect.Message { + mi := &file_conf_conf_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Data.ProtoReflect.Descriptor instead. +func (*Data) Descriptor() ([]byte, []int) { + return file_conf_conf_proto_rawDescGZIP(), []int{2} +} + +func (x *Data) GetDatabase() *Data_Database { + if x != nil { + return x.Database + } + return nil +} + +func (x *Data) GetRedis() *Data_Redis { + if x != nil { + return x.Redis + } + return nil +} + +func (x *Data) GetMongodb() *Data_Mongodb { + if x != nil { + return x.Mongodb + } + return nil +} + +func (x *Data) GetMq() *Data_Mq { + if x != nil { + return x.Mq + } + return nil +} + +type Server_HTTP struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Network string `protobuf:"bytes,1,opt,name=network,proto3" json:"network,omitempty"` + Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` +} + +func (x *Server_HTTP) Reset() { + *x = Server_HTTP{} + if protoimpl.UnsafeEnabled { + mi := &file_conf_conf_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Server_HTTP) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Server_HTTP) ProtoMessage() {} + +func (x *Server_HTTP) ProtoReflect() protoreflect.Message { + mi := &file_conf_conf_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Server_HTTP.ProtoReflect.Descriptor instead. +func (*Server_HTTP) Descriptor() ([]byte, []int) { + return file_conf_conf_proto_rawDescGZIP(), []int{1, 0} +} + +func (x *Server_HTTP) GetNetwork() string { + if x != nil { + return x.Network + } + return "" +} + +func (x *Server_HTTP) GetAddr() string { + if x != nil { + return x.Addr + } + return "" +} + +type Server_GRPC struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Network string `protobuf:"bytes,1,opt,name=network,proto3" json:"network,omitempty"` + Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` +} + +func (x *Server_GRPC) Reset() { + *x = Server_GRPC{} + if protoimpl.UnsafeEnabled { + mi := &file_conf_conf_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Server_GRPC) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Server_GRPC) ProtoMessage() {} + +func (x *Server_GRPC) ProtoReflect() protoreflect.Message { + mi := &file_conf_conf_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Server_GRPC.ProtoReflect.Descriptor instead. +func (*Server_GRPC) Descriptor() ([]byte, []int) { + return file_conf_conf_proto_rawDescGZIP(), []int{1, 1} +} + +func (x *Server_GRPC) GetNetwork() string { + if x != nil { + return x.Network + } + return "" +} + +func (x *Server_GRPC) GetAddr() string { + if x != nil { + return x.Addr + } + return "" +} + +type Data_Database struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Driver string `protobuf:"bytes,1,opt,name=driver,proto3" json:"driver,omitempty"` + Source string `protobuf:"bytes,2,opt,name=source,proto3" json:"source,omitempty"` +} + +func (x *Data_Database) Reset() { + *x = Data_Database{} + if protoimpl.UnsafeEnabled { + mi := &file_conf_conf_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Data_Database) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Data_Database) ProtoMessage() {} + +func (x *Data_Database) ProtoReflect() protoreflect.Message { + mi := &file_conf_conf_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Data_Database.ProtoReflect.Descriptor instead. +func (*Data_Database) Descriptor() ([]byte, []int) { + return file_conf_conf_proto_rawDescGZIP(), []int{2, 0} +} + +func (x *Data_Database) GetDriver() string { + if x != nil { + return x.Driver + } + return "" +} + +func (x *Data_Database) GetSource() string { + if x != nil { + return x.Source + } + return "" +} + +type Data_Redis struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Network string `protobuf:"bytes,1,opt,name=network,proto3" json:"network,omitempty"` + Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` + Db int64 `protobuf:"varint,3,opt,name=db,proto3" json:"db,omitempty"` + Password string `protobuf:"bytes,4,opt,name=password,proto3" json:"password,omitempty"` +} + +func (x *Data_Redis) Reset() { + *x = Data_Redis{} + if protoimpl.UnsafeEnabled { + mi := &file_conf_conf_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Data_Redis) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Data_Redis) ProtoMessage() {} + +func (x *Data_Redis) ProtoReflect() protoreflect.Message { + mi := &file_conf_conf_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Data_Redis.ProtoReflect.Descriptor instead. +func (*Data_Redis) Descriptor() ([]byte, []int) { + return file_conf_conf_proto_rawDescGZIP(), []int{2, 1} +} + +func (x *Data_Redis) GetNetwork() string { + if x != nil { + return x.Network + } + return "" +} + +func (x *Data_Redis) GetAddr() string { + if x != nil { + return x.Addr + } + return "" +} + +func (x *Data_Redis) GetDb() int64 { + if x != nil { + return x.Db + } + return 0 +} + +func (x *Data_Redis) GetPassword() string { + if x != nil { + return x.Password + } + return "" +} + +type Data_Mongodb struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Network string `protobuf:"bytes,1,opt,name=network,proto3" json:"network,omitempty"` + Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` + User string `protobuf:"bytes,3,opt,name=user,proto3" json:"user,omitempty"` + Password string `protobuf:"bytes,4,opt,name=password,proto3" json:"password,omitempty"` + Db string `protobuf:"bytes,5,opt,name=db,proto3" json:"db,omitempty"` +} + +func (x *Data_Mongodb) Reset() { + *x = Data_Mongodb{} + if protoimpl.UnsafeEnabled { + mi := &file_conf_conf_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Data_Mongodb) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Data_Mongodb) ProtoMessage() {} + +func (x *Data_Mongodb) ProtoReflect() protoreflect.Message { + mi := &file_conf_conf_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Data_Mongodb.ProtoReflect.Descriptor instead. +func (*Data_Mongodb) Descriptor() ([]byte, []int) { + return file_conf_conf_proto_rawDescGZIP(), []int{2, 2} +} + +func (x *Data_Mongodb) GetNetwork() string { + if x != nil { + return x.Network + } + return "" +} + +func (x *Data_Mongodb) GetAddr() string { + if x != nil { + return x.Addr + } + return "" +} + +func (x *Data_Mongodb) GetUser() string { + if x != nil { + return x.User + } + return "" +} + +func (x *Data_Mongodb) GetPassword() string { + if x != nil { + return x.Password + } + return "" +} + +func (x *Data_Mongodb) GetDb() string { + if x != nil { + return x.Db + } + return "" +} + +type Data_Mq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` + Position string `protobuf:"bytes,3,opt,name=position,proto3" json:"position,omitempty"` + Entrust string `protobuf:"bytes,4,opt,name=entrust,proto3" json:"entrust,omitempty"` + Start string `protobuf:"bytes,5,opt,name=start,proto3" json:"start,omitempty"` +} + +func (x *Data_Mq) Reset() { + *x = Data_Mq{} + if protoimpl.UnsafeEnabled { + mi := &file_conf_conf_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Data_Mq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Data_Mq) ProtoMessage() {} + +func (x *Data_Mq) ProtoReflect() protoreflect.Message { + mi := &file_conf_conf_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Data_Mq.ProtoReflect.Descriptor instead. +func (*Data_Mq) Descriptor() ([]byte, []int) { + return file_conf_conf_proto_rawDescGZIP(), []int{2, 3} +} + +func (x *Data_Mq) GetAddress() string { + if x != nil { + return x.Address + } + return "" +} + +func (x *Data_Mq) GetType() string { + if x != nil { + return x.Type + } + return "" +} + +func (x *Data_Mq) GetPosition() string { + if x != nil { + return x.Position + } + return "" +} + +func (x *Data_Mq) GetEntrust() string { + if x != nil { + return x.Entrust + } + return "" +} + +func (x *Data_Mq) GetStart() string { + if x != nil { + return x.Start + } + return "" +} + +var File_conf_conf_proto protoreflect.FileDescriptor + +var file_conf_conf_proto_rawDesc = []byte{ + 0x0a, 0x0f, 0x63, 0x6f, 0x6e, 0x66, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x12, 0x0a, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x22, 0x5d, 0x0a, + 0x09, 0x42, 0x6f, 0x6f, 0x74, 0x73, 0x74, 0x72, 0x61, 0x70, 0x12, 0x2a, 0x0a, 0x06, 0x73, 0x65, + 0x72, 0x76, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x6b, 0x72, 0x61, + 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x06, + 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x24, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, + 0x69, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0xe4, 0x01, 0x0a, + 0x06, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x2b, 0x0a, 0x04, 0x68, 0x74, 0x74, 0x70, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, + 0x70, 0x69, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x52, 0x04, + 0x68, 0x74, 0x74, 0x70, 0x12, 0x2b, 0x0a, 0x04, 0x67, 0x72, 0x70, 0x63, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, + 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x47, 0x52, 0x50, 0x43, 0x52, 0x04, 0x67, 0x72, 0x70, + 0x63, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x05, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x1a, 0x34, 0x0a, 0x04, 0x48, 0x54, 0x54, 0x50, 0x12, + 0x18, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, + 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x64, 0x64, 0x72, 0x1a, 0x34, 0x0a, + 0x04, 0x47, 0x52, 0x50, 0x43, 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x12, + 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, + 0x64, 0x64, 0x72, 0x22, 0xdc, 0x04, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x12, 0x35, 0x0a, 0x08, + 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, + 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x44, 0x61, 0x74, 0x61, + 0x2e, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x52, 0x08, 0x64, 0x61, 0x74, 0x61, 0x62, + 0x61, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x05, 0x72, 0x65, 0x64, 0x69, 0x73, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, + 0x44, 0x61, 0x74, 0x61, 0x2e, 0x52, 0x65, 0x64, 0x69, 0x73, 0x52, 0x05, 0x72, 0x65, 0x64, 0x69, + 0x73, 0x12, 0x32, 0x0a, 0x07, 0x6d, 0x6f, 0x6e, 0x67, 0x6f, 0x64, 0x62, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, + 0x44, 0x61, 0x74, 0x61, 0x2e, 0x4d, 0x6f, 0x6e, 0x67, 0x6f, 0x64, 0x62, 0x52, 0x07, 0x6d, 0x6f, + 0x6e, 0x67, 0x6f, 0x64, 0x62, 0x12, 0x23, 0x0a, 0x02, 0x6d, 0x71, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x13, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x44, + 0x61, 0x74, 0x61, 0x2e, 0x4d, 0x71, 0x52, 0x02, 0x6d, 0x71, 0x1a, 0x3a, 0x0a, 0x08, 0x44, 0x61, + 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x12, 0x16, + 0x0a, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, + 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x1a, 0x61, 0x0a, 0x05, 0x52, 0x65, 0x64, 0x69, 0x73, 0x12, + 0x18, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, + 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x64, 0x64, 0x72, 0x12, 0x0e, 0x0a, + 0x02, 0x64, 0x62, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x64, 0x62, 0x12, 0x1a, 0x0a, + 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x1a, 0x77, 0x0a, 0x07, 0x4d, 0x6f, 0x6e, + 0x67, 0x6f, 0x64, 0x62, 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x12, 0x12, + 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x64, + 0x64, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, + 0x72, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, + 0x72, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x64, 0x62, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, + 0x64, 0x62, 0x1a, 0x7e, 0x0a, 0x02, 0x4d, 0x71, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, + 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, + 0x73, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, + 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, + 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x65, 0x6e, 0x74, 0x72, 0x75, 0x73, 0x74, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x65, 0x6e, 0x74, 0x72, 0x75, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, + 0x73, 0x74, 0x61, 0x72, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x73, 0x74, 0x61, + 0x72, 0x74, 0x42, 0x27, 0x5a, 0x25, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x6d, 0x61, 0x6b, 0x69, 0x6e, + 0x67, 0x2d, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, + 0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x3b, 0x63, 0x6f, 0x6e, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, +} + +var ( + file_conf_conf_proto_rawDescOnce sync.Once + file_conf_conf_proto_rawDescData = file_conf_conf_proto_rawDesc +) + +func file_conf_conf_proto_rawDescGZIP() []byte { + file_conf_conf_proto_rawDescOnce.Do(func() { + file_conf_conf_proto_rawDescData = protoimpl.X.CompressGZIP(file_conf_conf_proto_rawDescData) + }) + return file_conf_conf_proto_rawDescData +} + +var file_conf_conf_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_conf_conf_proto_goTypes = []any{ + (*Bootstrap)(nil), // 0: kratos.api.Bootstrap + (*Server)(nil), // 1: kratos.api.Server + (*Data)(nil), // 2: kratos.api.Data + (*Server_HTTP)(nil), // 3: kratos.api.Server.HTTP + (*Server_GRPC)(nil), // 4: kratos.api.Server.GRPC + (*Data_Database)(nil), // 5: kratos.api.Data.Database + (*Data_Redis)(nil), // 6: kratos.api.Data.Redis + (*Data_Mongodb)(nil), // 7: kratos.api.Data.Mongodb + (*Data_Mq)(nil), // 8: kratos.api.Data.Mq +} +var file_conf_conf_proto_depIdxs = []int32{ + 1, // 0: kratos.api.Bootstrap.server:type_name -> kratos.api.Server + 2, // 1: kratos.api.Bootstrap.data:type_name -> kratos.api.Data + 3, // 2: kratos.api.Server.http:type_name -> kratos.api.Server.HTTP + 4, // 3: kratos.api.Server.grpc:type_name -> kratos.api.Server.GRPC + 5, // 4: kratos.api.Data.database:type_name -> kratos.api.Data.Database + 6, // 5: kratos.api.Data.redis:type_name -> kratos.api.Data.Redis + 7, // 6: kratos.api.Data.mongodb:type_name -> kratos.api.Data.Mongodb + 8, // 7: kratos.api.Data.mq:type_name -> kratos.api.Data.Mq + 8, // [8:8] is the sub-list for method output_type + 8, // [8:8] is the sub-list for method input_type + 8, // [8:8] is the sub-list for extension type_name + 8, // [8:8] is the sub-list for extension extendee + 0, // [0:8] is the sub-list for field type_name +} + +func init() { file_conf_conf_proto_init() } +func file_conf_conf_proto_init() { + if File_conf_conf_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_conf_conf_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*Bootstrap); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_conf_conf_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*Server); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_conf_conf_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*Data); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_conf_conf_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*Server_HTTP); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_conf_conf_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*Server_GRPC); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_conf_conf_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*Data_Database); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_conf_conf_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*Data_Redis); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_conf_conf_proto_msgTypes[7].Exporter = func(v any, i int) any { + switch v := v.(*Data_Mongodb); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_conf_conf_proto_msgTypes[8].Exporter = func(v any, i int) any { + switch v := v.(*Data_Mq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_conf_conf_proto_rawDesc, + NumEnums: 0, + NumMessages: 9, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_conf_conf_proto_goTypes, + DependencyIndexes: file_conf_conf_proto_depIdxs, + MessageInfos: file_conf_conf_proto_msgTypes, + }.Build() + File_conf_conf_proto = out.File + file_conf_conf_proto_rawDesc = nil + file_conf_conf_proto_goTypes = nil + file_conf_conf_proto_depIdxs = nil +} diff --git a/internal/conf/conf.proto b/internal/conf/conf.proto new file mode 100644 index 0000000..c57691a --- /dev/null +++ b/internal/conf/conf.proto @@ -0,0 +1,54 @@ +syntax = "proto3"; +package kratos.api; + +option go_package = "matchmaking-system/internal/conf;conf"; + +message Bootstrap { + Server server = 1; + Data data = 2; +} + +message Server { + message HTTP { + string network = 1; + string addr = 2; + } + message GRPC { + string network = 1; + string addr = 2; + } + HTTP http = 1; + GRPC grpc = 2; + string check = 3; +} + +message Data { + message Database { + string driver = 1; + string source = 2; + } + message Redis { + string network = 1; + string addr = 2; + int64 db = 3; + string password = 4; + } + message Mongodb{ + string network = 1; + string addr = 2; + string user = 3; + string password = 4; + string db = 5; + } + message Mq{ + string address =1; + string type=2; + string position=3; + string entrust=4; + string start=5; + } + Database database = 1; + Redis redis = 2; + Mongodb mongodb =3; + Mq mq =4; +} diff --git a/internal/data/README.md b/internal/data/README.md new file mode 100644 index 0000000..a71aa6e --- /dev/null +++ b/internal/data/README.md @@ -0,0 +1,38 @@ +# 一、Data 模块功能 +### 功能块: [数字币(合约|现货|秒合约)、股票(美股|泰股|马股|印尼股|印度股|新加坡股|港股|英股)、新股申购(美股|泰股|马股|印尼股|印度股|新加坡股|港股|英股)、大宗交易(美股|泰股|马股|印尼股|印度股|新加坡股|港股|英股)、期权(印度)] +``` + 1、自动监控服务功能 + 1>初始化代码列表 + 2>监控代码价格(行情|设置)缓存 + 3>监控挂单 + 4>监控持仓 + 2、调用服务功能(详细逻辑-->见相关功能设计文档) + 1>下单 + 2>止盈止损 + 3>撤单 + 4>平仓 + 5>一键平仓 + 3、相关调用文档(http://g.jd66.cc:3001/project/56/interface/api) +``` + +# 二、Data 模块优化【TODO】 +### 分布式计算(用户最小单元,即为:5000个用户启动5000个任务队列)-(优点:有序队列、高并发、计算速度(例如:mysql死锁、数据的一致性、快速计算)) +``` + 一、交易处理 + 1>用户下单 -> 用户挂单队列周期性有序执行 -> 返回结果(UI交互) + 2>挂单计算 -> 处理状态|开仓价格|开仓手续费等(队列缓存:清理) -> 写入用户存储队列(挂单到持仓资产变更) + 3>持仓计算 -> 处理状态|平仓价格|平仓手续费等(队列缓存:清理) -> 写入用户存储队列(持仓到平仓资产变更) + 4>存储计算 -> 有序执行(挂单|持仓) -> 处理用户存储队列 + + 二、用户撤单 + 1>用户挂单队列 -> 清理用户挂单队列的订单 -> 写入用户存储队列(挂单到撤单资产变更) + + 三、用户修改订单(止盈止损) + 1>用户持仓队列 -> 更新用户持仓队列订单 -> 写入用户存储队列(更新用户订单信息) + + 四、用户平仓 + 1>平仓 -> 写入用户存储队列(持仓到平仓资产变更) -> 清理持仓队列中的订单 -> 返回结果(UI交互) + + 五、用户一键平仓(返回结果是否要异步处理) + 1>平仓 -> 写入用户存储队列(持仓到平仓资产变更) -> 清理持仓队列中的订单 -> 返回结果(UI交互) +``` \ No newline at end of file diff --git a/internal/data/aliyun.go b/internal/data/aliyun.go new file mode 100644 index 0000000..74e99c9 --- /dev/null +++ b/internal/data/aliyun.go @@ -0,0 +1,272 @@ +package data + +import ( + "context" + "errors" + "fmt" + "github.com/alibabacloud-go/tea/tea" + "github.com/go-kratos/kratos/v2/log" + "matchmaking-system/internal/data/redis" + "matchmaking-system/internal/data/sms" + "matchmaking-system/internal/pkg/flags" + + openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client" + dySmsApi20180501 "github.com/alibabacloud-go/dysmsapi-20180501/v2/client" + util "github.com/alibabacloud-go/tea-utils/v2/service" + uuid "github.com/satori/go.uuid" +) + +var ( + ps = fmt.Sprintf + prefix = "msg" +) + +// aLiYunRepo +// @Description: +type aLiYunRepo struct { + data *Data + + log *log.Helper +} + +// NewALiYunRepo +// +// @Description: +// @param data +// @param logger +// @return sms.ALiYunRepo +func NewALiYunRepo(data *Data, logger log.Logger) sms.ALiYunRepo { + return &aLiYunRepo{ + data: data, + log: log.NewHelper(logger), + } +} + +// SendVerificationCode +// +// @Description: +// @receiver al +// @param ctx +// @param phoneNumber +// @return code +// @return err +func (al *aLiYunRepo) SendVerificationCode(ctx context.Context, phoneNumber string) (code string, err error) { + // Verify if the verification code can be obtained (1-minute validity period) + _, found := al.data.cacheDB.Get(phoneNumber) + if found { + err = errors.New("Please do not send the verification code again.") + return + } + + // Generate verification code + verifyCode := sms.CreateRandCode(ctx) + // Generate Message Body + message := al.getVerifyCodeReq(ctx, phoneNumber, verifyCode) + + // Write to database + if err = al.SaveBoUserSms(nil); err != nil { + return flags.SetNull, err + } + + // Sends sms + //result, _err := al.SendSms(message) + //if _err != nil { + // _err = errors.New("请输入正确的手机号") + // return internal.ResultStr, _err + //} + result := "Return value after sending SMS" + + fmt.Println(flags.SetNull, message, result) + + // Update to database + if err = al.UpdateBoUserSms(ctx, nil); err != nil { + err = errors.New("update data db error") + return flags.SetNull, err + } + + // Request valid within 1 minute + al.data.cacheDB.SetDefault(phoneNumber, 1) + + // Set SMS verification code cache to be valid within 5 minutes + + err = redis.SetCacheData(ctx, al.data.redisDB, ps("%s:%s", prefix, phoneNumber), verifyCode, 5) + if err != nil { + err = errors.New("cache key error") + return flags.SetNull, err + } + + return verifyCode, nil +} + +// CheckVerificationCode +// +// @Description: +// @receiver al +// @param ctx +// @param phoneNumber +// @param verificationCode +// @return err + +func (al *aLiYunRepo) CheckVerificationCode(ctx context.Context, phoneNumber, verificationCode string) (err error) { + code, err := redis.GetCacheData(ctx, al.data.redisDB, ps("%s:%s", prefix, phoneNumber)) + if err != nil { + if err.Error() == "redis: nil" { + // init cache data + if err = redis.SetCacheData(ctx, al.data.redisDB, ps("%s:%s", prefix, phoneNumber), verificationCode, 5); err != nil { + return errors.New("Internal service error.") + } + code = verificationCode + } + } + + if len(code) == 0 { + err = errors.New("The verification code has expired.") + return + } + + if verificationCode != code { + err = errors.New("Verification code input error.") + return + } + + return err +} + +// CheckVerificationCodeNew +// +// @Description: +// @receiver al +// @param ctx +// @param phoneNumber +// @return string +// @return error +func (al *aLiYunRepo) CheckVerificationCodeNew(ctx context.Context, phoneNumber string) (string, error) { + code, err := redis.GetCacheData(ctx, al.data.redisDB, ps("%s:%s", prefix, phoneNumber)) + if err != nil { + if err.Error() == "redis: nil" { + code = flags.SetNull + } else { + err = errors.New("Internal service error.") + return flags.SetNull, err + } + } + + return code, nil +} + +// getVerifyCodeReq +// +// @Description: +// @receiver al +// @param ctx +// @param phoneNumber +// @param code +// @return req +func (al *aLiYunRepo) getVerifyCodeReq(ctx context.Context, phoneNumber, code string) (req dySmsApi20180501.SendMessageToGlobeRequest) { + verifyCodeFrom := sms.CreateRandCodeFrom(ctx, 10) + + req = dySmsApi20180501.SendMessageToGlobeRequest{ + From: tea.String(verifyCodeFrom), // 发送方标识;支持SenderId的发送,只允许数字+字母,含有字母标识最长11位,纯数字标识支持15位 + To: tea.String(phoneNumber), // 接收短信号码;号码格式为:国际区号+号码 + Message: tea.String(code), // 修改短信内容 + TaskId: tea.String(uuid.NewV4().String()), // 任务ID;长度不要超过255 + } + + return +} + +// CreateClient Initialize the Client with the AccessKey of the account +// +// @Description: +// @receiver al +// @param ctx +// @param accessKeyId +// @param accessKeySecret +// @return _result +// @return _err +func (al *aLiYunRepo) CreateClient(accessKeyId *string, accessKeySecret *string) (_result *dySmsApi20180501.Client, _err error) { + configs := &openapi.Config{ + // Required, your AccessKey ID + AccessKeyId: accessKeyId, + // Required, your AccessKey secret + AccessKeySecret: accessKeySecret, + } + // Endpoint + configs.Endpoint = tea.String(flags.SetNull) // al.data.confAly.Aliyun.EndPoint + _result = &dySmsApi20180501.Client{} + _result, _err = dySmsApi20180501.NewClient(configs) + + return _result, _err +} + +// SendSms TODO: al.data.confAly.Aliyun.AccessKeyId al.data.confAly.Aliyun.AccessKeySecret +// +// @Description: +// @receiver al +// @param ctx +// @param req +// @return res +// @return _err +func (al *aLiYunRepo) SendSms(req dySmsApi20180501.SendMessageToGlobeRequest) (res *dySmsApi20180501.SendMessageToGlobeResponse, _err error) { + client, _err := al.CreateClient(tea.String(flags.SetNull), tea.String(flags.SetNull)) + if _err != nil { + return nil, _err + } + + defer func() { + if r := tea.Recover(recover()); r != nil { + _err = r + } + }() + + runtime := &util.RuntimeOptions{} + + // Copy the code to run, please print the return value of the API by yourself. + result, _err := client.SendMessageToGlobeWithOptions(&req, runtime) + if _err != nil { + return nil, _err + } + + if *result.Body.ResponseCode != "OK" { + _err = errors.New(result.String()) + } + + return result, _err +} + +// SaveBoUserSms +// +// @Description: +// @receiver al +// @param ctx +// @param sms +// @return error +func (al *aLiYunRepo) SaveBoUserSms(sms interface{}) error { + _, err := al.data.mysqlDB.Table("bo_user_sms").Insert(&sms) + if err != nil { + return err + } + + return nil +} + +// UpdateBoUserSms +// +// @Description: +// @receiver al +// @param ctx +// @param sms +// @return error +func (al *aLiYunRepo) UpdateBoUserSms(ctx context.Context, sms interface{}) error { + //_, err := al.data.mysqlDB.Table("bo_user_sms"). + // Where("`from` = ?", sms.From). + // Where("`to` = ?", sms.To). + // Where("task_id = ?", sms.TaskId). + // Where("message = ?", sms.Message). + // Update(&sms) + //if err != nil { + // return err + //} + + return nil +} diff --git a/internal/data/cache/cache.go b/internal/data/cache/cache.go new file mode 100644 index 0000000..5b5d531 --- /dev/null +++ b/internal/data/cache/cache.go @@ -0,0 +1,16 @@ +package cache + +import ( + "github.com/patrickmn/go-cache" + "matchmaking-system/internal/conf" + "time" +) + +// NewCacheDB +// +// @Description: +// @param c +// @return *cache.Cache +func NewCacheDB(c *conf.Data) *cache.Cache { + return cache.New(time.Minute, time.Minute) +} diff --git a/internal/data/cache/cache_test.go b/internal/data/cache/cache_test.go new file mode 100644 index 0000000..e7f8f6c --- /dev/null +++ b/internal/data/cache/cache_test.go @@ -0,0 +1,28 @@ +package cache + +import ( + "github.com/patrickmn/go-cache" + "matchmaking-system/internal/conf" + "reflect" + "testing" +) + +func TestNewCacheDB(t *testing.T) { + type args struct { + c *conf.Data + } + tests := []struct { + name string + args args + want *cache.Cache + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewCacheDB(tt.args.c); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewCacheDB() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/data/control.go b/internal/data/control.go new file mode 100644 index 0000000..2daecfb --- /dev/null +++ b/internal/data/control.go @@ -0,0 +1,558 @@ +package data + +import ( + "github.com/go-kratos/kratos/v2/log" + "github.com/go-xorm/xorm" + "github.com/redis/go-redis/v9" + "matchmaking-system/internal/biz" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "strings" + "sync" +) + +var ( + Reds *redis.Client + Msql *xorm.EngineGroup + Uo *userOrderRepo + + spots *SpotsSymbol // 数字币-现货 + contract *ContractSymbol // 数字币-合约 + second *SecondSymbol // 数字币-秒合约 + forexWh *ForexSymbol // 外汇 + moneyZh *MoneySymbol // 综合(现货|合约|外汇) + shareUs *ShareUsSymbol // 股票-美股 + shareIdn *ShareIdnSymbol // 股票-印尼 + shareMys *ShareMysSymbol // 股票-马股 + shareTha *ShareThaSymbol // 股票-泰股 + shareInr *ShareInrSymbol // 股票-印度 + shareGbx *ShareGbxSymbol // 股票-英国 + shareSgd *ShareSgdSymbol // 股票-新加坡 + shareHkd *ShareHkdSymbol // 股票-香港 + shareEur *ShareEurSymbol // 股票-德国 + shareFur *ShareFurSymbol // 股票-法国 + shareBrl *ShareBrlSymbol // 股票-巴西 + shareJpy *ShareJpySymbol // 股票-日本 + optionInr *OptionInrSymbol // 期权-印度 +) + +// userOrderRepo +// @Description: +type userOrderRepo struct { + data *Data + + log *log.Helper +} + +// InitBase +// +// @Description: 初始化工具 +// @param ctx +// @param uo +func InitBase(uo *Data) { + Reds = uo.redisDB + Msql = uo.mysqlDB + Uo = &userOrderRepo{} + // 数字币 + spots = &SpotsSymbol{SpotsMap: make(chan []byte), SpotsMapSymbol: sync.Map{}} + second = &SecondSymbol{SecondMap: make(chan []byte), SecondMapSymbol: sync.Map{}} + contract = &ContractSymbol{ContractMap: make(chan []byte), ContractMapSymbol: sync.Map{}} + forexWh = &ForexSymbol{ForexMap: make(chan []byte), ForexMapSymbol: sync.Map{}} + // 综合 + moneyZh = &MoneySymbol{MoneySpotsMap: make(chan []byte), MoneySpotsMapSymbol: sync.Map{}, + MoneyContractMap: make(chan []byte), MoneyContractMapSymbol: sync.Map{}, + MoneyForexMap: make(chan []byte), MoneyForexMapSymbol: sync.Map{}} + // 股票 + shareUs = &ShareUsSymbol{UsMap: make(chan []byte), UsSetMap: make(chan []byte), UsMapSymbol: sync.Map{}, UsSetMapSymbol: sync.Map{}} + shareMys = &ShareMysSymbol{MysMap: make(chan []byte), MysSetMap: make(chan []byte), MysMapSymbol: sync.Map{}, MysSetMapSymbol: sync.Map{}} + shareTha = &ShareThaSymbol{ThaMap: make(chan []byte), ThaSetMap: make(chan []byte), ThaMapSymbol: sync.Map{}, ThaSetMapSymbol: sync.Map{}} + shareIdn = &ShareIdnSymbol{IdnMap: make(chan []byte), IdnSetMap: make(chan []byte), IdnMapSymbol: sync.Map{}, IdnSetMapSymbol: sync.Map{}} + shareInr = &ShareInrSymbol{InrMap: make(chan []byte), InrSetMap: make(chan []byte), InrMapSymbol: sync.Map{}, InrSetMapSymbol: sync.Map{}} + shareGbx = &ShareGbxSymbol{GbxMap: make(chan []byte), GbxSetMap: make(chan []byte), GbxMapSymbol: sync.Map{}, GbxSetMapSymbol: sync.Map{}} + shareSgd = &ShareSgdSymbol{SgdMap: make(chan []byte), SgdSetMap: make(chan []byte), SgdMapSymbol: sync.Map{}, SgdSetMapSymbol: sync.Map{}} + shareHkd = &ShareHkdSymbol{HkdMap: make(chan []byte), HkdSetMap: make(chan []byte), HkdMapSymbol: sync.Map{}, HkdSetMapSymbol: sync.Map{}} + shareEur = &ShareEurSymbol{EurMap: make(chan []byte), EurSetMap: make(chan []byte), EurMapSymbol: sync.Map{}, EurSetMapSymbol: sync.Map{}} + shareFur = &ShareFurSymbol{FurMap: make(chan []byte), FurSetMap: make(chan []byte), FurMapSymbol: sync.Map{}, FurSetMapSymbol: sync.Map{}} + shareBrl = &ShareBrlSymbol{BrlMap: make(chan []byte), BrlSetMap: make(chan []byte), BrlMapSymbol: sync.Map{}, BrlSetMapSymbol: sync.Map{}} + shareJpy = &ShareJpySymbol{JpyMap: make(chan []byte), JpySetMap: make(chan []byte), JpyMapSymbol: sync.Map{}, JpySetMapSymbol: sync.Map{}} + optionInr = &OptionInrSymbol{OpiMap: make(chan []byte), OpiSetMap: make(chan []byte), OpiMapSymbol: sync.Map{}, OpiSetMapSymbol: sync.Map{}} +} + +// NewUserOrderRepo +// +// @Description: 初始化交易对和股票代码 +// @param data +// @param logger +// @return biz.UserOrderRepo +func NewUserOrderRepo(data *Data, logger log.Logger) biz.UserOrderRepo { + InitBase(data) + + switch flags.CheckEnvironment { + case flags.CheckSymbolInit: // 交易对初始化 + InitSymbol(data) + case flags.CheckShareInit: // 股票代码初始化 + InitCode(data) + case flags.CheckCacheInit: // 初始化订单缓存 + InitCache(data) + case flags.CheckClearInit: // 清理多余订单缓存 + InitClearCacheOrder(data) + case flags.CheckByOrderNoInit: // 恢复IPO订单OrderNo匹配OrderId + InitIpoRedisCacheOrder(data) + case flags.CheckAdmin: // 管理订阅Wss服务 + checkSecond := strings.Contains(flags.CheckAdminService, flags.CheckSecond) // 秒合约 + checkContract := strings.Contains(flags.CheckAdminService, flags.CheckContract) // 合约 + checkForex := strings.Contains(flags.CheckAdminService, flags.CheckForex) // 外汇 + checkMoney := strings.Contains(flags.CheckAdminService, flags.CheckMoney) // 综合(现货|合约|外汇) + checkShareUs := strings.Contains(flags.CheckAdminService, flags.CheckShareUs) // 美股 + checkShareTha := strings.Contains(flags.CheckAdminService, flags.CheckShareTha) // 泰股 + checkShareIdn := strings.Contains(flags.CheckAdminService, flags.CheckShareIdn) // 印尼股 + checkShareInr := strings.Contains(flags.CheckAdminService, flags.CheckShareInr) // 印度股 + checkShareMys := strings.Contains(flags.CheckAdminService, flags.CheckShareMys) // 马股 + checkShareSgd := strings.Contains(flags.CheckAdminService, flags.CheckShareSgd) // 新加坡股 + checkShareHkd := strings.Contains(flags.CheckAdminService, flags.CheckShareHkd) // 港股 + checkShareGbx := strings.Contains(flags.CheckAdminService, flags.CheckShareGbx) // 英股 + checkShareFur := strings.Contains(flags.CheckAdminService, flags.CheckShareFur) // 法股 + checkShareEur := strings.Contains(flags.CheckAdminService, flags.CheckShareEur) // 德股 + checkShareJpy := strings.Contains(flags.CheckAdminService, flags.CheckShareJpy) // 日股 + checkShareBrl := strings.Contains(flags.CheckAdminService, flags.CheckShareBrl) // 巴西股 + checkOptionInr := strings.Contains(flags.CheckAdminService, flags.CheckOptionInr) // 期权股 + if checkSecond { + InitAdminSecond(data) + } + if checkContract { + InitAdminContract(data) + } + if checkForex { + InitAdminForex(data) + } + if checkMoney { + InitAdminMoney(data) + } + if checkShareUs { + InitAdminShareUs(data) + } + if checkShareTha { + InitAdminShareTha(data) + } + if checkShareIdn { + InitAdminShareIdn(data) + } + if checkShareInr { + InitAdminShareInr(data) + } + if checkShareMys { + InitAdminShareMys(data) + } + if checkShareSgd { + InitAdminShareSgd(data) + } + if checkShareHkd { + InitAdminShareHkd(data) + } + if checkShareGbx { + InitAdminShareGbx(data) + } + if checkShareFur { + InitAdminShareFur(data) + } + if checkShareEur { + InitAdminShareEur(data) + } + if checkShareJpy { + InitAdminShareJpy(data) + } + if checkShareBrl { + InitAdminShareBrl(data) + } + if checkOptionInr { + InitAdminOptionInr(data) + } + default: + applogger.Debug("NewUserOrderRepo:请输入初始化的环境变量.") + } + return &userOrderRepo{ + data: data, + log: log.NewHelper(logger), + } +} + +// NewUserSpotsRepo +// +// @Description: 现货服务 +// @param data +// @param logger +// @return biz.UserSpotsOrderRepo +func NewUserSpotsRepo(data *Data, logger log.Logger) biz.UserSpotsOrderRepo { + switch flags.CheckEnvironment { + case flags.CheckSport: // 现货服务 + InitSpots(data) + default: + applogger.Debug("NewUserOrderRepo:请输入现货初始化的环境变量.") + } + return &userOrderRepo{ + data: data, + log: log.NewHelper(logger), + } +} + +// NewUserSecondRepo +// +// @Description: 秒合约服务 +// @param data +// @param logger +// @return biz.UserSecondOrderRepo +func NewUserSecondRepo(data *Data, logger log.Logger) biz.UserSecondOrderRepo { + switch flags.CheckEnvironment { + case flags.CheckSecond: // 秒合约服务 + InitSecond(data) + default: + applogger.Debug("NewUserOrderRepo:请输入秒合约初始化的环境变量.") + } + return &userOrderRepo{ + data: data, + log: log.NewHelper(logger), + } +} + +// NewUserContractRepo +// +// @Description: 合约服务 +// @param data +// @param logger +// @return biz.UserContractOrderRepo +func NewUserContractRepo(data *Data, logger log.Logger) biz.UserContractOrderRepo { + switch flags.CheckEnvironment { + case flags.CheckContract: // 合约服务 + InitContract(data) + default: + applogger.Debug("NewUserOrderRepo:请输入合约初始化的环境变量.") + } + return &userOrderRepo{ + data: data, + log: log.NewHelper(logger), + } +} + +// NewUserForexRepo +// +// @Description: 外汇服务 +// @param data +// @param logger +// @return biz.UserForexOrderRepo +func NewUserForexRepo(data *Data, logger log.Logger) biz.UserForexOrderRepo { + switch flags.CheckEnvironment { + case flags.CheckForex: // 合约服务 + InitForex(data) + default: + applogger.Debug("NewUserOrderRepo:请输入外汇初始化的环境变量.") + } + return &userOrderRepo{ + data: data, + log: log.NewHelper(logger), + } +} + +// NewUserMoneyRepo +// +// @Description: 综合-(现货|合约|外汇) +// @param data +// @param logger +// @return biz.UserMoneyOrderRepo +func NewUserMoneyRepo(data *Data, logger log.Logger) biz.UserMoneyOrderRepo { + switch flags.CheckEnvironment { + case flags.CheckMoney: // 综合(现货|合约|外汇)服务 + InitMoney(data) + default: + applogger.Debug("NewUserOrderRepo:请输入综合(现货|合约|外汇)初始化的环境变量.") + } + return &userOrderRepo{ + data: data, + log: log.NewHelper(logger), + } +} + +// NewUserShareUsRepo +// +// @Description: 美股 +// @param data +// @param logger +// @return biz.UserShareUsOrderRepo +func NewUserShareUsRepo(data *Data, logger log.Logger) biz.UserShareUsOrderRepo { + switch flags.CheckEnvironment { + case flags.CheckShareUs: // 美股服务 + InitStockUs(data) + default: + applogger.Debug("NewUserOrderRepo:请输入美股初始化的环境变量.") + } + return &userOrderRepo{ + data: data, + log: log.NewHelper(logger), + } +} + +// NewUserShareThaRepo +// +// @Description: 泰股 +// @param data +// @param logger +// @return biz.UserShareThaOrderRepo +func NewUserShareThaRepo(data *Data, logger log.Logger) biz.UserShareThaOrderRepo { + switch flags.CheckEnvironment { + case flags.CheckShareTha: // 泰股服务 + InitStockTha(data) + default: + applogger.Debug("NewUserOrderRepo:请输入泰股初始化的环境变量.") + } + return &userOrderRepo{ + data: data, + log: log.NewHelper(logger), + } +} + +// NewUserShareIdnRepo +// +// @Description: 印尼股 +// @param data +// @param logger +// @return biz.UserShareIdnOrderRepo +func NewUserShareIdnRepo(data *Data, logger log.Logger) biz.UserShareIdnOrderRepo { + switch flags.CheckEnvironment { + case flags.CheckShareIdn: // 印尼股服务 + InitStockIdn(data) + default: + applogger.Debug("NewUserOrderRepo:请输入印尼股初始化的环境变量.") + } + return &userOrderRepo{ + data: data, + log: log.NewHelper(logger), + } +} + +// NewUserShareInrRepo +// +// @Description: 印度股 +// @param data +// @param logger +// @return biz.UserShareInrOrderRepo +func NewUserShareInrRepo(data *Data, logger log.Logger) biz.UserShareInrOrderRepo { + switch flags.CheckEnvironment { + case flags.CheckShareInr: // 印度股服务 + InitStockInr(data) + default: + applogger.Debug("NewUserOrderRepo:请输入印度股初始化的环境变量.") + } + return &userOrderRepo{ + data: data, + log: log.NewHelper(logger), + } +} + +// NewUserShareGbxRepo +// +// @Description: 英股 +// @param data +// @param logger +// @return biz.UserShareGbxOrderRepo +func NewUserShareGbxRepo(data *Data, logger log.Logger) biz.UserShareGbxOrderRepo { + switch flags.CheckEnvironment { + case flags.CheckShareGbx: // 英股服务 + InitStockGbx(data) + default: + applogger.Debug("NewUserOrderRepo:请输入英股初始化的环境变量.") + } + return &userOrderRepo{ + data: data, + log: log.NewHelper(logger), + } +} + +// NewUserShareMysRepo +// +// @Description: 马股 +// @param data +// @param logger +// @return biz.UserShareMysOrderRepo +func NewUserShareMysRepo(data *Data, logger log.Logger) biz.UserShareMysOrderRepo { + switch flags.CheckEnvironment { + case flags.CheckShareMys: // 马股服务 + InitStockMys(data) + default: + applogger.Debug("NewUserOrderRepo:请输入马股初始化的环境变量.") + } + return &userOrderRepo{ + data: data, + log: log.NewHelper(logger), + } +} + +// NewUserShareSgdRepo +// +// @Description: 新加坡股 +// @param data +// @param logger +// @return biz.UserShareSgdOrderRepo +func NewUserShareSgdRepo(data *Data, logger log.Logger) biz.UserShareSgdOrderRepo { + switch flags.CheckEnvironment { + case flags.CheckShareSgd: // 新加坡股服务 + InitStockSgd(data) + default: + applogger.Debug("NewUserOrderRepo:请输入新加坡股初始化的环境变量.") + } + return &userOrderRepo{ + data: data, + log: log.NewHelper(logger), + } +} + +// NewUserShareEurRepo +// +// @Description: 德股 +// @param data +// @param logger +// @return biz.UserShareEurOrderRepo +func NewUserShareEurRepo(data *Data, logger log.Logger) biz.UserShareEurOrderRepo { + switch flags.CheckEnvironment { + case flags.CheckShareEur: // 德股服务 + InitStockEur(data) + default: + applogger.Debug("NewUserOrderRepo:请输入德股初始化的环境变量.") + } + return &userOrderRepo{ + data: data, + log: log.NewHelper(logger), + } +} + +// NewUserShareBrlRepo +// +// @Description: 德股 +// @param data +// @param logger +// @return biz.UserShareBrlOrderRepo +func NewUserShareBrlRepo(data *Data, logger log.Logger) biz.UserShareBrlOrderRepo { + switch flags.CheckEnvironment { + case flags.CheckShareBrl: // 巴西股服务 + InitStockBrl(data) + default: + applogger.Debug("NewUserOrderRepo:请输入巴西股初始化的环境变量.") + } + return &userOrderRepo{ + data: data, + log: log.NewHelper(logger), + } +} + +// NewUserShareFurRepo +// +// @Description: 法股 +// @param data +// @param logger +// @return biz.UserShareFurOrderRepo +func NewUserShareFurRepo(data *Data, logger log.Logger) biz.UserShareFurOrderRepo { + switch flags.CheckEnvironment { + case flags.CheckShareFur: // 法股服务 + InitStockFur(data) + default: + applogger.Debug("NewUserOrderRepo:请输入法股初始化的环境变量.") + } + return &userOrderRepo{ + data: data, + log: log.NewHelper(logger), + } +} + +// NewUserShareJpyRepo +// +// @Description: 日股 +// @param data +// @param logger +// @return biz.UserShareJpyOrderRepo +func NewUserShareJpyRepo(data *Data, logger log.Logger) biz.UserShareJpyOrderRepo { + switch flags.CheckEnvironment { + case flags.CheckShareJpy: // 日股服务 + InitStockJpy(data) + default: + applogger.Debug("NewUserOrderRepo:请输入日股初始化的环境变量.") + } + return &userOrderRepo{ + data: data, + log: log.NewHelper(logger), + } +} + +// NewUserShareHkdRepo +// +// @Description: 港股 +// @param data +// @param logger +// @return biz.UserShareHkdOrderRepo +func NewUserShareHkdRepo(data *Data, logger log.Logger) biz.UserShareHkdOrderRepo { + switch flags.CheckEnvironment { + case flags.CheckShareHkd: // 港股服务 + InitStockHkd(data) + default: + applogger.Debug("NewUserOrderRepo:请输入港股初始化的环境变量.") + } + return &userOrderRepo{ + data: data, + log: log.NewHelper(logger), + } +} + +// NewUserOptionInrRepo +// +// @Description: 期权-印度股 +// @param data +// @param logger +// @return biz.UserOptionInrOrderRepo +func NewUserOptionInrRepo(data *Data, logger log.Logger) biz.UserOptionInrOrderRepo { + switch flags.CheckEnvironment { + case flags.CheckOptionInr: // 印度期权股服务 + InitOptionInr(data) + default: + applogger.Debug("NewUserOrderRepo:请输入期权-印度股初始化的环境变量.") + } + return &userOrderRepo{ + data: data, + log: log.NewHelper(logger), + } +} + +// NewUserShareBlkRepo +// +// @Description: 大宗交易服务 +// @param data +// @param logger +// @return biz.UserShareBlockOrderRepo +func NewUserShareBlkRepo(data *Data, logger log.Logger) biz.UserShareBlockOrderRepo { + switch flags.CheckEnvironment { + case flags.CheckShareBlk: // 大宗交易服务 + InitStockBlk(data) + case flags.CheckAdminBlk: // 管理员大宗交易后台服务订阅 + InitAdminShareBlk(data) + default: + applogger.Debug("NewUserOrderRepo:请输入大宗交易服务初始化的环境变量.") + } + return &userOrderRepo{ + data: data, + log: log.NewHelper(logger), + } +} + +// NewUserBackendRepo +// +// @Description: 后台-数据服务 +// @param data +// @param logger +// @return biz.UserBackendRepo +func NewUserBackendRepo(data *Data, logger log.Logger) biz.UserBackendRepo { + switch flags.CheckEnvironment { + case flags.CheckBackend: // 后台数据服务 + default: + applogger.Debug("NewUserOrderRepo:请输入后台-后台初始化的环境变量.") + } + return &userOrderRepo{ + data: data, + log: log.NewHelper(logger), + } +} diff --git a/internal/data/control_admin.go b/internal/data/control_admin.go new file mode 100644 index 0000000..80a05f3 --- /dev/null +++ b/internal/data/control_admin.go @@ -0,0 +1,229 @@ +package data + +import ( + "context" +) + +// InitAdminContract +// +// @Description: 管理员合约订阅 +// @param data +func InitAdminContract(data *Data) { + go SubscribeQuotesContract(context.Background(), data, contract) // 合约下单交易对行情订阅 + go InitSubscribeQuotesContract(contract) // 检查交易订单订阅标识状态机 + go OrderSubAdminContractSubscribeBySum(data) // 合约浮动盈亏计算 +} + +// InitAdminForex +// +// @Description: 管理员外汇订阅 +// @param data +func InitAdminForex(data *Data) { + go SubscribeQuotesForex(context.Background(), data, forexWh) // 外汇下单交易对行情订阅 + go InitSubscribeQuotesForex(forexWh) // 检查交易订单订阅标识状态机 + go OrderSubAdminForexSubscribeBySum(data) // 外汇浮动盈亏计算 +} + +// InitAdminMoney +// +// @Description: 管理员综合(现货|合约|外汇)行情订阅 +// @param data +func InitAdminMoney(data *Data) { + go InitSubscribeQuotesMoneySpots(moneyZh) // 综合-现货交易对订阅标识状态机 + go InitSubscribeQuotesMoneyContract(moneyZh) // 综合-合约交易对订阅标识状态机 + go InitSubscribeQuotesMoneyForex(moneyZh) // 综合-外汇交易对订阅标识状态机 + go SubscribeQuotesMoneySpots(context.Background(), data, moneyZh) // 综合-现货下单交易对行情订阅 + go SubscribeQuotesMoneyContract(context.Background(), data, moneyZh) // 综合-合约下单交易对行情订阅 + go SubscribeQuotesMoneyForex(context.Background(), data, moneyZh) // 综合-外汇下单交易对行情订阅 + go OrderSubAdminMoneySubscribeBySum(data) // 综合-(现货|合约|外汇)浮动盈亏计算 +} + +// InitAdminSecond +// +// @Description: 管理员秒合约订阅 +// @param data +func InitAdminSecond(data *Data) { + go SubscribeQuotesSecond(context.Background(), data, second) // 秒合约下单交易对行情订阅 + go InitSubscribeQuotesSecond() // 检查交易订单订阅标识状态机 +} + +// InitAdminShareUs +// +// @Description: 管理员股票-美股订阅 +// @param data +func InitAdminShareUs(data *Data) { + go InitCacheSymbolShareUs(context.Background(), data) // 初始化-美股股票代码 + go InitSubscribeShareUs(shareUs, false) // 检查交易订单订阅标识状态机 + go OrderSubAdminShareUsSubscribeBySum(data) // 美股浮动盈亏计算 + go InitShareUsCloseCachePrice(false) // 同步闭盘价 + go InitShareUsCloseNewPrice(false) // 同步实时行情 + go InitShareUsPriceSetUp(false) // 同步插针行情 +} + +// InitAdminShareMys +// +// @Description: 管理员股票-马股订阅 +// @param data +func InitAdminShareMys(data *Data) { + go InitCacheSymbolShareMys(context.Background(), data) // 初始化-马股股票代码 + go InitSubscribeShareMys(shareMys, false) // 检查交易订单订阅标识状态机 + go OrderSubAdminShareMysSubscribeBySum(data) // 马股浮动盈亏计算 + go InitShareMysCloseCachePrice(false) // 同步闭盘价 + go InitShareMysCloseNewPrice(false) // 同步实时行情 + go InitShareMysPriceSetUp(false) // 同步插针行情 +} + +// InitAdminShareTha +// +// @Description: 管理员股票-泰股订阅 +// @param data +func InitAdminShareTha(data *Data) { + go InitCacheSymbolShareTha(context.Background(), data) // 初始化-泰股股票代码 + go InitSubscribeShareTha(shareTha, false) // 检查交易订单订阅标识状态机 + go OrderSubAdminShareThaSubscribeBySum(data) // 泰股浮动盈亏计算 + go InitShareThaCloseCachePrice(false) // 同步闭盘价 + go InitShareThaCloseNewPrice(false) // 同步实时行情 + go InitShareThaPriceSetUp(false) // 同步插针行情 +} + +// InitAdminShareSgd +// +// @Description: 管理员股票-新加坡股订阅 +// @param data +func InitAdminShareSgd(data *Data) { + go InitCacheSymbolShareSgd(context.Background(), data) // 初始化-新加坡股票代码 + go InitSubscribeShareSgd(shareSgd, false) // 检查交易订单订阅标识状态机 + go OrderSubAdminShareSgdSubscribeBySum(data) // 新加坡股浮动盈亏计算 + go InitShareSgdCloseCachePrice(false) // 同步闭盘价 + go InitShareSgdCloseNewPrice(false) // 同步实时行情 + go InitShareSgdPriceSetUp(false) // 同步插针行情 +} + +// InitAdminShareIdn +// +// @Description: 管理员股票-印尼股订阅 +// @param data +func InitAdminShareIdn(data *Data) { + go InitCacheSymbolShareIdn(context.Background(), data) // 初始化-印尼股票代码 + go InitSubscribeShareIdn(shareIdn, false) // 检查交易订单订阅标识状态机 + go OrderSubAdminShareIdnSubscribeBySum(data) // 印尼股浮动盈亏计算 + go InitShareIdnCloseCachePrice(false) // 同步闭盘价 + go InitShareIdnCloseNewPrice(false) // 同步实时行情 + go InitShareIdnPriceSetUp(false) // 同步插针行情 +} + +// InitAdminShareInr +// +// @Description: 管理员股票-印度股订阅 +// @param data +func InitAdminShareInr(data *Data) { + go InitCacheSymbolShareInr(context.Background(), data) // 初始化-印度股票代码 + go InitSubscribeShareInr(shareInr, false) // 检查交易订单订阅标识状态机 + go OrderSubAdminShareInrSubscribeBySum(data) // 印度股浮动盈亏计算 + go InitShareInrCloseCachePrice(false) // 同步股闭盘价 + go InitShareInrCloseNewPrice(false) // 同步实时行情 + go InitShareInrPriceSetUp(false) // 同步插针行情 +} + +// InitAdminShareGbx +// +// @Description: 管理员股票-英股订阅 +// @param data +func InitAdminShareGbx(data *Data) { + go InitCacheSymbolShareGbx(context.Background(), data) // 初始化-英股股票代码 + go InitSubscribeShareGbx(shareGbx, false) // 检查交易订单订阅标识状态机 + go OrderSubAdminShareGbxSubscribeBySum(data) // 英股浮动盈亏计算 + go InitShareGbxCloseCachePrice(false) // 同步闭盘价 + go InitShareGbxCloseNewPrice(false) // 同步实时行情 + go InitShareGbxPriceSetUp(false) // 同步插针行情 +} + +// InitAdminShareEur +// +// @Description: 管理员股票-德股订阅 +// @param data +func InitAdminShareEur(data *Data) { + go InitCacheSymbolShareEur(context.Background(), data) // 初始化-德股股票代码 + go InitSubscribeShareEur(shareEur, false) // 检查交易订单订阅标识状态机 + go OrderSubAdminShareEurSubscribeBySum(data) // 德股浮动盈亏计算 + go InitShareEurCloseCachePrice(false) // 同步闭盘价 + go InitShareEurCloseNewPrice(false) // 同步实时行情 + go InitShareEurPriceSetUp(false) // 同步插针行情 +} + +// InitAdminShareFur +// +// @Description: 管理员股票-法股订阅 +// @param data +func InitAdminShareFur(data *Data) { + go InitCacheSymbolShareFur(context.Background(), data) // 初始化-法股股票代码 + go InitSubscribeShareFur(shareFur, false) // 检查交易订单订阅标识状态机 + go OrderSubAdminShareFurSubscribeBySum(data) // 法股浮动盈亏计算 + go InitShareFurCloseCachePrice(false) // 同步闭盘价 + go InitShareFurCloseNewPrice(false) // 同步实时行情 + go InitShareFurPriceSetUp(false) // 同步插针行情 +} + +// InitAdminShareJpy +// +// @Description: 管理员股票-日股订阅 +// @param data +func InitAdminShareJpy(data *Data) { + go InitCacheSymbolShareJpy(context.Background(), data) // 初始化-日股票代码 + go InitSubscribeShareJpy(shareJpy, false) // 检查交易订单订阅标识状态机 + go OrderSubAdminShareJpySubscribeBySum(data) // 日股浮动盈亏计算 + go InitShareJpyCloseCachePrice(false) // 同步闭盘价 + go InitShareJpyCloseNewPrice(false) // 同步实时行情 + go InitShareJpyPriceSetUp(false) // 同步插针行情 +} + +// InitAdminShareBrl +// +// @Description: 管理员股票-巴西股订阅 +// @param data +func InitAdminShareBrl(data *Data) { + go InitCacheSymbolShareBrl(context.Background(), data) // 初始化-巴西股股票代码 + go InitSubscribeShareBrl(shareBrl, false) // 检查交易订单订阅标识状态机 + go OrderSubAdminShareBrlSubscribeBySum(data) // 巴西股浮动盈亏计算 + go InitShareBrlCloseCachePrice(false) // 同步闭盘价 + go InitShareBrlCloseNewPrice(false) // 同步实时行情 + go InitShareBrlPriceSetUp(false) // 同步插针行情 +} + +// InitAdminShareHkd +// +// @Description: 管理员股票-港股订阅 +// @param data +func InitAdminShareHkd(data *Data) { + go InitCacheSymbolShareHkd(context.Background(), data) // 初始化-港股股票代码 + go InitSubscribeShareHkd(shareHkd, false) // 检查交易订单订阅标识状态机 + go OrderSubAdminShareHkdSubscribeBySum(data) // 港股浮动盈亏计算 + go InitShareHkdCloseCachePrice(false) // 同步闭盘价 + go InitShareHkdCloseNewPrice(false) // 同步实时行情 + go InitShareHkdPriceSetUp(false) // 同步插针行情 +} + +// InitAdminShareBlk +// +// @Description: 管理员股票-大宗股交易订阅 +// @param data +func InitAdminShareBlk(data *Data) { + go InitCacheSymbolShareBlk(context.Background(), data) // 初始化-大宗交易股票代码 + go OrderSubAdminShareBlkSubscribeBySum() // 大宗交易股浮动盈亏计算 + SubscribeShareBlk() // 大宗(美股|泰股|马股|印尼股|印度股|新加坡股|港股|英股)下单交易对行情订阅 + InitSubscribeShareBlk(shareUs, shareTha, shareMys, shareIdn, shareInr, shareSgd, shareHkd, shareGbx, shareEur, shareFur, shareBrl, shareJpy) // 检查交易订单订阅标识状态机 + InitShareBlkCloseCachePrice() // 闭盘价处理 + InitShareBlkSetUpPrice() // 插针价 +} + +// InitAdminOptionInr +// +// @Description: 管理员股票-期权-印度股订阅 +// @param data +func InitAdminOptionInr(data *Data) { + go InitCacheSymbolOptionInr(context.Background(), data) // 初始化-期权(印度)股票代码 + go SubscribeOptionInr(context.Background(), data, optionInr) // 印度期权股下单交易对行情订阅 + go InitSubscribeOptionInr(optionInr) // 检查交易订单订阅标识状态机 + go OrderSubAdminOptionInrSubscribeBySum(data) // 印度期权浮动盈亏计算 + go SubscriptionDataInformation(context.Background()) +} diff --git a/internal/data/control_ainit.go b/internal/data/control_ainit.go new file mode 100644 index 0000000..9655c8f --- /dev/null +++ b/internal/data/control_ainit.go @@ -0,0 +1,70 @@ +package data + +import ( + "context" +) + +// InitSymbol +// +// @Description: 初始化数字币交易对(现货|合约|秒合约|外汇) +// @param data +func InitSymbol(data *Data) { + InitCacheSymbolSpots(context.Background(), data) // 初始化-现货交易对 + InitCacheSymbolContract(context.Background(), data) // 初始化-合约(秒合约)交易对 + InitCacheSymbolForex(context.Background(), data) // 初始化-外汇交易对 +} + +// InitCode +// +// @Description: 初始化股票代码(美股|泰股|印尼股|印度股|马股|新加坡|期权-印度|港股) +// @param data +func InitCode(data *Data) { + InitCacheSymbolShareUs(context.Background(), data) // 初始化-美股股票代码 + InitCacheSymbolShareTha(context.Background(), data) // 初始化-泰股股票代码 + InitCacheSymbolShareIdn(context.Background(), data) // 初始化-印尼股票代码 + InitCacheSymbolShareInr(context.Background(), data) // 初始化-印度股票代码 + InitCacheSymbolShareMys(context.Background(), data) // 初始化-马股股票代码 + InitCacheSymbolShareSgd(context.Background(), data) // 初始化-新加坡股票代码 + InitCacheSymbolShareHkd(context.Background(), data) // 初始化-港股股票代码 + InitCacheSymbolOptionInr(context.Background(), data) // 初始化-期权(印度)股票代码 + InitCacheSymbolShareBlk(context.Background(), data) // 初始化-大宗交易股票代码 +} + +// InitCache +// +// @Description: 恢复美股|泰股|马股|印尼股|印度股|新加坡股|港股|期权|大宗交易|订单缓存数据 +// @param data +func InitCache(data *Data) { + RestoreCacheShareUs(data) + RestoreCacheShareEur(data) + RestoreCacheShareFur(data) + RestoreCacheShareGbx(data) + RestoreCacheShareTha(data) + RestoreCacheShareMys(data) + RestoreCacheShareIdn(data) + RestoreCacheShareInr(data) + RestoreCacheShareSgd(data) + RestoreCacheShareHkd(data) +} + +// InitClearCacheOrder +// +// @Description: 通过市场订单表清理订单垃圾缓存数据 +// @param data +func InitClearCacheOrder(data *Data) { + RestoreClearCacheShareUs(data) + RestoreClearCacheShareTha(data) + RestoreClearCacheShareMys(data) + RestoreClearCacheShareIdn(data) + RestoreClearCacheShareInr(data) + RestoreClearCacheShareSgd(data) + RestoreClearCacheShareHkd(data) +} + +// InitIpoRedisCacheOrder +// +// @Description: 恢复IPO-OrderNo匹配OrderId +// @param data +func InitIpoRedisCacheOrder(data *Data) { + TradeIPoInrByOrderNo(data) +} diff --git a/internal/data/control_forex.go b/internal/data/control_forex.go new file mode 100644 index 0000000..5c19955 --- /dev/null +++ b/internal/data/control_forex.go @@ -0,0 +1,16 @@ +package data + +import ( + "context" +) + +// InitContract +// +// @Description: 外汇交易 +// @param data +func InitForex(data *Data) { + go SubscribeQuotesForex(context.Background(), data, forexWh) // 外汇下单交易对行情订阅 + go InitSubscribeQuotesForex(forexWh) // 检查交易订单订阅标识状态机 + go ForexTransactionEntrust(context.Background()) // 监控外汇挂单缓存队列 + go ForexTransactionPosition(context.Background()) // 监控外汇持仓缓存队列 +} diff --git a/internal/data/control_money.go b/internal/data/control_money.go new file mode 100644 index 0000000..6c2c1c6 --- /dev/null +++ b/internal/data/control_money.go @@ -0,0 +1,22 @@ +package data + +import ( + "context" +) + +// InitMoney +// +// @Description: 外汇交易 +// @param data +func InitMoney(data *Data) { + go InitSubscribeQuotesMoneySpots(moneyZh) // 综合-现货交易对订阅标识状态机 + go InitSubscribeQuotesMoneyContract(moneyZh) // 综合-合约交易对订阅标识状态机 + go InitSubscribeQuotesMoneyForex(moneyZh) // 综合-外汇交易对订阅标识状态机 + + go SubscribeQuotesMoneySpots(context.Background(), data, moneyZh) // 综合-现货下单交易对行情订阅 + go SubscribeQuotesMoneyContract(context.Background(), data, moneyZh) // 综合-合约下单交易对行情订阅 + go SubscribeQuotesMoneyForex(context.Background(), data, moneyZh) // 综合-外汇下单交易对行情订阅 + + go MoneyTransactionEntrust(context.Background()) // 综合-监控(现货|合约|外汇)挂单缓存队列 + go MoneyTransactionPosition(context.Background()) // 综合-监控(现货|合约|外汇)持仓缓存队列 +} diff --git a/internal/data/control_option.go b/internal/data/control_option.go new file mode 100644 index 0000000..d0cd2f0 --- /dev/null +++ b/internal/data/control_option.go @@ -0,0 +1,18 @@ +package data + +import ( + "context" +) + +// InitOptionInr +// +// @Description: 期权-印度股交易 +// @param data +func InitOptionInr(data *Data) { + go InitCacheSymbolOptionInr(context.Background(), data) // 初始化-期权(印度)股票代码 + go SubscriptionDataInformation(context.Background()) + go SubscribeOptionInr(context.Background(), data, optionInr) // 期权-印度交易订单行情订阅 + go InitSubscribeOptionInr(optionInr) // 检查交易订单订阅标识状态机 + go OptionInrTransactionEntrust(context.Background(), data) // 监控期权-印度股挂单信息缓存队列 + go OptionInrTransactionPosition(context.Background()) // 监控期权-印度股持仓信息缓存队列 +} diff --git a/internal/data/control_share.go b/internal/data/control_share.go new file mode 100644 index 0000000..df153e6 --- /dev/null +++ b/internal/data/control_share.go @@ -0,0 +1,186 @@ +package data + +import ( + "context" +) + +// InitStockUs +// +// @Description: 美股交易 +// @param data +func InitStockUs(data *Data) { + go InitCacheSymbolShareUs(context.Background(), data) // 初始化-美股股票代码 + go InitSubscribeShareUs(shareUs, false) // 检查交易订单订阅标识状态机 + go ShareUsTransactionEntrust(context.Background()) // 监控美股挂单信息缓存队列 + go ShareUsTransactionPosition(context.Background()) // 监控美股持仓信息缓存队列 + go InitShareUsCloseCachePrice(false) // 同步闭盘价 + go InitShareUsCloseNewPrice(false) // 同步实时行情 + go InitShareUsPriceSetUp(false) // 同步插针行情 +} + +// InitStockMys +// +// @Description: 马股交易 +// @param data +func InitStockMys(data *Data) { + go InitCacheSymbolShareMys(context.Background(), data) // 初始化-马股股票代码 + go InitSubscribeShareMys(shareMys, false) // 检查交易订单订阅标识状态机 + go ShareMysTransactionEntrust(context.Background()) // 监控马股挂单信息缓存队列 + go ShareMysTransactionPosition(context.Background()) // 监控马股持仓信息缓存队列 + go InitShareMysCloseCachePrice(false) // 同步闭盘价 + go InitShareMysCloseNewPrice(false) // 同步实时行情 + go InitShareMysPriceSetUp(false) // 同步插针行情 +} + +// InitStockTha +// +// @Description: 泰股交易 +// @param data +func InitStockTha(data *Data) { + go InitCacheSymbolShareTha(context.Background(), data) // 初始化-泰股股票代码 + go InitSubscribeShareTha(shareTha, false) // 检查交易订单订阅标识状态机 + go ShareThaTransactionEntrust(context.Background()) // 监控泰股挂单信息缓存队列 + go ShareThaTransactionPosition(context.Background()) // 监控泰股持仓信息缓存队列 + go InitShareThaCloseCachePrice(false) // 同步闭盘价 + go InitShareThaCloseNewPrice(false) // 同步实时行情 + go InitShareThaPriceSetUp(false) // 同步插针行情 +} + +// InitStockIdn +// +// @Description: 印尼股交易 +// @param data +func InitStockIdn(data *Data) { + go InitCacheSymbolShareIdn(context.Background(), data) // 初始化-印尼股票代码 + go InitSubscribeShareIdn(shareIdn, false) // 检查交易订单订阅标识状态机 + go ShareIdnTransactionEntrust(context.Background()) // 监控印尼股挂单信息缓存队列 + go ShareIdnTransactionPosition(context.Background()) // 监控印尼股持仓信息缓存队列 + go InitShareIdnCloseCachePrice(false) // 同步闭盘价 + go InitShareIdnCloseNewPrice(false) // 同步实时行情 + go InitShareIdnPriceSetUp(false) // 同步插针行情 +} + +// InitStockInr +// +// @Description: 印度股交易 +// @param data +func InitStockInr(data *Data) { + go InitCacheSymbolShareInr(context.Background(), data) // 初始化-印度股票代码 + go InitSubscribeShareInr(shareInr, false) // 检查交易订单订阅标识状态机 + go ShareInrTransactionEntrust(context.Background()) // 监控印股挂单信息缓存队列 + go ShareInrTransactionPosition(context.Background()) // 监控印度股持仓信息缓存队列 + go InitShareInrCloseCachePrice(false) // 同步闭盘价 + go InitShareInrCloseNewPrice(false) // 同步实时行情 + go InitShareInrPriceSetUp(false) // 同步插针行情 +} + +// InitStockSgd +// +// @Description: 新加坡股交易 +// @param data +func InitStockSgd(data *Data) { + go InitCacheSymbolShareSgd(context.Background(), data) // 初始化-新加坡股票代码 + go InitSubscribeShareSgd(shareSgd, false) // 检查交易订单订阅标识状态机 + go ShareSgdTransactionEntrust(context.Background()) // 监控新加坡股挂单信息缓存队列 + go ShareSgdTransactionPosition(context.Background()) // 监控新加坡股持仓信息缓存队列 + go InitShareSgdCloseCachePrice(false) // 同步闭盘价 + go InitShareSgdCloseNewPrice(false) // 同步实时行情 + go InitShareSgdPriceSetUp(false) // 同步插针行情 +} + +// InitStockEur +// +// @Description: 德股交易 +// @param data +func InitStockEur(data *Data) { + go InitCacheSymbolShareEur(context.Background(), data) // 初始化-德股票代码 + go InitSubscribeShareEur(shareEur, false) // 检查交易订单订阅标识状态机 + go ShareEurTransactionEntrust(context.Background()) // 监控德股挂单信息缓存队列 + go ShareEurTransactionPosition(context.Background()) // 监控德股持仓信息缓存队列 + go InitShareEurCloseCachePrice(false) // 同步闭盘价 + go InitShareEurCloseNewPrice(false) // 同步实时行情 + go InitShareEurPriceSetUp(false) // 同步插针行情 +} + +// InitStockFur +// +// @Description: 法股交易 +// @param data +func InitStockFur(data *Data) { + go InitCacheSymbolShareFur(context.Background(), data) // 初始化-法股票代码 + go InitSubscribeShareFur(shareFur, false) // 检查交易订单订阅标识状态机 + go ShareFurTransactionEntrust(context.Background()) // 监控法股挂单信息缓存队列 + go ShareFurTransactionPosition(context.Background()) // 监控法股持仓信息缓存队列 + go InitShareFurCloseCachePrice(false) // 同步闭盘价 + go InitShareFurCloseNewPrice(false) // 同步实时行情 + go InitShareFurPriceSetUp(false) // 同步插针行情 +} + +// InitStockJpy +// +// @Description: 日股交易 +// @param data +func InitStockJpy(data *Data) { + go InitCacheSymbolShareJpy(context.Background(), data) // 初始化-日股票代码 + go InitSubscribeShareJpy(shareJpy, false) // 检查交易订单订阅标识状态机 + go ShareJpyTransactionEntrust(context.Background()) // 监控日股挂单信息缓存队列 + go ShareJpyTransactionPosition(context.Background()) // 监控日股持仓信息缓存队列 + go InitShareJpyCloseCachePrice(false) // 同步闭盘价 + go InitShareJpyCloseNewPrice(false) // 同步实时行情 + go InitShareJpyPriceSetUp(false) // 同步插针行情 +} + +// InitStockBrl +// +// @Description: 巴西股交易 +// @param data +func InitStockBrl(data *Data) { + go InitCacheSymbolShareBrl(context.Background(), data) // 初始化-巴西股票代码 + go InitSubscribeShareBrl(shareBrl, false) // 检查交易订单订阅标识状态机 + go ShareBrlTransactionEntrust(context.Background()) // 监控巴西股挂单信息缓存队列 + go ShareBrlTransactionPosition(context.Background()) // 监控巴西股持仓信息缓存队列 + go InitShareBrlCloseCachePrice(false) // 同步闭盘价 + go InitShareBrlCloseNewPrice(false) // 同步实时行情 + go InitShareBrlPriceSetUp(false) // 同步插针行情 +} + +// InitStockHkd +// +// @Description: 港股交易 +// @param data +func InitStockHkd(data *Data) { + go InitCacheSymbolShareHkd(context.Background(), data) // 初始化-港股股票代码 + go InitSubscribeShareHkd(shareHkd, false) // 检查交易订单订阅标识状态机 + go ShareHkdTransactionEntrust(context.Background()) // 监控港股挂单信息缓存队列 + go ShareHkdTransactionPosition(context.Background()) // 监控港度股持仓信息缓存队列 + go InitShareHkdCloseCachePrice(false) // 同步闭盘价 + go InitShareHkdCloseNewPrice(false) // 同步实时行情 + go InitShareHkdPriceSetUp(false) // 同步插针行情 +} + +// InitStockGbx +// +// @Description: 英股交易 +// @param data +func InitStockGbx(data *Data) { + go InitCacheSymbolShareGbx(context.Background(), data) // 初始化-英股票代码 + go InitSubscribeShareGbx(shareGbx, false) // 检查交易订单订阅标识状态机 + go ShareGbxTransactionEntrust(context.Background()) // 监控英股挂单信息缓存队列 + go ShareGbxTransactionPosition(context.Background()) // 监控英度股持仓信息缓存队列 + go InitShareGbxCloseCachePrice(false) // 同步闭盘价 + go InitShareGbxCloseNewPrice(false) // 同步实时行情 + go InitShareGbxPriceSetUp(false) // 同步插针行情 +} + +// InitStockBlk +// +// @Description: 大宗股交易 +// @param data +func InitStockBlk(data *Data) { + go InitCacheSymbolShareBlk(context.Background(), data) // 初始化-大宗交易股票代码 + SubscribeShareBlk() // 大宗(美股|泰股|马股|印尼股|印度股|新加坡股|港股|英股)下单交易对行情订阅 + InitSubscribeShareBlk(shareUs, shareTha, shareMys, shareIdn, shareInr, shareSgd, shareHkd, shareGbx, shareEur, shareFur, shareBrl, shareJpy) // 检查交易订单订阅标识状态机 + ShareBlkTransactionEntrust(context.Background()) // 监控大宗(美股|泰股|马股|印尼股|印度股|新加坡股|港股|英股)交易股挂单信息缓存队列 + InitShareBlkCloseCachePrice() // 监控大宗(美股|泰股|马股|印尼股|印度股|新加坡股|港股|英股)股票代码闭盘价格 + InitShareBlkSetUpPrice() // 插针价 +} diff --git a/internal/data/control_virtual.go b/internal/data/control_virtual.go new file mode 100644 index 0000000..977a9e8 --- /dev/null +++ b/internal/data/control_virtual.go @@ -0,0 +1,36 @@ +package data + +import ( + "context" +) + +// InitSpots +// +// @Description: 现货交易 +// @param data +func InitSpots(data *Data) { + go SubscribeQuotesSpots(context.Background(), data, spots) // 现货下单交易对行情订阅 + go InitSubscribeQuotesSpots(spots) // 检查交易订单订阅标识状态机 + go SpotsTransaction() // 监控现货挂单缓存队列 +} + +// InitContract +// +// @Description: 合约交易 +// @param data +func InitContract(data *Data) { + go SubscribeQuotesContract(context.Background(), data, contract) // 合约下单交易对行情订阅 + go InitSubscribeQuotesContract(contract) // 检查交易订单订阅标识状态机 + go ContractTransactionEntrust(context.Background()) // 监控合约挂单缓存队列 + go ContractTransactionPosition(context.Background()) // 监控合约持仓缓存队列 +} + +// InitSecond +// +// @Description: 秒合约交易 +// @param data +func InitSecond(data *Data) { + go SubscribeQuotesSecond(context.Background(), data, second) // 秒合约下单交易对行情订阅 + go InitSubscribeQuotesSecond() // 检查交易订单订阅标识状态机 + go SecondTransactionPosition(context.Background()) // 监控秒合约持仓缓存队列 +} diff --git a/internal/data/convert/order.go b/internal/data/convert/order.go new file mode 100644 index 0000000..b1211e3 --- /dev/null +++ b/internal/data/convert/order.go @@ -0,0 +1,4587 @@ +package convert + +import ( + "context" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + "math/rand" + "strconv" + "time" + + models "matchmaking-system/internal/pkg/model" +) + +// CreateRandCodeOrder +// +// @Description: +// @param n +// @return string +func CreateRandCodeOrder(n int) string { + timestamp := time.Now().UnixNano() / 1000000 // 毫秒级时间戳 + + code := flags.SetNull + for i := 0; i < n; i++ { + code = fmt.Sprintf("%s%d", code, rand.Intn(10)) + } + + return fmt.Sprintf("%d%s", timestamp, code) +} + +// BotStockTrade +// +// @Description: (美股下单|美股设置止损止盈|美股撤单|美股平仓) +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockTrade +func BotStockTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockTrade { + marketPrice := decimal.RequireFromString(order.MarketMoney) + cost := decimal.RequireFromString(order.ServiceCost) + pryNum, err := strconv.Atoi(order.PryNum) + if err != nil { + pryNum = 1 + } + + var lp, mp string + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + lp = order.LimitPrice + mp = order.LimitPrice + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + lp = order.MarketPrice + mp = order.MarketPrice + } + } + + if order.StopWinPrice == flags.SetNull { + order.StopWinPrice = decimal.Zero.String() + } + if order.StopLossPrice == flags.SetNull { + order.StopLossPrice = decimal.Zero.String() + } + if order.LimitPrice == flags.SetNull { + order.LimitPrice = decimal.Zero.String() + } + if order.MarketPrice == flags.SetNull { + order.MarketPrice = decimal.Zero.String() + } + + // total order Money + orderMoney := marketPrice.Add(cost) + + return models.BotStockTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + Status: flags.EntrustStatus, + ServiceCost: order.ServiceCost, + OrderNumber: order.OrderNumber, + OrderMoney: orderMoney.String(), + OrderId: orderId, + MarketMoney: order.MarketMoney, + LimitPrice: lp, + MarketPrice: mp, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + DealPrice: decimal.Zero.String(), + PryNum: pryNum, + } +} + +// BotStockBlockTrade +// +// @Description: 大宗(美股|马股|泰股|印尼股|印度股|新加坡股|港股)交易订单表 +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockBlockTrade +func BotStockBlockTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockBlockTrade { + marketPrice := decimal.RequireFromString(order.MarketMoney) + cost := decimal.RequireFromString(order.ServiceCost) + pryNum, err := strconv.Atoi(order.PryNum) + if err != nil { + pryNum = 1 + } + + var lp, mp string + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + lp = order.LimitPrice + mp = order.LimitPrice + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + lp = order.MarketPrice + mp = order.MarketPrice + } + } + + if order.StopWinPrice == flags.SetNull { + order.StopWinPrice = decimal.Zero.String() + } + if order.StopLossPrice == flags.SetNull { + order.StopLossPrice = decimal.Zero.String() + } + if order.LimitPrice == flags.SetNull { + order.LimitPrice = decimal.Zero.String() + } + if order.MarketPrice == flags.SetNull { + order.MarketPrice = decimal.Zero.String() + } + + // total order Money + orderMoney := marketPrice.Add(cost) + + return models.BotStockBlockTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + Status: flags.EntrustStatus, + ServiceCost: order.ServiceCost, + OrderNumber: order.OrderNumber, + OrderMoney: orderMoney.String(), + OrderId: orderId, + MarketMoney: order.MarketMoney, + LimitPrice: lp, + MarketPrice: mp, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + DealPrice: decimal.Zero.String(), + PryNum: pryNum, + Type: int(order.Type), + } +} + +// BotStockHkdTrade +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockTrade +func BotStockHkdTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockHkdTrade { + marketPrice := decimal.RequireFromString(order.MarketMoney) + cost := decimal.RequireFromString(order.ServiceCost) + pryNum, err := strconv.Atoi(order.PryNum) + if err != nil { + pryNum = 1 + } + + var lp, mp string + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + lp = order.LimitPrice + mp = order.LimitPrice + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + lp = order.MarketPrice + mp = order.MarketPrice + } + } + + if order.StopWinPrice == flags.SetNull { + order.StopWinPrice = decimal.Zero.String() + } + if order.StopLossPrice == flags.SetNull { + order.StopLossPrice = decimal.Zero.String() + } + if order.LimitPrice == flags.SetNull { + order.LimitPrice = decimal.Zero.String() + } + if order.MarketPrice == flags.SetNull { + order.MarketPrice = decimal.Zero.String() + } + + // total order Money + orderMoney := marketPrice.Add(cost) + + return models.BotStockHkdTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + Status: flags.EntrustStatus, + ServiceCost: order.ServiceCost, + OrderNumber: order.OrderNumber, + OrderMoney: orderMoney.String(), + OrderId: orderId, + MarketMoney: order.MarketMoney, + LimitPrice: lp, + MarketPrice: mp, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + DealPrice: decimal.Zero.String(), + PryNum: pryNum, + } +} + +// BotStockStopByOrderId +// +// @Description: +// @param ctx +// @param order +// @return models.BotStockTrade +func BotStockStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockTrade { + return models.BotStockTrade{ + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StopWinPrice: order.StopWinPrice, + UpdateTime: time.Now(), + } +} + +// BotStockBlockStopByOrderId +// +// @Description: +// @param ctx +// @param order +// @return models.BotStockBlockTrade +func BotStockBlockStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockBlockTrade { + return models.BotStockBlockTrade{ + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StopWinPrice: order.StopWinPrice, + UpdateTime: time.Now(), + } +} + +// BotStockStopHkdByOrderId +// +// @Description: +// @param ctx +// @param order +// @return models.BotStockHkdTrade +func BotStockStopHkdByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockHkdTrade { + return models.BotStockHkdTrade{ + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StopWinPrice: order.StopWinPrice, + UpdateTime: time.Now(), + } +} + +// BotStockCancelByOrderId +// +// @Description: +// @param ctx +// @return models.BotStockTrade +func BotStockCancelByOrderId(ctx context.Context) models.BotStockTrade { + return models.BotStockTrade{ + Status: flags.CancelStatus, + UpdateTime: time.Now(), + } +} + +// BotStockBlockCancelByOrderId +// +// @Description: +// @param ctx +// @return models.BotStockBlockTrade +func BotStockBlockCancelByOrderId(ctx context.Context) models.BotStockBlockTrade { + return models.BotStockBlockTrade{ + Status: flags.CancelStatus, + UpdateTime: time.Now(), + } +} + +// BotStockHkdCancelByOrderId +// +// @Description: +// @param ctx +// @return models.BotStockHkdTrade +func BotStockHkdCancelByOrderId(ctx context.Context) models.BotStockHkdTrade { + return models.BotStockHkdTrade{ + Status: flags.CancelStatus, + UpdateTime: time.Now(), + } +} + +// UpdateBotUserStock +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStock +func UpdateBotUserStock(ctx context.Context, usableNum, frozenNum string) models.BotUserStock { + return models.BotUserStock{ + UpdateTime: time.Now(), + FrozenNum: frozenNum, + UsableNum: usableNum, + } +} + +// UpdateBotUserStockHkd +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockHkd +func UpdateBotUserStockHkd(ctx context.Context, usableNum, frozenNum string) models.BotUserStockHkd { + return models.BotUserStockHkd{ + UpdateTime: time.Now(), + FrozenNum: frozenNum, + UsableNum: usableNum, + } +} + +// CreateBotUserStock +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStock +func CreateBotUserStock(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStock { + return models.BotUserStock{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// CreateBotUserStockHkd +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockHkd +func CreateBotUserStockHkd(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockHkd { + return models.BotUserStockHkd{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// UpdateOpenBotStockTrade +// +// @Description: +// @param ctx +// @param price +// @param orderNumber +// @param totalMoney +// @param serviceCost +// @return models.BotStockTrade +func UpdateOpenBotStockTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, marketMoney string) models.BotStockTrade { + return models.BotStockTrade{ + OpenTime: time.Now(), + DealPrice: price, + ServiceCost: serviceCost, + OrderNumber: orderNumber, + OrderMoney: totalMoney, + MarketMoney: marketMoney, + Status: flags.PositionStatus, + } +} + +// UpdateOpenBotStockBlockTrade +// +// @Description: 大宗(美股)交易 +// @param ctx +// @param price +// @param orderNumber +// @param totalMoney +// @param serviceCost +// @param marketMoney +// @return models.BotStockBlockTrade +func UpdateOpenBotStockBlockTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, marketMoney string) models.BotStockBlockTrade { + return models.BotStockBlockTrade{ + OpenTime: time.Now(), + DealPrice: price, + ServiceCost: serviceCost, + OrderNumber: orderNumber, + OrderMoney: totalMoney, + MarketMoney: marketMoney, + Status: flags.PositionStatus, + } +} + +// UpdateOpenBotStockHkdTrade +// +// @Description: +// @param ctx +// @param price +// @param orderNumber +// @param totalMoney +// @param serviceCost +// @param marketMoney +// @return models.BotStockHkdTrade +func UpdateOpenBotStockHkdTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, marketMoney string) models.BotStockHkdTrade { + return models.BotStockHkdTrade{ + OpenTime: time.Now(), + DealPrice: price, + ServiceCost: serviceCost, + OrderNumber: orderNumber, + OrderMoney: totalMoney, + MarketMoney: marketMoney, + Status: flags.PositionStatus, + } +} + +// UpdateCloseBotStockTrade +// +// @Description: +// @param ctx +// @param price +// @param totalMoney +// @param serviceCost +// @return models.BotStockTrade +func UpdateCloseBotStockTrade(ctx context.Context, price, serviceCost string) models.BotStockTrade { + return models.BotStockTrade{ + ClosingTime: time.Now(), + ClosingPrice: price, + ClosingCost: serviceCost, + Status: flags.CloseStatus, + } +} + +// UpdateCloseBotStockBlockTrade +// +// @Description: +// @param ctx +// @param price +// @param serviceCost +// @return models.BotStockBlockTrade +func UpdateCloseBotStockBlockTrade(ctx context.Context, price, serviceCost string) models.BotStockBlockTrade { + return models.BotStockBlockTrade{ + ClosingTime: time.Now(), + ClosingPrice: price, + ClosingCost: serviceCost, + Status: flags.CloseStatus, + } +} + +// UpdateCloseBotStockHkdTrade +// +// @Description: +// @param ctx +// @param price +// @param serviceCost +// @return models.BotStockHkdTrade +func UpdateCloseBotStockHkdTrade(ctx context.Context, price, serviceCost string) models.BotStockHkdTrade { + return models.BotStockHkdTrade{ + ClosingTime: time.Now(), + ClosingPrice: price, + ClosingCost: serviceCost, + Status: flags.CloseStatus, + } +} + +// CreatBotUserStockLog +// +// @Description: +// @param ctx +// @param userId +// @param code +// @param symbol +// @param changeNum +// @param orderId +// @return models.BotUserStockLog +func CreatBotUserStockLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockLog { + return models.BotUserStockLog{ + OrderId: orderId, + UserId: int(userId), + ChangeNum: changeNum, + ChangeType: int(code), + CreateTime: time.Now(), + UpdateTime: time.Now(), + StockId: symbol, + BeforeNum: decimal.Zero.String(), + } +} + +// CreatBotUserStockBlockLog +// +// @Description: +// @param ctx +// @param userId +// @param code +// @param symbol +// @param changeNum +// @param orderId +// @param typeStatus +// @return models.BotUserStockBlockLog +func CreatBotUserStockBlockLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string, typeStatus int64) models.BotUserStockBlockLog { + return models.BotUserStockBlockLog{ + OrderId: orderId, + UserId: int(userId), + ChangeNum: changeNum, + ChangeType: int(code), + CreateTime: time.Now(), + UpdateTime: time.Now(), + StockId: symbol, + BeforeNum: decimal.Zero.String(), + Type: int(typeStatus), + } +} + +// CreatBotUserStockHkdLog +// +// @Description: +// @param ctx +// @param userId +// @param code +// @param symbol +// @param changeNum +// @param orderId +// @return models.BotUserStockHkdLog +func CreatBotUserStockHkdLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockHkdLog { + return models.BotUserStockHkdLog{ + OrderId: orderId, + UserId: int(userId), + ChangeNum: changeNum, + ChangeType: int(code), + CreateTime: time.Now(), + UpdateTime: time.Now(), + StockId: symbol, + BeforeNum: decimal.Zero.String(), + } +} + +// BotStockTradePre +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockTrade +func BotStockTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockTrade { + if order.StopWinPrice == flags.SetNull { + order.StopWinPrice = decimal.Zero.String() + } + if order.StopLossPrice == flags.SetNull { + order.StopLossPrice = decimal.Zero.String() + } + if order.MarketPrice == flags.SetNull { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == flags.SetNull { + order.LimitPrice = decimal.Zero.String() + } + + return models.BotStockTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + ServiceCost: order.ServiceCost, + MarketPrice: order.MarketPrice, + MarketMoney: order.MarketMoney, + LimitPrice: order.LimitPrice, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + OrderId: orderId, + Status: flags.PositionStatus, + OpenTime: time.Now(), + DealPrice: order.LimitPrice, + OrderNumber: order.OrderNumber, + OrderMoney: order.MarketMoney, + ClosingPrice: decimal.Zero.String(), + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + PryNum: flags.SetPreOne, + } +} + +// CreatBotUserStockPre +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStock +func CreatBotUserStockPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStock { + return models.BotUserStock{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// CreatBotUserStockIdnPre +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStock +func CreatBotUserStockIdnPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockIdn { + return models.BotUserStockIdn{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// CreatBotUserStockMysPre +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockMys +func CreatBotUserStockMysPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockMys { + return models.BotUserStockMys{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// CreatBotUserStockThaPre +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockTha +func CreatBotUserStockThaPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockTha { + return models.BotUserStockTha{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// CreatBotUserStockInPre +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockIn +func CreatBotUserStockInPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockIn { + return models.BotUserStockIn{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// CreatBotUserStockSgdPre +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockSgd +func CreatBotUserStockSgdPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockSgd { + return models.BotUserStockSgd{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// CreatBotUserStockGbxPre +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockGbx +func CreatBotUserStockGbxPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockGbx { + return models.BotUserStockGbx{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// CreatBotUserStockEurPre +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockEur +func CreatBotUserStockEurPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockEur { + return models.BotUserStockEur{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// CreatBotUserStockBrlPre +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockBrl +func CreatBotUserStockBrlPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockBrl { + return models.BotUserStockBrl{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// CreatBotUserStockFurPre +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockFur +func CreatBotUserStockFurPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockFur { + return models.BotUserStockFur{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// CreatBotUserStockJpyPre +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockJp +func CreatBotUserStockJpyPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockJp { + return models.BotUserStockJp{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// CreatBotUserStockHkdPre +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockHkd +func CreatBotUserStockHkdPre(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockHkd { + return models.BotUserStockHkd{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// UpdateBotUserStockPre +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStock +func UpdateBotUserStockPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStock { + return models.BotUserStock{ + UsableNum: usableNum, + FrozenNum: frozenNum, + UpdateTime: time.Now(), + } +} + +// UpdateBotUserStockIdnPre +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockIdn +func UpdateBotUserStockIdnPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockIdn { + return models.BotUserStockIdn{ + UsableNum: usableNum, + FrozenNum: frozenNum, + UpdateTime: time.Now(), + } +} + +// UpdateBotUserStockMysPre +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockMys +func UpdateBotUserStockMysPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockMys { + return models.BotUserStockMys{ + UsableNum: usableNum, + FrozenNum: frozenNum, + UpdateTime: time.Now(), + } +} + +// UpdateBotUserStockThaPre +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockTha +func UpdateBotUserStockThaPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockTha { + return models.BotUserStockTha{ + UsableNum: usableNum, + FrozenNum: frozenNum, + UpdateTime: time.Now(), + } +} + +// UpdateBotUserStockInPre +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockIn +func UpdateBotUserStockInPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockIn { + return models.BotUserStockIn{ + UsableNum: usableNum, + FrozenNum: frozenNum, + UpdateTime: time.Now(), + } +} + +// UpdateBotUserStockSgdPre +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockSgd +func UpdateBotUserStockSgdPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockSgd { + return models.BotUserStockSgd{ + UsableNum: usableNum, + FrozenNum: frozenNum, + UpdateTime: time.Now(), + } +} + +// UpdateBotUserStockGbxPre +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockGbx +func UpdateBotUserStockGbxPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockGbx { + return models.BotUserStockGbx{ + UsableNum: usableNum, + FrozenNum: frozenNum, + UpdateTime: time.Now(), + } +} + +// UpdateBotUserStockEurPre +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockEur +func UpdateBotUserStockEurPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockEur { + return models.BotUserStockEur{ + UsableNum: usableNum, + FrozenNum: frozenNum, + UpdateTime: time.Now(), + } +} + +// UpdateBotUserStockBrlPre +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockBrl +func UpdateBotUserStockBrlPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockBrl { + return models.BotUserStockBrl{ + UsableNum: usableNum, + FrozenNum: frozenNum, + UpdateTime: time.Now(), + } +} + +// UpdateBotUserStockFurPre +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockFur +func UpdateBotUserStockFurPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockFur { + return models.BotUserStockFur{ + UsableNum: usableNum, + FrozenNum: frozenNum, + UpdateTime: time.Now(), + } +} + +// UpdateBotUserStockJpyPre +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockJp +func UpdateBotUserStockJpyPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockJp { + return models.BotUserStockJp{ + UsableNum: usableNum, + FrozenNum: frozenNum, + UpdateTime: time.Now(), + } +} + +// UpdateBotUserStockHkdPre +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockHkd +func UpdateBotUserStockHkdPre(ctx context.Context, usableNum, frozenNum string) models.BotUserStockHkd { + return models.BotUserStockHkd{ + UsableNum: usableNum, + FrozenNum: frozenNum, + UpdateTime: time.Now(), + } +} + +// BotStockIdnTrade +// +// @Description: (印尼股下单|印尼股设置止损止盈|印尼股撤单|印尼股平仓) +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockIdnTrade +func BotStockIdnTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockIdnTrade { + marketPrice := decimal.RequireFromString(order.MarketMoney) + cost := decimal.RequireFromString(order.ServiceCost) + // total order Money + orderMoney := marketPrice.Add(cost) + pryNum, err := strconv.Atoi(order.PryNum) + if err != nil { + pryNum = 0 + } + + var lp, mp string + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + lp = order.LimitPrice + mp = order.LimitPrice + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + lp = order.MarketPrice + mp = order.MarketPrice + } + } + if order.StopLossPrice == flags.SetNull { + order.StopLossPrice = decimal.Zero.String() + } + if order.StopWinPrice == flags.SetNull { + order.StopWinPrice = decimal.Zero.String() + } + if order.LimitPrice == flags.SetNull { + order.LimitPrice = decimal.Zero.String() + } + if order.MarketPrice == flags.SetNull { + order.MarketPrice = decimal.Zero.String() + } + return models.BotStockIdnTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopType: int(order.StopType), + StockId: order.StockId, + Status: flags.EntrustStatus, + ServiceCost: order.ServiceCost, + OrderNumber: order.OrderNumber, + OrderMoney: orderMoney.String(), + OrderId: orderId, + MarketMoney: order.MarketMoney, + LimitPrice: lp, + MarketPrice: mp, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + StopLossPrice: order.StopLossPrice, + StopWinPrice: order.StopWinPrice, + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + DealPrice: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + PryNum: pryNum, + } +} + +// BotStockInrTrade +// +// @Description: (印度股下单|印度股设置止损止盈|印度股撤单|印度股平仓) +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockInTrade +func BotStockInrTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockInTrade { + marketPrice := decimal.RequireFromString(order.MarketMoney) + cost := decimal.RequireFromString(order.ServiceCost) + // total order Money + orderMoney := marketPrice.Add(cost) + pryNum, err := strconv.Atoi(order.PryNum) + if err != nil { + pryNum = 1 + } + + var lp, mp string + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + lp = order.LimitPrice + mp = order.LimitPrice + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + lp = order.MarketPrice + mp = order.MarketPrice + } + } + + if order.StopLossPrice == flags.SetNull { + order.StopLossPrice = decimal.Zero.String() + } + if order.StopWinPrice == flags.SetNull { + order.StopWinPrice = decimal.Zero.String() + } + if order.LimitPrice == flags.SetNull { + order.LimitPrice = decimal.Zero.String() + } + if order.MarketPrice == flags.SetNull { + order.MarketPrice = decimal.Zero.String() + } + return models.BotStockInTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + Status: flags.EntrustStatus, + ServiceCost: order.ServiceCost, + OrderNumber: order.OrderNumber, + OrderMoney: orderMoney.String(), + OrderId: orderId, + MarketMoney: order.MarketMoney, + LimitPrice: lp, + MarketPrice: mp, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + DealPrice: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + PryNum: pryNum, + } +} + +// BotStockGbxTrade +// +// @Description: (英股下单|英股设置止损止盈|英股撤单|英股平仓) +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockGbxTrade +func BotStockGbxTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockGbxTrade { + marketPrice := decimal.RequireFromString(order.MarketMoney) + cost := decimal.RequireFromString(order.ServiceCost) + // total order Money + orderMoney := marketPrice.Add(cost) + pryNum, err := strconv.Atoi(order.PryNum) + if err != nil { + pryNum = 1 + } + + var lp, mp string + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + lp = order.LimitPrice + mp = order.LimitPrice + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + lp = order.MarketPrice + mp = order.MarketPrice + } + } + + if order.StopLossPrice == flags.SetNull { + order.StopLossPrice = decimal.Zero.String() + } + if order.StopWinPrice == flags.SetNull { + order.StopWinPrice = decimal.Zero.String() + } + if order.LimitPrice == flags.SetNull { + order.LimitPrice = decimal.Zero.String() + } + if order.MarketPrice == flags.SetNull { + order.MarketPrice = decimal.Zero.String() + } + return models.BotStockGbxTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + Status: flags.EntrustStatus, + ServiceCost: order.ServiceCost, + OrderNumber: order.OrderNumber, + OrderMoney: orderMoney.String(), + OrderId: orderId, + MarketMoney: order.MarketMoney, + LimitPrice: lp, + MarketPrice: mp, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + DealPrice: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + PryNum: pryNum, + } +} + +// BotStockOptionInrTrade +// +// @Description: (印度期权股下单|印度期权股设置止损止盈|印度期权股撤单|印度期权股平仓) +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockOptionInrTrade +func BotStockOptionInrTrade(ctx context.Context, userId int64, orderId, marginRatio string, order structure.ShareOrder) models.BotStockOptionInrTrade { + pryNum, err := strconv.Atoi(order.PryNum) + if err != nil { + pryNum = 1 + } + orderMoney := decimal.RequireFromString(marginRatio).Add(decimal.RequireFromString(order.ServiceCost)).String() + + multiplier, err := strconv.Atoi(order.Multiplier) + if err != nil { + multiplier = 1 + } + + var lp, mp string + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + lp = order.LimitPrice + mp = order.LimitPrice + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + lp = order.MarketPrice + mp = order.MarketPrice + } + } + if order.StrikePrice == flags.SetNull { + order.StrikePrice = decimal.Zero.String() + } + if order.StopLossPrice == flags.SetNull { + order.StopLossPrice = decimal.Zero.String() + } + if order.StopWinPrice == flags.SetNull { + order.StopWinPrice = decimal.Zero.String() + } + if order.LimitPrice == flags.SetNull { + order.LimitPrice = decimal.Zero.String() + } + if order.MarketPrice == flags.SetNull { + order.MarketPrice = decimal.Zero.String() + } + if order.Bid == flags.SetNull { + order.Bid = decimal.Zero.String() + } + if order.Ask == flags.SetNull { + order.Ask = decimal.Zero.String() + } + ratio := decimal.RequireFromString(flags.DecimalOne).Sub(decimal.RequireFromString(order.Ratio)).IntPart() + + return models.BotStockOptionInrTrade{ + UserId: int(userId), + OrderId: orderId, + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + Status: flags.EntrustStatus, + ServiceCost: order.ServiceCost, + OrderNumber: order.OrderNumber, + MarketMoney: marginRatio, + OrderMoney: orderMoney, + LimitPrice: lp, + MarketPrice: mp, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + DealPrice: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + PryNum: pryNum, + StopTime: order.StopTime, + StrikePrice: order.StrikePrice, + Multiplier: multiplier, + CostPrice: decimal.Zero.String(), + TradingType: int(order.TradingType), + Ratio: int(ratio), + StockCode: order.StockCode, + Bid: order.Bid, + Ask: order.Ask, + } +} + +// BotStockIdnStopByOrderId +// +// @Description: +// @param ctx +// @param order +// @return models.BotStockIdnTrade +func BotStockIdnStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockIdnTrade { + return models.BotStockIdnTrade{ + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StopWinPrice: order.StopWinPrice, + UpdateTime: time.Now(), + } +} + +// BotStockInStopByOrderId +// +// @Description: +// @param ctx +// @param order +// @return models.BotStockInTrade +func BotStockInStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockInTrade { + return models.BotStockInTrade{ + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StopWinPrice: order.StopWinPrice, + UpdateTime: time.Now(), + } +} + +// BotStockGbxStopByOrderId +// +// @Description: +// @param ctx +// @param order +// @return models.BotStockGbxTrade +func BotStockGbxStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockGbxTrade { + return models.BotStockGbxTrade{ + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StopWinPrice: order.StopWinPrice, + UpdateTime: time.Now(), + } +} + +// BotStockOptionInrStopByOrderId +// +// @Description: +// @param ctx +// @param order +// @return models.BotStockOptionInrTrade +func BotStockOptionInrStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockOptionInrTrade { + return models.BotStockOptionInrTrade{ + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StopWinPrice: order.StopWinPrice, + UpdateTime: time.Now(), + } +} + +// BotStockIdnCancelByOrderId +// +// @Description: +// @param ctx +// @return models.BotStockIdnTrade +func BotStockIdnCancelByOrderId(ctx context.Context) models.BotStockIdnTrade { + return models.BotStockIdnTrade{ + Status: flags.CancelStatus, + UpdateTime: time.Now(), + } +} + +// BotStockInCancelByOrderId +// +// @Description: +// @param ctx +// @return models.BotStockIdnTrade +func BotStockInCancelByOrderId(ctx context.Context) models.BotStockInTrade { + return models.BotStockInTrade{ + Status: flags.CancelStatus, + UpdateTime: time.Now(), + } +} + +// BotStockGbxCancelByOrderId +// +// @Description: +// @param ctx +// @return models.BotStockGbxTrade +func BotStockGbxCancelByOrderId(ctx context.Context) models.BotStockGbxTrade { + return models.BotStockGbxTrade{ + Status: flags.CancelStatus, + UpdateTime: time.Now(), + } +} + +// BotStockOptionInrCancelByOrderId +// +// @Description: +// @param ctx +// @return models.BotStockOptionInrTrade +func BotStockOptionInrCancelByOrderId(ctx context.Context) models.BotStockOptionInrTrade { + return models.BotStockOptionInrTrade{ + Status: flags.CancelStatus, + UpdateTime: time.Now(), + } +} + +// UpdateBotUserStockIdn +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockIdn +func UpdateBotUserStockIdn(ctx context.Context, usableNum, frozenNum string) models.BotUserStockIdn { + return models.BotUserStockIdn{ + UpdateTime: time.Now(), + FrozenNum: frozenNum, + UsableNum: usableNum, + } +} + +// UpdateBotUserStockIn +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockIn +func UpdateBotUserStockIn(ctx context.Context, usableNum, frozenNum string) models.BotUserStockIn { + return models.BotUserStockIn{ + UpdateTime: time.Now(), + FrozenNum: frozenNum, + UsableNum: usableNum, + } +} + +// UpdateBotUserStockGbx +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockGbx +func UpdateBotUserStockGbx(ctx context.Context, usableNum, frozenNum string) models.BotUserStockGbx { + return models.BotUserStockGbx{ + UpdateTime: time.Now(), + FrozenNum: frozenNum, + UsableNum: usableNum, + } +} + +// UpdateBotUserStockOptionInr +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockOptionInr +func UpdateBotUserStockOptionInr(ctx context.Context, usableNum, frozenNum string) models.BotUserStockOptionInr { + return models.BotUserStockOptionInr{ + UpdateTime: time.Now(), + FrozenNum: frozenNum, + UsableNum: usableNum, + } +} + +// CreateBotUserStockIdn +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockIdn +func CreateBotUserStockIdn(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockIdn { + return models.BotUserStockIdn{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// CreateBotUserStockIn +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockIn +func CreateBotUserStockIn(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockIn { + return models.BotUserStockIn{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// CreateBotUserStockGbx +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockGbx +func CreateBotUserStockGbx(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockGbx { + return models.BotUserStockGbx{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// CreateBotUserStockOptionInr +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockOptionInr +func CreateBotUserStockOptionInr(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockOptionInr { + return models.BotUserStockOptionInr{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// UpdateOpenBotStockIdnTrade +// +// @Description: +// @param ctx +// @param price +// @param orderNumber +// @param totalMoney +// @param serviceCost +// @return models.BotStockIdnTrade +func UpdateOpenBotStockIdnTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarketMoney string) models.BotStockIdnTrade { + return models.BotStockIdnTrade{ + OpenTime: time.Now(), + DealPrice: price, + ServiceCost: serviceCost, + OrderNumber: orderNumber, + OrderMoney: totalMoney, + MarketMoney: openMarketMoney, + Status: flags.PositionStatus, + } +} + +// UpdateOpenBotStockInTrade +// +// @Description: +// @param ctx +// @param price +// @param orderNumber +// @param totalMoney +// @param serviceCost +// @param openMarketMoney +// @return models.BotStockInTrade +func UpdateOpenBotStockInTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarketMoney string) models.BotStockInTrade { + return models.BotStockInTrade{ + OpenTime: time.Now(), + DealPrice: price, + ServiceCost: serviceCost, + OrderNumber: orderNumber, + OrderMoney: totalMoney, + MarketMoney: openMarketMoney, + Status: flags.PositionStatus, + } +} + +// UpdateOpenBotStockGbxTrade +// +// @Description: +// @param ctx +// @param price +// @param orderNumber +// @param totalMoney +// @param serviceCost +// @param openMarketMoney +// @return models.BotStockGbxTrade +func UpdateOpenBotStockGbxTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarketMoney string) models.BotStockGbxTrade { + return models.BotStockGbxTrade{ + OpenTime: time.Now(), + DealPrice: price, + ServiceCost: serviceCost, + OrderNumber: orderNumber, + OrderMoney: totalMoney, + MarketMoney: openMarketMoney, + Status: flags.PositionStatus, + } +} + +// UpdateOpenBotStockOptionInrTrade +// +// @Description: +// @param ctx +// @param price +// @param orderNumber +// @param totalMoney +// @param serviceCost +// @param openMarketMoney +// @return models.BotStockOptionInrTrade +func UpdateOpenBotStockOptionInrTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarketMoney string) models.BotStockOptionInrTrade { + return models.BotStockOptionInrTrade{ + OpenTime: time.Now(), + DealPrice: price, + ServiceCost: serviceCost, + OrderNumber: orderNumber, + OrderMoney: totalMoney, + MarketMoney: openMarketMoney, + Status: flags.PositionStatus, + CostPrice: decimal.Zero.String(), + } +} + +// UpdateCloseBotStockIdnTrade +// +// @Description: +// @param ctx +// @param price +// @param totalMoney +// @param serviceCost +// @return models.BotStockIdnTrade +func UpdateCloseBotStockIdnTrade(ctx context.Context, price, serviceCost string) models.BotStockIdnTrade { + return models.BotStockIdnTrade{ + ClosingTime: time.Now(), + ClosingPrice: price, + ClosingCost: serviceCost, + Status: flags.CloseStatus, + } +} + +// UpdateCloseBotStockInTrade +// +// @Description: +// @param ctx +// @param price +// @param serviceCost +// @return models.BotStockInTrade +func UpdateCloseBotStockInTrade(ctx context.Context, price, serviceCost string) models.BotStockInTrade { + return models.BotStockInTrade{ + ClosingTime: time.Now(), + ClosingPrice: price, + ClosingCost: serviceCost, + Status: flags.CloseStatus, + } +} + +// UpdateCloseBotStockGbxTrade +// +// @Description: +// @param ctx +// @param price +// @param serviceCost +// @return models.BotStockGbxTrade +func UpdateCloseBotStockGbxTrade(ctx context.Context, price, serviceCost string) models.BotStockGbxTrade { + return models.BotStockGbxTrade{ + ClosingTime: time.Now(), + ClosingPrice: price, + ClosingCost: serviceCost, + Status: flags.CloseStatus, + } +} + +// UpdateCloseBotStockOptionInrTrade +// +// @Description: +// @param ctx +// @param price +// @param serviceCost +// @return models.BotStockOptionInrTrade +func UpdateCloseBotStockOptionInrTrade(ctx context.Context, price, serviceCost string) models.BotStockOptionInrTrade { + return models.BotStockOptionInrTrade{ + ClosingTime: time.Now(), + ClosingPrice: price, + ClosingCost: serviceCost, + Status: flags.CloseStatus, + } +} + +// CreatBotUserStockIdnLog +// +// @Description: +// @param ctx +// @param userId +// @param code +// @param symbol +// @param changeNum +// @param orderId +// @return models.BotUserStockIdnLog +func CreatBotUserStockIdnLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockIdnLog { + return models.BotUserStockIdnLog{ + OrderId: orderId, + UserId: int(userId), + ChangeNum: changeNum, + ChangeType: int(code), + CreateTime: time.Now(), + UpdateTime: time.Now(), + StockId: symbol, + BeforeNum: decimal.Zero.String(), + } +} + +// CreatBotUserStockInLog +// +// @Description: +// @param ctx +// @param userId +// @param code +// @param symbol +// @param changeNum +// @param orderId +// @return models.BotUserStockInLog +func CreatBotUserStockInLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockInLog { + return models.BotUserStockInLog{ + OrderId: orderId, + UserId: int(userId), + ChangeNum: changeNum, + ChangeType: int(code), + CreateTime: time.Now(), + UpdateTime: time.Now(), + StockId: symbol, + BeforeNum: decimal.Zero.String(), + } +} + +// CreatBotUserStockGbxLog +// +// @Description: +// @param ctx +// @param userId +// @param code +// @param symbol +// @param changeNum +// @param orderId +// @return models.BotUserStockGbxLog +func CreatBotUserStockGbxLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockGbxLog { + return models.BotUserStockGbxLog{ + OrderId: orderId, + UserId: int(userId), + ChangeNum: changeNum, + ChangeType: int(code), + CreateTime: time.Now(), + UpdateTime: time.Now(), + StockId: symbol, + BeforeNum: decimal.Zero.String(), + } +} + +// CreatBotUserStockOptionInrLog +// +// @Description: +// @param ctx +// @param userId +// @param code +// @param symbol +// @param changeNum +// @param orderId +// @return models.BotUserStockOptionInrLog +func CreatBotUserStockOptionInrLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockOptionInrLog { + return models.BotUserStockOptionInrLog{ + OrderId: orderId, + UserId: int(userId), + ChangeNum: changeNum, + ChangeType: int(code), + CreateTime: time.Now(), + UpdateTime: time.Now(), + StockId: symbol, + BeforeNum: decimal.Zero.String(), + } +} + +// BotStockIdnTradePre (印度新股申购下单|设置止损止盈|撤单|平仓) +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockIdnTrade +func BotStockIdnTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockIdnTrade { + if order.StopWinPrice == flags.SetNull { + order.StopWinPrice = decimal.Zero.String() + } + if order.StopLossPrice == flags.SetNull { + order.StopLossPrice = decimal.Zero.String() + } + if order.MarketPrice == flags.SetNull { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == flags.SetNull { + order.LimitPrice = decimal.Zero.String() + } + + return models.BotStockIdnTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + ServiceCost: order.ServiceCost, + MarketPrice: order.MarketPrice, + MarketMoney: order.MarketMoney, + LimitPrice: order.LimitPrice, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + OrderId: orderId, + Status: flags.PositionStatus, + OpenTime: time.Now(), + DealPrice: order.LimitPrice, + OrderNumber: order.OrderNumber, + OrderMoney: order.MarketMoney, + OvernightCost: decimal.Zero.String(), + ClosingCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + PryNum: flags.SetPreOne, + } +} + +// BotStockMysTrade (马股下单|马股设置止损止盈|马股撤单|马股平仓) +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockMysTrade +func BotStockMysTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockMysTrade { + marketPrice := decimal.RequireFromString(order.MarketMoney) + cost := decimal.RequireFromString(order.ServiceCost) + // total order Money + orderMoney := marketPrice.Add(cost) + pryNum, err := strconv.Atoi(order.PryNum) + if err != nil { + pryNum = 1 + } + + var lp, mp string + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + lp = order.LimitPrice + mp = order.LimitPrice + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + lp = order.MarketPrice + mp = order.MarketPrice + } + } + + if order.StopLossPrice == flags.SetNull { + order.StopLossPrice = decimal.Zero.String() + } + if order.StopWinPrice == flags.SetNull { + order.StopWinPrice = decimal.Zero.String() + } + if order.MarketPrice == flags.SetNull { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == flags.SetNull { + order.LimitPrice = decimal.Zero.String() + } + + return models.BotStockMysTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + Status: flags.EntrustStatus, + ServiceCost: order.ServiceCost, + OrderNumber: order.OrderNumber, + OrderMoney: orderMoney.String(), + OrderId: orderId, + MarketMoney: order.MarketMoney, + LimitPrice: lp, + MarketPrice: mp, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + DealPrice: decimal.Zero.String(), + PryNum: pryNum, + } +} + +// BotStockMysStopByOrderId +// +// @Description: +// @param ctx +// @param order +// @return models.BotStockMysTrade +func BotStockMysStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockMysTrade { + return models.BotStockMysTrade{ + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StopWinPrice: order.StopWinPrice, + UpdateTime: time.Now(), + } +} + +// BotStockMysCancelByOrderId +// +// @Description: +// @param ctx +// @return models.BotStockMysTrade +func BotStockMysCancelByOrderId(ctx context.Context) models.BotStockMysTrade { + return models.BotStockMysTrade{ + Status: flags.CancelStatus, + UpdateTime: time.Now(), + } +} + +// UpdateBotUserStockMys +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockMys +func UpdateBotUserStockMys(ctx context.Context, usableNum, frozenNum string) models.BotUserStockMys { + return models.BotUserStockMys{ + UpdateTime: time.Now(), + FrozenNum: frozenNum, + UsableNum: usableNum, + } +} + +// CreateBotUserStockMys +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockMys +func CreateBotUserStockMys(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockMys { + return models.BotUserStockMys{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// UpdateOpenBotStockMysTrade +// +// @Description: +// @param ctx +// @param price +// @param orderNumber +// @param totalMoney +// @param serviceCost +// @return models.BotStockMysTrade +func UpdateOpenBotStockMysTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarkerMoney string) models.BotStockMysTrade { + return models.BotStockMysTrade{ + OpenTime: time.Now(), + DealPrice: price, + ServiceCost: serviceCost, + OrderNumber: orderNumber, + OrderMoney: totalMoney, + MarketMoney: openMarkerMoney, + Status: flags.PositionStatus, + } +} + +// UpdateCloseBotStockMysTrade +// +// @Description: +// @param ctx +// @param price +// @param totalMoney +// @param serviceCost +// @return models.BotStockMysTrade +func UpdateCloseBotStockMysTrade(ctx context.Context, price, serviceCost string) models.BotStockMysTrade { + return models.BotStockMysTrade{ + ClosingTime: time.Now(), + ClosingPrice: price, + ClosingCost: serviceCost, + Status: flags.CloseStatus, + } +} + +// CreatBotUserStockMysLog +// +// @Description: +// @param ctx +// @param userId +// @param code +// @param symbol +// @param changeNum +// @param orderId +// @return models.BotUserStockMysLog +func CreatBotUserStockMysLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockMysLog { + return models.BotUserStockMysLog{ + OrderId: orderId, + UserId: int(userId), + ChangeNum: changeNum, + ChangeType: int(code), + CreateTime: time.Now(), + UpdateTime: time.Now(), + StockId: symbol, + BeforeNum: decimal.Zero.String(), + } +} + +// BotStockMysTradePre +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockMysTrade +func BotStockMysTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockMysTrade { + if order.StopWinPrice == flags.SetNull { + order.StopWinPrice = decimal.Zero.String() + } + if order.StopLossPrice == flags.SetNull { + order.StopLossPrice = decimal.Zero.String() + } + if order.MarketPrice == flags.SetNull { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == flags.SetNull { + order.LimitPrice = decimal.Zero.String() + } + return models.BotStockMysTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + ServiceCost: order.ServiceCost, + MarketPrice: order.MarketPrice, + MarketMoney: order.MarketMoney, + LimitPrice: order.LimitPrice, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + OrderId: orderId, + Status: flags.PositionStatus, + OpenTime: time.Now(), + DealPrice: order.LimitPrice, + OrderNumber: order.OrderNumber, + OrderMoney: order.MarketMoney, + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + PryNum: flags.SetPreOne, + } +} + +// BotStockThaTrade (泰股下单|泰股设置止损止盈|泰股撤单|泰股平仓) +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockThaTrade +func BotStockThaTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockThaTrade { + marketPrice := decimal.RequireFromString(order.MarketMoney) + cost := decimal.RequireFromString(order.ServiceCost) + // total order Money + orderMoney := marketPrice.Add(cost) + pryNum, err := strconv.Atoi(order.PryNum) + if err != nil { + pryNum = 1 + } + + var lp, mp string + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + lp = order.LimitPrice + mp = order.LimitPrice + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + lp = order.MarketPrice + mp = order.MarketPrice + } + } + + if order.StopLossPrice == flags.SetNull { + order.StopLossPrice = decimal.Zero.String() + } + if order.StopWinPrice == flags.SetNull { + order.StopWinPrice = decimal.Zero.String() + } + if order.MarketPrice == flags.SetNull { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == flags.SetNull { + order.LimitPrice = decimal.Zero.String() + } + + return models.BotStockThaTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + Status: flags.EntrustStatus, + ServiceCost: order.ServiceCost, + OrderNumber: order.OrderNumber, + OrderMoney: orderMoney.String(), + OrderId: orderId, + MarketMoney: order.MarketMoney, + MarketPrice: mp, + LimitPrice: lp, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + DealPrice: decimal.Zero.String(), + PryNum: pryNum, + } +} + +// BotStockSgdTrade (新加坡股下单|新加坡股设置止损止盈|新加坡股撤单|新加坡股平仓) +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockSgdTrade +func BotStockSgdTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockSgdTrade { + marketPrice := decimal.RequireFromString(order.MarketMoney) + cost := decimal.RequireFromString(order.ServiceCost) + // total order Money + orderMoney := marketPrice.Add(cost) + pryNum, err := strconv.Atoi(order.PryNum) + if err != nil { + pryNum = 1 + } + + var lp, mp string + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + lp = order.LimitPrice + mp = order.LimitPrice + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + lp = order.MarketPrice + mp = order.MarketPrice + } + } + + if order.StopLossPrice == flags.SetNull { + order.StopLossPrice = decimal.Zero.String() + } + if order.StopWinPrice == flags.SetNull { + order.StopWinPrice = decimal.Zero.String() + } + if order.MarketPrice == flags.SetNull { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == flags.SetNull { + order.LimitPrice = decimal.Zero.String() + } + + return models.BotStockSgdTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + Status: flags.EntrustStatus, + ServiceCost: order.ServiceCost, + OrderNumber: order.OrderNumber, + OrderMoney: orderMoney.String(), + OrderId: orderId, + MarketMoney: order.MarketMoney, + MarketPrice: mp, + LimitPrice: lp, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + DealPrice: decimal.Zero.String(), + PryNum: pryNum, + } +} + +// BotStockEurTrade (德股下单|德股设置止损止盈|德股撤单|德股平仓) +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockEurTrade +func BotStockEurTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockEurTrade { + marketPrice := decimal.RequireFromString(order.MarketMoney) + cost := decimal.RequireFromString(order.ServiceCost) + // total order Money + orderMoney := marketPrice.Add(cost) + pryNum, err := strconv.Atoi(order.PryNum) + if err != nil { + pryNum = 1 + } + + var lp, mp string + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + lp = order.LimitPrice + mp = order.LimitPrice + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + lp = order.MarketPrice + mp = order.MarketPrice + } + } + + if order.StopLossPrice == flags.SetNull { + order.StopLossPrice = decimal.Zero.String() + } + if order.StopWinPrice == flags.SetNull { + order.StopWinPrice = decimal.Zero.String() + } + if order.MarketPrice == flags.SetNull { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == flags.SetNull { + order.LimitPrice = decimal.Zero.String() + } + + return models.BotStockEurTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + Status: flags.EntrustStatus, + ServiceCost: order.ServiceCost, + OrderNumber: order.OrderNumber, + OrderMoney: orderMoney.String(), + OrderId: orderId, + MarketMoney: order.MarketMoney, + MarketPrice: mp, + LimitPrice: lp, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + DealPrice: decimal.Zero.String(), + PryNum: pryNum, + } +} + +// BotStockBrlTrade +// +// @Description: (巴西股下单|设置止损止盈|撤单|平仓) +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockBrlTrade +func BotStockBrlTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockBrlTrade { + marketPrice := decimal.RequireFromString(order.MarketMoney) + cost := decimal.RequireFromString(order.ServiceCost) + // total order Money + orderMoney := marketPrice.Add(cost) + pryNum, err := strconv.Atoi(order.PryNum) + if err != nil { + pryNum = 1 + } + + var lp, mp string + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + lp = order.LimitPrice + mp = order.LimitPrice + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + lp = order.MarketPrice + mp = order.MarketPrice + } + } + + if order.StopLossPrice == flags.SetNull { + order.StopLossPrice = decimal.Zero.String() + } + if order.StopWinPrice == flags.SetNull { + order.StopWinPrice = decimal.Zero.String() + } + if order.MarketPrice == flags.SetNull { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == flags.SetNull { + order.LimitPrice = decimal.Zero.String() + } + + return models.BotStockBrlTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + Status: flags.EntrustStatus, + ServiceCost: order.ServiceCost, + OrderNumber: order.OrderNumber, + OrderMoney: orderMoney.String(), + OrderId: orderId, + MarketMoney: order.MarketMoney, + MarketPrice: mp, + LimitPrice: lp, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + DealPrice: decimal.Zero.String(), + PryNum: pryNum, + } +} + +// BotStockEurTrade (法股下单|德股设置止损止盈|德股撤单|德股平仓) +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockFurTrade +func BotStockFurTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockFurTrade { + marketPrice := decimal.RequireFromString(order.MarketMoney) + cost := decimal.RequireFromString(order.ServiceCost) + // total order Money + orderMoney := marketPrice.Add(cost) + pryNum, err := strconv.Atoi(order.PryNum) + if err != nil { + pryNum = 1 + } + + var lp, mp string + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + lp = order.LimitPrice + mp = order.LimitPrice + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + lp = order.MarketPrice + mp = order.MarketPrice + } + } + + if order.StopLossPrice == flags.SetNull { + order.StopLossPrice = decimal.Zero.String() + } + if order.StopWinPrice == flags.SetNull { + order.StopWinPrice = decimal.Zero.String() + } + if order.MarketPrice == flags.SetNull { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == flags.SetNull { + order.LimitPrice = decimal.Zero.String() + } + + return models.BotStockFurTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + Status: flags.EntrustStatus, + ServiceCost: order.ServiceCost, + OrderNumber: order.OrderNumber, + OrderMoney: orderMoney.String(), + OrderId: orderId, + MarketMoney: order.MarketMoney, + MarketPrice: mp, + LimitPrice: lp, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + DealPrice: decimal.Zero.String(), + PryNum: pryNum, + } +} + +// BotStockJpyTrade (日股下单|德股设置止损止盈|德股撤单|德股平仓) +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockFurTrade +func BotStockJpyTrade(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockJpTrade { + marketPrice := decimal.RequireFromString(order.MarketMoney) + cost := decimal.RequireFromString(order.ServiceCost) + // total order Money + orderMoney := marketPrice.Add(cost) + pryNum, err := strconv.Atoi(order.PryNum) + if err != nil { + pryNum = 1 + } + + var lp, mp string + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + lp = order.LimitPrice + mp = order.LimitPrice + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + lp = order.MarketPrice + mp = order.MarketPrice + } + } + + if order.StopLossPrice == flags.SetNull { + order.StopLossPrice = decimal.Zero.String() + } + if order.StopWinPrice == flags.SetNull { + order.StopWinPrice = decimal.Zero.String() + } + if order.MarketPrice == flags.SetNull { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == flags.SetNull { + order.LimitPrice = decimal.Zero.String() + } + + return models.BotStockJpTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + Status: flags.EntrustStatus, + ServiceCost: order.ServiceCost, + OrderNumber: order.OrderNumber, + OrderMoney: orderMoney.String(), + OrderId: orderId, + MarketMoney: order.MarketMoney, + MarketPrice: mp, + LimitPrice: lp, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + DealPrice: decimal.Zero.String(), + PryNum: pryNum, + } +} + +// BotStockThaStopByOrderId +// +// @Description: +// @param ctx +// @param order +// @return models.BotStockThaTrade +func BotStockThaStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockThaTrade { + return models.BotStockThaTrade{ + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StopWinPrice: order.StopWinPrice, + UpdateTime: time.Now(), + } +} + +// BotStockSgdStopByOrderId +// +// @Description: +// @param ctx +// @param order +// @return models.BotStockSgdTrade +func BotStockSgdStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockSgdTrade { + return models.BotStockSgdTrade{ + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StopWinPrice: order.StopWinPrice, + UpdateTime: time.Now(), + } +} + +// BotStockEurStopByOrderId +// +// @Description: +// @param ctx +// @param order +// @return models.BotStockEurTrade +func BotStockEurStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockEurTrade { + return models.BotStockEurTrade{ + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StopWinPrice: order.StopWinPrice, + UpdateTime: time.Now(), + } +} + +// BotStockBrlStopByOrderId +// +// @Description: +// @param ctx +// @param order +// @return models.BotStockBrlTrade +func BotStockBrlStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockBrlTrade { + return models.BotStockBrlTrade{ + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StopWinPrice: order.StopWinPrice, + UpdateTime: time.Now(), + } +} + +// BotStockFurStopByOrderId +// +// @Description: +// @param ctx +// @param order +// @return models.BotStockFurTrade +func BotStockFurStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockFurTrade { + return models.BotStockFurTrade{ + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StopWinPrice: order.StopWinPrice, + UpdateTime: time.Now(), + } +} + +// BotStockJpyStopByOrderId +// +// @Description: +// @param ctx +// @param order +// @return models.BotStockJpTrade +func BotStockJpyStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotStockJpTrade { + return models.BotStockJpTrade{ + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StopWinPrice: order.StopWinPrice, + UpdateTime: time.Now(), + } +} + +// BotStockThaCancelByOrderId +// +// @Description: +// @param ctx +// @return models.BotStockThaTrade +func BotStockThaCancelByOrderId(ctx context.Context) models.BotStockThaTrade { + return models.BotStockThaTrade{ + Status: flags.CancelStatus, + UpdateTime: time.Now(), + } +} + +// BotStockSgdCancelByOrderId +// +// @Description: +// @param ctx +// @return models.BotStockSgdTrade +func BotStockSgdCancelByOrderId(ctx context.Context) models.BotStockSgdTrade { + return models.BotStockSgdTrade{ + Status: flags.CancelStatus, + UpdateTime: time.Now(), + } +} + +// BotStockEurCancelByOrderId +// +// @Description: +// @param ctx +// @return models.BotStockEurTrade +func BotStockEurCancelByOrderId(ctx context.Context) models.BotStockEurTrade { + return models.BotStockEurTrade{ + Status: flags.CancelStatus, + UpdateTime: time.Now(), + } +} + +// BotStockBrlCancelByOrderId +// +// @Description: +// @param ctx +// @return models.BotStockBrlTrade +func BotStockBrlCancelByOrderId(ctx context.Context) models.BotStockBrlTrade { + return models.BotStockBrlTrade{ + Status: flags.CancelStatus, + UpdateTime: time.Now(), + } +} + +// BotStockFurCancelByOrderId +// +// @Description: +// @param ctx +// @return models.BotStockFurTrade +func BotStockFurCancelByOrderId(ctx context.Context) models.BotStockFurTrade { + return models.BotStockFurTrade{ + Status: flags.CancelStatus, + UpdateTime: time.Now(), + } +} + +// BotStockJpyCancelByOrderId +// +// @Description: +// @param ctx +// @return models.BotStockJpTrade +func BotStockJpyCancelByOrderId(ctx context.Context) models.BotStockJpTrade { + return models.BotStockJpTrade{ + Status: flags.CancelStatus, + UpdateTime: time.Now(), + } +} + +// UpdateBotUserStockTha +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockTha +func UpdateBotUserStockTha(ctx context.Context, usableNum, frozenNum string) models.BotUserStockTha { + return models.BotUserStockTha{ + UpdateTime: time.Now(), + FrozenNum: frozenNum, + UsableNum: usableNum, + } +} + +// UpdateBotUserStockSgd +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockSgd +func UpdateBotUserStockSgd(ctx context.Context, usableNum, frozenNum string) models.BotUserStockSgd { + return models.BotUserStockSgd{ + UpdateTime: time.Now(), + FrozenNum: frozenNum, + UsableNum: usableNum, + } +} + +// UpdateBotUserStockEur +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockEur +func UpdateBotUserStockEur(ctx context.Context, usableNum, frozenNum string) models.BotUserStockEur { + return models.BotUserStockEur{ + UpdateTime: time.Now(), + FrozenNum: frozenNum, + UsableNum: usableNum, + } +} + +// UpdateBotUserStockBrl +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockBrl +func UpdateBotUserStockBrl(ctx context.Context, usableNum, frozenNum string) models.BotUserStockBrl { + return models.BotUserStockBrl{ + UpdateTime: time.Now(), + FrozenNum: frozenNum, + UsableNum: usableNum, + } +} + +// UpdateBotUserStockFur +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockEur +func UpdateBotUserStockFur(ctx context.Context, usableNum, frozenNum string) models.BotUserStockFur { + return models.BotUserStockFur{ + UpdateTime: time.Now(), + FrozenNum: frozenNum, + UsableNum: usableNum, + } +} + +// UpdateBotUserStockJpy +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserStockJp +func UpdateBotUserStockJpy(ctx context.Context, usableNum, frozenNum string) models.BotUserStockJp { + return models.BotUserStockJp{ + UpdateTime: time.Now(), + FrozenNum: frozenNum, + UsableNum: usableNum, + } +} + +// CreateBotUserStockTha +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockTha +func CreateBotUserStockTha(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockTha { + return models.BotUserStockTha{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// CreateBotUserStockSgd +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockSgd +func CreateBotUserStockSgd(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockSgd { + return models.BotUserStockSgd{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// CreateBotUserStockEur +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockEur +func CreateBotUserStockEur(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockEur { + return models.BotUserStockEur{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// CreateBotUserStockBrl +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockBrl +func CreateBotUserStockBrl(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockBrl { + return models.BotUserStockBrl{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// CreateBotUserStockFur +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockFur +func CreateBotUserStockFur(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockFur { + return models.BotUserStockFur{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// CreateBotUserStockJpy +// +// @Description: +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return models.BotUserStockJp +func CreateBotUserStockJpy(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) models.BotUserStockJp { + return models.BotUserStockJp{ + UserId: int(userId), + StockId: stockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// UpdateOpenBotStockThaTrade +// +// @Description: +// @param ctx +// @param price +// @param orderNumber +// @param totalMoney +// @param serviceCost +// @return models.BotStockThaTrade +func UpdateOpenBotStockThaTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarkerMoney string) models.BotStockThaTrade { + return models.BotStockThaTrade{ + OpenTime: time.Now(), + DealPrice: price, + ServiceCost: serviceCost, + OrderNumber: orderNumber, + OrderMoney: totalMoney, + MarketMoney: openMarkerMoney, + Status: flags.PositionStatus, + } +} + +// UpdateOpenBotStockSgdTrade +// +// @Description: +// @param ctx +// @param price +// @param orderNumber +// @param totalMoney +// @param serviceCost +// @param openMarkerMoney +// @return models.BotStockSgdTrade +func UpdateOpenBotStockSgdTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarkerMoney string) models.BotStockSgdTrade { + return models.BotStockSgdTrade{ + OpenTime: time.Now(), + DealPrice: price, + ServiceCost: serviceCost, + OrderNumber: orderNumber, + OrderMoney: totalMoney, + MarketMoney: openMarkerMoney, + Status: flags.PositionStatus, + } +} + +// UpdateOpenBotStockEurTrade +// +// @Description: +// @param ctx +// @param price +// @param orderNumber +// @param totalMoney +// @param serviceCost +// @param openMarkerMoney +// @return models.BotStockEurTrade +func UpdateOpenBotStockEurTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarkerMoney string) models.BotStockEurTrade { + return models.BotStockEurTrade{ + OpenTime: time.Now(), + DealPrice: price, + ServiceCost: serviceCost, + OrderNumber: orderNumber, + OrderMoney: totalMoney, + MarketMoney: openMarkerMoney, + Status: flags.PositionStatus, + } +} + +// UpdateOpenBotStockBrlTrade +// +// @Description: +// @param ctx +// @param price +// @param orderNumber +// @param totalMoney +// @param serviceCost +// @param openMarkerMoney +// @return models.BotStockBrlTrade +func UpdateOpenBotStockBrlTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarkerMoney string) models.BotStockBrlTrade { + return models.BotStockBrlTrade{ + OpenTime: time.Now(), + DealPrice: price, + ServiceCost: serviceCost, + OrderNumber: orderNumber, + OrderMoney: totalMoney, + MarketMoney: openMarkerMoney, + Status: flags.PositionStatus, + } +} + +// UpdateOpenBotStockFurTrade +// +// @Description: +// @param ctx +// @param price +// @param orderNumber +// @param totalMoney +// @param serviceCost +// @param openMarkerMoney +// @return models.BotStockFurTrade +func UpdateOpenBotStockFurTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarkerMoney string) models.BotStockFurTrade { + return models.BotStockFurTrade{ + OpenTime: time.Now(), + DealPrice: price, + ServiceCost: serviceCost, + OrderNumber: orderNumber, + OrderMoney: totalMoney, + MarketMoney: openMarkerMoney, + Status: flags.PositionStatus, + } +} + +// UpdateOpenBotStockJpyTrade +// +// @Description: +// @param ctx +// @param price +// @param orderNumber +// @param totalMoney +// @param serviceCost +// @param openMarkerMoney +// @return models.BotStockJpTrade +func UpdateOpenBotStockJpyTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost, openMarkerMoney string) models.BotStockJpTrade { + return models.BotStockJpTrade{ + OpenTime: time.Now(), + DealPrice: price, + ServiceCost: serviceCost, + OrderNumber: orderNumber, + OrderMoney: totalMoney, + MarketMoney: openMarkerMoney, + Status: flags.PositionStatus, + } +} + +// UpdateCloseBotStockThaTrade +// +// @Description: +// @param ctx +// @param price +// @param totalMoney +// @param serviceCost +// @return models.BotStockThaTrade +func UpdateCloseBotStockThaTrade(ctx context.Context, price, serviceCost string) models.BotStockThaTrade { + return models.BotStockThaTrade{ + ClosingTime: time.Now(), + ClosingPrice: price, + ClosingCost: serviceCost, + Status: flags.CloseStatus, + } +} + +// UpdateCloseBotStockSgdTrade +// +// @Description: +// @param ctx +// @param price +// @param serviceCost +// @return models.BotStockSgdTrade +func UpdateCloseBotStockSgdTrade(ctx context.Context, price, serviceCost string) models.BotStockSgdTrade { + return models.BotStockSgdTrade{ + ClosingTime: time.Now(), + ClosingPrice: price, + ClosingCost: serviceCost, + Status: flags.CloseStatus, + } +} + +// UpdateCloseBotStockEurTrade +// +// @Description: +// @param ctx +// @param price +// @param serviceCost +// @return models.BotStockEurTrade +func UpdateCloseBotStockEurTrade(ctx context.Context, price, serviceCost string) models.BotStockEurTrade { + return models.BotStockEurTrade{ + ClosingTime: time.Now(), + ClosingPrice: price, + ClosingCost: serviceCost, + Status: flags.CloseStatus, + } +} + +// UpdateCloseBotStockBrlTrade +// +// @Description: +// @param ctx +// @param price +// @param serviceCost +// @return models.BotStockBrlTrade +func UpdateCloseBotStockBrlTrade(ctx context.Context, price, serviceCost string) models.BotStockBrlTrade { + return models.BotStockBrlTrade{ + ClosingTime: time.Now(), + ClosingPrice: price, + ClosingCost: serviceCost, + Status: flags.CloseStatus, + } +} + +// UpdateCloseBotStockFurTrade +// +// @Description: +// @param ctx +// @param price +// @param serviceCost +// @return models.BotStockFurTrade +func UpdateCloseBotStockFurTrade(ctx context.Context, price, serviceCost string) models.BotStockFurTrade { + return models.BotStockFurTrade{ + ClosingTime: time.Now(), + ClosingPrice: price, + ClosingCost: serviceCost, + Status: flags.CloseStatus, + } +} + +// UpdateCloseBotStockJpyTrade +// +// @Description: +// @param ctx +// @param price +// @param serviceCost +// @return models.BotStockJpTrade +func UpdateCloseBotStockJpyTrade(ctx context.Context, price, serviceCost string) models.BotStockJpTrade { + return models.BotStockJpTrade{ + ClosingTime: time.Now(), + ClosingPrice: price, + ClosingCost: serviceCost, + Status: flags.CloseStatus, + } +} + +// CreatBotUserStockThaLog +// +// @Description: +// @param ctx +// @param userId +// @param code +// @param symbol +// @param changeNum +// @param orderId +// @return models.BotUserStockThaLog +func CreatBotUserStockThaLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockThaLog { + return models.BotUserStockThaLog{ + OrderId: orderId, + UserId: int(userId), + ChangeNum: changeNum, + ChangeType: int(code), + CreateTime: time.Now(), + UpdateTime: time.Now(), + StockId: symbol, + BeforeNum: decimal.Zero.String(), + } +} + +// CreatBotUserStockEurLog +// +// @Description: +// @param ctx +// @param userId +// @param code +// @param symbol +// @param changeNum +// @param orderId +// @return models.BotUserStockEurLog +func CreatBotUserStockEurLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockEurLog { + return models.BotUserStockEurLog{ + OrderId: orderId, + UserId: int(userId), + ChangeNum: changeNum, + ChangeType: int(code), + CreateTime: time.Now(), + UpdateTime: time.Now(), + StockId: symbol, + BeforeNum: decimal.Zero.String(), + } +} + +// CreatBotUserStockBrlLog +// +// @Description: +// @param ctx +// @param userId +// @param code +// @param symbol +// @param changeNum +// @param orderId +// @return models.BotUserStockBrlLog +func CreatBotUserStockBrlLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockBrlLog { + return models.BotUserStockBrlLog{ + OrderId: orderId, + UserId: int(userId), + ChangeNum: changeNum, + ChangeType: int(code), + CreateTime: time.Now(), + UpdateTime: time.Now(), + StockId: symbol, + BeforeNum: decimal.Zero.String(), + } +} + +// CreatBotUserStockFurLog +// +// @Description: +// @param ctx +// @param userId +// @param code +// @param symbol +// @param changeNum +// @param orderId +// @return models.BotUserStockFurLog +func CreatBotUserStockFurLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockFurLog { + return models.BotUserStockFurLog{ + OrderId: orderId, + UserId: int(userId), + ChangeNum: changeNum, + ChangeType: int(code), + CreateTime: time.Now(), + UpdateTime: time.Now(), + StockId: symbol, + BeforeNum: decimal.Zero.String(), + } +} + +// CreatBotUserStockJpyLog +// +// @Description: +// @param ctx +// @param userId +// @param code +// @param symbol +// @param changeNum +// @param orderId +// @return models.BotUserStockJpLog +func CreatBotUserStockJpyLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockJpLog { + return models.BotUserStockJpLog{ + OrderId: orderId, + UserId: int(userId), + ChangeNum: changeNum, + ChangeType: int(code), + CreateTime: time.Now(), + UpdateTime: time.Now(), + StockId: symbol, + BeforeNum: decimal.Zero.String(), + } +} + +// CreatBotUserStockSgdLog +// +// @Description: +// @param ctx +// @param userId +// @param code +// @param symbol +// @param changeNum +// @param orderId +// @return models.BotUserStockSgdLog +func CreatBotUserStockSgdLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserStockSgdLog { + return models.BotUserStockSgdLog{ + OrderId: orderId, + UserId: int(userId), + ChangeNum: changeNum, + ChangeType: int(code), + CreateTime: time.Now(), + UpdateTime: time.Now(), + StockId: symbol, + BeforeNum: decimal.Zero.String(), + } +} + +// BotStockThaTradePre +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockThaTrade +func BotStockThaTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockThaTrade { + if order.StopWinPrice == "" { + order.StopWinPrice = decimal.Zero.String() + } + if order.StopLossPrice == "" { + order.StopLossPrice = decimal.Zero.String() + } + if order.MarketPrice == "" { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == "" { + order.LimitPrice = decimal.Zero.String() + } + return models.BotStockThaTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + ServiceCost: order.ServiceCost, + MarketPrice: order.MarketPrice, + MarketMoney: order.MarketMoney, + LimitPrice: order.LimitPrice, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + OrderId: orderId, + Status: flags.PositionStatus, + OpenTime: time.Now(), + DealPrice: order.LimitPrice, + OrderNumber: order.OrderNumber, + OrderMoney: order.MarketMoney, + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + PryNum: flags.SetPreOne, + } +} + +// BotStockInTradePre +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockInTrade +func BotStockInTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockInTrade { + if order.StopLossPrice == "" { + order.StopLossPrice = decimal.Zero.String() + } + if order.StopWinPrice == "" { + order.StopWinPrice = decimal.Zero.String() + } + if order.MarketPrice == "" { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == "" { + order.LimitPrice = decimal.Zero.String() + } + return models.BotStockInTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + ServiceCost: order.ServiceCost, + MarketPrice: order.MarketPrice, + MarketMoney: order.MarketMoney, + LimitPrice: order.LimitPrice, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + OrderId: orderId, + Status: flags.PositionStatus, + OpenTime: time.Now(), + DealPrice: order.LimitPrice, + OrderNumber: order.OrderNumber, + OrderMoney: order.MarketMoney, + OvernightCost: decimal.Zero.String(), + ClosingCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + PryNum: flags.SetPreOne, + } +} + +// BotStockSgdTradePre +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockSgdTrade +func BotStockSgdTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockSgdTrade { + if order.StopLossPrice == "" { + order.StopLossPrice = decimal.Zero.String() + } + if order.StopWinPrice == "" { + order.StopWinPrice = decimal.Zero.String() + } + if order.MarketPrice == "" { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == "" { + order.LimitPrice = decimal.Zero.String() + } + return models.BotStockSgdTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + ServiceCost: order.ServiceCost, + MarketPrice: order.MarketPrice, + MarketMoney: order.MarketMoney, + LimitPrice: order.LimitPrice, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + OrderId: orderId, + Status: flags.PositionStatus, + OpenTime: time.Now(), + DealPrice: order.LimitPrice, + OrderNumber: order.OrderNumber, + OrderMoney: order.MarketMoney, + OvernightCost: decimal.Zero.String(), + ClosingCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + PryNum: flags.SetPreOne, + } +} + +// BotStockGbxTradePre +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockGbxTrade +func BotStockGbxTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockGbxTrade { + if order.StopLossPrice == "" { + order.StopLossPrice = decimal.Zero.String() + } + if order.StopWinPrice == "" { + order.StopWinPrice = decimal.Zero.String() + } + if order.MarketPrice == "" { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == "" { + order.LimitPrice = decimal.Zero.String() + } + return models.BotStockGbxTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + ServiceCost: order.ServiceCost, + MarketPrice: order.MarketPrice, + MarketMoney: order.MarketMoney, + LimitPrice: order.LimitPrice, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + OrderId: orderId, + Status: flags.PositionStatus, + OpenTime: time.Now(), + DealPrice: order.LimitPrice, + OrderNumber: order.OrderNumber, + OrderMoney: order.MarketMoney, + OvernightCost: decimal.Zero.String(), + ClosingCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + PryNum: flags.SetPreOne, + } +} + +// BotStockEurTradePre +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockEurTrade +func BotStockEurTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockEurTrade { + if order.StopLossPrice == "" { + order.StopLossPrice = decimal.Zero.String() + } + if order.StopWinPrice == "" { + order.StopWinPrice = decimal.Zero.String() + } + if order.MarketPrice == "" { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == "" { + order.LimitPrice = decimal.Zero.String() + } + return models.BotStockEurTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + ServiceCost: order.ServiceCost, + MarketPrice: order.MarketPrice, + MarketMoney: order.MarketMoney, + LimitPrice: order.LimitPrice, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + OrderId: orderId, + Status: flags.PositionStatus, + OpenTime: time.Now(), + DealPrice: order.LimitPrice, + OrderNumber: order.OrderNumber, + OrderMoney: order.MarketMoney, + OvernightCost: decimal.Zero.String(), + ClosingCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + PryNum: flags.SetPreOne, + } +} + +// BotStockBrlTradePre +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockBrlTrade +func BotStockBrlTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockBrlTrade { + if order.StopLossPrice == "" { + order.StopLossPrice = decimal.Zero.String() + } + if order.StopWinPrice == "" { + order.StopWinPrice = decimal.Zero.String() + } + if order.MarketPrice == "" { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == "" { + order.LimitPrice = decimal.Zero.String() + } + return models.BotStockBrlTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + ServiceCost: order.ServiceCost, + MarketPrice: order.MarketPrice, + MarketMoney: order.MarketMoney, + LimitPrice: order.LimitPrice, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + OrderId: orderId, + Status: flags.PositionStatus, + OpenTime: time.Now(), + DealPrice: order.LimitPrice, + OrderNumber: order.OrderNumber, + OrderMoney: order.MarketMoney, + OvernightCost: decimal.Zero.String(), + ClosingCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + PryNum: flags.SetPreOne, + } +} + +// BotStockFurTradePre +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockFurTrade +func BotStockFurTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockFurTrade { + if order.StopLossPrice == "" { + order.StopLossPrice = decimal.Zero.String() + } + if order.StopWinPrice == "" { + order.StopWinPrice = decimal.Zero.String() + } + if order.MarketPrice == "" { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == "" { + order.LimitPrice = decimal.Zero.String() + } + return models.BotStockFurTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + ServiceCost: order.ServiceCost, + MarketPrice: order.MarketPrice, + MarketMoney: order.MarketMoney, + LimitPrice: order.LimitPrice, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + OrderId: orderId, + Status: flags.PositionStatus, + OpenTime: time.Now(), + DealPrice: order.LimitPrice, + OrderNumber: order.OrderNumber, + OrderMoney: order.MarketMoney, + OvernightCost: decimal.Zero.String(), + ClosingCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + PryNum: flags.SetPreOne, + } +} + +// BotStockJpyTradePre +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockJpTrade +func BotStockJpyTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockJpTrade { + if order.StopLossPrice == "" { + order.StopLossPrice = decimal.Zero.String() + } + if order.StopWinPrice == "" { + order.StopWinPrice = decimal.Zero.String() + } + if order.MarketPrice == "" { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == "" { + order.LimitPrice = decimal.Zero.String() + } + return models.BotStockJpTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + ServiceCost: order.ServiceCost, + MarketPrice: order.MarketPrice, + MarketMoney: order.MarketMoney, + LimitPrice: order.LimitPrice, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + OrderId: orderId, + Status: flags.PositionStatus, + OpenTime: time.Now(), + DealPrice: order.LimitPrice, + OrderNumber: order.OrderNumber, + OrderMoney: order.MarketMoney, + OvernightCost: decimal.Zero.String(), + ClosingCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + PryNum: flags.SetPreOne, + } +} + +// BotStockHkdTradePre +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotStockHkdTrade +func BotStockHkdTradePre(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) models.BotStockHkdTrade { + if order.StopLossPrice == "" { + order.StopLossPrice = decimal.Zero.String() + } + if order.StopWinPrice == "" { + order.StopWinPrice = decimal.Zero.String() + } + if order.MarketPrice == "" { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == "" { + order.LimitPrice = decimal.Zero.String() + } + return models.BotStockHkdTrade{ + UserId: int(userId), + TradeType: int(order.TradeType), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StockId: order.StockId, + ServiceCost: order.ServiceCost, + MarketPrice: order.MarketPrice, + MarketMoney: order.MarketMoney, + LimitPrice: order.LimitPrice, + DealType: int(order.DealType), + CreateTime: time.Now(), + UpdateTime: time.Now(), + OrderId: orderId, + Status: flags.PositionStatus, + OpenTime: time.Now(), + DealPrice: order.LimitPrice, + OrderNumber: order.OrderNumber, + OrderMoney: order.MarketMoney, + OvernightCost: decimal.Zero.String(), + ClosingCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + PryNum: flags.SetPreOne, + } +} + +// BotDigitalTrade (现货(下单|平仓)操作) +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotDigitalTrade +func BotDigitalTrade(ctx context.Context, userId int64, orderId string, order structure.SpotsOrder) models.BotDigitalTrade { + marketPrice := decimal.RequireFromString(order.OrderMoney) + cost := decimal.RequireFromString(order.ServiceCost) + // total order Money + orderMoney := marketPrice.Add(cost) + + if order.MarketPrice == "" { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == "" { + order.LimitPrice = decimal.Zero.String() + } + if order.MarketPrice == "" { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == "" { + order.LimitPrice = decimal.Zero.String() + } + if order.DealPrice == "" { + order.DealPrice = decimal.Zero.String() + } + + return models.BotDigitalTrade{ + UserId: int(userId), + UpdateTime: time.Now(), + TradeType: int(order.TradeType), + TotalMoney: orderMoney.String(), + Status: flags.EntrustStatus, + ServiceCost: order.ServiceCost, + OrderNumber: order.OrderNumber, + OrderMoney: order.OrderMoney, + OrderId: orderId, + MarketPrice: order.MarketPrice, + LimitPrice: order.LimitPrice, + DigitalId: order.DigitalId, + DealType: int(order.DealType), + DealPrice: order.DealPrice, + CreateTime: time.Now(), + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + } +} + +// UpdateBotDigitalCancelByOrderId +// +// @Description: +// @param ctx +// @return models.BotDigitalTrade +func UpdateBotDigitalCancelByOrderId(ctx context.Context) models.BotDigitalTrade { + return models.BotDigitalTrade{ + Status: flags.CancelStatus, + UpdateTime: time.Now(), + } +} + +// UpdateBotDigitalStatusByOrderId +// +// @Description: +// @param ctx +// @param closingPrice +// @param closingCost +// @param orderMoneyPrice +// @param totalMoneyPrice +// @param OrderNumber +// @return models.BotDigitalTrade +func UpdateBotDigitalStatusByOrderId(ctx context.Context, closingPrice, closingCost, orderMoneyPrice, totalMoneyPrice, OrderNumber string) models.BotDigitalTrade { + return models.BotDigitalTrade{ + Status: flags.CloseStatus, + ClosingPrice: closingPrice, + ClosingCost: closingCost, + OrderMoney: orderMoneyPrice, + TotalMoney: totalMoneyPrice, + OrderNumber: OrderNumber, + ClosingTime: time.Now(), + UpdateTime: time.Now(), + } +} +func UpdateBotMoneyStatusByOrderId(ctx context.Context, closingPrice, closingCost, orderMoneyPrice, totalMoneyPrice, OrderNumber string) models.BotMoneyTrade { + return models.BotMoneyTrade{ + Status: flags.CloseStatus, + ClosingPrice: closingPrice, + ClosingCost: closingCost, + OrderMoney: orderMoneyPrice, + OrderNumber: OrderNumber, + ClosingTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// UpdateBotUserDigital +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserDigital +func UpdateBotUserDigital(ctx context.Context, usableNum, frozenNum string) models.BotUserDigital { + return models.BotUserDigital{ + UpdateTime: time.Now(), + UsableNum: usableNum, + FrozenNum: frozenNum, + } +} +func UpdateBotUserMoneySpots(ctx context.Context, usableNum, frozenNum string) models.BotUserMoney { + return models.BotUserMoney{ + UpdateTime: time.Now(), + UsableNum: usableNum, + FrozenNum: frozenNum, + } +} + +// UpdateBotUserDigitalByUsableNum +// +// @Description: +// @param ctx +// @param usableNum +// @return models.BotUserDigital +func UpdateBotUserDigitalByUsableNum(ctx context.Context, usableNum string) models.BotUserDigital { + return models.BotUserDigital{ + UpdateTime: time.Now(), + UsableNum: usableNum, + } +} + +// UpdateBotUserDigitalByFrozenNum +// +// @Description: +// @param ctx +// @param frozenNum +// @return models.BotUserDigital +func UpdateBotUserDigitalByFrozenNum(ctx context.Context, frozenNum string) models.BotUserDigital { + return models.BotUserDigital{ + UpdateTime: time.Now(), + FrozenNum: frozenNum, + } +} + +// CreatBotUserBrokerage +// +// @Description: +// @param ctx +// @param backType +// @param userId +// @param LevelType +// @param fee +// @param brokerageNum +// @param orderId +// @return models.BotUserBrokerage +func CreatBotUserBrokerage(ctx context.Context, backType, userId, LevelType int, fee, brokerageNum, orderId string) models.BotUserBrokerage { + return models.BotUserBrokerage{ + OrderId: orderId, + BackType: backType, + UserId: userId, + LevelType: LevelType, + CreateTime: time.Now(), + ServiceFee: fee, + BrokerageNum: brokerageNum, + } +} + +// CreatBotTradeFee +// +// @Description: +// @param ctx +// @param userId +// @param code +// @param marketCode +// @param fee +// @param orderId +// @return models.BotTradeFee +func CreatBotTradeFee(ctx context.Context, userId, code, marketCode int, fee, orderId string) models.BotTradeFee { + return models.BotTradeFee{ + AccountType: code, + CreateTime: time.Now(), + ServiceFee: fee, + TradeNo: orderId, + TradeType: marketCode, + UserId: userId, + } +} + +// BotUserDigital +// +// @Description: +// @param ctx +// @param userId +// @param usableNum +// @param frozenNum +// @param order +// @return models.BotUserDigital +func BotUserDigital(ctx context.Context, userId int64, usableNum, frozenNum string, order structure.SpotsOrder) models.BotUserDigital { + return models.BotUserDigital{ + UserId: int(userId), + DigitalId: order.DigitalId, + FrozenNum: frozenNum, + UsableNum: usableNum, + UpdateTime: time.Now(), + CreateTime: time.Now(), + } +} +func BotUserMoneySpots(ctx context.Context, userId int64, usableNum, frozenNum string, order structure.MoneyOrder) models.BotUserMoney { + return models.BotUserMoney{ + UserId: int(userId), + StockId: order.StockId, + FrozenNum: frozenNum, + UsableNum: usableNum, + UpdateTime: time.Now(), + CreateTime: time.Now(), + } +} + +// CreatBotUserDigitalLog +// +// @Description: +// @param ctx +// @param userId +// @param code +// @param symbol +// @param changeNum +// @param orderId +// @return models.BotUserDigitalLog +func CreatBotUserDigitalLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserDigitalLog { + return models.BotUserDigitalLog{ + OrderId: orderId, + UserId: int(userId), + BeforeNum: decimal.Zero.String(), + ChangeNum: changeNum, + ChangeType: int(code), + CreateTime: time.Now(), + UpdateTime: time.Now(), + DigitalId: symbol, + } +} + +// BotContractTrade (合约下单|设置止损止盈|撤单|平仓) +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotContractTrade +func BotContractTrade(ctx context.Context, userId int64, orderId string, order structure.ContractOrder) models.BotContractTrade { + marketPrice := decimal.RequireFromString(order.OrderAmount) + cost := decimal.RequireFromString(order.ServiceCost) + pryNum := decimal.RequireFromString(order.PryNum).IntPart() + + state := 0 + if order.Time > 0 { + state = 1 + } + + // total order Money + orderMoney := marketPrice.Add(cost) + + if order.StopWinPrice == "" { + order.StopWinPrice = decimal.Zero.String() + } + if order.StopLossPrice == "" { + order.StopLossPrice = decimal.Zero.String() + } + if order.MarketPrice == "" { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == "" { + order.LimitPrice = decimal.Zero.String() + } + + return models.BotContractTrade{ + UserId: int(userId), + UpdateTime: time.Now(), + TradeType: int(order.TradeType), + TotalMoney: orderMoney.String(), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + Status: flags.EntrustStatus, + ServiceCost: order.ServiceCost, + OrderNumber: order.OrderNumber, + OrderMoney: order.EarnestMoney, + OrderId: orderId, + MarketPrice: order.MarketPrice, + LimitPrice: order.LimitPrice, + EarnestMoney: order.EarnestMoney, + DealType: int(order.DealType), + CreateTime: time.Now(), + ContractId: order.ContractId, + FaceValue: order.System.FaceValue.IntPart(), + PryNum: int(pryNum), + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + DealPrice: decimal.Zero.String(), + SecondTime: int(order.Time), + State: state, + } +} + +// BotForexTrade +// +// @Description: (外汇下单|设置止损止盈|撤单|平仓) +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotForexTrade +func BotForexTrade(ctx context.Context, userId int64, orderId string, order structure.ForexOrder) models.BotForexTrade { + marketPrice := decimal.RequireFromString(order.OrderAmount) + cost := decimal.RequireFromString(order.ServiceCost) + pryNum := decimal.RequireFromString(order.PryNum).IntPart() + + state := 0 + if order.Time > 0 { + state = 1 + } + + // total order Money + orderMoney := marketPrice.Add(cost) + + if order.StopWinPrice == "" { + order.StopWinPrice = decimal.Zero.String() + } + if order.StopLossPrice == "" { + order.StopLossPrice = decimal.Zero.String() + } + if order.MarketPrice == "" { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == "" { + order.LimitPrice = decimal.Zero.String() + } + + return models.BotForexTrade{ + UserId: int(userId), + UpdateTime: time.Now(), + TradeType: int(order.TradeType), + TotalMoney: orderMoney.String(), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + Status: flags.EntrustStatus, + ServiceCost: order.ServiceCost, + OrderNumber: order.OrderNumber, + OrderMoney: order.EarnestMoney, + OrderId: orderId, + MarketPrice: order.MarketPrice, + LimitPrice: order.LimitPrice, + EarnestMoney: order.EarnestMoney, + DealType: int(order.DealType), + CreateTime: time.Now(), + ContractId: order.ForexId, + FaceValue: order.System.FaceValue.IntPart(), + PryNum: int(pryNum), + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + DealPrice: decimal.Zero.String(), + SecondTime: int(order.Time), + State: state, + } +} + +// BotMoneyTrade +// +// @Description: (综合(现货|合约|外汇)下单|设置止损止盈|撤单|平仓) +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotMoneyTrade +func BotMoneyTrade(ctx context.Context, userId int64, orderId string, order structure.MoneyOrder) models.BotMoneyTrade { + marketPrice := decimal.RequireFromString(order.OrderAmount) + cost := decimal.RequireFromString(order.ServiceCost) + pryNum := decimal.RequireFromString(order.PryNum).IntPart() + + // total order Money + orderMoney := marketPrice.Add(cost) + + if order.StopWinPrice == "" { + order.StopWinPrice = decimal.Zero.String() + } + if order.StopLossPrice == "" { + order.StopLossPrice = decimal.Zero.String() + } + if order.MarketPrice == "" { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == "" { + order.LimitPrice = decimal.Zero.String() + } + + return models.BotMoneyTrade{ + UserId: int(userId), + UpdateTime: time.Now(), + TradeType: int(order.TradeType), + MarketMoney: order.EarnestMoney, + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + Status: flags.EntrustStatus, + ServiceCost: order.ServiceCost, + OrderNumber: order.OrderNumber, + OrderMoney: orderMoney.String(), + OrderId: orderId, + MarketPrice: order.MarketPrice, + LimitPrice: order.LimitPrice, + DealType: int(order.DealType), + CreateTime: time.Now(), + StockId: order.StockId, + FaceValue: 1, + PryNum: int(pryNum), + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + DealPrice: decimal.Zero.String(), + MarketType: int(order.Type), + } +} + +// BotContractSecTrade (秒合约下单|设置止损止盈|撤单|平仓) +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param order +// @return models.BotContractSecTrade +func BotContractSecTrade(ctx context.Context, userId int64, orderId string, order structure.ContractOrder) models.BotContractSecTrade { + marketPrice := decimal.RequireFromString(order.OrderAmount) + cost := decimal.RequireFromString(order.ServiceCost) + pryNum := decimal.RequireFromString(order.PryNum).IntPart() + + state := 0 + if order.Time > 0 { + state = 1 + } + + // total order Money + orderMoney := marketPrice.Add(cost) + + if order.StopWinPrice == "" { + order.StopWinPrice = decimal.Zero.String() + } + if order.StopLossPrice == "" { + order.StopLossPrice = decimal.Zero.String() + } + if order.MarketPrice == "" { + order.MarketPrice = decimal.Zero.String() + } + if order.LimitPrice == "" { + order.LimitPrice = decimal.Zero.String() + } + + return models.BotContractSecTrade{ + UserId: int(userId), + UpdateTime: time.Now(), + TradeType: int(order.TradeType), + TotalMoney: orderMoney.String(), + StopWinPrice: order.StopWinPrice, + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + Status: flags.EntrustStatus, + ServiceCost: order.ServiceCost, + OrderNumber: order.OrderNumber, + OrderMoney: order.EarnestMoney, + OrderId: orderId, + MarketPrice: order.MarketPrice, + LimitPrice: order.LimitPrice, + EarnestMoney: order.EarnestMoney, + DealType: int(order.DealType), + CreateTime: time.Now(), + ContractId: order.ContractId, + FaceValue: order.System.FaceValue.IntPart(), + PryNum: int(pryNum), + ClosingCost: decimal.Zero.String(), + OvernightCost: decimal.Zero.String(), + ClosingPrice: decimal.Zero.String(), + DealPrice: decimal.Zero.String(), + SecondTime: int(order.Time), + State: state, + OrderStatus: 0, + OrderValue: decimal.Zero.String(), + } +} + +// UpdateOpenBotContractTrade +// +// @Description: +// @param ctx +// @param price +// @param orderNumber +// @param totalMoney +// @param serviceCost +// @return models.BotContractTrade +func UpdateOpenBotContractTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost string) models.BotContractTrade { + return models.BotContractTrade{ + OpenTime: time.Now(), + DealPrice: price, + ServiceCost: serviceCost, + OrderNumber: orderNumber, + TotalMoney: totalMoney, + Status: flags.PositionStatus, + } +} +func UpdateOpenBotForexTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost string) models.BotForexTrade { + return models.BotForexTrade{ + OpenTime: time.Now(), + DealPrice: price, + ServiceCost: serviceCost, + OrderNumber: orderNumber, + TotalMoney: totalMoney, + Status: flags.PositionStatus, + } +} +func UpdateOpenBotMoneyTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost string) models.BotMoneyTrade { + return models.BotMoneyTrade{ + OpenTime: time.Now(), + DealPrice: price, + ServiceCost: serviceCost, + OrderNumber: orderNumber, + OrderMoney: totalMoney, + Status: flags.PositionStatus, + } +} + +// UpdateOpenBotContractSecTrade +// +// @Description: +// @param ctx +// @param price +// @param orderNumber +// @param totalMoney +// @param serviceCost +// @return models.BotContractTrade +func UpdateOpenBotContractSecTrade(ctx context.Context, price, orderNumber, totalMoney, serviceCost string) models.BotContractSecTrade { + return models.BotContractSecTrade{ + OpenTime: time.Now(), + DealPrice: price, + ServiceCost: serviceCost, + OrderNumber: orderNumber, + TotalMoney: totalMoney, + Status: flags.PositionStatus, + } +} + +// UpdateCloseBotContractTrade +// +// @Description: +// @param ctx +// @param price +// @param earnestMoney +// @param totalMoney +// @param serviceCost +// @return models.BotContractTrade +func UpdateCloseBotContractTrade(ctx context.Context, price, earnestMoney, totalMoney, serviceCost string) models.BotContractTrade { + return models.BotContractTrade{ + ClosingTime: time.Now(), + ClosingPrice: price, + EarnestMoney: earnestMoney, + TotalMoney: totalMoney, + ClosingCost: serviceCost, + Status: flags.CloseStatus, + } +} +func UpdateCloseBotForexTrade(ctx context.Context, price, earnestMoney, totalMoney, serviceCost string) models.BotForexTrade { + return models.BotForexTrade{ + ClosingTime: time.Now(), + ClosingPrice: price, + EarnestMoney: earnestMoney, + TotalMoney: totalMoney, + ClosingCost: serviceCost, + Status: flags.CloseStatus, + } +} +func UpdateCloseBotMoneyTrade(ctx context.Context, price, earnestMoney, totalMoney, serviceCost string, status int) models.BotMoneyTrade { + return models.BotMoneyTrade{ + ClosingTime: time.Now(), + ClosingPrice: price, + MarketMoney: earnestMoney, + OrderMoney: totalMoney, + ClosingCost: serviceCost, + Status: status, //flags.CloseStatus, + } +} + +// UpdateCloseBotContractSecTrade +// +// @Description: +// @param ctx +// @param price +// @param earnestMoney +// @param totalMoney +// @param serviceCost +// @return models.BotContractSecTrade +func UpdateCloseBotContractSecTrade(ctx context.Context, price, earnestMoney, totalMoney, serviceCost, orderValue string, orderStatus int, closeTime time.Time) models.BotContractSecTrade { + return models.BotContractSecTrade{ + ClosingTime: closeTime, + ClosingPrice: price, + EarnestMoney: earnestMoney, + TotalMoney: totalMoney, + ClosingCost: serviceCost, + Status: flags.CloseStatus, + OrderStatus: orderStatus, + OrderValue: orderValue, + } +} + +// BotContractStopByOrderId +// +// @Description: +// @param ctx +// @param order +// @return models.BotContractTrade +func BotContractStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotContractTrade { + return models.BotContractTrade{ + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StopWinPrice: order.StopWinPrice, + UpdateTime: time.Now(), + } +} + +func BotForexStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotForexTrade { + return models.BotForexTrade{ + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StopWinPrice: order.StopWinPrice, + UpdateTime: time.Now(), + } +} +func BotMoneyStopByOrderId(ctx context.Context, order structure.StopOrder) models.BotMoneyTrade { + return models.BotMoneyTrade{ + StopType: int(order.StopType), + StopLossPrice: order.StopLossPrice, + StopWinPrice: order.StopWinPrice, + UpdateTime: time.Now(), + } +} + +// BotContractCancelByOrderId +// +// @Description: +// @param ctx +// @return models.BotContractTrade +func BotContractCancelByOrderId(ctx context.Context) models.BotContractTrade { + return models.BotContractTrade{ + Status: flags.CancelStatus, + UpdateTime: time.Now(), + } +} +func BotForexCancelByOrderId(ctx context.Context) models.BotForexTrade { + return models.BotForexTrade{ + Status: flags.CancelStatus, + UpdateTime: time.Now(), + } +} +func BotMoneyCancelByOrderId(ctx context.Context) models.BotMoneyTrade { + return models.BotMoneyTrade{ + Status: flags.CancelStatus, + UpdateTime: time.Now(), + } +} + +// BotContractClosingByOrderId +// +// @Description: +// @param ctx +// @return models.BotContractTrade +func BotContractClosingByOrderId(ctx context.Context) models.BotContractTrade { + return models.BotContractTrade{ + Status: flags.CloseStatus, + UpdateTime: time.Now(), + } +} + +// UpdateBotUserContract +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserContract +func UpdateBotUserContract(ctx context.Context, usableNum, frozenNum string) models.BotUserContract { + return models.BotUserContract{ + UpdateTime: time.Now(), + UsableNum: usableNum, + FrozenNum: frozenNum, + } +} + +// UpdateBotUserForex +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserForex +func UpdateBotUserForex(ctx context.Context, usableNum, frozenNum string) models.BotUserForex { + return models.BotUserForex{ + UpdateTime: time.Now(), + UsableNum: usableNum, + FrozenNum: frozenNum, + } +} + +// UpdateBotUserMoney +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserMoney +func UpdateBotUserMoney(ctx context.Context, usableNum, frozenNum string) models.BotUserMoney { + return models.BotUserMoney{ + UpdateTime: time.Now(), + UsableNum: usableNum, + FrozenNum: frozenNum, + } +} + +// UpdateBotUserContractSec +// +// @Description: +// @param ctx +// @param usableNum +// @param frozenNum +// @return models.BotUserContract +func UpdateBotUserContractSec(ctx context.Context, usableNum, frozenNum string) models.BotUserContractSec { + return models.BotUserContractSec{ + UpdateTime: time.Now(), + UsableNum: usableNum, + FrozenNum: frozenNum, + } +} + +// CreatBotUserContract +// +// @Description: +// @param ctx +// @param userId +// @param usableNum +// @param frozenNum +// @param order +// @return models.BotUserContract +func CreatBotUserContract(ctx context.Context, userId int64, usableNum, frozenNum string, order structure.ContractOrder) models.BotUserContract { + return models.BotUserContract{ + UserId: int(userId), + ContractId: order.ContractId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} +func CreatBotUserForex(ctx context.Context, userId int64, usableNum, frozenNum string, order structure.ForexOrder) models.BotUserForex { + return models.BotUserForex{ + UserId: int(userId), + ContractId: order.ForexId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} +func CreatBotUserMoney(ctx context.Context, userId int64, usableNum, frozenNum string, order structure.MoneyOrder) models.BotUserMoney { + return models.BotUserMoney{ + UserId: int(userId), + StockId: order.StockId, + UsableNum: usableNum, + FrozenNum: frozenNum, + CreateTime: time.Now(), + UpdateTime: time.Now(), + } +} + +// CreatBotUserContractLog +// +// @Description: +// @param ctx +// @param userId +// @param code +// @param symbol +// @param changeNum +// @param orderId +// @return models.BotUserContractLog +func CreatBotUserContractLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserContractLog { + return models.BotUserContractLog{ + OrderId: orderId, + UserId: int(userId), + ChangeNum: changeNum, + ChangeType: int(code), + CreateTime: time.Now(), + UpdateTime: time.Now(), + ContractId: symbol, + BeforeNum: decimal.Zero.String(), + } +} +func CreatBotUserForexLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserForexLog { + return models.BotUserForexLog{ + OrderId: orderId, + UserId: int(userId), + ChangeNum: changeNum, + ChangeType: int(code), + CreateTime: time.Now(), + UpdateTime: time.Now(), + ContractId: symbol, + BeforeNum: decimal.Zero.String(), + } +} +func CreatBotUserMoneyLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserMoneyLog { + return models.BotUserMoneyLog{ + OrderId: orderId, + UserId: int(userId), + ChangeNum: changeNum, + ChangeType: int(code), + CreateTime: time.Now(), + UpdateTime: time.Now(), + StockId: symbol, + BeforeNum: decimal.Zero.String(), + } +} + +// CreatBotUserContractSecLog +// +// @Description: +// @param ctx +// @param userId +// @param code +// @param symbol +// @param changeNum +// @param orderId +// @return models.BotUserContractLog +func CreatBotUserContractSecLog(ctx context.Context, userId, code int64, symbol, changeNum, orderId string) models.BotUserContractSecLog { + return models.BotUserContractSecLog{ + OrderId: orderId, + UserId: int(userId), + ChangeNum: changeNum, + ChangeType: int(code), + CreateTime: time.Now(), + UpdateTime: time.Now(), + ContractId: symbol, + BeforeNum: decimal.Zero.String(), + } +} diff --git a/internal/data/convert/order_test.go b/internal/data/convert/order_test.go new file mode 100644 index 0000000..3136998 --- /dev/null +++ b/internal/data/convert/order_test.go @@ -0,0 +1,2525 @@ +package convert + +import ( + "context" + "matchmaking-system/internal/biz/structure" + models "matchmaking-system/internal/pkg/model" + "reflect" + "testing" + "time" +) + +func TestBotContractCancelByOrderId(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + args args + want models.BotContractTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotContractCancelByOrderId(tt.args.ctx); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotContractCancelByOrderId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotContractClosingByOrderId(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + args args + want models.BotContractTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotContractClosingByOrderId(tt.args.ctx); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotContractClosingByOrderId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotContractSecTrade(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + orderId string + order structure.ContractOrder + } + tests := []struct { + name string + args args + want models.BotContractSecTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotContractSecTrade(tt.args.ctx, tt.args.userId, tt.args.orderId, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotContractSecTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotContractStopByOrderId(t *testing.T) { + type args struct { + ctx context.Context + order structure.StopOrder + } + tests := []struct { + name string + args args + want models.BotContractTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotContractStopByOrderId(tt.args.ctx, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotContractStopByOrderId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotContractTrade(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + orderId string + order structure.ContractOrder + } + tests := []struct { + name string + args args + want models.BotContractTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotContractTrade(tt.args.ctx, tt.args.userId, tt.args.orderId, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotContractTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotDigitalTrade(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + orderId string + order structure.SpotsOrder + } + tests := []struct { + name string + args args + want models.BotDigitalTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotDigitalTrade(tt.args.ctx, tt.args.userId, tt.args.orderId, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotDigitalTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockCancelByOrderId(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + args args + want models.BotStockTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockCancelByOrderId(tt.args.ctx); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockCancelByOrderId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockHkdCancelByOrderId(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + args args + want models.BotStockHkdTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockHkdCancelByOrderId(tt.args.ctx); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockHkdCancelByOrderId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockHkdTrade(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + orderId string + order structure.ShareOrder + } + tests := []struct { + name string + args args + want models.BotStockHkdTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockHkdTrade(tt.args.ctx, tt.args.userId, tt.args.orderId, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockHkdTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockHkdTradePre(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + orderId string + order structure.ShareOrder + } + tests := []struct { + name string + args args + want models.BotStockHkdTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockHkdTradePre(tt.args.ctx, tt.args.userId, tt.args.orderId, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockHkdTradePre() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockIdnCancelByOrderId(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + args args + want models.BotStockIdnTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockIdnCancelByOrderId(tt.args.ctx); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockIdnCancelByOrderId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockIdnStopByOrderId(t *testing.T) { + type args struct { + ctx context.Context + order structure.StopOrder + } + tests := []struct { + name string + args args + want models.BotStockIdnTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockIdnStopByOrderId(tt.args.ctx, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockIdnStopByOrderId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockIdnTrade(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + orderId string + order structure.ShareOrder + } + tests := []struct { + name string + args args + want models.BotStockIdnTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockIdnTrade(tt.args.ctx, tt.args.userId, tt.args.orderId, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockIdnTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockIdnTradePre(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + orderId string + order structure.ShareOrder + } + tests := []struct { + name string + args args + want models.BotStockIdnTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockIdnTradePre(tt.args.ctx, tt.args.userId, tt.args.orderId, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockIdnTradePre() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockInCancelByOrderId(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + args args + want models.BotStockInTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockInCancelByOrderId(tt.args.ctx); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockInCancelByOrderId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockInStopByOrderId(t *testing.T) { + type args struct { + ctx context.Context + order structure.StopOrder + } + tests := []struct { + name string + args args + want models.BotStockInTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockInStopByOrderId(tt.args.ctx, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockInStopByOrderId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockInTradePre(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + orderId string + order structure.ShareOrder + } + tests := []struct { + name string + args args + want models.BotStockInTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockInTradePre(tt.args.ctx, tt.args.userId, tt.args.orderId, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockInTradePre() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockInrTrade(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + orderId string + order structure.ShareOrder + } + tests := []struct { + name string + args args + want models.BotStockInTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockInrTrade(tt.args.ctx, tt.args.userId, tt.args.orderId, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockInrTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockMysCancelByOrderId(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + args args + want models.BotStockMysTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockMysCancelByOrderId(tt.args.ctx); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockMysCancelByOrderId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockMysStopByOrderId(t *testing.T) { + type args struct { + ctx context.Context + order structure.StopOrder + } + tests := []struct { + name string + args args + want models.BotStockMysTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockMysStopByOrderId(tt.args.ctx, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockMysStopByOrderId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockMysTrade(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + orderId string + order structure.ShareOrder + } + tests := []struct { + name string + args args + want models.BotStockMysTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockMysTrade(tt.args.ctx, tt.args.userId, tt.args.orderId, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockMysTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockMysTradePre(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + orderId string + order structure.ShareOrder + } + tests := []struct { + name string + args args + want models.BotStockMysTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockMysTradePre(tt.args.ctx, tt.args.userId, tt.args.orderId, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockMysTradePre() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockOptionInrCancelByOrderId(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + args args + want models.BotStockOptionInrTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockOptionInrCancelByOrderId(tt.args.ctx); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockOptionInrCancelByOrderId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockOptionInrStopByOrderId(t *testing.T) { + type args struct { + ctx context.Context + order structure.StopOrder + } + tests := []struct { + name string + args args + want models.BotStockOptionInrTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockOptionInrStopByOrderId(tt.args.ctx, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockOptionInrStopByOrderId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockOptionInrTrade(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + orderId string + order structure.ShareOrder + } + tests := []struct { + name string + args args + want models.BotStockOptionInrTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockOptionInrTrade(tt.args.ctx, tt.args.userId, tt.args.orderId, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockOptionInrTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockSgdCancelByOrderId(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + args args + want models.BotStockSgdTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockSgdCancelByOrderId(tt.args.ctx); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockSgdCancelByOrderId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockSgdStopByOrderId(t *testing.T) { + type args struct { + ctx context.Context + order structure.StopOrder + } + tests := []struct { + name string + args args + want models.BotStockSgdTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockSgdStopByOrderId(tt.args.ctx, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockSgdStopByOrderId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockSgdTrade(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + orderId string + order structure.ShareOrder + } + tests := []struct { + name string + args args + want models.BotStockSgdTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockSgdTrade(tt.args.ctx, tt.args.userId, tt.args.orderId, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockSgdTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockSgdTradePre(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + orderId string + order structure.ShareOrder + } + tests := []struct { + name string + args args + want models.BotStockSgdTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockSgdTradePre(tt.args.ctx, tt.args.userId, tt.args.orderId, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockSgdTradePre() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockStopByOrderId(t *testing.T) { + type args struct { + ctx context.Context + order structure.StopOrder + } + tests := []struct { + name string + args args + want models.BotStockTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockStopByOrderId(tt.args.ctx, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockStopByOrderId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockStopHkdByOrderId(t *testing.T) { + type args struct { + ctx context.Context + order structure.StopOrder + } + tests := []struct { + name string + args args + want models.BotStockHkdTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockStopHkdByOrderId(tt.args.ctx, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockStopHkdByOrderId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockThaCancelByOrderId(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + args args + want models.BotStockThaTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockThaCancelByOrderId(tt.args.ctx); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockThaCancelByOrderId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockThaStopByOrderId(t *testing.T) { + type args struct { + ctx context.Context + order structure.StopOrder + } + tests := []struct { + name string + args args + want models.BotStockThaTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockThaStopByOrderId(tt.args.ctx, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockThaStopByOrderId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockThaTrade(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + orderId string + order structure.ShareOrder + } + tests := []struct { + name string + args args + want models.BotStockThaTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockThaTrade(tt.args.ctx, tt.args.userId, tt.args.orderId, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockThaTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockThaTradePre(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + orderId string + order structure.ShareOrder + } + tests := []struct { + name string + args args + want models.BotStockThaTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockThaTradePre(tt.args.ctx, tt.args.userId, tt.args.orderId, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockThaTradePre() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockTrade(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + orderId string + order structure.ShareOrder + } + tests := []struct { + name string + args args + want models.BotStockTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockTrade(tt.args.ctx, tt.args.userId, tt.args.orderId, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotStockTradePre(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + orderId string + order structure.ShareOrder + } + tests := []struct { + name string + args args + want models.BotStockTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotStockTradePre(tt.args.ctx, tt.args.userId, tt.args.orderId, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotStockTradePre() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBotUserDigital(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + usableNum string + frozenNum string + order structure.SpotsOrder + } + tests := []struct { + name string + args args + want models.BotUserDigital + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := BotUserDigital(tt.args.ctx, tt.args.userId, tt.args.usableNum, tt.args.frozenNum, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("BotUserDigital() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreatBotTradeFee(t *testing.T) { + type args struct { + ctx context.Context + userId int + code int + marketCode int + fee string + orderId string + } + tests := []struct { + name string + args args + want models.BotTradeFee + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreatBotTradeFee(tt.args.ctx, tt.args.userId, tt.args.code, tt.args.marketCode, tt.args.fee, tt.args.orderId); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatBotTradeFee() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreatBotUserBrokerage(t *testing.T) { + type args struct { + ctx context.Context + backType int + userId int + LevelType int + fee string + brokerageNum string + orderId string + } + tests := []struct { + name string + args args + want models.BotUserBrokerage + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreatBotUserBrokerage(tt.args.ctx, tt.args.backType, tt.args.userId, tt.args.LevelType, tt.args.fee, tt.args.brokerageNum, tt.args.orderId); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatBotUserBrokerage() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreatBotUserContract(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + usableNum string + frozenNum string + order structure.ContractOrder + } + tests := []struct { + name string + args args + want models.BotUserContract + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreatBotUserContract(tt.args.ctx, tt.args.userId, tt.args.usableNum, tt.args.frozenNum, tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatBotUserContract() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreatBotUserContractLog(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + code int64 + symbol string + changeNum string + orderId string + } + tests := []struct { + name string + args args + want models.BotUserContractLog + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreatBotUserContractLog(tt.args.ctx, tt.args.userId, tt.args.code, tt.args.symbol, tt.args.changeNum, tt.args.orderId); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatBotUserContractLog() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreatBotUserContractSecLog(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + code int64 + symbol string + changeNum string + orderId string + } + tests := []struct { + name string + args args + want models.BotUserContractSecLog + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreatBotUserContractSecLog(tt.args.ctx, tt.args.userId, tt.args.code, tt.args.symbol, tt.args.changeNum, tt.args.orderId); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatBotUserContractSecLog() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreatBotUserDigitalLog(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + code int64 + symbol string + changeNum string + orderId string + } + tests := []struct { + name string + args args + want models.BotUserDigitalLog + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreatBotUserDigitalLog(tt.args.ctx, tt.args.userId, tt.args.code, tt.args.symbol, tt.args.changeNum, tt.args.orderId); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatBotUserDigitalLog() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreatBotUserStockHkdLog(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + code int64 + symbol string + changeNum string + orderId string + } + tests := []struct { + name string + args args + want models.BotUserStockHkdLog + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreatBotUserStockHkdLog(tt.args.ctx, tt.args.userId, tt.args.code, tt.args.symbol, tt.args.changeNum, tt.args.orderId); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatBotUserStockHkdLog() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreatBotUserStockHkdPre(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + stockId string + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockHkd + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreatBotUserStockHkdPre(tt.args.ctx, tt.args.userId, tt.args.stockId, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatBotUserStockHkdPre() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreatBotUserStockIdnLog(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + code int64 + symbol string + changeNum string + orderId string + } + tests := []struct { + name string + args args + want models.BotUserStockIdnLog + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreatBotUserStockIdnLog(tt.args.ctx, tt.args.userId, tt.args.code, tt.args.symbol, tt.args.changeNum, tt.args.orderId); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatBotUserStockIdnLog() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreatBotUserStockIdnPre(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + stockId string + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockIdn + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreatBotUserStockIdnPre(tt.args.ctx, tt.args.userId, tt.args.stockId, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatBotUserStockIdnPre() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreatBotUserStockInLog(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + code int64 + symbol string + changeNum string + orderId string + } + tests := []struct { + name string + args args + want models.BotUserStockInLog + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreatBotUserStockInLog(tt.args.ctx, tt.args.userId, tt.args.code, tt.args.symbol, tt.args.changeNum, tt.args.orderId); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatBotUserStockInLog() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreatBotUserStockInPre(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + stockId string + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockIn + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreatBotUserStockInPre(tt.args.ctx, tt.args.userId, tt.args.stockId, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatBotUserStockInPre() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreatBotUserStockLog(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + code int64 + symbol string + changeNum string + orderId string + } + tests := []struct { + name string + args args + want models.BotUserStockLog + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreatBotUserStockLog(tt.args.ctx, tt.args.userId, tt.args.code, tt.args.symbol, tt.args.changeNum, tt.args.orderId); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatBotUserStockLog() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreatBotUserStockMysLog(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + code int64 + symbol string + changeNum string + orderId string + } + tests := []struct { + name string + args args + want models.BotUserStockMysLog + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreatBotUserStockMysLog(tt.args.ctx, tt.args.userId, tt.args.code, tt.args.symbol, tt.args.changeNum, tt.args.orderId); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatBotUserStockMysLog() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreatBotUserStockMysPre(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + stockId string + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockMys + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreatBotUserStockMysPre(tt.args.ctx, tt.args.userId, tt.args.stockId, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatBotUserStockMysPre() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreatBotUserStockOptionInrLog(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + code int64 + symbol string + changeNum string + orderId string + } + tests := []struct { + name string + args args + want models.BotUserStockOptionInrLog + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreatBotUserStockOptionInrLog(tt.args.ctx, tt.args.userId, tt.args.code, tt.args.symbol, tt.args.changeNum, tt.args.orderId); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatBotUserStockOptionInrLog() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreatBotUserStockPre(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + stockId string + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStock + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreatBotUserStockPre(tt.args.ctx, tt.args.userId, tt.args.stockId, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatBotUserStockPre() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreatBotUserStockSgdLog(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + code int64 + symbol string + changeNum string + orderId string + } + tests := []struct { + name string + args args + want models.BotUserStockSgdLog + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreatBotUserStockSgdLog(tt.args.ctx, tt.args.userId, tt.args.code, tt.args.symbol, tt.args.changeNum, tt.args.orderId); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatBotUserStockSgdLog() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreatBotUserStockSgdPre(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + stockId string + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockSgd + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreatBotUserStockSgdPre(tt.args.ctx, tt.args.userId, tt.args.stockId, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatBotUserStockSgdPre() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreatBotUserStockThaLog(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + code int64 + symbol string + changeNum string + orderId string + } + tests := []struct { + name string + args args + want models.BotUserStockThaLog + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreatBotUserStockThaLog(tt.args.ctx, tt.args.userId, tt.args.code, tt.args.symbol, tt.args.changeNum, tt.args.orderId); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatBotUserStockThaLog() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreatBotUserStockThaPre(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + stockId string + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockTha + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreatBotUserStockThaPre(tt.args.ctx, tt.args.userId, tt.args.stockId, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreatBotUserStockThaPre() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreateBotUserStock(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + stockId string + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStock + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreateBotUserStock(tt.args.ctx, tt.args.userId, tt.args.stockId, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreateBotUserStock() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreateBotUserStockHkd(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + stockId string + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockHkd + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreateBotUserStockHkd(tt.args.ctx, tt.args.userId, tt.args.stockId, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreateBotUserStockHkd() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreateBotUserStockIdn(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + stockId string + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockIdn + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreateBotUserStockIdn(tt.args.ctx, tt.args.userId, tt.args.stockId, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreateBotUserStockIdn() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreateBotUserStockIn(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + stockId string + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockIn + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreateBotUserStockIn(tt.args.ctx, tt.args.userId, tt.args.stockId, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreateBotUserStockIn() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreateBotUserStockMys(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + stockId string + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockMys + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreateBotUserStockMys(tt.args.ctx, tt.args.userId, tt.args.stockId, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreateBotUserStockMys() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreateBotUserStockOptionInr(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + stockId string + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockOptionInr + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreateBotUserStockOptionInr(tt.args.ctx, tt.args.userId, tt.args.stockId, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreateBotUserStockOptionInr() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreateBotUserStockSgd(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + stockId string + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockSgd + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreateBotUserStockSgd(tt.args.ctx, tt.args.userId, tt.args.stockId, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreateBotUserStockSgd() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreateBotUserStockTha(t *testing.T) { + type args struct { + ctx context.Context + userId int64 + stockId string + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockTha + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreateBotUserStockTha(tt.args.ctx, tt.args.userId, tt.args.stockId, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("CreateBotUserStockTha() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreateRandCodeOrder(t *testing.T) { + type args struct { + n int + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreateRandCodeOrder(tt.args.n); got != tt.want { + t.Errorf("CreateRandCodeOrder() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotDigitalCancelByOrderId(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + args args + want models.BotDigitalTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotDigitalCancelByOrderId(tt.args.ctx); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotDigitalCancelByOrderId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotDigitalStatusByOrderId(t *testing.T) { + type args struct { + ctx context.Context + closingPrice string + closingCost string + orderMoneyPrice string + totalMoneyPrice string + OrderNumber string + } + tests := []struct { + name string + args args + want models.BotDigitalTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotDigitalStatusByOrderId(tt.args.ctx, tt.args.closingPrice, tt.args.closingCost, tt.args.orderMoneyPrice, tt.args.totalMoneyPrice, tt.args.OrderNumber); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotDigitalStatusByOrderId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotUserContract(t *testing.T) { + type args struct { + ctx context.Context + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserContract + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotUserContract(tt.args.ctx, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotUserContract() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotUserContractSec(t *testing.T) { + type args struct { + ctx context.Context + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserContractSec + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotUserContractSec(tt.args.ctx, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotUserContractSec() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotUserDigital(t *testing.T) { + type args struct { + ctx context.Context + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserDigital + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotUserDigital(tt.args.ctx, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotUserDigital() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotUserDigitalByFrozenNum(t *testing.T) { + type args struct { + ctx context.Context + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserDigital + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotUserDigitalByFrozenNum(tt.args.ctx, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotUserDigitalByFrozenNum() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotUserDigitalByUsableNum(t *testing.T) { + type args struct { + ctx context.Context + usableNum string + } + tests := []struct { + name string + args args + want models.BotUserDigital + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotUserDigitalByUsableNum(tt.args.ctx, tt.args.usableNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotUserDigitalByUsableNum() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotUserStock(t *testing.T) { + type args struct { + ctx context.Context + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStock + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotUserStock(tt.args.ctx, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotUserStock() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotUserStockHkd(t *testing.T) { + type args struct { + ctx context.Context + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockHkd + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotUserStockHkd(tt.args.ctx, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotUserStockHkd() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotUserStockHkdPre(t *testing.T) { + type args struct { + ctx context.Context + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockHkd + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotUserStockHkdPre(tt.args.ctx, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotUserStockHkdPre() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotUserStockIdn(t *testing.T) { + type args struct { + ctx context.Context + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockIdn + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotUserStockIdn(tt.args.ctx, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotUserStockIdn() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotUserStockIdnPre(t *testing.T) { + type args struct { + ctx context.Context + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockIdn + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotUserStockIdnPre(tt.args.ctx, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotUserStockIdnPre() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotUserStockIn(t *testing.T) { + type args struct { + ctx context.Context + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockIn + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotUserStockIn(tt.args.ctx, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotUserStockIn() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotUserStockInPre(t *testing.T) { + type args struct { + ctx context.Context + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockIn + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotUserStockInPre(tt.args.ctx, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotUserStockInPre() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotUserStockMys(t *testing.T) { + type args struct { + ctx context.Context + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockMys + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotUserStockMys(tt.args.ctx, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotUserStockMys() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotUserStockMysPre(t *testing.T) { + type args struct { + ctx context.Context + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockMys + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotUserStockMysPre(tt.args.ctx, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotUserStockMysPre() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotUserStockOptionInr(t *testing.T) { + type args struct { + ctx context.Context + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockOptionInr + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotUserStockOptionInr(tt.args.ctx, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotUserStockOptionInr() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotUserStockPre(t *testing.T) { + type args struct { + ctx context.Context + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStock + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotUserStockPre(tt.args.ctx, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotUserStockPre() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotUserStockSgd(t *testing.T) { + type args struct { + ctx context.Context + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockSgd + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotUserStockSgd(tt.args.ctx, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotUserStockSgd() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotUserStockSgdPre(t *testing.T) { + type args struct { + ctx context.Context + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockSgd + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotUserStockSgdPre(tt.args.ctx, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotUserStockSgdPre() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotUserStockTha(t *testing.T) { + type args struct { + ctx context.Context + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockTha + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotUserStockTha(tt.args.ctx, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotUserStockTha() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateBotUserStockThaPre(t *testing.T) { + type args struct { + ctx context.Context + usableNum string + frozenNum string + } + tests := []struct { + name string + args args + want models.BotUserStockTha + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateBotUserStockThaPre(tt.args.ctx, tt.args.usableNum, tt.args.frozenNum); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateBotUserStockThaPre() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateCloseBotContractSecTrade(t *testing.T) { + type args struct { + ctx context.Context + price string + earnestMoney string + totalMoney string + serviceCost string + orderValue string + orderStatus int + closeTime time.Time + } + tests := []struct { + name string + args args + want models.BotContractSecTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateCloseBotContractSecTrade(tt.args.ctx, tt.args.price, tt.args.earnestMoney, tt.args.totalMoney, tt.args.serviceCost, tt.args.orderValue, tt.args.orderStatus, tt.args.closeTime); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateCloseBotContractSecTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateCloseBotContractTrade(t *testing.T) { + type args struct { + ctx context.Context + price string + earnestMoney string + totalMoney string + serviceCost string + } + tests := []struct { + name string + args args + want models.BotContractTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateCloseBotContractTrade(tt.args.ctx, tt.args.price, tt.args.earnestMoney, tt.args.totalMoney, tt.args.serviceCost); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateCloseBotContractTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateCloseBotStockHkdTrade(t *testing.T) { + type args struct { + ctx context.Context + price string + serviceCost string + } + tests := []struct { + name string + args args + want models.BotStockHkdTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateCloseBotStockHkdTrade(tt.args.ctx, tt.args.price, tt.args.serviceCost); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateCloseBotStockHkdTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateCloseBotStockIdnTrade(t *testing.T) { + type args struct { + ctx context.Context + price string + serviceCost string + } + tests := []struct { + name string + args args + want models.BotStockIdnTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateCloseBotStockIdnTrade(tt.args.ctx, tt.args.price, tt.args.serviceCost); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateCloseBotStockIdnTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateCloseBotStockInTrade(t *testing.T) { + type args struct { + ctx context.Context + price string + serviceCost string + } + tests := []struct { + name string + args args + want models.BotStockInTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateCloseBotStockInTrade(tt.args.ctx, tt.args.price, tt.args.serviceCost); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateCloseBotStockInTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateCloseBotStockMysTrade(t *testing.T) { + type args struct { + ctx context.Context + price string + serviceCost string + } + tests := []struct { + name string + args args + want models.BotStockMysTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateCloseBotStockMysTrade(tt.args.ctx, tt.args.price, tt.args.serviceCost); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateCloseBotStockMysTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateCloseBotStockOptionInrTrade(t *testing.T) { + type args struct { + ctx context.Context + price string + serviceCost string + } + tests := []struct { + name string + args args + want models.BotStockOptionInrTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateCloseBotStockOptionInrTrade(tt.args.ctx, tt.args.price, tt.args.serviceCost); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateCloseBotStockOptionInrTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateCloseBotStockSgdTrade(t *testing.T) { + type args struct { + ctx context.Context + price string + serviceCost string + } + tests := []struct { + name string + args args + want models.BotStockSgdTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateCloseBotStockSgdTrade(tt.args.ctx, tt.args.price, tt.args.serviceCost); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateCloseBotStockSgdTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateCloseBotStockThaTrade(t *testing.T) { + type args struct { + ctx context.Context + price string + serviceCost string + } + tests := []struct { + name string + args args + want models.BotStockThaTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateCloseBotStockThaTrade(tt.args.ctx, tt.args.price, tt.args.serviceCost); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateCloseBotStockThaTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateCloseBotStockTrade(t *testing.T) { + type args struct { + ctx context.Context + price string + serviceCost string + } + tests := []struct { + name string + args args + want models.BotStockTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateCloseBotStockTrade(tt.args.ctx, tt.args.price, tt.args.serviceCost); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateCloseBotStockTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateOpenBotContractSecTrade(t *testing.T) { + type args struct { + ctx context.Context + price string + orderNumber string + totalMoney string + serviceCost string + } + tests := []struct { + name string + args args + want models.BotContractSecTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateOpenBotContractSecTrade(tt.args.ctx, tt.args.price, tt.args.orderNumber, tt.args.totalMoney, tt.args.serviceCost); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateOpenBotContractSecTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateOpenBotContractTrade(t *testing.T) { + type args struct { + ctx context.Context + price string + orderNumber string + totalMoney string + serviceCost string + } + tests := []struct { + name string + args args + want models.BotContractTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateOpenBotContractTrade(tt.args.ctx, tt.args.price, tt.args.orderNumber, tt.args.totalMoney, tt.args.serviceCost); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateOpenBotContractTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateOpenBotStockHkdTrade(t *testing.T) { + type args struct { + ctx context.Context + price string + orderNumber string + totalMoney string + serviceCost string + marketMoney string + } + tests := []struct { + name string + args args + want models.BotStockHkdTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateOpenBotStockHkdTrade(tt.args.ctx, tt.args.price, tt.args.orderNumber, tt.args.totalMoney, tt.args.serviceCost, tt.args.marketMoney); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateOpenBotStockHkdTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateOpenBotStockIdnTrade(t *testing.T) { + type args struct { + ctx context.Context + price string + orderNumber string + totalMoney string + serviceCost string + openMarketMoney string + } + tests := []struct { + name string + args args + want models.BotStockIdnTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateOpenBotStockIdnTrade(tt.args.ctx, tt.args.price, tt.args.orderNumber, tt.args.totalMoney, tt.args.serviceCost, tt.args.openMarketMoney); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateOpenBotStockIdnTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateOpenBotStockInTrade(t *testing.T) { + type args struct { + ctx context.Context + price string + orderNumber string + totalMoney string + serviceCost string + openMarketMoney string + } + tests := []struct { + name string + args args + want models.BotStockInTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateOpenBotStockInTrade(tt.args.ctx, tt.args.price, tt.args.orderNumber, tt.args.totalMoney, tt.args.serviceCost, tt.args.openMarketMoney); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateOpenBotStockInTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateOpenBotStockMysTrade(t *testing.T) { + type args struct { + ctx context.Context + price string + orderNumber string + totalMoney string + serviceCost string + openMarkerMoney string + } + tests := []struct { + name string + args args + want models.BotStockMysTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateOpenBotStockMysTrade(tt.args.ctx, tt.args.price, tt.args.orderNumber, tt.args.totalMoney, tt.args.serviceCost, tt.args.openMarkerMoney); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateOpenBotStockMysTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateOpenBotStockOptionInrTrade(t *testing.T) { + type args struct { + ctx context.Context + price string + orderNumber string + totalMoney string + serviceCost string + openMarketMoney string + } + tests := []struct { + name string + args args + want models.BotStockOptionInrTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateOpenBotStockOptionInrTrade(tt.args.ctx, tt.args.price, tt.args.orderNumber, tt.args.totalMoney, tt.args.serviceCost, tt.args.openMarketMoney); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateOpenBotStockOptionInrTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateOpenBotStockSgdTrade(t *testing.T) { + type args struct { + ctx context.Context + price string + orderNumber string + totalMoney string + serviceCost string + openMarkerMoney string + } + tests := []struct { + name string + args args + want models.BotStockSgdTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateOpenBotStockSgdTrade(tt.args.ctx, tt.args.price, tt.args.orderNumber, tt.args.totalMoney, tt.args.serviceCost, tt.args.openMarkerMoney); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateOpenBotStockSgdTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateOpenBotStockThaTrade(t *testing.T) { + type args struct { + ctx context.Context + price string + orderNumber string + totalMoney string + serviceCost string + openMarkerMoney string + } + tests := []struct { + name string + args args + want models.BotStockThaTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateOpenBotStockThaTrade(tt.args.ctx, tt.args.price, tt.args.orderNumber, tt.args.totalMoney, tt.args.serviceCost, tt.args.openMarkerMoney); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateOpenBotStockThaTrade() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateOpenBotStockTrade(t *testing.T) { + type args struct { + ctx context.Context + price string + orderNumber string + totalMoney string + serviceCost string + marketMoney string + } + tests := []struct { + name string + args args + want models.BotStockTrade + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UpdateOpenBotStockTrade(tt.args.ctx, tt.args.price, tt.args.orderNumber, tt.args.totalMoney, tt.args.serviceCost, tt.args.marketMoney); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UpdateOpenBotStockTrade() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/data/convert/share.go b/internal/data/convert/share.go new file mode 100644 index 0000000..ceec67c --- /dev/null +++ b/internal/data/convert/share.go @@ -0,0 +1,51 @@ +package convert + +import ( + "encoding/json" + "matchmaking-system/internal/biz/structure" +) + +// ConvertAggregates +// +// @Description: +// @param body +// @return *structure.Aggregates +// @return error +func ConvertAggregates(body string) (*structure.Aggregates, error) { + var aggregates structure.Aggregates + if err := json.Unmarshal([]byte(body), &aggregates); err != nil { + return nil, err + } + + return &aggregates, nil +} + +// ConvertInTraDay +// +// @Description: +// @param body +// @return []*structure.InTraDay +// @return error +func ConvertInTraDay(body string) ([]*structure.InTraDay, error) { + var inTraDay []*structure.InTraDay + if err := json.Unmarshal([]byte(body), &inTraDay); err != nil { + return nil, err + } + + return inTraDay, nil +} + +// ConvertEod +// +// @Description: +// @param body +// @return []*structure.Eod +// @return error +func ConvertEod(body string) ([]*structure.Eod, error) { + var eod []*structure.Eod + if err := json.Unmarshal([]byte(body), &eod); err != nil { + return nil, err + } + + return eod, nil +} diff --git a/internal/data/convert/share_test.go b/internal/data/convert/share_test.go new file mode 100644 index 0000000..6314e8e --- /dev/null +++ b/internal/data/convert/share_test.go @@ -0,0 +1,85 @@ +package convert + +import ( + "matchmaking-system/internal/biz/structure" + "reflect" + "testing" +) + +func TestConvertAggregates(t *testing.T) { + type args struct { + body string + } + tests := []struct { + name string + args args + want *structure.Aggregates + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := ConvertAggregates(tt.args.body) + if (err != nil) != tt.wantErr { + t.Errorf("ConvertAggregates() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("ConvertAggregates() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestConvertEod(t *testing.T) { + type args struct { + body string + } + tests := []struct { + name string + args args + want []*structure.Eod + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := ConvertEod(tt.args.body) + if (err != nil) != tt.wantErr { + t.Errorf("ConvertEod() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("ConvertEod() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestConvertInTraDay(t *testing.T) { + type args struct { + body string + } + tests := []struct { + name string + args args + want []*structure.InTraDay + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := ConvertInTraDay(tt.args.body) + if (err != nil) != tt.wantErr { + t.Errorf("ConvertInTraDay() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("ConvertInTraDay() got = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/data/data.go b/internal/data/data.go new file mode 100644 index 0000000..a27c6ec --- /dev/null +++ b/internal/data/data.go @@ -0,0 +1,97 @@ +package data + +import ( + "github.com/go-kratos/kratos/v2/log" + "github.com/go-xorm/xorm" + "github.com/google/wire" + "github.com/patrickmn/go-cache" + "go.mongodb.org/mongo-driver/mongo" + "matchmaking-system/internal/conf" + "matchmaking-system/internal/data/mq/consumer" + "matchmaking-system/internal/data/mq/producers" + + _ "github.com/go-sql-driver/mysql" + res "github.com/redis/go-redis/v9" + che "matchmaking-system/internal/data/cache" + msql "matchmaking-system/internal/data/mysql" + red "matchmaking-system/internal/data/redis" +) + +// ProviderSet is data providers. +var ProviderSet = wire.NewSet( + NewData, // new data + msql.NewMySql, // mysql data + //mgo.NewMongodb, // mongo data + //mq.NewMqConsumer, // mq consumer + //mq.NewMqProducer, // mq producer + red.NewRedis, // redis data + che.NewCacheDB, // cache db + NewALiYunRepo, // aLiYun repo + NewUserOrderRepo, // user repo + NewUserSpotsRepo, // user spots + NewUserSecondRepo, // user second + NewUserContractRepo, // user contract + NewUserForexRepo, // user forex + NewUserMoneyRepo, // user money + NewUserShareUsRepo, // user shareUs + NewUserShareThaRepo, // user shareTha + NewUserShareIdnRepo, // user shareIdn + NewUserShareInrRepo, // user shareInr + NewUserShareGbxRepo, // user shareGbx + NewUserShareMysRepo, // user shareMys + NewUserShareSgdRepo, // user shareSgd + NewUserShareHkdRepo, // user shareHkd + NewUserShareEurRepo, // user shareEur + NewUserShareFurRepo, // user shareFur + NewUserShareBrlRepo, // user shareBrl + NewUserShareJpyRepo, // user shareJpy + NewUserShareBlkRepo, // user shareBlk + NewUserOptionInrRepo, // user optionInr + NewUserBackendRepo, // user backend +) + +// Data +// @Description: +type Data struct { + mysqlDB *xorm.EngineGroup + mongoDB *mongo.Client + cacheDB *cache.Cache + redisDB *res.Client + mqProducer *producers.Producer + mqConsumer *consumer.Consumer +} + +// NewData . +// +// @Description: +// @param c +// @param logger +// @param mysqlDB +// @param mongoDB +// @param redisDB +// @param cacheDB +// @return *Data +// @return func() +// @return error +func NewData( + c *conf.Data, + logger log.Logger, + mysqlDB *xorm.EngineGroup, + //mongoDB *mongo.Client, + //mqProducer *producers.Producer, + //mqConsumer *consumer.Consumer, + redisDB *res.Client, + cacheDB *cache.Cache) (*Data, func(), error) { + cleanup := func() { + log.NewHelper(logger).Info("closing the data resources") + } + + return &Data{ + mysqlDB: mysqlDB, + //mongoDB: mongoDB, + //mqProducer: mqProducer, + //mqConsumer: mqConsumer, + redisDB: redisDB, + cacheDB: cacheDB}, + cleanup, nil +} diff --git a/internal/data/memory/bigcache.go b/internal/data/memory/bigcache.go new file mode 100644 index 0000000..61e0e32 --- /dev/null +++ b/internal/data/memory/bigcache.go @@ -0,0 +1,40 @@ +package memory + +import ( + "github.com/allegro/bigcache" + "time" +) + +// NewBigCache +// +// @Description: 初始化交易-实时数据缓存 +// @return *bigcache.BigCache +func NewBigCache() *bigcache.BigCache { + config := bigcache.Config{ + // Set the number of partitions, which must be an integer multiple of 2 + Shards: 1024, + // After LifeWindow, cached objects are considered inactive, but they are not deleted + LifeWindow: 480 * time.Second, + // After CleanWindow, objects that are considered inactive will be deleted, with 0 representing no operation + CleanWindow: 450 * time.Second, + // Set the maximum number of storage objects, which can only be set during initialization + //MaxEntriesInWindow: 1000 * 10 * 60, + MaxEntriesInWindow: 1, + // The maximum number of bytes for cache objects, which can only be set during initialization + MaxEntrySize: 500, + // Print memory allocation information + Verbose: true, + // Set the maximum cache value (in MB), where 0 represents unlimited + HardMaxCacheSize: 0, //8192 + // When the cache expires or is deleted, a callback function can be set with parameters (key, val), and the default is nil + OnRemove: nil, + // When the cache expires or is deleted, a callback function can be set with parameters such as (key, val, reason). The default setting is nil and not set + OnRemoveWithReason: nil, + } + cache, err := bigcache.NewBigCache(config) + if err != nil { + return nil + } + + return cache +} diff --git a/internal/data/memory/bigcache_test.go b/internal/data/memory/bigcache_test.go new file mode 100644 index 0000000..78e55e5 --- /dev/null +++ b/internal/data/memory/bigcache_test.go @@ -0,0 +1,23 @@ +package memory + +import ( + "github.com/allegro/bigcache" + "reflect" + "testing" +) + +func TestNewBigCache(t *testing.T) { + tests := []struct { + name string + want *bigcache.BigCache + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewBigCache(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewBigCache() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/data/memory/forexinit.go b/internal/data/memory/forexinit.go new file mode 100644 index 0000000..0d7e83c --- /dev/null +++ b/internal/data/memory/forexinit.go @@ -0,0 +1,62 @@ +package memory + +import ( + "github.com/allegro/bigcache" + "github.com/shopspring/decimal" + "matchmaking-system/internal/pkg/utils" +) + +var ( + ForexCache *bigcache.BigCache // 外汇买一卖一报价缓存 + ForexPriceSetUp *bigcache.BigCache // 外汇插针价格缓存 + ForexFloating *bigcache.BigCache // 外汇统计总浮动盈亏 + ForexImmediateCache *bigcache.BigCache // 外汇即时报价缓存 +) + +// init +// +// @Description: 初始化内存缓存 +func init() { + ForexCache = NewBigCache() + ForexPriceSetUp = NewBigCache() + ForexFloating = NewBigCache() + ForexImmediateCache = NewBigCache() +} + +// GetForexCache +// +// @Description: 外汇行情 +// @param key +// @return []byte +// @return error +func GetForexCache(key string) ([]byte, error) { + conP, err := ForexPriceSetUp.Get(key) + if err != nil || string(conP) == decimal.Zero.String() || len(utils.StrReplace(string(conP))) == 0 { + conN, errs := ForexCache.Get(key) + if errs != nil { + return []byte{}, errs + } + return conN, nil + } + + return conP, err +} + +// GetForexImmediateCache +// +// @Description: 外汇即时报价 +// @param key +// @return []byte +// @return error +func GetForexImmediateCache(key string) ([]byte, error) { + conP, err := ForexPriceSetUp.Get(key) + if err != nil || string(conP) == decimal.Zero.String() || len(utils.StrReplace(string(conP))) == 0 { + conN, errs := ForexImmediateCache.Get(key) + if errs != nil { + return []byte{}, errs + } + return conN, nil + } + + return conP, err +} diff --git a/internal/data/memory/moneyinit.go b/internal/data/memory/moneyinit.go new file mode 100644 index 0000000..6e04b65 --- /dev/null +++ b/internal/data/memory/moneyinit.go @@ -0,0 +1,102 @@ +package memory + +import ( + "github.com/allegro/bigcache" + "github.com/shopspring/decimal" + "matchmaking-system/internal/pkg/utils" +) + +var ( + MoneyForexCache *bigcache.BigCache // 综合-外汇买一卖一报价缓存 + MoneyForexPriceSetUp *bigcache.BigCache // 综合-外汇插针价格缓存 + MoneyForexImmediateCache *bigcache.BigCache // 综合-外汇即时报价缓存 + MoneySpotsCache *bigcache.BigCache // 综合-现货行情缓存 + MoneyContractCache *bigcache.BigCache // 综合-合约行情缓存 + MoneyContractPriceSetUp *bigcache.BigCache // 综合-合约插针价格缓存 + MoneyTotalFloating *bigcache.BigCache // 综合-(现货|合约|外汇)统计总浮动盈亏 +) + +// init +// +// @Description: 初始化内存缓存 +func init() { + MoneyForexCache = NewBigCache() + MoneyForexPriceSetUp = NewBigCache() + MoneyForexImmediateCache = NewBigCache() + MoneySpotsCache = NewBigCache() + MoneyContractCache = NewBigCache() + MoneyContractPriceSetUp = NewBigCache() + MoneyTotalFloating = NewBigCache() +} + +// GetMoneySpotsCache +// +// @Description: 综合-现货行情数据 +// @param key +// @return []byte +// @return error +func GetMoneySpotsCache(key string) ([]byte, error) { + conN, err := MoneySpotsCache.Get(key) + if err != nil { + return []byte{}, err + } + + return conN, err +} + +// GetMoneyContractCache +// +// @Description: 综合-合约行情数据 +// @param key +// @return []byte +// @return error +func GetMoneyContractCache(key string) ([]byte, error) { + conP, err := MoneyContractPriceSetUp.Get(key) + if err != nil || string(conP) == decimal.Zero.String() || len(utils.StrReplace(string(conP))) == 0 { + conN, errs := MoneyContractCache.Get(key) + if errs != nil { + return []byte{}, errs + } + return conN, nil + } + + return conP, err +} + +// GetMoneyImmediateCache +// +// @Description: 综合-外汇实时行情 +// @param key +// @return []byte +// @return error +func GetMoneyForexImmediateCache(key string) ([]byte, error) { + conP, err := MoneyForexPriceSetUp.Get(key) + if err != nil || string(conP) == decimal.Zero.String() || len(utils.StrReplace(string(conP))) == 0 { + conN, errs := MoneyForexImmediateCache.Get(key) + if errs != nil { + return []byte{}, errs + } + return conN, nil + } + + return conP, err +} + +// GetMoneyCache +// +// @Description: 综合-外汇(买一卖一)实时行情 +// @param key +// @return []byte +// @return error +func GetMoneyForexCache(key string) ([]byte, error) { + conP, err := MoneyForexPriceSetUp.Get(key) + if err != nil || string(conP) == decimal.Zero.String() || len(utils.StrReplace(string(conP))) == 0 { + conN, errs := MoneyForexCache.Get(key) + if errs != nil { + return []byte{}, errs + } + return conN, nil + } + + return conP, err +} diff --git a/internal/data/memory/optioninit.go b/internal/data/memory/optioninit.go new file mode 100644 index 0000000..6951e99 --- /dev/null +++ b/internal/data/memory/optioninit.go @@ -0,0 +1,92 @@ +package memory + +import ( + "github.com/allegro/bigcache" + "github.com/shopspring/decimal" + "matchmaking-system/internal/pkg/utils" +) + +var ( + OptionInrCache *bigcache.BigCache // 期权印度股行情缓存 + OptionInrChgMark *bigcache.BigCache // 期权印度股买涨|买跌-涨跌幅标识 + OptionInrClosePrice *bigcache.BigCache // 期权印度股闭盘价格 + OptionInrForcedClosure *bigcache.BigCache // 期权印度股设置强平阈值 + OptionInrFloating *bigcache.BigCache // 期权印度股统计总浮动盈亏 + OptionInrStrike *bigcache.BigCache // 期权印度股行权价 + OptionInrBid *bigcache.BigCache // 期权印度买一价格 + OptionInrAsk *bigcache.BigCache // 期权印度卖一价格 +) + +// init +// +// @Description: 初始化期权-内存缓存 +func init() { + OptionInrCache = NewBigCache() + OptionInrChgMark = NewBigCache() + OptionInrClosePrice = NewBigCache() + OptionInrForcedClosure = NewBigCache() + OptionInrFloating = NewBigCache() + OptionInrStrike = NewBigCache() + OptionInrBid = NewBigCache() + OptionInrAsk = NewBigCache() +} + +// GetOptionInrStrike +// +// @Description: 期权-印度行权价 +// @param key +// @return []byte +// @return error +func GetOptionInrStrike(key string) ([]byte, error) { + inrP, err := OptionInrStrike.Get(key) + if err != nil { + return []byte("0"), nil + } + + return inrP, nil +} + +// GetOptionInrCache +// +// @Description: 期权-印度交易价格(用来计算浮动盈亏) +// @param key +// @return []byte +// @return error +func GetOptionInrCache(key string) ([]byte, error) { + inrP, err := OptionInrCache.Get(key) + if err != nil || string(inrP) == decimal.Zero.String() || len(utils.StrReplace(string(inrP))) == 0 { + return []byte("0"), nil + } + + return inrP, nil +} + +// GetOptionInrBid +// +// @Description: 期权-印度买一价格 +// @param key +// @return []byte +// @return error +func GetOptionInrBid(key string) ([]byte, error) { + inrP, err := OptionInrBid.Get(key) + if err != nil { + return []byte("0"), nil + } + + return inrP, nil +} + +// GetOptionInrAsk +// +// @Description: 期权-印度卖一价格 +// @param key +// @return []byte +// @return error +func GetOptionInrAsk(key string) ([]byte, error) { + inrP, err := OptionInrAsk.Get(key) + if err != nil { + return []byte("0"), nil + } + + return inrP, nil +} diff --git a/internal/data/memory/shareinit.go b/internal/data/memory/shareinit.go new file mode 100644 index 0000000..a8a7f05 --- /dev/null +++ b/internal/data/memory/shareinit.go @@ -0,0 +1,512 @@ +package memory + +import ( + "github.com/allegro/bigcache" + "github.com/shopspring/decimal" + "matchmaking-system/internal/pkg/utils" +) + +var ( + // 美股 + ShareUsCache *bigcache.BigCache // 美股行情缓存 + ShareUsChgMark *bigcache.BigCache // 美股买涨|买跌-涨跌幅标识 + ShareUsClosePrice *bigcache.BigCache // 美股闭盘价格 + ShareUsPriceSetUp *bigcache.BigCache // 美股设置盘前|盘后价格 + ShareUsForcedClosure *bigcache.BigCache // 美股设置强平阈值 + ShareUsFloating *bigcache.BigCache // 美股统计总浮动盈亏 + // 印尼股 + ShareIdnCache *bigcache.BigCache // 印尼股行情缓存 + ShareIdnChgMark *bigcache.BigCache // 印尼股买涨|买跌-涨跌幅标识 + ShareIdnClosePrice *bigcache.BigCache // 印尼闭盘价格 + ShareIdnPriceSetUp *bigcache.BigCache // 印尼股设置盘前|盘后价格 + ShareIdnForcedClosure *bigcache.BigCache // 印尼设置强平阈值 + ShareIdnFloating *bigcache.BigCache // 印尼股统计总浮动盈亏 + // 马股 + ShareMysCache *bigcache.BigCache // 马股行情缓存 + ShareMysChgMark *bigcache.BigCache // 马股买涨|买跌-涨跌幅标识 + ShareMysClosePrice *bigcache.BigCache // 马股闭盘价格 + ShareMysPriceSetUp *bigcache.BigCache // 马股设置盘前|盘后价格 + ShareMysForcedClosure *bigcache.BigCache // 马股设置强平阈值 + ShareMysFloating *bigcache.BigCache // 马股统计总浮动盈亏 + // 泰股 + ShareThaCache *bigcache.BigCache // 泰股行情缓存 + ShareThaChgMark *bigcache.BigCache // 泰股买涨|买跌-涨跌幅标识 + ShareThaClosePrice *bigcache.BigCache // 泰股闭盘价格 + ShareThaPriceSetUp *bigcache.BigCache // 泰股设置盘前|盘后价格 + ShareThaForcedClosure *bigcache.BigCache // 泰股设置强平阈值 + ShareThaFloating *bigcache.BigCache // 泰股统计总浮动盈亏 + // 印度股 + ShareInrCache *bigcache.BigCache // 印度股行情缓存 + ShareInrChgMark *bigcache.BigCache // 印度股买涨|买跌-涨跌幅标识 + ShareInrClosePrice *bigcache.BigCache // 印度股闭盘价格 + ShareInrPriceSetUp *bigcache.BigCache // 印度股设置盘前|盘后价格 + ShareInrForcedClosure *bigcache.BigCache // 印度股设置强平阈值 + ShareInrFloating *bigcache.BigCache // 印度股统计总浮动盈亏 + // 新加坡股 + ShareSgdCache *bigcache.BigCache // 新加坡股行情缓存 + ShareSgdChgMark *bigcache.BigCache // 新加坡股买涨|买跌-涨跌幅标识 + ShareSgdClosePrice *bigcache.BigCache // 新加坡股闭盘价格 + ShareSgdPriceSetUp *bigcache.BigCache // 新加坡股设置盘前|盘后价格 + ShareSgdForcedClosure *bigcache.BigCache // 新加坡股设置强平阈值 + ShareSgdFloating *bigcache.BigCache // 新加坡股统计总浮动盈亏 + // 港股 + ShareHkdCache *bigcache.BigCache // 港股行情缓存 + ShareHkdChgMark *bigcache.BigCache // 港股买涨|买跌-涨跌幅标识 + ShareHkdClosePrice *bigcache.BigCache // 港股闭盘价格 + ShareHkdPriceSetUp *bigcache.BigCache // 港股设置盘前|盘后价格 + ShareHkdForcedClosure *bigcache.BigCache // 港股设置强平阈值 + ShareHkdFloating *bigcache.BigCache // 港股统计总浮动盈亏 + // 英股 + ShareGbxCache *bigcache.BigCache // 英股行情缓存 + ShareGbxChgMark *bigcache.BigCache // 英股买涨|买跌-涨跌幅标识 + ShareGbxClosePrice *bigcache.BigCache // 英股闭盘价格 + ShareGbxPriceSetUp *bigcache.BigCache // 英股设置盘前|盘后价格 + ShareGbxForcedClosure *bigcache.BigCache // 英股设置强平阈值 + ShareGbxFloating *bigcache.BigCache // 英股统计总浮动盈亏 + // 德股 + ShareEurCache *bigcache.BigCache // 德股行情缓存 + ShareEurChgMark *bigcache.BigCache // 德股买涨|买跌-涨跌幅标识 + ShareEurClosePrice *bigcache.BigCache // 德股闭盘价格 + ShareEurPriceSetUp *bigcache.BigCache // 德股设置盘前|盘后价格 + ShareEurForcedClosure *bigcache.BigCache // 德股设置强平阈值 + ShareEurFloating *bigcache.BigCache // 德股统计总浮动盈亏 + // 法股 + ShareFurCache *bigcache.BigCache // 法股行情缓存 + ShareFurChgMark *bigcache.BigCache // 法股买涨|买跌-涨跌幅标识 + ShareFurClosePrice *bigcache.BigCache // 法股闭盘价格 + ShareFurPriceSetUp *bigcache.BigCache // 法股设置盘前|盘后价格 + ShareFurForcedClosure *bigcache.BigCache // 法股设置强平阈值 + ShareFurFloating *bigcache.BigCache // 法股统计总浮动盈亏 + // 巴西股 + ShareBrlCache *bigcache.BigCache // 巴西股行情缓存 + ShareBrlChgMark *bigcache.BigCache // 巴西股买涨|买跌-涨跌幅标识 + ShareBrlClosePrice *bigcache.BigCache // 巴西股闭盘价格 + ShareBrlPriceSetUp *bigcache.BigCache // 巴西股设置盘前|盘后价格 + ShareBrlForcedClosure *bigcache.BigCache // 巴西股设置强平阈值 + ShareBrlFloating *bigcache.BigCache // 巴西股统计总浮动盈亏 + // 日本股 + ShareJpyCache *bigcache.BigCache // 日本股行情缓存 + ShareJpyChgMark *bigcache.BigCache // 日本股买涨|买跌-涨跌幅标识 + ShareJpyClosePrice *bigcache.BigCache // 日本股闭盘价格 + ShareJpyPriceSetUp *bigcache.BigCache // 日本股设置盘前|盘后价格 + ShareJpyForcedClosure *bigcache.BigCache // 日本股设置强平阈值 + ShareJpyFloating *bigcache.BigCache // 日本股统计总浮动盈亏 + // 大宗交易 + ShareBlkFloating *bigcache.BigCache // 大宗交易统计总浮动盈亏 +) + +// init +// +// @Description: 初始化股票-内存缓存 +func init() { + // 股票-美股 + ShareUsCache = NewBigCache() + ShareUsChgMark = NewBigCache() + ShareUsClosePrice = NewBigCache() + ShareUsPriceSetUp = NewBigCache() + ShareUsForcedClosure = NewBigCache() + ShareUsFloating = NewBigCache() + // 股票-印尼股 + ShareIdnCache = NewBigCache() + ShareIdnChgMark = NewBigCache() + ShareIdnClosePrice = NewBigCache() + ShareIdnPriceSetUp = NewBigCache() + ShareIdnForcedClosure = NewBigCache() + ShareIdnFloating = NewBigCache() + // 股票-马股 + ShareMysCache = NewBigCache() + ShareMysChgMark = NewBigCache() + ShareMysClosePrice = NewBigCache() + ShareMysPriceSetUp = NewBigCache() + ShareMysForcedClosure = NewBigCache() + ShareMysFloating = NewBigCache() + // 股票-泰股 + ShareThaCache = NewBigCache() + ShareThaChgMark = NewBigCache() + ShareThaClosePrice = NewBigCache() + ShareThaPriceSetUp = NewBigCache() + ShareThaForcedClosure = NewBigCache() + ShareThaFloating = NewBigCache() + // 股票-印度股 + ShareInrCache = NewBigCache() + ShareInrChgMark = NewBigCache() + ShareInrClosePrice = NewBigCache() + ShareInrPriceSetUp = NewBigCache() + ShareInrForcedClosure = NewBigCache() + ShareInrFloating = NewBigCache() + // 股票-新加坡股 + ShareSgdCache = NewBigCache() + ShareSgdChgMark = NewBigCache() + ShareSgdClosePrice = NewBigCache() + ShareSgdPriceSetUp = NewBigCache() + ShareSgdForcedClosure = NewBigCache() + ShareSgdFloating = NewBigCache() + // 股票-港股 + ShareHkdCache = NewBigCache() + ShareHkdChgMark = NewBigCache() + ShareHkdClosePrice = NewBigCache() + ShareHkdPriceSetUp = NewBigCache() + ShareHkdForcedClosure = NewBigCache() + ShareHkdFloating = NewBigCache() + // 股票-英股 + ShareGbxCache = NewBigCache() + ShareGbxChgMark = NewBigCache() + ShareGbxClosePrice = NewBigCache() + ShareGbxPriceSetUp = NewBigCache() + ShareGbxForcedClosure = NewBigCache() + ShareGbxFloating = NewBigCache() + // 股票-德股 + ShareEurCache = NewBigCache() + ShareEurChgMark = NewBigCache() + ShareEurClosePrice = NewBigCache() + ShareEurPriceSetUp = NewBigCache() + ShareEurForcedClosure = NewBigCache() + ShareEurFloating = NewBigCache() + // 股票-法股 + ShareFurCache = NewBigCache() + ShareFurChgMark = NewBigCache() + ShareFurClosePrice = NewBigCache() + ShareFurPriceSetUp = NewBigCache() + ShareFurForcedClosure = NewBigCache() + ShareFurFloating = NewBigCache() + // 股票-巴西股 + ShareBrlCache = NewBigCache() + ShareBrlChgMark = NewBigCache() + ShareBrlClosePrice = NewBigCache() + ShareBrlPriceSetUp = NewBigCache() + ShareBrlForcedClosure = NewBigCache() + ShareBrlFloating = NewBigCache() + // 股票-日本股 + ShareJpyCache = NewBigCache() + ShareJpyChgMark = NewBigCache() + ShareJpyClosePrice = NewBigCache() + ShareJpyPriceSetUp = NewBigCache() + ShareJpyForcedClosure = NewBigCache() + ShareJpyFloating = NewBigCache() + // 大宗交易-(美股|泰股|马股|印尼股|印度股|新加坡股|港股|英股|德股|法股|日本股) + ShareBlkFloating = NewBigCache() +} + +// GetShareUsCache +// +// @Description: 股票-美股市价(市价|盘前|盘后) +// @param key +// @return []byte +// @return error +func GetShareUsCache(key string) ([]byte, error) { + usP, err := ShareUsPriceSetUp.Get(key) + if err != nil || string(usP) == decimal.Zero.String() || len(utils.StrReplace(string(usP))) == 0 { + usS, errs := ShareUsCache.Get(key) + if errs != nil { + return []byte{}, err + } + return usS, nil + } + + return usP, nil +} +func GetShareUsCacheWs(key string) ([]byte, error) { + usP, err := ShareUsCache.Get(key) + if err != nil || string(usP) == decimal.Zero.String() || len(utils.StrReplace(string(usP))) == 0 { + return []byte{}, err + } + + return usP, nil +} + +// GetShareThaCache +// +// @Description: 股票-泰股市价(市价|盘前|盘后) +// @param key +// @return []byte +// @return error +func GetShareThaCache(key string) ([]byte, error) { + thaP, err := ShareThaPriceSetUp.Get(key) + if err != nil || string(thaP) == decimal.Zero.String() || len(utils.StrReplace(string(thaP))) == 0 { + thaS, errs := ShareThaCache.Get(key) + if errs != nil { + return []byte{}, err + } + return thaS, nil + } + + return thaP, nil +} +func GetShareThaCacheWs(key string) ([]byte, error) { + thaP, err := ShareThaCache.Get(key) + if err != nil || string(thaP) == decimal.Zero.String() || len(utils.StrReplace(string(thaP))) == 0 { + return []byte{}, err + } + + return thaP, nil +} + +// GetShareIdnCache +// +// @Description: 股票-印尼股市价(市价|盘前|盘后) +// @param key +// @return []byte +// @return error +func GetShareIdnCache(key string) ([]byte, error) { + idnP, err := ShareIdnPriceSetUp.Get(key) + if err != nil || string(idnP) == decimal.Zero.String() || len(utils.StrReplace(string(idnP))) == 0 { + idnS, errs := ShareIdnCache.Get(key) + if errs != nil { + return []byte{}, err + } + return idnS, nil + } + + return idnP, nil +} +func GetShareIdnCacheWs(key string) ([]byte, error) { + idnP, err := ShareIdnCache.Get(key) + if err != nil || string(idnP) == decimal.Zero.String() || len(utils.StrReplace(string(idnP))) == 0 { + return []byte{}, err + } + + return idnP, nil +} + +// GetShareMysCache +// +// @Description: 股票-马股市价(市价|盘前|盘后) +// @param key +// @return []byte +// @return error +func GetShareMysCache(key string) ([]byte, error) { + mysP, err := ShareMysPriceSetUp.Get(key) + if err != nil || string(mysP) == decimal.Zero.String() || len(utils.StrReplace(string(mysP))) == 0 { + mysS, errs := ShareMysCache.Get(key) + if errs != nil { + return []byte{}, err + } + return mysS, nil + } + + return mysP, nil +} +func GetShareMysCacheWs(key string) ([]byte, error) { + mysP, err := ShareMysCache.Get(key) + if err != nil || string(mysP) == decimal.Zero.String() || len(utils.StrReplace(string(mysP))) == 0 { + return []byte{}, err + } + + return mysP, nil +} + +// GetShareInrCache +// +// @Description: 股票-印度股市价(市价|盘前|盘后) +// @param key +// @return []byte +// @return error +func GetShareInrCache(key string) ([]byte, error) { + inrP, err := ShareInrPriceSetUp.Get(key) + if err != nil || string(inrP) == decimal.Zero.String() || len(utils.StrReplace(string(inrP))) == 0 { + inrS, errs := ShareInrCache.Get(key) + if errs != nil { + return []byte{}, err + } + return inrS, nil + } + + return inrP, nil +} +func GetShareInrCacheWs(key string) ([]byte, error) { + inrP, err := ShareInrCache.Get(key) + if err != nil || string(inrP) == decimal.Zero.String() || len(utils.StrReplace(string(inrP))) == 0 { + return []byte{}, err + } + + return inrP, nil +} + +// GetShareSgdCache +// +// @Description: 股票-新加坡股市价(市价|盘前|盘后) +// @param key +// @return []byte +// @return error +func GetShareSgdCache(key string) ([]byte, error) { + inrP, err := ShareSgdPriceSetUp.Get(key) + if err != nil || string(inrP) == decimal.Zero.String() || len(utils.StrReplace(string(inrP))) == 0 { + inrS, errs := ShareSgdCache.Get(key) + if errs != nil { + return []byte{}, err + } + return inrS, nil + } + + return inrP, nil +} +func GetShareSgdCacheWs(key string) ([]byte, error) { + inrP, err := ShareSgdCache.Get(key) + if err != nil || string(inrP) == decimal.Zero.String() || len(utils.StrReplace(string(inrP))) == 0 { + return []byte{}, err + } + + return inrP, nil +} + +// GetShareHkdCache +// +// @Description: 股票-港股市价(市价|盘前|盘后) +// @param key +// @return []byte +// @return error +func GetShareHkdCache(key string) ([]byte, error) { + inrP, err := ShareHkdPriceSetUp.Get(key) + if err != nil || string(inrP) == decimal.Zero.String() || len(utils.StrReplace(string(inrP))) == 0 { + inrS, errs := ShareHkdCache.Get(key) + if errs != nil { + return []byte{}, err + } + return inrS, nil + } + + return inrP, nil +} +func GetShareHkdCacheWs(key string) ([]byte, error) { + inrP, err := ShareHkdCache.Get(key) + if err != nil || string(inrP) == decimal.Zero.String() || len(utils.StrReplace(string(inrP))) == 0 { + return []byte{}, err + } + + return inrP, nil +} + +// GetShareGbxCache +// +// @Description: 股票-英股市价(市价|盘前|盘后) +// @param key +// @return []byte +// @return error +func GetShareGbxCache(key string) ([]byte, error) { + inrP, err := ShareGbxPriceSetUp.Get(key) + if err != nil || string(inrP) == decimal.Zero.String() || len(utils.StrReplace(string(inrP))) == 0 { + inrS, errs := ShareGbxCache.Get(key) + if errs != nil { + return []byte{}, err + } + return inrS, nil + } + + return inrP, nil +} +func GetShareGbxCacheWs(key string) ([]byte, error) { + inrP, err := ShareGbxCache.Get(key) + if err != nil || string(inrP) == decimal.Zero.String() || len(utils.StrReplace(string(inrP))) == 0 { + return []byte{}, err + } + + return inrP, nil +} + +// GetShareEurCache +// +// @Description: 股票-德股市价(市价|盘前|盘后) +// @param key +// @return []byte +// @return error +func GetShareEurCache(key string) ([]byte, error) { + inrP, err := ShareEurPriceSetUp.Get(key) + if err != nil || string(inrP) == decimal.Zero.String() || len(utils.StrReplace(string(inrP))) == 0 { + inrS, errs := ShareEurCache.Get(key) + if errs != nil { + return []byte{}, err + } + return inrS, nil + } + + return inrP, nil +} +func GetShareEurCacheWs(key string) ([]byte, error) { + inrP, err := ShareEurCache.Get(key) + if err != nil || string(inrP) == decimal.Zero.String() || len(utils.StrReplace(string(inrP))) == 0 { + return []byte{}, err + } + + return inrP, nil +} + +// GetShareFurCache +// +// @Description: 股票-法股市价(市价|盘前|盘后) +// @param key +// @return []byte +// @return error +func GetShareFurCache(key string) ([]byte, error) { + inrP, err := ShareFurPriceSetUp.Get(key) + if err != nil || string(inrP) == decimal.Zero.String() || len(utils.StrReplace(string(inrP))) == 0 { + inrS, errs := ShareFurCache.Get(key) + if errs != nil { + return []byte{}, err + } + return inrS, nil + } + + return inrP, nil +} +func GetShareFurCacheWs(key string) ([]byte, error) { + inrP, err := ShareFurCache.Get(key) + if err != nil || string(inrP) == decimal.Zero.String() || len(utils.StrReplace(string(inrP))) == 0 { + return []byte{}, err + } + + return inrP, nil +} + +// GetShareBrlCache +// +// @Description: 股票-巴西股市价(市价|盘前|盘后) +// @param key +// @return []byte +// @return error +func GetShareBrlCache(key string) ([]byte, error) { + inrP, err := ShareBrlPriceSetUp.Get(key) + if err != nil || string(inrP) == decimal.Zero.String() || len(utils.StrReplace(string(inrP))) == 0 { + inrS, errs := ShareBrlCache.Get(key) + if errs != nil { + return []byte{}, err + } + return inrS, nil + } + + return inrP, nil +} +func GetShareBrlCacheWs(key string) ([]byte, error) { + inrP, err := ShareBrlCache.Get(key) + if err != nil || string(inrP) == decimal.Zero.String() || len(utils.StrReplace(string(inrP))) == 0 { + return []byte{}, err + } + + return inrP, nil +} + +// GetShareJpyCache +// +// @Description: 股票-日股市价(市价|盘前|盘后) +// @param key +// @return []byte +// @return error +func GetShareJpyCache(key string) ([]byte, error) { + inrP, err := ShareJpyPriceSetUp.Get(key) + if err != nil || string(inrP) == decimal.Zero.String() || len(utils.StrReplace(string(inrP))) == 0 { + inrS, errs := ShareJpyCache.Get(key) + if errs != nil { + return []byte{}, err + } + return inrS, nil + } + + return inrP, nil +} +func GetShareJpyCacheWs(key string) ([]byte, error) { + inrP, err := ShareJpyCache.Get(key) + if err != nil || string(inrP) == decimal.Zero.String() || len(utils.StrReplace(string(inrP))) == 0 { + return []byte{}, err + } + + return inrP, nil +} diff --git a/internal/data/memory/virtualinit.go b/internal/data/memory/virtualinit.go new file mode 100644 index 0000000..1950551 --- /dev/null +++ b/internal/data/memory/virtualinit.go @@ -0,0 +1,76 @@ +package memory + +import ( + "github.com/allegro/bigcache" + "github.com/shopspring/decimal" + "matchmaking-system/internal/pkg/utils" +) + +var ( + // 现货 + SpotsCache *bigcache.BigCache // 现货行情缓存 + + // 合约 + ContractCache *bigcache.BigCache // 合约行情缓存 + ContractPriceSetUp *bigcache.BigCache // 合约插针价格缓存 + ContractFloating *bigcache.BigCache // 合约统计总浮动盈亏 + + // 秒合约 + SecondCache *bigcache.BigCache // 秒合约缓存 + SecondPriceSetUp *bigcache.BigCache // 秒合约插针缓存 +) + +// init +// +// @Description: 初始化虚拟币-内存缓存 +func init() { + // 数字币-现货 + SpotsCache = NewBigCache() + + // 数字币-合约 + ContractCache = NewBigCache() + ContractPriceSetUp = NewBigCache() + ContractFloating = NewBigCache() + + // 数字币-秒合约 + SecondCache = NewBigCache() + SecondPriceSetUp = NewBigCache() +} + +// GetContractCache +// +// @Description: 虚拟币-合约插针数据 +// @param key +// @return []byte +// @return error +func GetContractCache(key string) ([]byte, error) { + conP, err := ContractPriceSetUp.Get(key) + if err != nil || string(conP) == decimal.Zero.String() || len(utils.StrReplace(string(conP))) == 0 { + conN, errs := ContractCache.Get(key) + if errs != nil { + return []byte{}, errs + } + return conN, nil + } + + return conP, err +} + +// GetSecondCache +// +// @Description: 虚拟币-秒合约插针数据 +// @param key +// @return []byte +// @return error +func GetSecondCache(key string) ([]byte, error) { + conP, err := SecondPriceSetUp.Get(key) + if err != nil || string(conP) == decimal.Zero.String() || len(utils.StrReplace(string(conP))) == 0 { + conN, errs := SecondCache.Get(key) + if errs != nil { + return []byte{}, errs + } + return conN, nil + } + + return conP, err +} diff --git a/internal/data/mongo/mongo.go b/internal/data/mongo/mongo.go new file mode 100644 index 0000000..cf241e8 --- /dev/null +++ b/internal/data/mongo/mongo.go @@ -0,0 +1,368 @@ +package mongo + +import ( + "context" + "fmt" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" + "log" + "matchmaking-system/internal/conf" +) + +// NewMongodb +// +// @Description: +// @param c +// @return *mongo.Client +func NewMongodb(c *conf.Data) *mongo.Client { + mongodb := c.Mongodb.Db + urlStr := fmt.Sprintf("mongodb://%v:%v@%v/%v?ssl=false&authSource=admin", c.Mongodb.User, c.Mongodb.Password, c.Mongodb.Addr, mongodb) + clientOptions := options.Client().ApplyURI(urlStr) + client, err := mongo.Connect(context.TODO(), clientOptions) + if err != nil { + panic(err) + } + // Check the connection + err = client.Ping(context.TODO(), nil) + if err != nil { + panic(err) + } + + return &mongo.Client{} +} + +// mgoConnect +// +// @Description: +// @param mgoDb +// @param DataBase +// @param collection +// @return *mongo.Collection +func mgoConnect(mgoDb *mongo.Client, DataBase string, collection string) *mongo.Collection { + return mgoDb.Database(DataBase).Collection(collection) +} + +// MgoConnect +// +// @Description: +// @param mgoDb +// @param DataBase +// @param collection +// @return *mongo.Collection +func MgoConnect(mgoDb *mongo.Client, DataBase string, collection string) *mongo.Collection { + return mgoConnect(mgoDb, DataBase, collection) +} + +// MgoInsertOne +// +// @Description: +// @param mgoDb +// @param DataBase +// @param collection +// @param docs +// @return error +func MgoInsertOne(mgoDb *mongo.Client, DataBase string, collection string, docs interface{}) error { + c := mgoConnect(mgoDb, DataBase, collection) + if _, err := c.InsertOne(context.TODO(), docs); err != nil { + return err + } + + return nil +} + +// MgoInsertMany +// +// @Description: +// @param mgoDb +// @param DataBase +// @param collection +// @param docs +// @return error +func MgoInsertMany(mgoDb *mongo.Client, DataBase string, collection string, docs []interface{}) error { + c := mgoConnect(mgoDb, DataBase, collection) + if _, err := c.InsertMany(context.TODO(), docs); err != nil { + return err + } + + return nil +} + +// MgoUpdateID +// +// @Description: +// @param mgoDb +// @param DataBase +// @param collection +// @param id +// @param update +// @return error +func MgoUpdateID(mgoDb *mongo.Client, DataBase string, collection string, id interface{}, update interface{}) error { + c := mgoConnect(mgoDb, DataBase, collection) + if _, err := c.UpdateByID(context.TODO(), id, update); err != nil { + return err + } + + return nil +} + +// MgoUpdateOne +// +// @Description: +// @param mgoDb +// @param DataBase +// @param collection +// @param filter +// @param update +// @return error +func MgoUpdateOne(mgoDb *mongo.Client, DataBase string, collection string, filter interface{}, update interface{}) error { + c := mgoConnect(mgoDb, DataBase, collection) + if _, err := c.UpdateOne(context.TODO(), filter, update); err != nil { + return err + } + + return nil +} + +// MgoUpdateMany +// +// @Description: +// @param mgoDb +// @param DataBase +// @param collection +// @param filter +// @param update +// @return error +func MgoUpdateMany(mgoDb *mongo.Client, DataBase string, collection string, filter interface{}, update []interface{}) error { + c := mgoConnect(mgoDb, DataBase, collection) + if _, err := c.UpdateMany(context.TODO(), filter, update); err != nil { + return err + } + + return nil +} + +// MgoBulkWrite +// +// @Description: +// @param mgoDb +// @param DataBase +// @param collection +// @param models +// @return error +func MgoBulkWrite(mgoDb *mongo.Client, DataBase string, collection string, models []mongo.WriteModel) error { + c := mgoConnect(mgoDb, DataBase, collection) + _, err := c.BulkWrite(context.TODO(), models) + + if err != nil { + return err + } + + return err +} + +// MgoIsExist +// +// @Description: +// @param mgoDb +// @param DataBase +// @param collection +// @param filter +// @return bool +func MgoIsExist(mgoDb *mongo.Client, DataBase string, collection string, filter interface{}) bool { + c := mgoConnect(mgoDb, DataBase, collection) + cur, err := c.Find(context.TODO(), filter) + if err != nil { + return false + } + + var numDocs int + for cur.Next(context.Background()) { + numDocs++ + } + + return numDocs > 0 +} + +// MgoFind +// +// @Description: +// @param mgoDb +// @param DataBase +// @param collection +// @param filter +// @return interface{} +// @return error +func MgoFind(mgoDb *mongo.Client, DataBase string, collection string, filter interface{}) (interface{}, error) { + c := mgoConnect(mgoDb, DataBase, collection) + cursor, err := c.Find(context.TODO(), filter) + if err != nil { + return nil, err + } + var results []bson.M + if err = cursor.All(context.TODO(), &results); err != nil { + log.Fatal(err) + } + + return results, nil +} + +// MgoFindOne +// +// @Description: +// @param mgoDb +// @param DataBase +// @param collection +// @param filter +// @return bson.D +// @return error +func MgoFindOne(mgoDb *mongo.Client, DataBase string, collection string, filter interface{}) (bson.D, error) { + c := mgoConnect(mgoDb, DataBase, collection) + cur := c.FindOne(context.TODO(), filter) + var res bson.D + if err := cur.Decode(&res); err != nil { + return nil, err + } + + return res, nil +} + +// MgoFindAll +// +// @Description: +// @param mgoDb +// @param DataBase +// @param collection +// @param filter +// @return interface{} +// @return error +func MgoFindAll(mgoDb *mongo.Client, DataBase string, collection string, filter interface{}) (interface{}, error) { + c := mgoConnect(mgoDb, DataBase, collection) + cur, err := c.Find(context.TODO(), filter) + if err != nil { + return nil, err + } + var res interface{} + if err := cur.All(context.TODO(), &res); err != nil { + return nil, err + } + + return res, err +} + +// MgoDeleteOne +// +// @Description: +// @param mgoDb +// @param DataBase +// @param collection +// @param filter +// @return error +func MgoDeleteOne(mgoDb *mongo.Client, DataBase string, collection string, filter interface{}) error { + c := mgoConnect(mgoDb, DataBase, collection) + _, err := c.DeleteOne(context.TODO(), filter) + if err != nil { + return err + } + + return nil +} + +// MgoDeleteMany +// +// @Description: +// @param mgoDb +// @param DataBase +// @param collection +// @param filter +// @return error +func MgoDeleteMany(mgoDb *mongo.Client, DataBase string, collection string, filter interface{}) error { + c := mgoConnect(mgoDb, DataBase, collection) + _, err := c.DeleteMany(context.TODO(), filter) + if err != nil { + return err + } + + return nil +} + +// MgoPagingFind +// +// @Description: +// @param mgoDb +// @param DataBase +// @param collection +// @param filter +// @param limit +// @param page +// @param sort +// @return []bson.M +// @return error +func MgoPagingFind(mgoDb *mongo.Client, DataBase string, collection string, filter interface{}, limit, page int64, sort int) ([]bson.M, error) { + c := mgoConnect(mgoDb, DataBase, collection) + + var optionStr *options.FindOptions + if sort != 0 { + optionStr = options.Find().SetLimit(limit).SetSkip((limit * page) - limit).SetSort(bson.M{"Code": sort}) + } else { + optionStr = options.Find().SetLimit(limit).SetSkip((limit * page) - limit) + } + + cur, err := c.Find(context.Background(), filter, optionStr) + if err != nil { + return nil, err + } + + var results []bson.M + if err = cur.All(context.TODO(), &results); err != nil { + log.Fatal(err) + } + + return results, err +} + +// MgoFindTotal +// +// @Description: +// @param mgoDb +// @param DataBase +// @param collection +// @param filter +// @return int64 +// @return error +func MgoFindTotal(mgoDb *mongo.Client, DataBase string, collection string, filter interface{}) (int64, error) { + c := mgoConnect(mgoDb, DataBase, collection) + + total, err := c.CountDocuments(context.TODO(), filter) + if err != nil { + return 0, err + } + + return total, nil +} + +// MgoAggregate +// +// @Description: +// @param mgoDb +// @param DataBase +// @param collection +// @param filter +// @return interface{} +// @return error +func MgoAggregate(mgoDb *mongo.Client, DataBase string, collection string, filter mongo.Pipeline) (interface{}, error) { + c := mgoConnect(mgoDb, DataBase, collection) + + aggregate, err := c.Aggregate(context.TODO(), filter) + if err != nil { + return 0, err + } + + var showsWithInfo []map[string]interface{} + if err = aggregate.All(context.TODO(), &showsWithInfo); err != nil { + log.Printf("collection %s", err) + panic(err) + } + + return showsWithInfo, nil +} diff --git a/internal/data/mongo/mongo_test.go b/internal/data/mongo/mongo_test.go new file mode 100644 index 0000000..3d75fab --- /dev/null +++ b/internal/data/mongo/mongo_test.go @@ -0,0 +1,911 @@ +package mongo + +import ( + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo" + "matchmaking-system/internal/conf" + "reflect" + "testing" +) + +func TestMgoAggregate(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter mongo.Pipeline + } + tests := []struct { + name string + args args + want interface{} + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := MgoAggregate(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter) + if (err != nil) != tt.wantErr { + t.Errorf("MgoAggregate() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("MgoAggregate() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMgoBulkWrite(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + models []mongo.WriteModel + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := MgoBulkWrite(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.models); (err != nil) != tt.wantErr { + t.Errorf("MgoBulkWrite() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestMgoConnect(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + } + tests := []struct { + name string + args args + want *mongo.Collection + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := MgoConnect(tt.args.mgoDb, tt.args.DataBase, tt.args.collection); !reflect.DeepEqual(got, tt.want) { + t.Errorf("MgoConnect() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMgoDeleteMany(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter interface{} + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := MgoDeleteMany(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter); (err != nil) != tt.wantErr { + t.Errorf("MgoDeleteMany() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestMgoDeleteOne(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter interface{} + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := MgoDeleteOne(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter); (err != nil) != tt.wantErr { + t.Errorf("MgoDeleteOne() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestMgoFind(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter interface{} + } + tests := []struct { + name string + args args + want interface{} + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := MgoFind(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter) + if (err != nil) != tt.wantErr { + t.Errorf("MgoFind() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("MgoFind() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMgoFindAll(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter interface{} + } + tests := []struct { + name string + args args + want interface{} + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := MgoFindAll(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter) + if (err != nil) != tt.wantErr { + t.Errorf("MgoFindAll() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("MgoFindAll() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMgoFindOne(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter interface{} + } + tests := []struct { + name string + args args + want bson.D + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := MgoFindOne(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter) + if (err != nil) != tt.wantErr { + t.Errorf("MgoFindOne() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("MgoFindOne() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMgoFindTotal(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter interface{} + } + tests := []struct { + name string + args args + want int64 + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := MgoFindTotal(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter) + if (err != nil) != tt.wantErr { + t.Errorf("MgoFindTotal() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("MgoFindTotal() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMgoInsertMany(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + docs []interface{} + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := MgoInsertMany(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.docs); (err != nil) != tt.wantErr { + t.Errorf("MgoInsertMany() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestMgoInsertOne(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + docs interface{} + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := MgoInsertOne(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.docs); (err != nil) != tt.wantErr { + t.Errorf("MgoInsertOne() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestMgoIsExist(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter interface{} + } + tests := []struct { + name string + args args + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := MgoIsExist(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter); got != tt.want { + t.Errorf("MgoIsExist() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMgoPagingFind(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter interface{} + limit int64 + page int64 + sort int + } + tests := []struct { + name string + args args + want []bson.M + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := MgoPagingFind(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter, tt.args.limit, tt.args.page, tt.args.sort) + if (err != nil) != tt.wantErr { + t.Errorf("MgoPagingFind() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("MgoPagingFind() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMgoUpdateID(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + id interface{} + update interface{} + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := MgoUpdateID(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.id, tt.args.update); (err != nil) != tt.wantErr { + t.Errorf("MgoUpdateID() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestMgoUpdateMany(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter interface{} + update []interface{} + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := MgoUpdateMany(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter, tt.args.update); (err != nil) != tt.wantErr { + t.Errorf("MgoUpdateMany() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestMgoUpdateOne(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter interface{} + update interface{} + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := MgoUpdateOne(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter, tt.args.update); (err != nil) != tt.wantErr { + t.Errorf("MgoUpdateOne() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNewMongodb(t *testing.T) { + type args struct { + c *conf.Data + } + tests := []struct { + name string + args args + want *mongo.Client + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewMongodb(tt.args.c); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewMongodb() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_mgoConnect(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + } + tests := []struct { + name string + args args + want *mongo.Collection + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := mgoConnect(tt.args.mgoDb, tt.args.DataBase, tt.args.collection); !reflect.DeepEqual(got, tt.want) { + t.Errorf("mgoConnect() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMgoAggregate1(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter mongo.Pipeline + } + tests := []struct { + name string + args args + want interface{} + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := MgoAggregate(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter) + if (err != nil) != tt.wantErr { + t.Errorf("MgoAggregate() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("MgoAggregate() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMgoBulkWrite1(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + models []mongo.WriteModel + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := MgoBulkWrite(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.models); (err != nil) != tt.wantErr { + t.Errorf("MgoBulkWrite() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestMgoConnect1(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + } + tests := []struct { + name string + args args + want *mongo.Collection + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := MgoConnect(tt.args.mgoDb, tt.args.DataBase, tt.args.collection); !reflect.DeepEqual(got, tt.want) { + t.Errorf("MgoConnect() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMgoDeleteMany1(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter interface{} + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := MgoDeleteMany(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter); (err != nil) != tt.wantErr { + t.Errorf("MgoDeleteMany() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestMgoDeleteOne1(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter interface{} + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := MgoDeleteOne(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter); (err != nil) != tt.wantErr { + t.Errorf("MgoDeleteOne() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestMgoFind1(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter interface{} + } + tests := []struct { + name string + args args + want interface{} + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := MgoFind(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter) + if (err != nil) != tt.wantErr { + t.Errorf("MgoFind() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("MgoFind() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMgoFindAll1(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter interface{} + } + tests := []struct { + name string + args args + want interface{} + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := MgoFindAll(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter) + if (err != nil) != tt.wantErr { + t.Errorf("MgoFindAll() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("MgoFindAll() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMgoFindOne1(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter interface{} + } + tests := []struct { + name string + args args + want bson.D + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := MgoFindOne(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter) + if (err != nil) != tt.wantErr { + t.Errorf("MgoFindOne() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("MgoFindOne() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMgoFindTotal1(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter interface{} + } + tests := []struct { + name string + args args + want int64 + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := MgoFindTotal(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter) + if (err != nil) != tt.wantErr { + t.Errorf("MgoFindTotal() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("MgoFindTotal() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMgoInsertMany1(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + docs []interface{} + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := MgoInsertMany(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.docs); (err != nil) != tt.wantErr { + t.Errorf("MgoInsertMany() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestMgoInsertOne1(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + docs interface{} + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := MgoInsertOne(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.docs); (err != nil) != tt.wantErr { + t.Errorf("MgoInsertOne() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestMgoIsExist1(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter interface{} + } + tests := []struct { + name string + args args + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := MgoIsExist(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter); got != tt.want { + t.Errorf("MgoIsExist() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMgoPagingFind1(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter interface{} + limit int64 + page int64 + sort int + } + tests := []struct { + name string + args args + want []bson.M + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := MgoPagingFind(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter, tt.args.limit, tt.args.page, tt.args.sort) + if (err != nil) != tt.wantErr { + t.Errorf("MgoPagingFind() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("MgoPagingFind() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMgoUpdateID1(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + id interface{} + update interface{} + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := MgoUpdateID(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.id, tt.args.update); (err != nil) != tt.wantErr { + t.Errorf("MgoUpdateID() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestMgoUpdateMany1(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter interface{} + update []interface{} + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := MgoUpdateMany(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter, tt.args.update); (err != nil) != tt.wantErr { + t.Errorf("MgoUpdateMany() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestMgoUpdateOne1(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + filter interface{} + update interface{} + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := MgoUpdateOne(tt.args.mgoDb, tt.args.DataBase, tt.args.collection, tt.args.filter, tt.args.update); (err != nil) != tt.wantErr { + t.Errorf("MgoUpdateOne() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNewMongodb1(t *testing.T) { + type args struct { + c *conf.Data + } + tests := []struct { + name string + args args + want *mongo.Client + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewMongodb(tt.args.c); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewMongodb() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_mgoConnect1(t *testing.T) { + type args struct { + mgoDb *mongo.Client + DataBase string + collection string + } + tests := []struct { + name string + args args + want *mongo.Collection + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := mgoConnect(tt.args.mgoDb, tt.args.DataBase, tt.args.collection); !reflect.DeepEqual(got, tt.want) { + t.Errorf("mgoConnect() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/data/mq/README.md b/internal/data/mq/README.md new file mode 100644 index 0000000..ad1c5cd --- /dev/null +++ b/internal/data/mq/README.md @@ -0,0 +1,7 @@ +# RabbitMQ + +## 代办事项 +``` + 1、处理并发之后的委托数据信息,防止开仓更新数据库数据异常问题.(已解决,待更新(确认是否合理)--需要配置mq消息队列) + 2、处理并发之后的持仓数据信息,防止平仓更新数据库数据异常问题.(已解决,待更新--需要配置mq消息队列) +``` \ No newline at end of file diff --git a/internal/data/mq/consumer/consumer.go b/internal/data/mq/consumer/consumer.go new file mode 100644 index 0000000..4aa6803 --- /dev/null +++ b/internal/data/mq/consumer/consumer.go @@ -0,0 +1,75 @@ +package consumer + +import ( + "github.com/streadway/amqp" + "matchmaking-system/internal/conf" +) + +var ( + ConsumerEntrustMq *ChanEntrustStatus + ConsumerPositionMq *ChanPositionStatus +) + +// Consumer +// @Description: +type Consumer struct { + Entrust *ConsumerEntrust + Position *ConsumerPosition +} + +// NewConsumer +// +// @Description: 初始化消费者 +// @param f +// @param con +// @return *Consumer +// @return error +func NewConsumer(f *conf.Data, con *amqp.Connection) (*Consumer, error) { + // 初始化消费者队列管道 + ConsumerEntrustMq = &ChanEntrustStatus{ + ShareUsMq: make(chan []byte), // 美股-生产者消息队列 + ShareMysMq: make(chan []byte), // 马股-生产者消息队列 + ShareIdnMq: make(chan []byte), // 印尼股-生产者消息队列 + ShareThaMq: make(chan []byte), // 泰国股-生产者消息队列 + ShareInrMq: make(chan []byte), // 印度股-生产者消息队列 + ContractMq: make(chan []byte), // 合约-生产者消息队列 + ShareSgdMq: make(chan []byte), // 新加坡股-生产者消息队列 + ShareHkdMq: make(chan []byte), // 港股-生产者消息队列 + ShareGbxMq: make(chan []byte), // 英股-生产者消息队列 + ShareFurMq: make(chan []byte), // 法股-生产者消息队列 + ShareEurMq: make(chan []byte), // 德股-生产者消息队列 + ShareBrlMq: make(chan []byte), // 巴西股-生产者消息队列 + ShareJpyMq: make(chan []byte), // 日股-生产者消息队列 + ForexMq: make(chan []byte), // 外汇-生产者消息队列 + OptionInrMq: make(chan []byte)} // 期权(印度)-生产者消息队列 + + ConsumerPositionMq = &ChanPositionStatus{ + ShareUsMq: make(chan []byte), // 美股-消费者消息队列 + ShareMysMq: make(chan []byte), // 马股-消费者消息队列 + ShareIdnMq: make(chan []byte), // 印尼股-消费者消息队列 + ShareThaMq: make(chan []byte), // 泰股-消费者消息队列 + ShareInrMq: make(chan []byte), // 印度-消费者消息队列 + ContractMq: make(chan []byte), // 合约-消费者消息队列 + ForexMq: make(chan []byte), // 外汇-消费者消息队列 + ShareSgdMq: make(chan []byte), // 新加坡-消费者消息队列 + ShareHkdMq: make(chan []byte), // 港股-消费者消息队列 + ShareGbxMq: make(chan []byte), // 英股-消费者消息队列 + ShareFurMq: make(chan []byte), // 法股-消费者消息队列 + ShareEurMq: make(chan []byte), // 德股-消费者消息队列 + ShareBrlMq: make(chan []byte), // 巴西股-消费者消息队列 + ShareJpyMq: make(chan []byte), // 日股-消费者消息队列 + OptionInrMq: make(chan []byte)} // 期权(印度)-消费者消息队列 + + // 初始化持仓消费者消息队列通道 + entrust, err := NewEntrust(f, con) + if err != nil { + return nil, err + } + // 初始化平仓消费者消息队列通道 + position, err := NewPosition(f, con) + if err != nil { + return nil, err + } + + return &Consumer{Entrust: entrust, Position: position}, nil +} diff --git a/internal/data/mq/consumer/consumer_test.go b/internal/data/mq/consumer/consumer_test.go new file mode 100644 index 0000000..8be0636 --- /dev/null +++ b/internal/data/mq/consumer/consumer_test.go @@ -0,0 +1,35 @@ +package consumer + +import ( + "github.com/streadway/amqp" + "matchmaking-system/internal/conf" + "reflect" + "testing" +) + +func TestNewConsumer(t *testing.T) { + type args struct { + f *conf.Data + con *amqp.Connection + } + tests := []struct { + name string + args args + want *Consumer + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := NewConsumer(tt.args.f, tt.args.con) + if (err != nil) != tt.wantErr { + t.Errorf("NewConsumer() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewConsumer() got = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/data/mq/consumer/entrust.go b/internal/data/mq/consumer/entrust.go new file mode 100644 index 0000000..b9c6a77 --- /dev/null +++ b/internal/data/mq/consumer/entrust.go @@ -0,0 +1,130 @@ +package consumer + +import ( + "github.com/streadway/amqp" + "matchmaking-system/internal/conf" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" +) + +// ChanEntrustStatus +// @Description: +type ChanEntrustStatus struct { + ShareUsMq chan []byte // 美股 + ShareMysMq chan []byte // 马股 + ShareIdnMq chan []byte // 印尼股 + ShareThaMq chan []byte // 泰股 + ShareInrMq chan []byte // 印度股 + ShareGbxMq chan []byte // 英股 + ShareSgdMq chan []byte // 新加坡股 + ShareHkdMq chan []byte // 港股 + ShareEurMq chan []byte // 德股 + ShareFurMq chan []byte // 法股 + ShareBrlMq chan []byte // 巴西股 + ShareJpyMq chan []byte // 日本股 + OptionInrMq chan []byte // 期权(印度) + ContractMq chan []byte // 合约 + ForexMq chan []byte // 外汇 +} + +// ConsumerEntrust +// @Description: 持仓消息队列【委托--持仓】 +type ConsumerEntrust struct { + Conn *amqp.Connection + Channel *amqp.Channel + Queue *amqp.Queue +} + +// NewEntrust +// +// @Description: 初始化持仓消息列队 +// @param f +// @param con +// @return *ConsumerEntrust +// @return error +func NewEntrust(f *conf.Data, con *amqp.Connection) (*ConsumerEntrust, error) { + var err error + var queue amqp.Queue + ce := new(ConsumerEntrust) + + // Producer Link Service + ce.Conn = con + + // Create a consumer channel + ce.Channel, err = ce.Conn.Channel() + if err != nil { + applogger.Error("channel err:%v", err) + return ce, err + } + + // Declare a queue + queue, err = ce.Channel.QueueDeclare( + f.Mq.Entrust, + true, + false, + false, + false, + nil, + ) + ce.Queue = &queue + + return ce, nil +} + +// ConsumerNotice +// +// @Description: 处理接收到的消息 +// @receiver c +func (c *ConsumerEntrust) ConsumerNotice() { + msgs, err := c.Channel.Consume( + c.Queue.Name, + flags.SetNull, + true, + false, + false, + false, + nil, + ) + if err != nil { + applogger.Error("ConsumerNotice err:%v", err) + return + } + + applogger.Info("消费者消息接受通道........") + + for value := range msgs { + // TODO: 处理接收到的消息进行平仓操作 + switch flags.CheckEnvironment { + case flags.CheckContract: + ConsumerEntrustMq.ContractMq <- value.Body + case flags.CheckForex: + ConsumerEntrustMq.ForexMq <- value.Body + case flags.CheckShareUs: + ConsumerEntrustMq.ShareUsMq <- value.Body + case flags.CheckShareMys: + ConsumerEntrustMq.ShareMysMq <- value.Body + case flags.CheckShareTha: + ConsumerEntrustMq.ShareThaMq <- value.Body + case flags.CheckShareIdn: + ConsumerEntrustMq.ShareIdnMq <- value.Body + case flags.CheckShareInr: + ConsumerEntrustMq.ShareInrMq <- value.Body + case flags.CheckShareSgd: + ConsumerEntrustMq.ShareSgdMq <- value.Body + case flags.CheckShareHkd: + ConsumerEntrustMq.ShareHkdMq <- value.Body + case flags.CheckShareGbx: + ConsumerEntrustMq.ShareGbxMq <- value.Body + case flags.CheckShareEur: + ConsumerEntrustMq.ShareEurMq <- value.Body + case flags.CheckShareFur: + ConsumerEntrustMq.ShareFurMq <- value.Body + case flags.CheckShareBrl: + ConsumerEntrustMq.ShareBrlMq <- value.Body + case flags.CheckOptionInr: + ConsumerEntrustMq.OptionInrMq <- value.Body + default: + applogger.Error("服务启动标识错误.") + } + } +} diff --git a/internal/data/mq/consumer/position.go b/internal/data/mq/consumer/position.go new file mode 100644 index 0000000..617ac08 --- /dev/null +++ b/internal/data/mq/consumer/position.go @@ -0,0 +1,130 @@ +package consumer + +import ( + "github.com/streadway/amqp" + "matchmaking-system/internal/conf" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" +) + +// ChanPositionStatus +// @Description: +type ChanPositionStatus struct { + ShareUsMq chan []byte // 美股 + ShareMysMq chan []byte // 马股 + ShareIdnMq chan []byte // 印尼股 + ShareThaMq chan []byte // 泰股 + ShareInrMq chan []byte // 印度股 + ShareGbxMq chan []byte // 英股 + ShareSgdMq chan []byte // 新加坡股 + ShareHkdMq chan []byte // 港股 + ShareEurMq chan []byte // 德股 + ShareFurMq chan []byte // 法股 + ShareBrlMq chan []byte // 巴西股 + ShareJpyMq chan []byte // 日股 + OptionInrMq chan []byte // 期权(印度) + ContractMq chan []byte // 合约 + ForexMq chan []byte // 外汇 +} + +// ConsumerPosition +// @Description: 平仓消息队列(持仓--平仓) +type ConsumerPosition struct { + Conn *amqp.Connection + Channel *amqp.Channel + Queue *amqp.Queue +} + +// NewPosition +// +// @Description: 初始化平仓消息列队 +// @param f +// @param con +// @return *ConsumerEntrust +// @return error +func NewPosition(f *conf.Data, con *amqp.Connection) (*ConsumerPosition, error) { + var err error + var queue amqp.Queue + cp := new(ConsumerPosition) + + // Producer Link Service + cp.Conn = con + + // Create a consumer channel + cp.Channel, err = cp.Conn.Channel() + if err != nil { + applogger.Error("channel err:%v", err) + return cp, err + } + + // Declare a queue + queue, err = cp.Channel.QueueDeclare( + f.Mq.Position, + true, + false, + false, + false, + nil, + ) + cp.Queue = &queue + + return cp, nil +} + +// ConsumerNotice +// +// @Description: 处理接收到的消息 +// @receiver c +func (c *ConsumerPosition) ConsumerNotice() { + msgs, err := c.Channel.Consume( + c.Queue.Name, + flags.SetNull, + true, + false, + false, + false, + nil, + ) + if err != nil { + applogger.Error("ConsumerNotice err:%v", err) + return + } + + applogger.Info("消费者消息接受通道........") + + for value := range msgs { + // TODO: 处理接收到的消息进行平仓操作 + switch flags.CheckEnvironment { + case flags.CheckContract: + ConsumerPositionMq.ContractMq <- value.Body + case flags.CheckForex: + ConsumerPositionMq.ForexMq <- value.Body + case flags.CheckShareUs: + ConsumerPositionMq.ShareUsMq <- value.Body + case flags.CheckShareMys: + ConsumerPositionMq.ShareMysMq <- value.Body + case flags.CheckShareTha: + ConsumerPositionMq.ShareThaMq <- value.Body + case flags.CheckShareIdn: + ConsumerPositionMq.ShareIdnMq <- value.Body + case flags.CheckShareInr: + ConsumerPositionMq.ShareInrMq <- value.Body + case flags.CheckShareSgd: + ConsumerPositionMq.ShareSgdMq <- value.Body + case flags.CheckShareHkd: + ConsumerPositionMq.ShareHkdMq <- value.Body + case flags.CheckShareGbx: + ConsumerPositionMq.ShareGbxMq <- value.Body + case flags.CheckShareEur: + ConsumerPositionMq.ShareEurMq <- value.Body + case flags.CheckShareFur: + ConsumerPositionMq.ShareFurMq <- value.Body + case flags.CheckShareBrl: + ConsumerPositionMq.ShareBrlMq <- value.Body + case flags.CheckOptionInr: + ConsumerPositionMq.OptionInrMq <- value.Body + default: + applogger.Error("服务启动标识错误.") + } + } +} diff --git a/internal/data/mq/mq.go b/internal/data/mq/mq.go new file mode 100644 index 0000000..4aa193c --- /dev/null +++ b/internal/data/mq/mq.go @@ -0,0 +1,66 @@ +package mq + +import ( + "github.com/streadway/amqp" + "matchmaking-system/internal/conf" + "matchmaking-system/internal/data/mq/consumer" + "matchmaking-system/internal/data/mq/producers" + "matchmaking-system/internal/pkg/logging/applogger" +) + +// NewMqProducer +// +// @Description: TODO: 实例化Mq生产者 +// @param c +// @return *producers.Producer +func NewMqProducer(c *conf.Data) *producers.Producer { + conn, err := initMq(c.Mq.Address) + if err != nil { + applogger.Error("NewMq err:%v", err) + return nil + } + + // 生产者实例 + p, err := producers.NewProducer(c, conn) + if err != nil { + return nil + } + + return p +} + +// NewMqConsumer TODO: 实例化Mq消费者 +// +// @Description: +// @param c +// @return *consumer.Consumer +func NewMqConsumer(c *conf.Data) *consumer.Consumer { + conn, err := initMq(c.Mq.Address) + if err != nil { + applogger.Error("NewMq err:%v", err) + return nil + } + // 消费者实例 + cn, err := consumer.NewConsumer(c, conn) + if err != nil { + return nil + } + + return cn +} + +// initMq 实例化Mq(生产者|消费者)消息队列 +// +// @Description: +// @param c +// @return *amqp.Connection +// @return error +func initMq(address string) (*amqp.Connection, error) { + conn, err := amqp.Dial(address) + if err != nil { + applogger.Error("NewMq err:%v", err) + return nil, err + } + + return conn, nil +} diff --git a/internal/data/mq/mq_test.go b/internal/data/mq/mq_test.go new file mode 100644 index 0000000..4f8a1fd --- /dev/null +++ b/internal/data/mq/mq_test.go @@ -0,0 +1,76 @@ +package mq + +import ( + "github.com/streadway/amqp" + "matchmaking-system/internal/conf" + "matchmaking-system/internal/data/mq/consumer" + "matchmaking-system/internal/data/mq/producers" + "reflect" + "testing" +) + +func TestNewMqConsumer(t *testing.T) { + type args struct { + c *conf.Data + } + tests := []struct { + name string + args args + want *consumer.Consumer + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewMqConsumer(tt.args.c); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewMqConsumer() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestNewMqProducer(t *testing.T) { + type args struct { + c *conf.Data + } + tests := []struct { + name string + args args + want *producers.Producer + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewMqProducer(tt.args.c); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewMqProducer() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_initMq(t *testing.T) { + type args struct { + address string + } + tests := []struct { + name string + args args + want *amqp.Connection + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := initMq(tt.args.address) + if (err != nil) != tt.wantErr { + t.Errorf("initMq() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("initMq() got = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/data/mq/producers/entrust.go b/internal/data/mq/producers/entrust.go new file mode 100644 index 0000000..8ffc673 --- /dev/null +++ b/internal/data/mq/producers/entrust.go @@ -0,0 +1,93 @@ +package producers + +import ( + "github.com/streadway/amqp" + "matchmaking-system/internal/conf" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" +) + +// ProducerEntrust +// @Description: +type ProducerEntrust struct { + Conn *amqp.Connection + Channel *amqp.Channel + Queue *amqp.Queue +} + +// NewEntrust +// +// @Description: 初始化生产者持仓消息队列 +// @param f +// @param con +// @return *ProducerEntrust +// @return error +func NewEntrust(f *conf.Data, con *amqp.Connection) (*ProducerEntrust, error) { + var err error + var queue amqp.Queue + p := new(ProducerEntrust) + + // Producer Link Service + p.Conn = con + + // Create a producer message channel + p.Channel, err = p.Conn.Channel() + if err != nil { + applogger.Error("channel err:%v", err) + return p, err + } + + // Declare a queue + queue, err = p.Channel.QueueDeclare( + f.Mq.Position, + true, + false, + false, + false, + nil, + ) + p.Queue = &queue + + return p, nil +} + +// PushNotice +// +// @Description: 生产者推送消息 +// @receiver p +// @param msgCache +// @return error +func (p *ProducerEntrust) PushNotice(msgCache []byte) error { + if err := p.DealPublish(msgCache); err != nil { + applogger.Info("send message exception err:%v", err) + // TODO: 处理消息推送异常情况(需要尝试再次链接) + + return err + } + + return nil +} + +// DealPublish +// +// @Description: 处理推送消息 +// @receiver p +// @param body +// @return error +func (p *ProducerEntrust) DealPublish(body []byte) error { + err := p.Channel.Publish( + flags.SetNull, + p.Queue.Name, + false, + false, + amqp.Publishing{ + ContentType: "text/plain", + Body: body, + }) + if err != nil { + applogger.Error("message sending exception:%v", err) + return err + } + + return nil +} diff --git a/internal/data/mq/producers/position.go b/internal/data/mq/producers/position.go new file mode 100644 index 0000000..75fbbb6 --- /dev/null +++ b/internal/data/mq/producers/position.go @@ -0,0 +1,93 @@ +package producers + +import ( + "github.com/streadway/amqp" + "matchmaking-system/internal/conf" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" +) + +// ProducerPosition +// @Description: +type ProducerPosition struct { + Conn *amqp.Connection + Channel *amqp.Channel + Queue *amqp.Queue +} + +// NewPosition +// +// @Description: 初始化消费者平仓消息队列 +// @param f +// @param con +// @return *ProducerPosition +// @return error +func NewPosition(f *conf.Data, con *amqp.Connection) (*ProducerPosition, error) { + var err error + var queue amqp.Queue + p := new(ProducerPosition) + + // Producer Link Service + p.Conn = con + + // Create a producer message channel + p.Channel, err = p.Conn.Channel() + if err != nil { + applogger.Error("channel err:%v", err) + return p, err + } + + // Declare a queue + queue, err = p.Channel.QueueDeclare( + f.Mq.Position, + true, + false, + false, + false, + nil, + ) + p.Queue = &queue + + return p, nil +} + +// PushNotice +// +// @Description: 生产者推送消息 +// @receiver p +// @param msgCache +// @return error +func (p *ProducerPosition) PushNotice(msgCache []byte) error { + if err := p.dealPublish(msgCache); err != nil { + applogger.Info("send message exception err:%v", err) + // TODO: 处理消息推送异常情况(需要尝试再次链接) + + return err + } + + return nil +} + +// DealPublish +// +// @Description: 处理推送消息 +// @receiver p +// @param body +// @return error +func (p *ProducerPosition) dealPublish(body []byte) error { + err := p.Channel.Publish( + flags.SetNull, + p.Queue.Name, + false, + false, + amqp.Publishing{ + ContentType: "text/plain", + Body: body, + }) + if err != nil { + applogger.Error("message sending exception:%v", err) + return err + } + + return nil +} diff --git a/internal/data/mq/producers/producers.go b/internal/data/mq/producers/producers.go new file mode 100644 index 0000000..31b2c88 --- /dev/null +++ b/internal/data/mq/producers/producers.go @@ -0,0 +1,35 @@ +package producers + +import ( + "github.com/streadway/amqp" + "matchmaking-system/internal/conf" +) + +// Producer +// @Description: +type Producer struct { + Entrust *ProducerEntrust + Position *ProducerPosition +} + +// NewProducer +// +// @Description: 初始化生产者 +// @param f +// @param con +// @return *Producer +// @return error +func NewProducer(f *conf.Data, con *amqp.Connection) (*Producer, error) { + // 初始化生产者持仓消息队列 + entrust, err := NewEntrust(f, con) + if err != nil { + return nil, err + } + // 初始化生产者平仓消息队列 + position, err := NewPosition(f, con) + if err != nil { + return nil, err + } + + return &Producer{Entrust: entrust, Position: position}, nil +} diff --git a/internal/data/mq/producers/producers_test.go b/internal/data/mq/producers/producers_test.go new file mode 100644 index 0000000..fc3ef51 --- /dev/null +++ b/internal/data/mq/producers/producers_test.go @@ -0,0 +1,35 @@ +package producers + +import ( + "github.com/streadway/amqp" + "matchmaking-system/internal/conf" + "reflect" + "testing" +) + +func TestNewProducer(t *testing.T) { + type args struct { + f *conf.Data + con *amqp.Connection + } + tests := []struct { + name string + args args + want *Producer + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := NewProducer(tt.args.f, tt.args.con) + if (err != nil) != tt.wantErr { + t.Errorf("NewProducer() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewProducer() got = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/data/mysql/mysql.go b/internal/data/mysql/mysql.go new file mode 100644 index 0000000..3cabe83 --- /dev/null +++ b/internal/data/mysql/mysql.go @@ -0,0 +1,32 @@ +package mysql + +import ( + "github.com/go-xorm/xorm" + "matchmaking-system/internal/conf" +) + +// NewMySql +// +// @Description: +// @param c +// @return *xorm.EngineGroup +func NewMySql(c *conf.Data) *xorm.EngineGroup { + driver := c.Database.Driver + datasource := c.Database.Source + + cons := []string{datasource} + Engine, err := xorm.NewEngineGroup(driver, cons, xorm.RandomPolicy()) + if err != nil { + panic(err) + } + + Engine.ShowExecTime(true) + Engine.ShowSQL(true) + Engine.SetMaxOpenConns(500) + err = Engine.Ping() + if err != nil { + panic(err) + } + + return Engine +} diff --git a/internal/data/mysql/mysql_test.go b/internal/data/mysql/mysql_test.go new file mode 100644 index 0000000..37c5e06 --- /dev/null +++ b/internal/data/mysql/mysql_test.go @@ -0,0 +1,48 @@ +package mysql + +import ( + "github.com/go-xorm/xorm" + "matchmaking-system/internal/conf" + "reflect" + "testing" +) + +func TestNewMySql(t *testing.T) { + type args struct { + c *conf.Data + } + tests := []struct { + name string + args args + want *xorm.EngineGroup + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewMySql(tt.args.c); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewMySql() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestNewMySql1(t *testing.T) { + type args struct { + c *conf.Data + } + tests := []struct { + name string + args args + want *xorm.EngineGroup + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewMySql(tt.args.c); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewMySql() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/data/order_backend.go b/internal/data/order_backend.go new file mode 100644 index 0000000..dfdcd4f --- /dev/null +++ b/internal/data/order_backend.go @@ -0,0 +1,34 @@ +package data + +import ( + "context" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + models "matchmaking-system/internal/pkg/model" + "time" +) + +// UpdateBotUsersByIsReal +// +// @Description: 更新模拟账户KYC认证 +// @receiver uo +// @param ctx +// @param userId +// @return error +func (uo *userOrderRepo) UpdateBotUsersByIsReal(ctx context.Context, userId int64) error { + stock := models.BotUsers{ + UpdateTime: time.Now(), + IsReal: 1, + } + + checkNum, err := uo.data.mysqlDB.Table(flags.BotUsers). + Where("user_id = ?", userId). + Where("is_test_user = 2"). + Update(&stock) + if err != nil || checkNum < 0 { + applogger.Error("更新数据失败:%v", err) + return err + } + + return err +} diff --git a/internal/data/order_forex.go b/internal/data/order_forex.go new file mode 100644 index 0000000..745753d --- /dev/null +++ b/internal/data/order_forex.go @@ -0,0 +1,1358 @@ +package data + +import ( + "context" + "encoding/json" + "github.com/go-xorm/xorm" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "strings" + + orders "matchmaking-system/internal/data/convert" + forexd "matchmaking-system/internal/data/tradedeal/forex" + models "matchmaking-system/internal/pkg/model" +) + +// GetBotForexTradeList +// +// @Description: 外汇订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param userId +// @param status +// @return []*models.BotForexTrade +// @return int64 +// @return error +func (uo *userOrderRepo) GetBotForexTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotForexTrade, int64, error) { + totalCount, err := uo.data.mysqlDB.Table(flags.BotForexTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Count() + if err != nil { + return nil, 0, flags.ErrMySqlDB + } + if totalCount == 0 { + return nil, 0, nil + } + var contractList []*models.BotForexTrade + if err = uo.data.mysqlDB.Table(flags.BotForexTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Limit(int(pageSize), int(pageCount)). + Desc(GetOrderByStatusSort(status)). + Find(&contractList); err != nil { + return nil, 0, flags.ErrMySqlDB + } + + var contractUpdateList []*models.BotForexTrade + for _, value := range contractList { + value.KeepDecimal = GetKeepDecimal(flags.ForexSystemSetUpKey, value.ContractId) + contractUpdateList = append(contractUpdateList, value) + } + + return contractUpdateList, totalCount, nil +} + +// CreateBotForexTrade +// +// @Description: 外汇下单 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) CreateBotForexTrade(ctx context.Context, userId int64, order structure.ForexOrder) (string, error) { + // 1、外汇下单订阅 + forexId := strings.ToUpper(order.ForexId) + _, ok := forexWh.ForexMapSymbol.Load(forexId) + if ok { + go func() { + forexWh.ForexMap <- []byte(forexId) + }() + } + + // 2、获取系统设置 + system, err := GetForexSystemSetUp(forexId) + if err != nil || system == nil { + return flags.SetNull, flags.ErrContractOne + } + order.System = system + + // TODO: 3、获取外汇交易对的买一卖一价格 + //priceNew, err := GetDigitalCurrencyForexPrice(ctx, flags.Wh, forexId, order.TradeType) + //if len(priceNew) == 0 || err != nil { + // applogger.Error("%v CreateBotForexTrade.ForexSubMarketPrice:%v", common.ErrForex, err) + // return flags.SetNull, flags.ErrPriceUpdate + //} + + // 4、外汇下单判定 + // TODO: 杠杆校验 + //pryNum := decimal.RequireFromString(order.PryNum) + //if pryNum.Cmp(order.System.MinPry) < 0 || pryNum.Cmp(order.System.MaxPry) > 0 { + // return flags.SetNull, flags.ErrContractTow + //} + + // 下单判定设置(false无设置|true止盈止损) + checkBool, stopWinPrice, stopLossPrice, err := ForexVoteStopType(order) + if err != nil { + applogger.Error("%v CreateBotForexTrade.ForexVoteStopType:%v", common.ErrForex, err) + return flags.SetNull, err + } + + // 下单判定设置(限价|市价) + limitOrMarketPrice, err := uo.ForexVoteDealType(order) + if err != nil { + applogger.Error("%v CreateBotForexTrade.ForexVoteDealType:%v", common.ErrForex, err) + return flags.SetNull, err + } + + // 下单判定设置(买涨|买跌) + if err = uo.ForexVoteTradeType(order.TradeType, stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v CreateBotForexTrade.ForexVoteTradeType:%v", common.ErrForex, err) + return flags.SetNull, err + } + + // 5、外汇下单(订单信息|资产信息) + orderId, err := uo.ForexOrdersWriteDB(ctx, userId, order) + if err != nil || len(orderId) == 0 { + applogger.Error("%v CreateBotForexTrade.ForexOrdersWriteDB:%v", common.ErrForex, err) + return flags.SetNull, err + } + + // 6、写入缓存列表(挂单缓存|持仓缓存),等待撮合计算 + marketStatus, tallyCache, err := forexd.ForexCacheDeal(ctx, userId, orderId, limitOrMarketPrice.String(), order) + if err != nil || tallyCache == nil { + applogger.Error("%v CreateBotForexTrade.ForexCacheDeal:%v", common.ErrForex, err) + return flags.SetNull, err + } + + // 7、市价下单开仓处理(订单信息|资产信息|手续费|返佣|资产详情记录) + if marketStatus == setting.MarketForexPosition { + if err = ForexOpenPosition(ctx, uo.data.mysqlDB, userId, orderId, tallyCache.OpenPrice, order); err != nil { + applogger.Error("%v CreateBotForexTrade.ForexOpenPosition:%v", common.ErrForex, err) + return flags.SetNull, err + } + } + + // 8、写入(挂单|持仓)缓存列表 + if err = forexd.ForexPushAddCache(Reds, marketStatus, tallyCache); err != nil { + applogger.Error("%v CreateBotForexTrade.ForexPushAddCache:%v", common.ErrForex, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 9、写入用户订单订阅缓存列表 + orderIdKey := virtual.OrderIdListKey(setting.ForexSubscribe, userId) + if err = forexd.ForexHashSetOrderId(Reds, orderIdKey, tallyCache); err != nil { + applogger.Error("%v CreateBotForexTrade.ForexPushAddOrder:%v", common.ErrForex, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 10、写入管理员订单订阅缓存列表 + if err = forexd.ForexHashSetOrderId(Reds, setting.AdminForexSubscribe, tallyCache); err != nil { + applogger.Error("%v CreateBotForexTrade.ForexHashSetOrderId:%v", common.ErrForex, err) + return flags.SetNull, flags.ErrCacheDB + } + + return orderId, nil +} + +// ForexOrdersWriteDB +// +// @Description: 外汇下单处理 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) ForexOrdersWriteDB(ctx context.Context, userId int64, order structure.ForexOrder) (string, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v ForexOrdersWriteDB.NewSession:%v", common.ErrForex, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + usable, frozen, _, err = uo.GetBotUserForex(session, userId, flags.ForexUnit) + if err != nil { + applogger.Error("%v ForexOrdersWriteDB.GetBotUserForex:%v", common.ErrForex, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 检查用户订单下单资产 + if usable.IsZero() || usable.IsNegative() || frozen.IsNegative() { + return flags.SetNull, flags.ErrPublicOne + } + // 查询当前下单用户可用非账户和冻结金额 + var checkCount int + if order.ForexId != flags.ForexUnit { + usableNo, frozenNo, checkCount, err = uo.GetBotUserForex(session, userId, order.ForexId) + if err != nil { + applogger.Error("%v ForexOrdersWriteDB.GetBotUserForex.Fei:%v", common.ErrForex, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("非下单可用金额:%v", usableNo) + applogger.Debug("非下单冻结金额:%v", frozenNo) + } + + // 写入订单信息 + orderId, err := uo.VerifyBotForexTradeOrderId(session) + if err != nil { + applogger.Error("%v ForexOrdersWriteDB.VerifyBotForexTradeOrderId:%v", common.ErrForex, err) + return flags.SetNull, err + } + if !flags.CheckSetting { + applogger.Debug("下单Id:%v", orderId) + applogger.Debug("杠杆:%v", order.PryNum) + } + + // 写入订单表: 保证金 = (手数(1000 / 100000) * 合约单位(100000)) / 杠杆 * 汇率 + botStockTrade := orders.BotForexTrade(ctx, userId, orderId, order) + if err = uo.CreatBotForexTrade(session, botStockTrade); err != nil { + applogger.Error("%v ForexOrdersWriteDB.CreatBotForexTrade:%v", common.ErrForex, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 订单总金额 = 保证金 + 手续费 + earnestMoney := decimal.RequireFromString(order.EarnestMoney) // 保证金 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 手续费 + totalMoney := earnestMoney.Add(serviceCost) + + // 总金额下单判定 + residue := usable.Sub(totalMoney).Div(usable) + if usable.Cmp(totalMoney) < 0 || residue.Cmp(utils.DecimalsStrInt()) < 0 { + return flags.SetNull, flags.ErrPublicOne + } + + // (买涨|买跌)处理 + var usableNew, frozenNew, usableNewNo, frozenNewNo decimal.Decimal + usableNew = usable.Sub(totalMoney) // 可用资产 + frozenNew = frozen.Add(totalMoney) // 冻结资产 + if order.ForexId != flags.ForexUnit { + usableNewNo = usableNo // 可用非资产 + frozenNewNo = frozenNo // 冻结非资产 + } + + // 检查用户订单下单资产 + if usableNew.IsNegative() || usableNew.IsZero() { + return flags.SetNull, flags.ErrPublicTow + } + if !flags.CheckSetting { + applogger.Debug("下单后用户可用资产:%v", usableNew) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + applogger.Debug("下单后用户非可用资产:%v", usableNewNo) + applogger.Debug("下单后用户非冻结资产:%v", frozenNewNo) + } + + // 更新用户资产信息 + userForexUSDT := orders.UpdateBotUserForex(ctx, usableNew.String(), frozenNew.String()) + if err = uo.UpdateBotUserForex(session, userId, flags.ForexUnit, userForexUSDT); err != nil { + applogger.Error("%v ForexOrdersWriteDB.UpdateBotUserForex:%v", common.ErrForex, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 更新非资产信息 + if order.ForexId != flags.ForexUnit { + if checkCount == 0 { + userDigitalSymbol := orders.CreatBotUserForex(ctx, userId, usableNewNo.String(), frozenNewNo.String(), order) + err = uo.CreatBotUserForex(session, userDigitalSymbol) + if err != nil { + applogger.Error("%v ForexOrdersWriteDB.CreatBotUserForex:%v", common.ErrForex, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + userForex := orders.UpdateBotUserForex(ctx, usableNewNo.String(), frozenNewNo.String()) + if err = uo.UpdateBotUserForex(session, userId, order.ForexId, userForex); err != nil { + applogger.Error("%v ForexOrdersWriteDB.UpdateBotUserForex:%v", common.ErrForex, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v ForexOrdersWriteDB.Commit:%v", common.ErrForex, err) + return flags.SetNull, flags.ErrMySqlDB + } + + return orderId, nil +} + +// ForexOpenPosition +// +// @Description: 外汇开仓处理 +// @param ctx +// @param db +// @param userId +// @param orderId +// @param openPrice +// @param order +// @return error +func ForexOpenPosition(ctx context.Context, db *xorm.EngineGroup, userId int64, orderId, openPrice string, order structure.ForexOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v ForexOpenPosition.NewSession:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + usable, frozen, _, err = Uo.GetBotUserForex(session, userId, flags.ForexUnit) + if err != nil { + applogger.Error("%v ForexOpenPosition.GetBotUserForex:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrPublicThree + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + } + + if order.ForexId != flags.ForexUnit { + usableNo, frozenNo, _, err = Uo.GetBotUserForex(session, userId, order.ForexId) + if err != nil { + applogger.Error("%v ForexOpenPosition.GetBotUserForex:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + } + + earnestMoney := decimal.RequireFromString(order.EarnestMoney) // 下单保证金 + openOrderNumber := decimal.RequireFromString(order.OrderNumber) // 下单仓位 = 保证金 / (一手保证金 * 杠杆倍数) + serviceCost := decimal.RequireFromString(order.ServiceCost) // 下单手续费 + totalMoney := earnestMoney.Add(serviceCost) // 下单总金额 = (订单手续费 + 保证金) + openFaceValue := order.System.FaceValue // 面值(暂不使用) + openOrderPrice := decimal.RequireFromString(openPrice) // 开仓价格(下单金额) + pryNum := decimal.RequireFromString(order.PryNum) // 杠杆 + if !flags.CheckSetting { + applogger.Debug("下单订单杠杆:%v", pryNum) + applogger.Debug("下单保证金:%v", earnestMoney) + applogger.Debug("下单订单数量:%v", openOrderNumber) + applogger.Debug("下单订单手续费:%v", serviceCost) + applogger.Debug("下单订单总金额:%v", totalMoney) + } + + // 手续费记录 + openPriceNew := openOrderPrice.Mul(openOrderNumber).String() // 开仓手续费 = 开仓价格 * 仓位数 * 手续费比例 + cost, err := Uo.CalculateHandlingFees(ctx, session, int(userId), flags.ForexMarketType, flags.OpenBrokType, orderId, openPriceNew, openFaceValue.String()) + if err != nil { + applogger.Error("%v ForexOpenPosition.CalculateHandlingFees:%v", common.ErrForex, err) + return err + } + openServiceCost := decimal.RequireFromString(cost) // 开仓手续费 + openTotalMoney := earnestMoney.Add(openServiceCost) // 开仓总金额 = (保证金 + 开仓手续费) + floatPrice := totalMoney.Sub(openTotalMoney) // 计算容差 = 下单总额 - 开仓总额 + if !flags.CheckSetting { + applogger.Debug("开仓订单价格:%v", openOrderPrice) + applogger.Debug("开仓仓位:%v", openOrderNumber) + applogger.Debug("开仓手续费:%v", openServiceCost) + applogger.Debug("开仓总金额:%v", openTotalMoney) + applogger.Debug("下单开仓总金额容差值:%v", floatPrice) + } + + usableNew := usable.Add(floatPrice) // 可用资产(处理容差值) + frozenNew := frozen.Sub(totalMoney).Add(earnestMoney) // 冻结资产 = 冻结资产 - 下单冻结资产 + 开仓保证金 + usableNoNew := usableNo.Add(openOrderNumber) // 非可用资产 + frozenNoNew := frozenNo // 非冻结资产 + if !flags.CheckSetting { + applogger.Debug("下单后用户可用资产:%v", usableNew) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + } + applogger.Debug("下单冻结资产:%v", frozen) + applogger.Debug("下单后的冻结总资产:%v", totalMoney) + applogger.Debug("开仓后的保证金:%v", earnestMoney) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + applogger.Debug("下单后用户可用资产:%v", usableNew) + + // 检查用户平仓资产 + if usableNoNew.IsNegative() { + return flags.ErrPublicThree + } + + // 处理资产信息 + userForexUSDT := orders.UpdateBotUserForex(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserForex(session, userId, flags.ForexUnit, userForexUSDT); err != nil { + applogger.Error("%v ForexOpenPosition.UpdateBotUserForex:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + + // 更新非资产信息 + if order.ForexId != flags.ForexUnit { + userForex := orders.UpdateBotUserForex(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = Uo.UpdateBotUserForex(session, userId, order.ForexId, userForex); err != nil { + applogger.Error("%v ForexOpenPosition.UpdateBotUserForex:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + } + + // 处理订单信息(成交价|仓位|开仓时间|订单总金额|手续费|持仓状态) + trade := orders.UpdateOpenBotForexTrade(ctx, openPrice, openOrderNumber.String(), openTotalMoney.String(), openServiceCost.String()) + if err = Uo.UpdateBotForexTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v ForexOpenPosition.UpdateBotForexTradeByOrderId:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + + // 返佣记录|资金信息|资金详情信息 + if err = Uo.ForexRebateCalculation(ctx, session, int(userId), flags.ForexMarketType, flags.OpenBrokType, flags.OpenMRebate, cost, orderId); err != nil { + applogger.Error("%v ForexOpenPosition.ForexRebateCalculation:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + + // 更改交易日志记录方式 + var list []models.BotUserForexLog + qData0 := orders.CreatBotUserForexLog(ctx, userId, flags.CostMoney, flags.ForexUnit, NegativeValue(openServiceCost.String()), orderId) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserForexLog(ctx, userId, flags.Freeze, flags.ForexUnit, NegativeValue(earnestMoney.String()), orderId) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserForexLog(ctx, userId, flags.ChangeInto, order.ForexId, openOrderNumber.String(), orderId) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserForexLogList(session, list); err != nil { + applogger.Error("%v ForexOpenPosition.CreatBotUserForexLogList:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v ForexOpenPosition.Commit:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + + return nil +} + +// ForexClosingPosition +// +// @Description: 外汇平仓处理 +// @param ctx +// @param db +// @param orderId +// @param price +// @param order +// @return error +func ForexClosingPosition(ctx context.Context, db *xorm.EngineGroup, orderId string, price string, order structure.ForexOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v ForexClosingPosition.NewSession:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + + // 查询订单信息 + tread, err := Uo.GetBotForexTradeByOrderId(session, orderId, flags.PositionStatus) + if err != nil { + applogger.Error("%v ForexClosingPosition.GetBotForexTradeByOrderId:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + var userId int64 + var dealPrice, earnestMoney, orderNumber, totalAmount, serviceCost decimal.Decimal + if tread != nil { + userId = int64(tread.UserId) // 用户Id + earnestMoney = decimal.RequireFromString(tread.EarnestMoney) // 开仓保证金 + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.TotalMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + } + if !flags.CheckSetting { + applogger.Debug("下单开仓用户Id:%v", userId) + applogger.Debug("下单开仓开仓价格:%v", dealPrice) + applogger.Debug("下单开仓保证金:%v", earnestMoney) + applogger.Debug("下单开仓订单数量:%v", orderNumber) + applogger.Debug("下单开仓总金额:%v", totalAmount) + applogger.Debug("下单开仓手续费:%v", serviceCost) + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + usable, frozen, _, err = Uo.GetBotUserForex(session, userId, flags.ForexUnit) + if err != nil { + applogger.Error("%v ForexClosingPosition.GetBotUserForex:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + // 检查用户订单平仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrContractFive + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + } + + // 查询当前下单用户可用非账户和冻结金额 + if order.ForexId != flags.ForexUnit { + usableNo, frozenNo, _, err = Uo.GetBotUserForex(session, userId, order.ForexId) + if err != nil { + applogger.Error("%vForexClosingPosition.GetBotUserForex:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + } + if !flags.CheckSetting { + applogger.Debug("非下单可用金额:%v", usableNo) + applogger.Debug("非下单冻结金额:%v", frozenNo) + } + + closeFaceValue := order.System.FaceValue // 面值 + + // 手续费处理 + pryNum := decimal.RequireFromString(order.PryNum) // 杠杆 + closePrice := decimal.RequireFromString(price) // 平仓价格 + cloePriceCost := closePrice.Mul(orderNumber).String() // 平仓手续费 = 平仓价格 * 仓位数 * 手续费比例 * 面值 + cost, err := Uo.CalculateHandlingFees(ctx, session, int(userId), flags.ForexMarketType, flags.ClosingBrokType, orderId, cloePriceCost, closeFaceValue.String()) + if err != nil { + applogger.Error("%v ForexClosingPosition.CalculateHandlingFees:%v", common.ErrForex, err) + return err + } + closeServiceCost := decimal.RequireFromString(cost) + if !flags.CheckSetting { + applogger.Debug("平仓价格:%v", closePrice) + applogger.Debug("平仓手续费手续费:%v", closeServiceCost) + } + + //已经实现盈亏计算公式(已平仓结算方式) + //买涨 已经实现盈亏 = (平仓成交价-开仓成交价)*手数 + //买跌 已经实现盈亏 = (开仓成交价-平仓成交价)*手数 + var usableNew, frozenNew, usableNewNo, frozenNewNo, subPrice, resultPrice decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买涨 + subPrice = closePrice.Sub(dealPrice) + resultPrice = subPrice.Mul(orderNumber).Mul(closeFaceValue).Mul(pryNum) + case flags.TradeTypeSell: // 买跌 + subPrice = dealPrice.Sub(closePrice) + resultPrice = subPrice.Mul(orderNumber).Mul(closeFaceValue).Mul(pryNum) + default: + } + + // TODO: 判定亏损不能超过 = 保证金 + 平仓手续费 + if resultPrice.IsNegative() { + amountLoss := earnestMoney.Sub(closeServiceCost) + if resultPrice.Abs().Cmp(amountLoss) >= 0 { + resultPrice = amountLoss.Neg() + } + } + + // 用户资产账户 + usableNew = usable.Add(resultPrice).Add(earnestMoney).Sub(closeServiceCost) // 可用资产 = 原可用资产 + ((正负)盈亏*面值) + 保证金 - 手续费 + frozenNew = frozen.Sub(earnestMoney) // 冻结资产 + if frozenNew.IsNegative() { + frozenNew = decimal.Zero + } + // 用户非资产账户 + if order.ForexId != flags.ForexUnit { + usableNewNo = usableNo.Sub(orderNumber) // 可用非资产 = 原可用非资产 - 下单仓位数 + frozenNewNo = frozenNo // 可用非冻结资产 + } + + // 检查用户订单平仓资产 + if usableNewNo.IsNegative() { + return flags.ErrContractFive + } + if !flags.CheckSetting { + applogger.Debug("可用资产:%v", usableNew) + applogger.Debug("冻结资产:%v", frozenNew) + applogger.Debug("可用非资产:%v", usableNewNo) + applogger.Debug("冻结非资产:%v", frozenNewNo) + } + + // 平仓(处理资产表(资产)) + userForexUSDT := orders.UpdateBotUserForex(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserForex(session, userId, flags.ForexUnit, userForexUSDT); err != nil { + applogger.Error("%v ForexClosingPosition.UpdateBotUserForex:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + + // 平仓(处理资产表(非资产)) + if order.ForexId != flags.ForexUnit { + userForex := orders.UpdateBotUserForex(ctx, usableNewNo.String(), frozenNewNo.String()) + if err = Uo.UpdateBotUserForex(session, userId, order.ForexId, userForex); err != nil { + applogger.Error("%v ForexClosingPosition.UpdateBotUserForex:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + } + + // 平仓(处理订单信息(平仓价|保证金|平仓|订单总金额|平仓手续费|完成订单)) + trade := orders.UpdateCloseBotForexTrade(ctx, price, earnestMoney.String(), totalAmount.String(), cost) + if err = Uo.UpdateBotForexTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v ForexClosingPosition.UpdateBotForexTradeByOrderId:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + + // 平仓(返佣记录表|资产表|资金变动表) + if err = Uo.ForexRebateCalculation(ctx, session, int(userId), flags.ForexMarketType, flags.ClosingBrokType, flags.CloseMRebate, cost, orderId); err != nil { + applogger.Error("%v ForexClosingPosition.ForexRebateCalculation:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + + // 更改交易日志记录方式 + var list []models.BotUserForexLog + qData0 := orders.CreatBotUserForexLog(ctx, userId, flags.CostMoney, flags.ForexUnit, NegativeValue(closeServiceCost.String()), orderId) // 平仓(资金变动明细表(-平仓手续费)) + qData1 := orders.CreatBotUserForexLog(ctx, userId, flags.Thaw, flags.ForexUnit, earnestMoney.String(), orderId) // 平仓(资金变动明细表(+保证金)) + qData2 := orders.CreatBotUserForexLog(ctx, userId, flags.TransferOut, order.ForexId, NegativeValue(orderNumber.String()), orderId) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData0, qData1, qData2) + + // 平仓(资金变动明细表(正负盈亏)) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserForexLog(ctx, userId, flags.TransferOut, flags.ForexUnit, resultPrice.String(), orderId) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserForexLog(ctx, userId, flags.ChangeInto, flags.ForexUnit, resultPrice.String(), orderId) + list = append(list, qData4) + } + + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserForexLogList(session, list); err != nil { + applogger.Error("%v ForexClosingPosition.CreatBotUserForexLogList:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v ForexClosingPosition.Commit:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + + return nil +} + +// UpdateBotForexStopByOrderId +// +// @Description: 外汇设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotForexStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotForexStopByOrderId.NewSession:%v", common.ErrForex, err) + return false, flags.ErrMySqlDB + } + + // 设置止盈止损判定 + trade, err := uo.GetBotForexTradeByOrderId(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotForexStopByOrderId.GetBotForexTradeByOrderId:%v", common.ErrForex, err) + return false, flags.ErrMySqlDB + } + // 下单信息 + checkBool, stopWinPrice, stopLossPrice, err := uo.UpdateForexVoteStopType(order) + if err != nil { + applogger.Error("%v UpdateBotForexStopByOrderId.UpdateForexVoteStopType:%v", common.ErrForex, err) + return false, err + } + if !flags.CheckSetting { + applogger.Debug("获取当前止盈止损数据:%v,%v,%v", checkBool, stopWinPrice, stopLossPrice) + } + + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err := uo.UpdateForexVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotForexStopByOrderId.UpdateForexVoteDealType:%v", common.ErrForex, err) + return false, err + } + if !flags.CheckSetting { + applogger.Debug("获取当前开仓价格:%v", limitOrMarketPrice) + } + + // 下单判定设置(买涨|买跌) + if err = uo.ForexVoteTradeType(int64(trade.TradeType), stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v UpdateBotForexStopByOrderId.ForexVoteTradeType:%v", common.ErrForex, err) + return false, err + } + + // 更新订单表 + botStockTrade := orders.BotForexStopByOrderId(ctx, order) + err = uo.UpdateBotForexTradeByOrderId(session, order.OrderId, botStockTrade) + if err != nil { + applogger.Error("%v UpdateBotForexStopByOrderId.Update:%v", common.ErrForex, err) + return false, flags.ErrMySqlDB + } + + // 修改挂单缓存队列 + entrust, err := LoadLRangeList(setting.MarketForexPosition) + if err != nil { + applogger.Error("%v UpdateBotForexStopByOrderId.LoadLRangeList:%v", common.ErrForex, err) + return false, flags.ErrCacheDB + } + for key, value := range entrust { + var entrustJson forexd.ForexTallyCache + if err = json.Unmarshal([]byte(value), &entrustJson); err != nil { + applogger.Error("%v UpdateBotForexStopByOrderId.Unmarshal:%v", common.ErrForex, err) + return false, flags.ErrCacheDB + } + entrustJson.Order.StopType = order.StopType + entrustJson.Order.StopWinPrice = order.StopWinPrice + entrustJson.Order.StopLossPrice = order.StopLossPrice + if !flags.CheckSetting { + applogger.Debug("修改缓存中的止盈止损Type:%v", entrustJson.Order.StopType) + applogger.Debug("修改缓存中的止盈:%v", entrustJson.Order.StopWinPrice) + applogger.Debug("修改缓存中的止损:%v", entrustJson.Order.StopLossPrice) + } + var data []byte + data, err = json.Marshal(&entrustJson) + if err != nil { + applogger.Error("%v UpdateBotForexStopByOrderId.Marshal:%v", common.ErrForex, err) + return false, flags.ErrCacheDB + } + if order.OrderId == entrustJson.OrderId { + if err = Reds.HSet(context.Background(), setting.MarketForexPosition, key, string(data)).Err(); err != nil { + applogger.Error("%v UpdateBotForexStopByOrderId.HSet:%v", common.ErrForex, err) + return false, flags.ErrCacheDB + } + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotForexStopByOrderId.Commit:%v", common.ErrForex, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotForexCancelByOrderId +// +// @Description: 外汇撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotForexCancelByOrderId(ctx context.Context, orderId string) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotForexCancelByOrderId.NewSession:%v", common.ErrForex, err) + return false, flags.ErrMySqlDB + } + + // get BotForexTrade + tread, err := uo.GetBotForexTradeByOrderId(session, orderId, flags.EntrustStatus) + if err != nil { + applogger.Error("%v UpdateBotForexCancelByOrderId.GetBotForexTradeByOrderId:%v", common.ErrForex, err) + return false, flags.ErrMySqlDB + } + var userId int64 + var earnestMoneyT, serviceCostT, symbol, orderNumber string + if tread != nil { + userId = int64(tread.UserId) + earnestMoneyT = tread.EarnestMoney + serviceCostT = tread.ServiceCost + orderNumber = tread.OrderNumber + symbol = tread.ContractId + } + + // get BotUserStock By USD + var usable, frozen, usableNo, frozenNo decimal.Decimal + usable, frozen, _, err = uo.GetBotUserForex(session, userId, flags.ForexUnit) + if err != nil { + applogger.Error("%v UpdateBotForexCancelByOrderId.GetBotUserForex:%v", common.ErrForex, err) + return false, flags.ErrMySqlDB + } + + // 检查用户订单撤单资产 + if frozen.IsNegative() || usable.IsNegative() { + return false, flags.ErrPublicFour + } + if !flags.CheckSetting { + applogger.Debug("用户原始可用资金:%v", usable) + applogger.Debug("用户原始冻结资金:%v", frozen) + } + + if symbol != flags.ForexUnit { + usableNo, frozenNo, _, err = uo.GetBotUserForex(session, userId, tread.ContractId) + if err != nil { + applogger.Error("%v UpdateBotForexCancelByOrderId.GetBotUserForex:%v", common.ErrForex, err) + return false, flags.ErrPublicFour + } + } + if !flags.CheckSetting { + applogger.Debug("用户原始可用非资金:%v", usableNo) + applogger.Debug("用户原始冻结非资金:%v", frozenNo) + } + + // 更新订单信息 + botStockTrade := orders.BotForexCancelByOrderId(ctx) + if err = uo.UpdateBotForexTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotForexCancelByOrderId.UpdateBotForexTradeByOrderId:%v", common.ErrForex, err) + return false, flags.ErrPublicFour + } + + // Operational Spot Asset Table + earnestMoney := decimal.RequireFromString(earnestMoneyT) // 保证金 + serviceCost := decimal.RequireFromString(serviceCostT) // 订单手续费 + totalMoney := earnestMoney.Add(serviceCost) // 订单总金额 + if !flags.CheckSetting { + applogger.Debug("撤单用户ID:%v", userId) + applogger.Debug("下单交易对:%v", symbol) + applogger.Debug("撤单订单保证金:%v", earnestMoneyT) + applogger.Debug("撤单手续费:%v", serviceCostT) + applogger.Debug("撤单订单数量:%v", orderNumber) + applogger.Debug("撤单总金额数量:%v", totalMoney) + } + + // Update total asset data + usableNew := usable.Add(totalMoney) // 用户总资产 + frozenNew := frozen.Sub(totalMoney) // 用户冻结资产 + usableNoNew := usableNo // 用户非可用资产 + frozenNoNew := frozenNo // 用户非冻结资产 + + // 检查用户订单撤单资产 + if frozenNew.IsNegative() { + return false, flags.ErrContractSeven + } + if !flags.CheckSetting { + applogger.Debug("用户撤单可用总资产:%v", usableNew) + applogger.Debug("用户撤单冻结总资产:%v", frozenNew) + applogger.Debug("用户非撤单可用总资产:%v", usableNoNew) + applogger.Debug("用户非撤单冻结总资产:%v", frozenNoNew) + } + + userForexUSDT := orders.UpdateBotUserForex(ctx, usableNew.String(), frozenNew.String()) + if err = uo.UpdateBotUserForex(session, userId, flags.ForexUnit, userForexUSDT); err != nil { + applogger.Error("%v UpdateBotForexCancelByOrderId.UpdateBotUserForex:%v", common.ErrForex, err) + return false, flags.ErrMySqlDB + } + + if symbol != flags.ForexUnit { + userForex := orders.UpdateBotUserForex(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = uo.UpdateBotUserForex(session, userId, tread.ContractId, userForex); err != nil { + applogger.Error("%v UpdateBotForexCancelByOrderId.UpdateBotUserForex:%v", common.ErrForex, err) + return false, flags.ErrMySqlDB + } + } + + // 清理挂单缓存信息 + if err = Reds.HDel(context.Background(), setting.MarketForexEntrust, orderId).Err(); err != nil { + applogger.Error("%v UpdateBotForexCancelByOrderId.HDel:%v", common.ErrForex, err) + return false, flags.ErrCacheDB + } + + // 撤单更新订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(setting.ForexSubscribe, userId) + if err = UpdateForexSubscribeHashStatusByOrderId(orderId, userSubKey, flags.Cancel, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotForexCancelByOrderId.ForexSubscribe:%v", common.ErrForex, err) + return false, flags.ErrCacheDB + } + + // 撤单更新管理员订阅缓存订单状态 + if err = UpdateForexSubscribeHashStatusByOrderId(orderId, setting.AdminForexSubscribe, flags.Cancel, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotForexCancelByOrderId.AdminForexSubscribe:%v", common.ErrForex, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotForexCancelByOrderId.Commit:%v", common.ErrForex, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotForexClosingByOrderId +// +// @Description: 外汇平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotForexClosingByOrderId(ctx context.Context, orderId string) (bool, error) { + // 1、订单信息 + entrust, err := Reds.HGet(context.Background(), setting.MarketForexPosition, orderId).Result() + if err != nil { + applogger.Error("%v UpdateBotForexClosingByOrderId.MarketForexPosition.HGet:%v", common.ErrForex, err) + return false, flags.ErrMySqlDB + } + + var entrustJson forexd.ForexTallyCache + if err = json.Unmarshal([]byte(entrust), &entrustJson); err != nil { + applogger.Error("%v UpdateBotForexClosingByOrderId.Unmarshal:%v", common.ErrForex, err) + return false, flags.ErrCacheDB + } + if !flags.CheckSetting { + applogger.Debug("手动平仓:%v", entrustJson) + } + + // 2、当前最新价格 + var openPrice string + //switch entrustJson.Order.TradeType { + //case 1: // 外汇交易对买一最新报价 + // subKey := publicData.SymbolCache(flags.Wh, entrustJson.Symbol, flags.TradeTypeBuy) + // openPrice, err = forexd.ForexSubMarketPrice(ctx, subKey) // 外汇交易对买一最新报价 + // if err != nil { + // return false, flags.ErrContractEight + // } + //case 2: // 外汇交易对卖一最新报价 + // subKey := publicData.SymbolCache(flags.Wh, entrustJson.Symbol, flags.TradeTypeSell) + // openPrice, err = forexd.ForexSubMarketPrice(ctx, subKey) // 外汇交易对卖一最新报价 + // if err != nil { + // return false, flags.ErrContractEight + // } + //default: + // return false, flags.ErrContractEight + //} + newPrice, err := GetForexPriceNew(entrustJson.Symbol, entrustJson.Order.TradeType) + if err != nil { + applogger.Warn("%v UpdateBotForexClosingByOrderId.GetForexPriceNew:%v", common.ErrForex, err) + return false, err + } + openPrice = newPrice.String() + + if err = Reds.HDel(context.Background(), setting.MarketForexPosition, orderId).Err(); err != nil { + applogger.Error("%v UpdateBotForexClosingByOrderId.MarketForexPosition.HDel:%v", common.ErrForex, err) + return false, flags.ErrCacheDB + } + + // 3、平仓处理 + if err = ForexClosingPosition(ctx, uo.data.mysqlDB, orderId, openPrice, entrustJson.Order); err != nil { + applogger.Error("%v UpdateBotForexClosingByOrderId.ForexClosingPosition:%v", common.ErrForex, err) + return false, flags.ErrCacheDB + } + + // 4、平仓更新订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(setting.ForexSubscribe, entrustJson.UserId) + if err = UpdateForexSubscribeHashStatusByOrderId(orderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotForexClosingByOrderId.ForexSubscribe:%v", common.ErrForex, err) + return false, flags.ErrCacheDB + } + + // 5、平仓更新管理员订阅缓存订单状态 + if err = UpdateForexSubscribeHashStatusByOrderId(orderId, setting.AdminForexSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotForexCancelByOrderId.AdminForexSubscribe:%v", common.ErrForex, err) + return false, flags.ErrCacheDB + } + + return true, nil +} + +// UpdateBotForexClosingAllByOrderId +// +// @Description: 外汇一键平仓 +// @receiver uo +// @param ctx +// @param userId +// @return error +func (uo *userOrderRepo) UpdateBotForexClosingAllByOrderId(ctx context.Context, userId int64) error { + // 1、查询当前用户所有订单 + orderMap, err := uo.GetBotForexTradeByUserId(userId) + if err != nil { + applogger.Error("%v UpdateBotForexClosingAllByOrderId.GetBotForexTradeByUserId:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + + // 2、查询持仓缓存列表数据-1>清理持仓列表缓存 2>处理平仓数据 3>清理订单ID缓存列表 + for _, value := range orderMap { + var entrust string + entrust, err = Reds.HGet(context.Background(), setting.MarketForexPosition, value).Result() + if err != nil { + applogger.Error("%v UpdateBotForexClosingAllByOrderId.MarketForexPosition.LRange:%v", common.ErrForex, err) + return flags.ErrCacheDB + } + var entrustJson forexd.ForexTallyCache + if err = json.Unmarshal([]byte(entrust), &entrustJson); err != nil { + applogger.Error("%v UpdateBotForexClosingAllByOrderId.Unmarshal:%v", common.ErrForex, err) + return flags.ErrCacheDB + } + + // 获取当前外汇交易对买一卖一最新报价 + var openPrice string + //switch entrustJson.Order.TradeType { + //case 1: // 外汇交易对买一最新报价 + // subKey := publicData.SymbolCache(flags.Wh, entrustJson.Symbol, flags.TradeTypeBuy) + // openPrice, err = forexd.ForexSubMarketPrice(ctx, subKey) // 外汇交易对买一最新报价 + // if err != nil { + // return flags.ErrContractEight + // } + //case 2: // 外汇交易对卖一最新报价 + // subKey := publicData.SymbolCache(flags.Wh, entrustJson.Symbol, flags.TradeTypeSell) + // openPrice, err = forexd.ForexSubMarketPrice(ctx, subKey) // 外汇交易对卖一最新报价 + // if err != nil { + // return flags.ErrContractEight + // } + //default: + // return flags.ErrContractEight + //} + newPrice, err := GetForexPriceNew(entrustJson.Symbol, entrustJson.Order.TradeType) + if err != nil { + applogger.Warn("%v UpdateBotForexClosingAllByOrderId.GetForexPriceNew:%v", common.ErrForex, err) + return flags.ErrCacheDB + } + openPrice = newPrice.String() + + // 清理持仓缓存列表 + if err = Reds.HDel(context.Background(), setting.MarketForexPosition, value).Err(); err != nil { + applogger.Error("%v UpdateBotForexClosingAllByOrderId.MarketForexPosition.HDel:%v", common.ErrForex, err) + return flags.ErrCacheDB + } + + // 平仓 + if err = ForexClosingPosition(ctx, uo.data.mysqlDB, entrustJson.OrderId, openPrice, entrustJson.Order); err != nil { + applogger.Error("%v UpdateBotForexClosingAllByOrderId.ForexClosingPosition:%v", common.ErrForex, err) + return err + } + + // 平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ForexSubscribe, entrustJson.UserId) + if err = UpdateForexSubscribeHashStatusByOrderId(entrustJson.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotForexClosingAllByOrderId.ForexSubscribe:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + + // 平仓更新管理员订阅订单状态 + if err = UpdateForexSubscribeHashStatusByOrderId(entrustJson.OrderId, setting.AdminForexSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotForexCancelByOrderId.AdminForexSubscribe:%v", common.ErrForex, err) + return flags.ErrMySqlDB + } + } + + return nil +} + +// GetBotForexTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param status +// @return *models.BotForexTrade +// @return error +func (uo *userOrderRepo) GetBotForexTradeByOrderId(session *xorm.Session, orderId string, status int) (*models.BotForexTrade, error) { + var botForexTrade []models.BotForexTrade + if err := session.Table(flags.BotForexTrade). + Where("order_id = ?", orderId). + Where("`status` = ?", status). + Find(&botForexTrade); err != nil { + return nil, err + } + + for _, value := range botForexTrade { + return &value, nil + } + + return nil, nil +} + +// GetBotForexTradeByUserId +// +// @Description: +// @receiver uo +// @param ctx +// @param userId +// @return map[string]string +// @return error +func (uo *userOrderRepo) GetBotForexTradeByUserId(userId int64) (map[string]string, error) { + var botForexTrade []models.BotForexTrade + if err := uo.data.mysqlDB.Table(flags.BotForexTrade). + Where("user_id = ? ", userId). + Where("status = 1"). + Find(&botForexTrade); err != nil { + return nil, err + } + + botMap := make(map[string]string) + for _, value := range botForexTrade { + botMap[value.OrderId] = value.OrderId + } + + return botMap, nil +} + +// GetBotUserForex +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param symbol +// @return decimal.Decimal +// @return decimal.Decimal +// @return int +// @return error +func (uo *userOrderRepo) GetBotUserForex(session *xorm.Session, userId int64, symbol string) (decimal.Decimal, decimal.Decimal, int, error) { + var contractUSDT []models.BotUserForex + if err := session.Table(flags.BotUserForex). + Where("user_id = ?", userId). + Where("contract_id = ?", strings.ToUpper(symbol)). + Find(&contractUSDT); err != nil { + return decimal.Zero, decimal.Zero, 0, err + } + + var usableNum, frozenNum decimal.Decimal + for _, value := range contractUSDT { + usableNum = decimal.RequireFromString(value.UsableNum) // 资产可用余额 + frozenNum = decimal.RequireFromString(value.FrozenNum) // 资产冻结数量 + } + + return usableNum, frozenNum, len(contractUSDT), nil +} + +// ForexVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) ForexVoteDealType(order structure.ForexOrder) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + return limitOrMarketPrice, nil +} + +// UpdateForexVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) UpdateForexVoteDealType(order *models.BotForexTrade) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + if len(order.DealPrice) != 0 { + dealPrice := decimal.RequireFromString(order.DealPrice) + if !dealPrice.IsZero() { + limitOrMarketPrice = dealPrice + } + } + + return limitOrMarketPrice, nil +} + +// UpdateForexVoteStopType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) UpdateForexVoteStopType(order structure.StopOrder) (bool, decimal.Decimal, decimal.Decimal, error) { + var checkBool bool + var stopWinPrice, stopLossPrice decimal.Decimal + switch order.StopType { + case flags.StopTypeNone: // 暂无设置止盈止损 + checkBool = false + case flags.StopTypeSet: // 设置止盈止损 + if len(order.StopWinPrice) != 0 { + stopWinPrice = decimal.RequireFromString(order.StopWinPrice) + } + if len(order.StopLossPrice) != 0 { + stopLossPrice = decimal.RequireFromString(order.StopLossPrice) + } + // 判定设置是否都为零 + if stopWinPrice.IsZero() && stopLossPrice.IsZero() { + return checkBool, decimal.Decimal{}, decimal.Decimal{}, flags.ErrContractTen + } else { + checkBool = true + } + default: + return checkBool, stopWinPrice, stopLossPrice, flags.ErrContractEleven + } + + return checkBool, stopWinPrice, stopLossPrice, nil +} + +// ForexVoteTradeType +// +// @Description: 股票判定止盈止损配置 +// @receiver uo +// @param ctx +// @param tradeType +// @param stopWinPrice +// @param stopLossPrice +// @param price +// @param checkBool +// @return error +func (uo *userOrderRepo) ForexVoteTradeType(tradeType int64, stopWinPrice, stopLossPrice, price decimal.Decimal, checkBool bool) error { + if checkBool { + switch tradeType { + case flags.TradeTypeBuy: // 买涨 + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(price) <= 0 { + // 限价买涨下单,止盈价格必须大于限价 + return flags.ErrBuyStopWinPrice + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(price) >= 0 { + // 限价买涨下单,止损价格必须小于限价 + return flags.ErrBuyStopLossPrice + } + } + case flags.TradeTypeSell: // 买跌 + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(price) >= 0 { + // 限价买跌下单,止盈价格必须小于限价 + return flags.ErrSellStopWinPrice + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(price) <= 0 { + // 限价买跌下单,止损价格必须大于限价 + return flags.ErrSellStopLossPrice + } + } + default: + return flags.ErrContractTwelve + } + } + + return nil +} + +// CreatBotUserForex +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param digital +// @return error +func (uo *userOrderRepo) CreatBotUserForex(session *xorm.Session, digital models.BotUserForex) error { + _, err := session.Table(flags.BotUserForex).Insert(&digital) + if err != nil { + return err + } + + return nil +} + +// CreatBotForexTrade +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param trade +// @return error +func (uo *userOrderRepo) CreatBotForexTrade(session *xorm.Session, trade models.BotForexTrade) error { + _, err := session.Table(flags.BotForexTrade).Insert(&trade) + if err != nil { + return err + } + + return nil +} + +// UpdateBotForexTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param trade +// @return error +func (uo *userOrderRepo) UpdateBotForexTradeByOrderId(session *xorm.Session, orderId string, trade models.BotForexTrade) error { + _, err := session.Table(flags.BotForexTrade). + Where("order_id = ?", orderId). + Update(&trade) + if err != nil { + return err + } + + return nil +} + +// UpdateBotUserForex +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param symbol +// @param userForex +// @return error +func (uo *userOrderRepo) UpdateBotUserForex(session *xorm.Session, userId int64, symbol string, userForex models.BotUserForex) error { + _, err := session.Table(flags.BotUserForex). + Where("user_id = ?", userId). + Where("contract_id = ?", symbol). + Update(&userForex) + if err != nil { + return err + } + + return nil +} + +// VerifyBotForexTradeOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @return string +// @return error +func (uo *userOrderRepo) VerifyBotForexTradeOrderId(session *xorm.Session) (string, error) { + var orderId string + for { + orderId = orders.CreateRandCodeOrder(10) + + var orderList []models.BotForexTrade + err := session.Table(flags.BotForexTrade).Where("order_id = ?", orderId).Find(&orderList) + if err != nil || len(orderList) > 0 { + applogger.Error("%v VerifyBotForexTradeOrderId.Find:%v", common.ErrForex, err) + continue + } + + break + } + + return orderId, nil +} diff --git a/internal/data/order_money.go b/internal/data/order_money.go new file mode 100644 index 0000000..1665da2 --- /dev/null +++ b/internal/data/order_money.go @@ -0,0 +1,1826 @@ +package data + +import ( + "context" + "encoding/json" + "github.com/go-xorm/xorm" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "strconv" + "strings" + + orders "matchmaking-system/internal/data/convert" + Moneyd "matchmaking-system/internal/data/tradedeal/money" + models "matchmaking-system/internal/pkg/model" +) + +// GetBotMoneyTradeList +// +// @Description: 综合(现货|合约|外汇)订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param userId +// @param status +// @return []*models.BotMoneyTrade +// @return int64 +// @return error +func (uo *userOrderRepo) GetBotMoneyTradeList(ctx context.Context, pageSize, pageCount, userId, status, marketType int64) ([]*models.BotMoneyTrade, int64, error) { + var totalCount int64 + var err error + if marketType == 0 { + totalCount, err = uo.data.mysqlDB.Table(flags.BotMoneyTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Count() + } else { + totalCount, err = uo.data.mysqlDB.Table(flags.BotMoneyTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Where("market_type = ?", marketType). + Count() + } + if err != nil { + return nil, 0, flags.ErrMySqlDB + } + + if totalCount == 0 { + return nil, 0, nil + } + + var contractList []*models.BotMoneyTrade + if marketType == 0 { + err = uo.data.mysqlDB.Table(flags.BotMoneyTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Limit(int(pageSize), int(pageCount)). + Desc(GetOrderByStatusSort(status)). + Find(&contractList) + } else { + err = uo.data.mysqlDB.Table(flags.BotMoneyTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Where("market_type = ?", marketType). + Limit(int(pageSize), int(pageCount)). + Desc(GetOrderByStatusSort(status)). + Find(&contractList) + } + if err != nil { + return nil, 0, flags.ErrMySqlDB + } + + var contractUpdateList []*models.BotMoneyTrade + for _, value := range contractList { + switch value.MarketType { + case flags.SpotsMarketType: // 现货 + value.KeepDecimal = GetKeepDecimal(flags.SpotsSystemSetUpKey, value.StockId) + case flags.ContractMarketType: // 合约 + value.KeepDecimal = GetKeepDecimal(flags.ContractSystemSetUpKey, value.StockId) + case flags.ForexMarketType: // 综合(现货|合约|外汇) + value.KeepDecimal = GetKeepDecimal(flags.ForexSystemSetUpKey, value.StockId) + default: + continue + } + contractUpdateList = append(contractUpdateList, value) + } + + return contractUpdateList, totalCount, nil +} + +// CreateBotMoneyTrade +// +// @Description: 综合(现货|合约|外汇)下单 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) CreateBotMoneyTrade(ctx context.Context, userId int64, order structure.MoneyOrder) (string, error) { + // 1、综合(现货|合约|外汇)下单订阅 + var err error + var system *structure.ForexSystem + stockId := strings.ToUpper(order.StockId) + switch order.Type { + case flags.SpotsMarketType: // 现货 + _, ok := moneyZh.MoneySpotsMapSymbol.Load(strings.ToLower(stockId)) + if ok { + go func() { + moneyZh.MoneySpotsMap <- []byte(stockId) + }() + } + system = &structure.ForexSystem{ + MinPry: decimal.RequireFromString("1"), + MaxPry: decimal.RequireFromString("1"), + FaceValue: decimal.RequireFromString("1"), + CompelNum: decimal.RequireFromString("1"), + } + order.System = system + case flags.ContractMarketType: // 合约 + _, ok := moneyZh.MoneyContractMapSymbol.Load(stockId) + if ok { + go func() { + moneyZh.MoneyContractMap <- []byte(stockId) + }() + } + systemContract, err := GetContractSystemSetUp(stockId) + if err != nil || systemContract == nil { + return flags.SetNull, flags.ErrContractOne + } + system = &structure.ForexSystem{ + MinPry: systemContract.MinPry, + MaxPry: systemContract.MaxPry, + FaceValue: systemContract.FaceValue, + CompelNum: systemContract.CompelNum, + } + order.System = system + case flags.ForexMarketType: // 外汇 + _, ok := moneyZh.MoneyForexMapSymbol.Load(stockId) + if ok { + go func() { + moneyZh.MoneyForexMap <- []byte(stockId) + }() + } + system, err = GetForexSystemSetUp(stockId) + if err != nil || system == nil { + return flags.SetNull, flags.ErrContractOne + } + order.System = system + default: + return flags.SetNull, flags.ErrShareTen + } + + // 2、下单判定设置(false无设置|true止盈止损) + checkBool, stopWinPrice, stopLossPrice, err := MoneyVoteStopType(order) + if err != nil { + applogger.Error("%v CreateBotMoneyTrade.MoneyVoteStopType:%v", common.ErrMoney, err) + return flags.SetNull, err + } + + // 3、下单判定设置(限价|市价) + limitOrMarketPrice, err := uo.MoneyVoteDealType(order) + if err != nil { + applogger.Error("%v CreateBotMoneyTrade.MoneyVoteDealType:%v", common.ErrMoney, err) + return flags.SetNull, err + } + + // 4、下单判定设置(买涨|买跌) + if err = uo.MoneyVoteTradeType(order.TradeType, stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v CreateBotMoneyTrade.MoneyVoteTradeType:%v", common.ErrMoney, err) + return flags.SetNull, err + } + + // 5、综合(现货|合约|外汇)下单(订单信息|资产信息) + var orderId string + if order.Type == flags.SpotsMarketType { + orderId, err = uo.MoneyOrdersDealDB(ctx, userId, order) + if err != nil || len(orderId) == 0 { + applogger.Error("%v CreateBotMoneyTrade.MoneyOrdersDealDB:%v", common.ErrMoney, err) + return flags.SetNull, err + } + } else { + orderId, err = uo.MoneyOrdersWriteDB(ctx, userId, order) + if err != nil || len(orderId) == 0 { + applogger.Error("%v CreateBotMoneyTrade.MoneyOrdersWriteDB:%v", common.ErrMoney, err) + return flags.SetNull, err + } + } + + // 6、写入缓存列表(挂单缓存|持仓缓存),等待撮合计算 + marketStatus, tallyCache, err := Moneyd.MoneyCacheDeal(ctx, userId, orderId, limitOrMarketPrice.String(), order) + if err != nil || tallyCache == nil { + applogger.Error("%v CreateBotMoneyTrade.MoneyCacheDeal:%v", common.ErrMoney, err) + return flags.SetNull, err + } + + // 7、综合(现货|合约|外汇)市价单处理 + switch marketStatus { + case setting.MarketMoneyClose: // TODO:现货市价平仓 + if _, err = MoneyOrdersClosingDB(context.Background(), uo.data.mysqlDB, tallyCache.UserId, order, orderId, limitOrMarketPrice.String()); err != nil { + return flags.SetNull, err + } + default: + // 8、(合约|外汇)市价下单(开仓|平仓)处理(订单信息|资产信息|手续费|返佣|资产详情记录) + if marketStatus == setting.MarketMoneyPosition { + if err = MoneyOpenPosition(ctx, uo.data.mysqlDB, userId, orderId, tallyCache.OpenPrice, order); err != nil { + applogger.Error("%v CreateBotMoneyTrade.MoneyOpenPosition:%v", common.ErrMoney, err) + return flags.SetNull, err + } + } + // 9、写入(挂单|持仓)缓存列表 + if err = Moneyd.MoneyPushAddCache(Reds, marketStatus, tallyCache); err != nil { + applogger.Error("%v CreateBotMoneyTrade.MoneyPushAddCache:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrCacheDB + } + // TODO: 10、现货不参与用户订单缓存和管理员订单订阅缓存 + if order.Type != flags.SpotsMarketType { + // 11、写入用户订单订阅缓存列表 + orderIdKey := virtual.OrderIdListKey(setting.MoneySubscribe, userId) + if err = Moneyd.MoneyHashSetOrderId(Reds, orderIdKey, tallyCache); err != nil { + applogger.Error("%v CreateBotMoneyTrade.MoneyPushAddOrder:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 12、写入管理员订单订阅缓存列表 + if err = Moneyd.MoneyHashSetOrderId(Reds, setting.AdminMoneySubscribe, tallyCache); err != nil { + applogger.Error("%v CreateBotMoneyTrade.MoneyHashSetOrderId:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrCacheDB + } + } + } + + return orderId, nil +} + +// MoneyOrdersWriteDB +// +// @Description: 综合(现货|合约|外汇)下单处理 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) MoneyOrdersWriteDB(ctx context.Context, userId int64, order structure.MoneyOrder) (string, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v MoneyOrdersWriteDB.NewSession:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + usable, frozen, _, err = uo.GetBotUserMoney(session, userId, flags.MoneyUnit) + if err != nil { + applogger.Error("%v MoneyOrdersWriteDB.GetBotUserMoney:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 检查用户订单下单资产 + if usable.IsZero() || usable.IsNegative() || frozen.IsNegative() { + return flags.SetNull, flags.ErrPublicOne + } + + // 查询当前下单用户可用非账户和冻结金额 + var checkCount int + if order.StockId != flags.MoneyUnit { + usableNo, frozenNo, checkCount, err = uo.GetBotUserMoney(session, userId, order.StockId) + if err != nil { + applogger.Error("%v MoneyOrdersWriteDB.GetBotUserMoney.Fei:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("非下单可用金额:%v", usableNo) + applogger.Debug("非下单冻结金额:%v", frozenNo) + } + // 写入订单信息 + orderId, err := uo.VerifyBotMoneyTradeOrderId(session) + if err != nil { + applogger.Error("%v MoneyOrdersWriteDB.VerifyBotMoneyTradeOrderId:%v", common.ErrMoney, err) + return flags.SetNull, err + } + if !flags.CheckSetting { + applogger.Debug("下单Id:%v", orderId) + applogger.Debug("下单杠杆:%v", order.PryNum) + } + + // 写入订单表 + botMoneyTrade := orders.BotMoneyTrade(ctx, userId, orderId, order) + if err = uo.CreatBotMoneyTrade(session, botMoneyTrade); err != nil { + applogger.Error("%v MoneyOrdersWriteDB.CreatBotMoneyTrade:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 订单总金额 = 保证金 + 手续费 + earnestMoney := decimal.RequireFromString(order.EarnestMoney) // 保证金 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 手续费 + totalMoney := earnestMoney.Add(serviceCost) + + // 总金额下单判定 + if usable.Cmp(totalMoney) < 0 { + return flags.SetNull, flags.ErrPublicOne + } + + // (买涨|买跌)处理 + var usableNew, frozenNew, usableNewNo, frozenNewNo decimal.Decimal + usableNew = usable.Sub(totalMoney) // 可用资产 + frozenNew = frozen.Add(totalMoney) // 冻结资产 + if order.StockId != flags.MoneyUnit { + usableNewNo = usableNo // 可用非资产 + frozenNewNo = frozenNo // 冻结非资产 + } + + // 检查用户订单下单资产 + if usableNew.IsNegative() || usableNew.IsZero() { + return flags.SetNull, flags.ErrPublicTow + } + if !flags.CheckSetting { + applogger.Debug("下单后用户可用资产:%v", usableNew) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + applogger.Debug("下单后用户非可用资产:%v", usableNewNo) + applogger.Debug("下单后用户非冻结资产:%v", frozenNewNo) + } + + // 更新用户资产信息 + userMoneyUSDT := orders.UpdateBotUserMoney(ctx, usableNew.String(), frozenNew.String()) + if err = uo.UpdateBotUserMoney(session, userId, flags.MoneyUnit, userMoneyUSDT); err != nil { + applogger.Error("%v MoneyOrdersWriteDB.UpdateBotUserMoney:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 更新非资产信息 + if order.StockId != flags.MoneyUnit { + if checkCount == 0 { + userMoneySymbol := orders.CreatBotUserMoney(ctx, userId, usableNewNo.String(), frozenNewNo.String(), order) + err = uo.CreatBotUserMoney(session, userMoneySymbol) + if err != nil { + applogger.Error("%v MoneyOrdersWriteDB.CreatBotUserMoney:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + userMoney := orders.UpdateBotUserMoney(ctx, usableNewNo.String(), frozenNewNo.String()) + if err = uo.UpdateBotUserMoney(session, userId, order.StockId, userMoney); err != nil { + applogger.Error("%v MoneyOrdersWriteDB.UpdateBotUserMoney:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v MoneyOrdersWriteDB.Commit:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + + return orderId, nil +} + +// MoneyOpenPosition +// +// @Description: 综合(现货|合约|外汇)开仓处理 +// @param ctx +// @param db +// @param userId +// @param orderId +// @param openPrice +// @param order +// @return error +func MoneyOpenPosition(ctx context.Context, db *xorm.EngineGroup, userId int64, orderId, openPrice string, order structure.MoneyOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v MoneyOpenPosition.NewSession:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + usable, frozen, _, err = Uo.GetBotUserMoney(session, userId, flags.MoneyUnit) + if err != nil { + applogger.Error("%v MoneyOpenPosition.GetBotUserMoney:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单开仓价格:%v", openPrice) + } + + if order.StockId != flags.MoneyUnit { + usableNo, frozenNo, _, err = Uo.GetBotUserMoney(session, userId, order.StockId) + if err != nil { + applogger.Error("%v MoneyOpenPosition.GetBotUserMoney:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + } + + earnestMoney := decimal.RequireFromString(order.EarnestMoney) // 下单保证金 + openOrderNumber := decimal.RequireFromString(order.OrderNumber) // 下单仓位 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 下单手续费 + totalMoney := earnestMoney.Add(serviceCost) // 下单总金额 = (订单手续费 + 保证金) + openOrderPrice := decimal.RequireFromString(openPrice) // 开仓价格(下单金额) + if !flags.CheckSetting { + applogger.Debug("下单订单杠杆:%v", order.PryNum) + applogger.Debug("下单保证金:%v", order.EarnestMoney) + applogger.Debug("下单订单数量:%v", order.OrderNumber) + applogger.Debug("下单订单手续费:%v", order.ServiceCost) + } + // 手续费记录 + var cost string + openPriceNew := openOrderPrice.Mul(openOrderNumber).String() // 开仓手续费 = 开仓价格 * 仓位数 * 手续费比例 + switch order.Type { + case flags.SpotsMarketType: // 现货 + cost, err = Uo.CalculateHandlingFees(ctx, session, int(userId), flags.SpotsMarketType, flags.OpenBrokType, orderId, openPriceNew, "1") + if err != nil { + applogger.Error("%v MoneyOpenPosition.CalculateHandlingFees:%v", common.ErrMoney, err) + return err + } + case flags.ContractMarketType: // 合约 + cost, err = Uo.CalculateHandlingFees(ctx, session, int(userId), flags.ContractMarketType, flags.OpenBrokType, orderId, openPriceNew, "1") + if err != nil { + applogger.Error("%v MoneyOpenPosition.CalculateHandlingFees:%v", common.ErrMoney, err) + return err + } + case flags.ForexMarketType: // 外汇 + cost, err = Uo.CalculateHandlingFees(ctx, session, int(userId), flags.ForexMarketType, flags.OpenBrokType, orderId, openPriceNew, "1") + if err != nil { + applogger.Error("%v MoneyOpenPosition.CalculateHandlingFees:%v", common.ErrMoney, err) + return err + } + } + openServiceCost := decimal.RequireFromString(cost) // 开仓手续费 + openTotalMoney := earnestMoney.Add(openServiceCost) // 开仓总金额 = (保证金 + 开仓手续费) + floatPrice := totalMoney.Sub(openTotalMoney) // 计算容差 = 下单总额 - 开仓总额 + if !flags.CheckSetting { + applogger.Debug("开仓订单价格:%v", openOrderPrice) + applogger.Debug("开仓仓位:%v", openOrderNumber) + applogger.Debug("开仓手续费:%v", openServiceCost) + applogger.Debug("开仓总金额:%v", openTotalMoney) + applogger.Debug("下单开仓总金额容差值:%v", floatPrice) + } + + usableNew := usable.Add(floatPrice) // 可用资产(处理容差值) + frozenNew := frozen.Sub(totalMoney).Add(earnestMoney) // 冻结资产 = 冻结资产 - 下单冻结资产 + 开仓保证金 + usableNoNew := usableNo.Add(openOrderNumber) // 非可用资产 + frozenNoNew := frozenNo // 非冻结资产 + if !flags.CheckSetting { + applogger.Debug("下单后用户可用资产:%v", usableNew) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + applogger.Debug("下单冻结资产:%v", frozen) + applogger.Debug("下单后的冻结总资产:%v", totalMoney) + applogger.Debug("开仓后的保证金:%v", earnestMoney) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + applogger.Debug("下单后用户可用资产:%v", usableNew) + } + + // 处理资产信息 + userMoneyUSDT := orders.UpdateBotUserMoney(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserMoney(session, userId, flags.MoneyUnit, userMoneyUSDT); err != nil { + applogger.Error("%v MoneyOpenPosition.UpdateBotUserMoney:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + + // 更新非资产信息 + if order.StockId != flags.MoneyUnit { + userMoney := orders.UpdateBotUserMoney(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = Uo.UpdateBotUserMoney(session, userId, order.StockId, userMoney); err != nil { + applogger.Error("%v MoneyOpenPosition.UpdateBotUserMoney:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + } + + // 处理订单信息(成交价|仓位|开仓时间|订单总金额|手续费|持仓状态) + trade := orders.UpdateOpenBotMoneyTrade(ctx, openPrice, openOrderNumber.String(), openTotalMoney.String(), openServiceCost.String()) + if err = Uo.UpdateBotMoneyTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v MoneyOpenPosition.UpdateBotMoneyTradeByOrderId:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + + // 返佣记录|资金信息|资金详情信息 + switch order.Type { + case flags.SpotsMarketType: // 现货 + if err = Uo.MoneyRebateCalculation(ctx, session, int(userId), flags.SpotsMarketType, flags.OpenBrokType, flags.OpenMRebate, cost, orderId); err != nil { + applogger.Error("%v MoneyOpenPosition.MoneyRebateCalculation:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + case flags.ContractMarketType: // 合约 + if err = Uo.MoneyRebateCalculation(ctx, session, int(userId), flags.ContractMarketType, flags.OpenBrokType, flags.OpenMRebate, cost, orderId); err != nil { + applogger.Error("%v MoneyOpenPosition.MoneyRebateCalculation:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + case flags.ForexMarketType: // 外汇 + if err = Uo.MoneyRebateCalculation(ctx, session, int(userId), flags.ForexMarketType, flags.OpenBrokType, flags.OpenMRebate, cost, orderId); err != nil { + applogger.Error("%v MoneyOpenPosition.MoneyRebateCalculation:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + default: + } + + // 更改交易日志记录方式 + var list []models.BotUserMoneyLog + qData0 := orders.CreatBotUserMoneyLog(ctx, userId, flags.CostMoney, flags.MoneyUnit, NegativeValue(openServiceCost.String()), orderId) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserMoneyLog(ctx, userId, flags.Freeze, flags.MoneyUnit, NegativeValue(earnestMoney.String()), orderId) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserMoneyLog(ctx, userId, flags.ChangeInto, order.StockId, openOrderNumber.String(), orderId) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserMoneyLogList(session, list); err != nil { + applogger.Error("%v MoneyOpenPosition.CreatBotUserMoneyLogList:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v MoneyOpenPosition.Commit:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + + return nil +} + +// MoneyClosingPosition +// +// @Description: 综合(现货|合约|外汇)平仓处理 +// @param ctx +// @param db +// @param orderId +// @param price +// @param order +// @return error +func MoneyClosingPosition(ctx context.Context, db *xorm.EngineGroup, orderId string, price string, order structure.MoneyOrder, status int) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v MoneyClosingPosition.NewSession:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + + // TODO: 处理状态 + var closeStatus int + switch order.Type { + case flags.SpotsMarketType: + closeStatus = flags.EntrustStatus + default: + closeStatus = flags.PositionStatus + } + + // 查询订单信息 + tread, err := Uo.GetBotMoneyTradeByOrderId(session, orderId, closeStatus) + if err != nil { + applogger.Error("%v MoneyClosingPosition.GetBotMoneyTradeByOrderId:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + var userId int64 + var dealPrice, earnestMoney, orderNumber, totalAmount, serviceCost, pryNum decimal.Decimal + if tread != nil { + userId = int64(tread.UserId) // 用户Id + earnestMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓保证金 + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + pryNum = decimal.RequireFromString(strconv.Itoa(tread.PryNum)) // 杠杆 + } + if !flags.CheckSetting { + applogger.Debug("下单开仓用户Id:%v", userId) + applogger.Debug("下单开仓开仓价格:%v", dealPrice) + applogger.Debug("下单开仓保证金:%v", earnestMoney) + applogger.Debug("下单开仓订单数量:%v", orderNumber) + applogger.Debug("下单开仓总金额:%v", totalAmount) + applogger.Debug("下单开仓手续费:%v", serviceCost) + applogger.Debug("下单开仓杠杆:%v", pryNum) + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + usable, frozen, _, err = Uo.GetBotUserMoney(session, userId, flags.MoneyUnit) + if err != nil { + applogger.Error("%v MoneyClosingPosition.GetBotUserMoney:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + } + + // 查询当前下单用户可用非账户和冻结金额 + if order.StockId != flags.MoneyUnit { + usableNo, frozenNo, _, err = Uo.GetBotUserMoney(session, userId, order.StockId) + if err != nil { + applogger.Error("%vMoneyClosingPosition.GetBotUserMoney:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + } + if !flags.CheckSetting { + applogger.Debug("非下单可用金额:%v", usableNo) + applogger.Debug("非下单冻结金额:%v", frozenNo) + } + + // TODO: 平仓手续费处理 + var cost string + closeFaceValue := order.System.FaceValue // 面值 + closePrice := decimal.RequireFromString(price) // 平仓价格 + cloePriceCost := closePrice.Mul(orderNumber).String() // 平仓手续费 = 平仓价格 * 仓位数 * 手续费比例 * 面值 + switch order.Type { + case flags.SpotsMarketType: // 现货 + cost, err = Uo.CalculateHandlingFees(ctx, session, int(userId), flags.SpotsMarketType, flags.ClosingBrokType, orderId, cloePriceCost, closeFaceValue.String()) + if err != nil { + applogger.Error("%v MoneyClosingPosition.CalculateHandlingFees:%v", common.ErrMoney, err) + return err + } + case flags.ContractMarketType: // 合约 + cost, err = Uo.CalculateHandlingFees(ctx, session, int(userId), flags.ContractMarketType, flags.ClosingBrokType, orderId, cloePriceCost, closeFaceValue.String()) + if err != nil { + applogger.Error("%v MoneyClosingPosition.CalculateHandlingFees:%v", common.ErrMoney, err) + return err + } + case flags.ForexMarketType: // 外汇 + cost, err = Uo.CalculateHandlingFees(ctx, session, int(userId), flags.ForexMarketType, flags.ClosingBrokType, orderId, cloePriceCost, closeFaceValue.String()) + if err != nil { + applogger.Error("%v MoneyClosingPosition.CalculateHandlingFees:%v", common.ErrMoney, err) + return err + } + } + closeServiceCost := decimal.RequireFromString(cost) + if !flags.CheckSetting { + applogger.Debug("平仓价格:%v", closePrice) + applogger.Debug("平仓手续费手续费:%v", closeServiceCost) + } + + //已经实现盈亏计算公式(已平仓结算方式) + //买涨 已经实现盈亏 = (平仓成交价-开仓成交价)*手数*杠杆 + //买跌 已经实现盈亏 = (开仓成交价-平仓成交价)*手数*杠杆 + var usableNew, frozenNew, usableNewNo, frozenNewNo, subPrice, resultPrice decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买涨 + subPrice = closePrice.Sub(dealPrice) + resultPrice = subPrice.Mul(orderNumber).Mul(closeFaceValue).Mul(pryNum) + case flags.TradeTypeSell: // 买跌 + subPrice = dealPrice.Sub(closePrice) + resultPrice = subPrice.Mul(orderNumber).Mul(closeFaceValue).Mul(pryNum) + default: + } + + // 用户资产账户 + usableNew = usable.Add(resultPrice).Add(earnestMoney).Sub(closeServiceCost) // 可用资产 = 原可用资产 + ((正负)盈亏*面值) + 保证金 - 手续费 + frozenNew = frozen.Sub(earnestMoney) // 冻结资产 + // 用户非资产账户 + if order.StockId != flags.MoneyUnit { + usableNewNo = usableNo.Sub(orderNumber) // 可用非资产 = 原可用非资产 - 下单仓位数 + frozenNewNo = frozenNo // 可用非冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("可用资产:%v", usableNew) + applogger.Debug("冻结资产:%v", frozenNew) + applogger.Debug("可用非资产:%v", usableNewNo) + applogger.Debug("冻结非资产:%v", frozenNewNo) + } + + // 平仓(处理资产表(资产)) + userMoneyUSDT := orders.UpdateBotUserMoney(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserMoney(session, userId, flags.MoneyUnit, userMoneyUSDT); err != nil { + applogger.Error("%v MoneyClosingPosition.UpdateBotUserMoney:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + + // 平仓(处理资产表(非资产)) + if order.StockId != flags.MoneyUnit { + userMoney := orders.UpdateBotUserMoney(ctx, usableNewNo.String(), frozenNewNo.String()) + if err = Uo.UpdateBotUserMoney(session, userId, order.StockId, userMoney); err != nil { + applogger.Error("%v MoneyClosingPosition.UpdateBotUserMoney:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + } + + // 平仓(处理订单信息(平仓价|保证金|平仓|订单总金额|平仓手续费|完成订单)) + trade := orders.UpdateCloseBotMoneyTrade(ctx, price, earnestMoney.String(), totalAmount.String(), cost, status) + if err = Uo.UpdateBotMoneyTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v MoneyClosingPosition.UpdateBotMoneyTradeByOrderId:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + + // TODO: 平仓(返佣记录表|资产表|资金变动表) + switch order.Type { + case flags.SpotsMarketType: // 现货 + if err = Uo.MoneyRebateCalculation(ctx, session, int(userId), flags.SpotsMarketType, flags.ClosingBrokType, flags.CloseMRebate, cost, orderId); err != nil { + applogger.Error("%v MoneyClosingPosition.MoneyRebateCalculation:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + case flags.ContractMarketType: // 合约 + if err = Uo.MoneyRebateCalculation(ctx, session, int(userId), flags.ContractMarketType, flags.ClosingBrokType, flags.CloseMRebate, cost, orderId); err != nil { + applogger.Error("%v MoneyClosingPosition.MoneyRebateCalculation:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + case flags.ForexMarketType: // 外汇 + if err = Uo.MoneyRebateCalculation(ctx, session, int(userId), flags.ForexMarketType, flags.ClosingBrokType, flags.CloseMRebate, cost, orderId); err != nil { + applogger.Error("%v MoneyClosingPosition.MoneyRebateCalculation:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + } + + // 更改交易日志记录方式 + var list []models.BotUserMoneyLog + qData0 := orders.CreatBotUserMoneyLog(ctx, userId, flags.CostMoney, flags.MoneyUnit, NegativeValue(closeServiceCost.String()), orderId) // 平仓(资金变动明细表(-平仓手续费)) + qData1 := orders.CreatBotUserMoneyLog(ctx, userId, flags.Thaw, flags.MoneyUnit, earnestMoney.String(), orderId) // 平仓(资金变动明细表(+保证金)) + qData2 := orders.CreatBotUserMoneyLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData0, qData1, qData2) + + // 平仓(资金变动明细表(正负盈亏)) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserMoneyLog(ctx, userId, flags.TransferOut, flags.MoneyUnit, resultPrice.String(), orderId) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserMoneyLog(ctx, userId, flags.ChangeInto, flags.MoneyUnit, resultPrice.String(), orderId) + list = append(list, qData4) + } + + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserMoneyLogList(session, list); err != nil { + applogger.Error("%v MoneyClosingPosition.CreatBotUserMoneyLogList:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v MoneyClosingPosition.Commit:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + + return nil +} + +// UpdateBotMoneyStopByOrderId +// +// @Description: 综合(现货|合约|外汇)设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotMoneyStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotMoneyStopByOrderId.NewSession:%v", common.ErrMoney, err) + return false, flags.ErrMySqlDB + } + + // 设置止盈止损判定 + trade, err := uo.GetBotMoneyTradeByOrderId(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotMoneyStopByOrderId.GetBotMoneyTradeByOrderId:%v", common.ErrMoney, err) + return false, flags.ErrMySqlDB + } + // 下单信息 + checkBool, stopWinPrice, stopLossPrice, err := uo.UpdateMoneyVoteStopType(order) + if err != nil { + applogger.Error("%v UpdateBotMoneyStopByOrderId.UpdateMoneyVoteStopType:%v", common.ErrMoney, err) + return false, err + } + if !flags.CheckSetting { + applogger.Debug("获取当前止盈止损数据:%v,%v,%v", checkBool, stopWinPrice, stopLossPrice) + } + + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err := uo.UpdateMoneyVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotMoneyStopByOrderId.UpdateMoneyVoteDealType:%v", common.ErrMoney, err) + return false, err + } + if !flags.CheckSetting { + applogger.Debug("获取当前开仓价格:%v", limitOrMarketPrice) + } + + // 下单判定设置(买涨|买跌) + if err = uo.MoneyVoteTradeType(int64(trade.TradeType), stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v UpdateBotMoneyStopByOrderId.MoneyVoteTradeType:%v", common.ErrMoney, err) + return false, err + } + + // 更新订单表 + botStockTrade := orders.BotMoneyStopByOrderId(ctx, order) + err = uo.UpdateBotMoneyTradeByOrderId(session, order.OrderId, botStockTrade) + if err != nil { + applogger.Error("%v UpdateBotMoneyStopByOrderId.Update:%v", common.ErrMoney, err) + return false, flags.ErrMySqlDB + } + + // 修改挂单缓存队列 + entrust, err := LoadLRangeList(setting.MarketMoneyPosition) + if err != nil { + applogger.Error("%v UpdateBotMoneyStopByOrderId.LoadLRangeList:%v", common.ErrMoney, err) + return false, flags.ErrCacheDB + } + for key, value := range entrust { + var entrustJson Moneyd.MoneyTallyCache + if err = json.Unmarshal([]byte(value), &entrustJson); err != nil { + applogger.Error("%v UpdateBotMoneyStopByOrderId.Unmarshal:%v", common.ErrMoney, err) + return false, flags.ErrCacheDB + } + entrustJson.Order.StopType = order.StopType + entrustJson.Order.StopWinPrice = order.StopWinPrice + entrustJson.Order.StopLossPrice = order.StopLossPrice + if !flags.CheckSetting { + applogger.Debug("修改缓存中的止盈止损Type:%v", entrustJson.Order.StopType) + applogger.Debug("修改缓存中的止盈:%v", entrustJson.Order.StopWinPrice) + applogger.Debug("修改缓存中的止损:%v", entrustJson.Order.StopLossPrice) + } + var data []byte + data, err = json.Marshal(&entrustJson) + if err != nil { + applogger.Error("%v UpdateBotMoneyStopByOrderId.Marshal:%v", common.ErrMoney, err) + return false, flags.ErrCacheDB + } + if order.OrderId == entrustJson.OrderId { + if err = Reds.HSet(context.Background(), setting.MarketMoneyPosition, key, string(data)).Err(); err != nil { + applogger.Error("%v UpdateBotMoneyStopByOrderId.HSet:%v", common.ErrMoney, err) + return false, flags.ErrCacheDB + } + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotMoneyStopByOrderId.Commit:%v", common.ErrMoney, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotMoneyCancelByOrderId +// +// @Description: 综合(现货|合约|外汇)撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotMoneyCancelByOrderId(ctx context.Context, orderId string) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotMoneyCancelByOrderId.NewSession:%v", common.ErrMoney, err) + return false, flags.ErrMySqlDB + } + + // get BotMoneyTrade + tread, err := uo.GetBotMoneyTradeByOrderId(session, orderId, flags.EntrustStatus) + if err != nil { + applogger.Error("%v UpdateBotMoneyCancelByOrderId.GetBotMoneyTradeByOrderId:%v", common.ErrMoney, err) + return false, flags.ErrMySqlDB + } + var userId int64 + var earnestMoneyT, serviceCostT, symbol, orderNumber string + if tread != nil { + userId = int64(tread.UserId) + earnestMoneyT = tread.MarketMoney + serviceCostT = tread.ServiceCost + orderNumber = tread.OrderNumber + symbol = tread.StockId + } + + // get BotUserStock By USD + var usable, frozen, usableNo, frozenNo decimal.Decimal + usable, frozen, _, err = uo.GetBotUserMoney(session, userId, flags.MoneyUnit) + if err != nil { + applogger.Error("%v UpdateBotMoneyCancelByOrderId.GetBotUserMoney:%v", common.ErrMoney, err) + return false, flags.ErrMySqlDB + } + if !flags.CheckSetting { + applogger.Debug("用户原始可用资金:%v", usable) + applogger.Debug("用户原始冻结资金:%v", frozen) + } + + if symbol != flags.MoneyUnit { + usableNo, frozenNo, _, err = uo.GetBotUserMoney(session, userId, tread.StockId) + if err != nil { + applogger.Error("%v UpdateBotMoneyCancelByOrderId.GetBotUserMoney:%v", common.ErrMoney, err) + return false, flags.ErrPublicFour + } + } + if !flags.CheckSetting { + applogger.Debug("用户原始可用非资金:%v", usableNo) + applogger.Debug("用户原始冻结非资金:%v", frozenNo) + } + + // 更新订单信息 + botStockTrade := orders.BotMoneyCancelByOrderId(ctx) + if err = uo.UpdateBotMoneyTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotMoneyCancelByOrderId.UpdateBotMoneyTradeByOrderId:%v", common.ErrMoney, err) + return false, flags.ErrPublicFour + } + + // Operational Spot Asset Table + earnestMoney := decimal.RequireFromString(earnestMoneyT) // 保证金 + serviceCost := decimal.RequireFromString(serviceCostT) // 订单手续费 + totalMoney := earnestMoney.Add(serviceCost) // 订单总金额 + if !flags.CheckSetting { + applogger.Debug("撤单用户ID:%v", userId) + applogger.Debug("下单交易对:%v", symbol) + applogger.Debug("撤单订单保证金:%v", earnestMoneyT) + applogger.Debug("撤单手续费:%v", serviceCostT) + applogger.Debug("撤单订单数量:%v", orderNumber) + applogger.Debug("撤单总金额数量:%v", totalMoney) + } + + // Update total asset data + usableNew := usable.Add(totalMoney) // 用户总资产 + frozenNew := frozen.Sub(totalMoney) // 用户冻结资产 + usableNoNew := usableNo // 用户非可用资产 + frozenNoNew := frozenNo // 用户非冻结资产 + + // 检查用户订单撤单资产 + if frozenNew.IsNegative() { + return false, flags.ErrContractSeven + } + if !flags.CheckSetting { + applogger.Debug("用户撤单可用总资产:%v", usableNew) + applogger.Debug("用户撤单冻结总资产:%v", frozenNew) + applogger.Debug("用户非撤单可用总资产:%v", usableNoNew) + applogger.Debug("用户非撤单冻结总资产:%v", frozenNoNew) + } + + userMoneyUSD := orders.UpdateBotUserMoney(ctx, usableNew.String(), frozenNew.String()) + if err = uo.UpdateBotUserMoney(session, userId, flags.MoneyUnit, userMoneyUSD); err != nil { + applogger.Error("%v UpdateBotMoneyCancelByOrderId.UpdateBotUserMoney:%v", common.ErrMoney, err) + return false, flags.ErrMySqlDB + } + + if symbol != flags.MoneyUnit { + userMoney := orders.UpdateBotUserMoney(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = uo.UpdateBotUserMoney(session, userId, tread.StockId, userMoney); err != nil { + applogger.Error("%v UpdateBotMoneyCancelByOrderId.UpdateBotUserMoney:%v", common.ErrMoney, err) + return false, flags.ErrMySqlDB + } + } + + // 清理挂单缓存信息 + if err = Reds.HDel(context.Background(), setting.MarketMoneyEntrust, orderId).Err(); err != nil { + applogger.Error("%v UpdateBotMoneyCancelByOrderId.HDel:%v", common.ErrMoney, err) + return false, flags.ErrCacheDB + } + + if tread.MarketType != flags.SpotsMarketType { + // 撤单更新订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(setting.MoneySubscribe, userId) + if err = UpdateMoneySubscribeHashStatusByOrderId(orderId, userSubKey, flags.Cancel, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotMoneyCancelByOrderId.MoneySubscribe:%v", common.ErrMoney, err) + return false, flags.ErrCacheDB + } + + // 撤单更新管理员订阅缓存订单状态 + if err = UpdateMoneySubscribeHashStatusByOrderId(orderId, setting.AdminMoneySubscribe, flags.Cancel, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotMoneyCancelByOrderId.AdminMoneySubscribe:%v", common.ErrMoney, err) + return false, flags.ErrCacheDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotMoneyCancelByOrderId.Commit:%v", common.ErrMoney, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotMoneyClosingByOrderId +// +// @Description: 综合(现货|合约|外汇)平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotMoneyClosingByOrderId(ctx context.Context, orderId string) (bool, error) { + // 1、订单信息 + entrust, err := Reds.HGet(context.Background(), setting.MarketMoneyPosition, orderId).Result() + if err != nil { + applogger.Error("%v UpdateBotMoneyClosingByOrderId.MarketMoneyPosition.HGet:%v", common.ErrMoney, err) + return false, flags.ErrMySqlDB + } + + var entrustJson Moneyd.MoneyTallyCache + if err = json.Unmarshal([]byte(entrust), &entrustJson); err != nil { + applogger.Error("%v UpdateBotMoneyClosingByOrderId.Unmarshal:%v", common.ErrMoney, err) + return false, flags.ErrCacheDB + } + if !flags.CheckSetting { + applogger.Debug("手动平仓:%v", entrustJson) + } + + // 2、当前最新价格 + var closePrice decimal.Decimal + switch entrustJson.Order.Type { + case flags.SpotsMarketType: // 现货 + closePrice, err = GetMoneySpotsPrice(entrustJson.Symbol) + if err != nil { + applogger.Error("%v MoneyTransactionCalculationPosition.GetMoneyPrice:%v", common.ErrMoney, err) + return false, err + } + case flags.ContractMarketType: // 合约 + closePrice, err = GetMoneyContractPrice(entrustJson.Symbol) + if err != nil { + applogger.Error("%v MoneyTransactionCalculationPosition.GetMoneyPrice:%v", common.ErrMoney, err) + return false, err + } + case flags.ForexMarketType: // 外汇 + closePrice, err = GetMoneyForexPriceNew(entrustJson.Symbol) + if err != nil { + applogger.Error("%v MoneyTransactionCalculationPosition.GetMoneyPrice:%v", common.ErrMoney, err) + return false, err + } + } + if err = Reds.HDel(context.Background(), setting.MarketMoneyPosition, orderId).Err(); err != nil { + applogger.Error("%v UpdateBotMoneyClosingByOrderId.MarketMoneyPosition.HDel:%v", common.ErrMoney, err) + return false, flags.ErrCacheDB + } + + // 3、平仓处理 + if err = MoneyClosingPosition(ctx, uo.data.mysqlDB, orderId, closePrice.String(), entrustJson.Order, 3); err != nil { + applogger.Error("%v UpdateBotMoneyClosingByOrderId.MoneyClosingPosition:%v", common.ErrMoney, err) + return false, flags.ErrCacheDB + } + + // 4、平仓更新订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(setting.MoneySubscribe, entrustJson.UserId) + if err = UpdateMoneySubscribeHashStatusByOrderId(orderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotMoneyClosingByOrderId.MoneySubscribe:%v", common.ErrMoney, err) + return false, flags.ErrCacheDB + } + + // 5、平仓更新管理员订阅缓存订单状态 + if err = UpdateMoneySubscribeHashStatusByOrderId(orderId, setting.AdminMoneySubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotMoneyCancelByOrderId.AdminMoneySubscribe:%v", common.ErrMoney, err) + return false, flags.ErrCacheDB + } + + return true, nil +} + +// UpdateBotMoneyClosingAllByOrderId +// +// @Description: 综合(现货|合约|外汇)一键平仓 +// @receiver uo +// @param ctx +// @param userId +// @return error +func (uo *userOrderRepo) UpdateBotMoneyClosingAllByOrderId(ctx context.Context, userId int64) error { + // 1、查询当前用户所有订单 + orderMap, err := uo.GetBotMoneyTradeByUserId(userId) + if err != nil { + applogger.Error("%v UpdateBotMoneyClosingAllByOrderId.GetBotMoneyTradeByUserId:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + + // 2、查询持仓缓存列表数据-1>清理持仓列表缓存 2>处理平仓数据 3>清理订单ID缓存列表 + for _, value := range orderMap { + var entrust string + entrust, err = Reds.HGet(context.Background(), setting.MarketMoneyPosition, value).Result() + if err != nil { + applogger.Error("%v UpdateBotMoneyClosingAllByOrderId.MarketMoneyPosition.LRange:%v", common.ErrMoney, err) + return flags.ErrCacheDB + } + var entrustJson Moneyd.MoneyTallyCache + if err = json.Unmarshal([]byte(entrust), &entrustJson); err != nil { + applogger.Error("%v UpdateBotMoneyClosingAllByOrderId.Unmarshal:%v", common.ErrMoney, err) + return flags.ErrCacheDB + } + + // 获取当前综合(现货|合约|外汇)交易对买一卖一最新报价 + var closePrice decimal.Decimal + switch entrustJson.Order.Type { + case flags.SpotsMarketType: // 现货 + closePrice, err = GetMoneySpotsPrice(entrustJson.Symbol) + if err != nil { + applogger.Error("%v MoneyTransactionCalculationPosition.GetMoneyPrice:%v", common.ErrMoney, err) + return err + } + case flags.ContractMarketType: // 合约 + closePrice, err = GetMoneyContractPrice(entrustJson.Symbol) + if err != nil { + applogger.Error("%v MoneyTransactionCalculationPosition.GetMoneyPrice:%v", common.ErrMoney, err) + return err + } + case flags.ForexMarketType: // 外汇 + closePrice, err = GetMoneyForexPriceNew(entrustJson.Symbol) + if err != nil { + applogger.Error("%v MoneyTransactionCalculationPosition.GetMoneyPrice:%v", common.ErrMoney, err) + return err + } + } + if err = Reds.HDel(context.Background(), setting.MarketMoneyPosition, value).Err(); err != nil { + applogger.Error("%v UpdateBotMoneyClosingAllByOrderId.MarketMoneyPosition.HDel:%v", common.ErrMoney, err) + return flags.ErrCacheDB + } + + // 平仓 + if err = MoneyClosingPosition(ctx, uo.data.mysqlDB, entrustJson.OrderId, closePrice.String(), entrustJson.Order, 3); err != nil { + applogger.Error("%v UpdateBotMoneyClosingAllByOrderId.MoneyClosingPosition:%v", common.ErrMoney, err) + return err + } + + // 平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.MoneySubscribe, entrustJson.UserId) + if err = UpdateMoneySubscribeHashStatusByOrderId(entrustJson.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotMoneyClosingAllByOrderId.MoneySubscribe:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + + // 平仓更新管理员订阅订单状态 + if err = UpdateMoneySubscribeHashStatusByOrderId(entrustJson.OrderId, setting.AdminMoneySubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotMoneyCancelByOrderId.AdminMoneySubscribe:%v", common.ErrMoney, err) + return flags.ErrMySqlDB + } + } + + return nil +} + +// MoneyCreateOneClickRedemption +// +// @Description: 现货(开仓|平仓|一键兑换) +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) MoneyCreateOneClickRedemption(ctx context.Context, userId int64, order structure.MoneyOrder) (string, error) { + // 1、下单通知订阅 + stockId := strings.ToLower(order.StockId) + _, ok := moneyZh.MoneySpotsMapSymbol.Load(stockId) + if ok { + go func() { + moneyZh.MoneySpotsMap <- []byte(stockId) + }() + } + order.StockId = strings.ToUpper(order.StockId) + + // 交易币市价 + priceNew, err := GetMoneySpotsPrice(stockId) + if err != nil { + applogger.Error("%v CreateOneClickRedemption.GetMoneySpotsPrice:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrNetWorkMessage + } + + // 2、市价下单记录(1>下单判定 2>订单表 3>资产表[资产|其他交易对]) + order.MarketPrice = priceNew.String() + orderId, err := uo.MoneyOrdersDealDB(ctx, userId, order) + if err != nil || len(orderId) == 0 { + applogger.Error("%v CreateOneClickRedemption.SpotOrdersDealDB:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrSpotsMsgThree + } + + // 3、市价卖出下单 + switch order.DealType { + case flags.DealTypeMarket: // 市价下单(市价卖出平仓) + var openPrice decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买入 + case flags.TradeTypeSell: // 卖出 + openPrice = priceNew + default: + return flags.SetNull, flags.ErrSpotsMsgFour + } + // 市价下单平仓操作-->更新订单表|更新资产表|计算手续费|录入返佣明细|录入交易明细 + if _, err = MoneyOrdersClosingDB(context.Background(), uo.data.mysqlDB, userId, order, orderId, openPrice.String()); err != nil { + // 一键兑换失败,撤单操作 + _, err = uo.UpdateBotMoneyCancelByOrderId(ctx, orderId) + if err != nil { + applogger.Error("%v CreateOneClickRedemption.UpdateBotMoneyCancelByOrderId:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + return flags.SetNull, err + } + default: + return flags.SetNull, flags.ErrSpotMsgOne + } + + return orderId, nil +} +func (uo *userOrderRepo) MoneyOrdersDealDB(ctx context.Context, userId int64, order structure.MoneyOrder) (string, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v MoneyOrdersDealDB:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 查询当前用户买入或者卖出的可用总资产和冻结总资产 + usableOld, frozenOld, _, err := uo.GetBotUserMoney(session, userId, flags.MoneyUnit) + if err != nil { + applogger.Error("%v MoneyOrdersDealDB.GetBotUserMoney:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 查询当前用户买入或者卖出的可用总资产和冻结总非资产 + var checkCount int + var usableSymbolOld, frozenSymbolOld decimal.Decimal + if order.StockId != flags.MoneyUnit { + usableSymbolOld, frozenSymbolOld, checkCount, err = uo.GetBotUserMoney(session, userId, order.StockId) + if err != nil { + applogger.Error("%v MoneyOrdersDealDB.GetBotUserMoney:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + if !flags.CheckSetting { + applogger.Debug("可用资产:%v,冻结资产:%v", userId, frozenOld) + applogger.Debug("可用非资产:%v,冻结非资产:%v", usableSymbolOld, frozenSymbolOld) + } + + // 开仓录入订单表 + checkInt, orderId, err := uo.CreatBotMoneyTradeBySpots(ctx, session, userId, order) + if err != nil || checkInt <= 0 { + applogger.Error("%v MoneyOrdersDealDB.CreatBotDigitalTrade:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + + orderNumber := decimal.RequireFromString(order.OrderNumber) // 下单数量 + orderMoney := decimal.RequireFromString(order.MarketPrice).Mul(orderNumber) // 下单金额 = 訂單金額 * 訂單數量 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 下单手续费 + totalMoney := orderMoney.Add(serviceCost) // 下单总金额 + + if !flags.CheckSetting { + applogger.Debug("现货下单金额:%v", orderMoney) + applogger.Debug("现货下单数量:%v", orderNumber) + applogger.Debug("现货下单手续费:%v", serviceCost) + applogger.Debug("现货下单总金额:%v", totalMoney) + } + + // 通过交易类型处理下单: 1买入(冻结资产), 2卖出(冻结资产) + var usableNew, frozenNew, usableNewNo, frozenNewNo decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买入 + voteUsaBledOld := usableOld.Cmp(totalMoney) + voteMix := usableOld.Sub(totalMoney).Div(usableOld).Cmp(utils.DecimalsStrInt()) + if voteUsaBledOld < 0 || voteMix <= 0 { + return flags.SetNull, flags.ErrSpotsMsgSix + } + usableNew = usableOld.Sub(totalMoney) // 可用资产 + frozenNew = frozenOld.Add(totalMoney) // 冻结资产 + + usableNewNo = usableSymbolOld // 非可用资产 + frozenNewNo = frozenSymbolOld // 非冻结资产 + case flags.TradeTypeSell: // 卖出 + if usableSymbolOld.IsZero() || usableSymbolOld.Cmp(orderNumber) < 0 { + return flags.SetNull, flags.ErrPublicOne + } + usableNew = usableOld // 可用资产 + frozenNew = frozenOld // 非可用冻结资产 + + if order.StockId != flags.MoneyUnit { + usableNewNo = usableSymbolOld // 可用非资产 + frozenNewNo = frozenSymbolOld.Add(orderNumber) // 冻结非资产 + } + default: + return flags.SetNull, flags.ErrSpotsMsgSeven + } + + // 更新当前下单用户可用资产表 + useMoneyUSD := orders.UpdateBotUserMoneySpots(ctx, usableNew.String(), frozenNew.String()) + checkNum, err := uo.UpdateBotUserMoneySpots(session, userId, flags.MoneyUnit, useMoneyUSD) + if err != nil || checkNum <= 0 { + applogger.Error("%v MoneyOrdersDealDB.UpdateBotUserMoneySpots:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 更新非账户资金 + if order.StockId != flags.MoneyUnit { + if checkCount == 0 { + userMoneySymbol := orders.BotUserMoneySpots(ctx, userId, usableNewNo.String(), frozenNewNo.String(), order) + checkInt, err = uo.CreatBotUserMoneySpots(session, userMoneySymbol) + if err != nil || checkInt <= 0 { + applogger.Error("%v MoneyOrdersDealDB.CreatBotUserMoneySpots:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + userMoney := orders.UpdateBotUserMoneySpots(ctx, usableNewNo.String(), frozenNewNo.String()) + checkNum, err = uo.UpdateBotUserMoneySpots(session, userId, order.StockId, userMoney) + if err != nil || checkNum <= 0 { + applogger.Error("%v MoneyOrdersDealDB.UpdateBotUserMoneySpots:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + } + + err = session.Commit() + if err != nil { + applogger.Error("%v MoneyOrdersDealDB:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + + return orderId, nil +} +func (uo *userOrderRepo) CreatBotMoneyTradeBySpots(ctx context.Context, session *xorm.Session, userId int64, order structure.MoneyOrder) (int64, string, error) { + var orderId string + for { + orderId = orders.CreateRandCodeOrder(10) + orderList, err := uo.GetBotMoneyTradeByOrderIdSpots(orderId) + if err != nil || len(orderList) > 0 { + applogger.Error("%v CreatBotMoneyTrade.GetBotMoneyTradeByOrderIdSpots:%v", err) + continue + } + break + } + + botStockTrade := orders.BotMoneyTrade(ctx, userId, orderId, order) + checkInt, err := session.Table(flags.BotMoneyTrade).Insert(&botStockTrade) + if err != nil || checkInt < 0 { + return 0, flags.SetNull, err + } + + return checkInt, botStockTrade.OrderId, err +} +func (uo *userOrderRepo) GetBotMoneyTradeByOrderIdSpots(orderId string) ([]models.BotMoneyTrade, error) { + var botMoneyTrade []models.BotMoneyTrade + if err := uo.data.mysqlDB.Table(flags.BotMoneyTrade). + Where("order_id = ?", orderId). + Find(&botMoneyTrade); err != nil { + return nil, err + } + + return botMoneyTrade, nil +} +func (uo *userOrderRepo) UpdateBotUserMoneySpots(session *xorm.Session, userId int64, symbol string, userMoneyUSD models.BotUserMoney) (int64, error) { + checkNum, err := session.Table(flags.BotUserMoney). + Where("user_id = ?", userId). + Where("stock_id = ?", symbol). + Update(&userMoneyUSD) + if err != nil { + return 0, nil + } + + return checkNum, nil +} +func (uo *userOrderRepo) CreatBotUserMoneySpots(session *xorm.Session, money models.BotUserMoney) (int64, error) { + checkInt, err := session.Table(flags.BotUserMoney).Insert(&money) + if err != nil { + return 0, err + } + + return checkInt, nil +} +func MoneyOrdersClosingDB(ctx context.Context, db *xorm.EngineGroup, userId int64, order structure.MoneyOrder, orderId, closingPrice string) (string, error) { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v MoneyOrdersClosingDB.NewSession:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 当前用户(买入|卖出)的(可用|冻结)资产 + usableOld, frozenOld, _, err := Uo.GetBotUserMoney(session, userId, flags.MoneyUnit) + if err != nil { + applogger.Error("%v MoneyOrdersClosingDB.GetBotUserMoney:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 当前用户非(买入|卖出)的(可用|冻结)资产 + var usableNoOld, frozenNoOld decimal.Decimal + if order.StockId != flags.MoneyUnit { + usableNoOld, frozenNoOld, _, err = Uo.GetBotUserMoney(session, userId, order.StockId) + if err != nil { + applogger.Error("%v MoneyOrdersClosingDB.GetBotUserMoney:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + if !flags.CheckSetting { + applogger.Debug("可用资产:%v", usableOld) + applogger.Debug("冻结资产:%v", frozenOld) + applogger.Debug("非可用资产:%v", usableNoOld) + applogger.Debug("非冻结资产:%v", frozenNoOld) + } + + // Operational Spot Asset Table + orderNumber := decimal.RequireFromString(order.OrderNumber) // 订单数量 + orderMoney := orderNumber.Mul(decimal.RequireFromString(order.MarketPrice)) // 订单金额 = (订单数量 * 订单价格) + serviceCost := decimal.RequireFromString(order.ServiceCost) // 订单手续费 + totalMoney := orderMoney.Add(serviceCost) // 订单总金额 = (订单金额 + 手续费) + if !flags.CheckSetting { + applogger.Debug("平仓开仓价格:%v", order.MarketPrice) + applogger.Debug("平仓金额:%v", orderMoney) + applogger.Debug("平仓数量:%v", order.OrderNumber) + applogger.Debug("平仓手续费:%v", serviceCost) + applogger.Debug("平仓总金额:%v", totalMoney) + } + + // (开仓|平仓)价格重新计算:订单金额|手续费|订单总金额 + closePrice := decimal.RequireFromString(closingPrice) + orderNumberNew := orderMoney.Div(closePrice) // 订单数量 = 下单金额 / 平仓价格 + + // 平仓(手续费处理) + cost, err := Uo.CalculateHandlingFees(ctx, session, int(userId), flags.SpotsMarketType, int(order.TradeType), orderId, orderMoney.String(), flags.SetOne) + if err != nil { + applogger.Error("%v MoneyOrdersClosingDB.CalculateHandlingFees:%v", common.ErrMoney, err) + return flags.SetNull, err + } + openOrClosingCost := decimal.RequireFromString(cost) + totalMoneyPrice := orderNumberNew.Mul(closePrice).Add(openOrClosingCost) // (开仓|平仓)订单总金额 = (开仓|平仓)订单金额 + (开仓|平仓)订单手续费 + if !flags.CheckSetting { + applogger.Debug("平仓价格:%v", closingPrice) + applogger.Debug("平仓订单数量:%v", orderNumberNew) + applogger.Debug("平仓手续费:%v", cost) + applogger.Debug("平仓总金额:%v", totalMoneyPrice) + } + + // 判定是买入还是卖出 + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买入 + usableNew = usableOld.Add(totalMoney).Sub(totalMoneyPrice) // 用户总资产 + frozenNew = frozenOld.Sub(totalMoney) // 用户冻结资产 + if order.StockId != flags.MoneyUnit { + usableNoNew = usableNoOld.Add(orderNumberNew) // 非资产 + frozenNoNew = frozenNoOld // 非冻结资产 + } + case flags.TradeTypeSell: // 卖出 + usableNew = usableOld.Add(orderMoney).Sub(openOrClosingCost) // 用户可用资产 + frozenNew = frozenOld // 用户冻结资产 + if order.StockId != flags.MoneyUnit { + if orderNumberNew.Cmp(orderNumber) > 0 { + orderNumberNew = orderNumber + } + usableNoNew = usableNoOld.Sub(orderNumberNew) // 非可用资产 + frozenNoNew = frozenNoOld.Sub(orderNumber) // 非冻结资产 + } + default: + + } + if !flags.CheckSetting { + applogger.Debug("可用资产:%v", usableNew) + applogger.Debug("冻结资产:%v", frozenNew) + applogger.Debug("非可用资产:%v", usableNoNew) + applogger.Debug("非冻结资产:%v", frozenNoNew) + } + + // 更新用户资产信息 + userMoneyUSD := orders.UpdateBotUserMoneySpots(ctx, usableNew.String(), frozenNew.String()) + checkNum, err := Uo.UpdateBotUserMoneySpots(session, userId, flags.MoneyUnit, userMoneyUSD) + if err != nil || checkNum <= 0 { + applogger.Error("%v MoneyOrdersClosingDB.UpdateBotUserMoneySpots:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 更新订单信息 + botStockTrade := orders.UpdateBotMoneyStatusByOrderId(ctx, closingPrice, cost, orderMoney.String(), totalMoneyPrice.String(), orderNumberNew.String()) + if err = Uo.UpdateBotMoneyTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v MoneyOrdersClosingDB.UpdateBotMoneyTradeByOrderId:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 更新当前用户非的资产信息 + if order.StockId != flags.MoneyUnit { + userMoneySymbol := orders.UpdateBotUserMoneySpots(ctx, usableNoNew.String(), frozenNoNew.String()) + checkNum, err = Uo.UpdateBotUserMoneySpots(session, userId, order.StockId, userMoneySymbol) + if err != nil || checkNum <= 0 { + applogger.Error("%v MoneyOrdersClosingDB.UpdateBotUserMoneySpots:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + // 返佣记录表|资产表|资金变动表 + err = Uo.MoneyRebateCalculation(ctx, session, int(userId), flags.SpotsMarketType, flags.ClosingPosition, flags.CloseMRebate, cost, orderId) + if err != nil { + applogger.Error("%v MoneyOrdersClosingDB.MoneyRebateCalculation:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 交易明细表(资产|非资产|手续费) + err = Uo.CreatBotUserMoneyLog(ctx, session, userId, order.TradeType, order.StockId, orderMoney.String(), orderNumberNew.String(), cost, orderId) + if err != nil { + applogger.Error("%v MoneyOrdersClosingDB.CreatBotUserMoneyLog:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrSpotMsgTow + } + + err = session.Commit() + if err != nil { + applogger.Error("%v MoneyOrdersClosingDB.Commit:%v", common.ErrMoney, err) + return flags.SetNull, flags.ErrMySqlDB + } + + return orderId, nil +} + +// GetBotMoneyTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param status +// @return *models.BotMoneyTrade +// @return error +func (uo *userOrderRepo) GetBotMoneyTradeByOrderId(session *xorm.Session, orderId string, status int) (*models.BotMoneyTrade, error) { + var botMoneyTrade []models.BotMoneyTrade + if err := session.Table(flags.BotMoneyTrade). + Where("order_id = ?", orderId). + Where("`status` = ?", status). + Find(&botMoneyTrade); err != nil { + return nil, err + } + + for _, value := range botMoneyTrade { + return &value, nil + } + + return nil, nil +} + +// GetBotMoneyTradeByUserId +// +// @Description: +// @receiver uo +// @param ctx +// @param userId +// @return map[string]string +// @return error +func (uo *userOrderRepo) GetBotMoneyTradeByUserId(userId int64) (map[string]string, error) { + var botMoneyTrade []models.BotMoneyTrade + if err := uo.data.mysqlDB.Table(flags.BotMoneyTrade). + Where("user_id = ? ", userId). + Where("status = 1"). + Find(&botMoneyTrade); err != nil { + return nil, err + } + + botMap := make(map[string]string) + for _, value := range botMoneyTrade { + botMap[value.OrderId] = value.OrderId + } + + return botMap, nil +} + +// GetBotUserMoney +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param symbol +// @return decimal.Decimal +// @return decimal.Decimal +// @return int +// @return error +func (uo *userOrderRepo) GetBotUserMoney(session *xorm.Session, userId int64, symbol string) (decimal.Decimal, decimal.Decimal, int, error) { + var contractUSDT []models.BotUserMoney + if err := session.Table(flags.BotUserMoney). + Where("user_id = ?", userId). + Where("stock_id = ?", strings.ToUpper(symbol)). + Find(&contractUSDT); err != nil { + return decimal.Zero, decimal.Zero, 0, err + } + + var usableNum, frozenNum decimal.Decimal + for _, value := range contractUSDT { + usableNum = decimal.RequireFromString(value.UsableNum) // 资产可用余额 + frozenNum = decimal.RequireFromString(value.FrozenNum) // 资产冻结数量 + } + + return usableNum, frozenNum, len(contractUSDT), nil +} + +// MoneyVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) MoneyVoteDealType(order structure.MoneyOrder) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + return limitOrMarketPrice, nil +} + +// UpdateMoneyVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) UpdateMoneyVoteDealType(order *models.BotMoneyTrade) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + if len(order.DealPrice) != 0 { + dealPrice := decimal.RequireFromString(order.DealPrice) + if !dealPrice.IsZero() { + limitOrMarketPrice = dealPrice + } + } + + return limitOrMarketPrice, nil +} + +// UpdateMoneyVoteStopType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) UpdateMoneyVoteStopType(order structure.StopOrder) (bool, decimal.Decimal, decimal.Decimal, error) { + var checkBool bool + var stopWinPrice, stopLossPrice decimal.Decimal + switch order.StopType { + case flags.StopTypeNone: // 暂无设置止盈止损 + checkBool = false + case flags.StopTypeSet: // 设置止盈止损 + if len(order.StopWinPrice) != 0 { + stopWinPrice = decimal.RequireFromString(order.StopWinPrice) + } + if len(order.StopLossPrice) != 0 { + stopLossPrice = decimal.RequireFromString(order.StopLossPrice) + } + // 判定设置是否都为零 + if stopWinPrice.IsZero() && stopLossPrice.IsZero() { + return checkBool, decimal.Decimal{}, decimal.Decimal{}, flags.ErrContractTen + } else { + checkBool = true + } + default: + return checkBool, stopWinPrice, stopLossPrice, flags.ErrContractEleven + } + + return checkBool, stopWinPrice, stopLossPrice, nil +} + +// MoneyVoteTradeType +// +// @Description: 股票判定止盈止损配置 +// @receiver uo +// @param ctx +// @param tradeType +// @param stopWinPrice +// @param stopLossPrice +// @param price +// @param checkBool +// @return error +func (uo *userOrderRepo) MoneyVoteTradeType(tradeType int64, stopWinPrice, stopLossPrice, price decimal.Decimal, checkBool bool) error { + if checkBool { + switch tradeType { + case flags.TradeTypeBuy: // 买涨 + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(price) <= 0 { + // 限价买涨下单,止盈价格必须大于限价 + return flags.ErrBuyStopWinPrice + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(price) >= 0 { + // 限价买涨下单,止损价格必须小于限价 + return flags.ErrBuyStopLossPrice + } + } + case flags.TradeTypeSell: // 买跌 + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(price) >= 0 { + // 限价买跌下单,止盈价格必须小于限价 + return flags.ErrSellStopWinPrice + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(price) <= 0 { + // 限价买跌下单,止损价格必须大于限价 + return flags.ErrSellStopLossPrice + } + } + default: + return flags.ErrContractTwelve + } + } + + return nil +} + +// CreatBotUserMoney +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param digital +// @return error +func (uo *userOrderRepo) CreatBotUserMoney(session *xorm.Session, digital models.BotUserMoney) error { + _, err := session.Table(flags.BotUserMoney).Insert(&digital) + if err != nil { + return err + } + + return nil +} + +// CreatBotMoneyTrade +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param trade +// @return error +func (uo *userOrderRepo) CreatBotMoneyTrade(session *xorm.Session, trade models.BotMoneyTrade) error { + _, err := session.Table(flags.BotMoneyTrade).Insert(&trade) + if err != nil { + return err + } + + return nil +} + +// UpdateBotMoneyTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param trade +// @return error +func (uo *userOrderRepo) UpdateBotMoneyTradeByOrderId(session *xorm.Session, orderId string, trade models.BotMoneyTrade) error { + _, err := session.Table(flags.BotMoneyTrade). + Where("order_id = ?", orderId). + Update(&trade) + if err != nil { + return err + } + + return nil +} + +// UpdateBotUserMoney +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param symbol +// @param userMoney +// @return error +func (uo *userOrderRepo) UpdateBotUserMoney(session *xorm.Session, userId int64, symbol string, userMoney models.BotUserMoney) error { + _, err := session.Table(flags.BotUserMoney). + Where("user_id = ?", userId). + Where("stock_id = ?", symbol). + Update(&userMoney) + if err != nil { + return err + } + + return nil +} + +// VerifyBotMoneyTradeOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @return string +// @return error +func (uo *userOrderRepo) VerifyBotMoneyTradeOrderId(session *xorm.Session) (string, error) { + var orderId string + for { + orderId = orders.CreateRandCodeOrder(10) + + var orderList []models.BotMoneyTrade + err := session.Table(flags.BotMoneyTrade).Where("order_id = ?", orderId).Find(&orderList) + if err != nil || len(orderList) > 0 { + applogger.Error("%v VerifyBotMoneyTradeOrderId.Find:%v", common.ErrMoney, err) + continue + } + + break + } + + return orderId, nil +} diff --git a/internal/data/order_option_inr.go b/internal/data/order_option_inr.go new file mode 100644 index 0000000..3b96057 --- /dev/null +++ b/internal/data/order_option_inr.go @@ -0,0 +1,1365 @@ +package data + +import ( + "context" + "encoding/json" + "github.com/go-xorm/xorm" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + orders "matchmaking-system/internal/data/convert" + "matchmaking-system/internal/data/tradedeal/option" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + models "matchmaking-system/internal/pkg/model" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" +) + +// GetBotStockOptionInrTradeList +// +// @Description: 期权-印度股订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param userId +// @param status +// @return []*models.BotStockOptionInrTrade +// @return int64 +// @return error +func (uo *userOrderRepo) GetBotStockOptionInrTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockOptionInrTrade, int64, error) { + totalCount, err := uo.data.mysqlDB.Table(flags.BotStockOptionInrTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Count() + if err != nil { + return nil, 0, flags.ErrMySqlDB + } + if totalCount == 0 { + return nil, 0, nil + } + var stockList []*models.BotStockOptionInrTrade + if err = uo.data.mysqlDB.Table(flags.BotStockOptionInrTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Limit(int(pageSize), int(pageCount)). + Desc(GetOrderByStatusSort(status)). + Find(&stockList); err != nil { + return nil, 0, flags.ErrMySqlDB + } + + var stockUpdateList []*models.BotStockOptionInrTrade + for _, value := range stockList { + value.KeepDecimal = GetKeepDecimal(flags.OptionOpiSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.OptionOpiSystemSetUpKey, value.StockId) + stockUpdateList = append(stockUpdateList, value) + } + + return stockUpdateList, totalCount, nil +} + +// PlacingStockOptionInrOrders +// +// @Description: 期权-印度股下单 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) PlacingStockOptionInrOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) { + // 1、通知下单订阅 + symbol := order.StockCode + _, ok := optionInr.OpiMapSymbol.Load(symbol) + if !ok { + go func() { + optionInr.OpiMap <- []byte(symbol) + }() + } + + // 判定是否存在欠款订单 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe.Error(), nil + } + + // 杠杆初始化 + order = PryNumInit(order) + // 当前时间和到期时间相同-不容许下单 + //if !utils.TimeYYYMMDD(order.StopTime) { + // return flags.SetNull, flags.ErrIsParameter + //} + // 期权-印度股市场设置判定 + if CheckGlobalTread(flags.OpiMarket) { + return flags.SetNull, flags.ErrStopTread + } + // 保证金比例(后台配置) + order.Ratio = GetOptionInrForcedClosure(flags.OptionOpiSystemSetUpKey, symbol).String() + // 期权-强平阈值 + flatRatio := GetCacheForcedClosure(flags.OptionOpiSystemSetUpKey, symbol) + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), + } + order.System = system + // 2、股票下单判定 + // 下单判定设置(false无设置|true止盈止损) + checkBool, stopWinPrice, stopLossPrice, err := OptionInrVoteStopType(order) + if err != nil { + applogger.Error("%v PlacingStockOptionInrOrders.OptionInrVoteStopType:%v", common.ErrOptionInr, err) + return flags.SetNull, err + } + // 下单判定设置(限价|市价) + limitOrMarketPrice, err := uo.OptionInrVoteDealType(order) + if err != nil { + applogger.Error("%v PlacingStockOptionInrOrders.StockVoteDealType:%v", common.ErrOptionInr, err) + return flags.SetNull, err + } + // 下单判定设置(看涨|看跌) + ask := decimal.RequireFromString(order.Ask) + bid := decimal.RequireFromString(order.Bid) + if err = uo.VoteTradeTypeOption(order.DealType, order.TradeType, order.TradingType, stopWinPrice, stopLossPrice, limitOrMarketPrice, bid, ask, checkBool); err != nil { + applogger.Error("%v PlacingStockOptionInrOrders.StockVoteTradeType:%v", common.ErrOptionInr, err) + return flags.SetNull, err + } + // 3、订单持久化录入(处理资产信息) + marginRatio := GetOptionInrCostPrice(limitOrMarketPrice, order) // 保证金计算 + orderId, err := uo.OptionInrOrderWriteDB(ctx, userId, order, marginRatio) + if err != nil || len(orderId) == 0 { + applogger.Error("%v PlacingStockOptionInrOrders.OptionInrOrderWriteDB:%v", common.ErrOptionInr, err) + return flags.SetNull, err + } + // 4、处理订单信息 + marketStatus, shareOrder, err := option.OptionInrCacheDeal(ctx, userId, orderId, order) + if err != nil || shareOrder == nil { + applogger.Error("%v PlacingStockOptionInrOrders.OptionInrCacheDeal:%v", common.ErrOptionInr, err) + return flags.SetNull, err + } + if !flags.CheckSetting { + applogger.Debug("订单ID:%v", shareOrder.OrderId) + applogger.Debug("订单交易对:%v", shareOrder.Symbol) + applogger.Debug("订单状态:%v", shareOrder.Status) + applogger.Debug("订单用户ID:%v", shareOrder.UserId) + applogger.Debug("开盘价:%v", shareOrder.OpenPrice) + applogger.Debug("收盘价:%v", shareOrder.ClosingPrice) + applogger.Debug("下单信息:%v", shareOrder.Order) + } + // 5、订单(挂单|持仓)缓存列表,等待队列计算 + if err = option.OptionInrHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v PlacingStockOptionInrOrders.OptionInrHashUserOrder:%v", common.ErrOptionInr, err) + return flags.SetNull, flags.ErrCacheDB + } + // 6、用户订阅股票订单信息 + orderIdKey := virtual.OrderIdListKey(setting.OptionInrSubscribe, userId) + if err = option.OptionInrHashUserOrder(Reds, orderIdKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockOptionInrOrders.OptionInrSubscribe:%v", common.ErrOptionInr, err) + return flags.SetNull, flags.ErrCacheDB + } + // 7、管理员订阅订单信息 + if err = option.OptionInrHashUserOrder(Reds, setting.AdminOptionInrSubscribe, shareOrder); err != nil { + applogger.Error("%v PlacingStockOptionInrOrders.AdminOptionInrSubscribe:%v", common.ErrOptionInr, err) + return flags.SetNull, flags.ErrCacheDB + } + + return orderId, nil +} + +// OptionInrOrderWriteDB +// +// @Description: 期权-印度股下单处理 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @param limitOrMarketPrice +// @return string +// @return error +func (uo *userOrderRepo) OptionInrOrderWriteDB(ctx context.Context, userId int64, order structure.ShareOrder, marginRatio decimal.Decimal) (string, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v OptionInrOrderWriteDB.Begin:%v", common.ErrOptionInr, err) + return flags.SetNull, flags.ErrMySqlDB + } + // 用户期权-印度股资产信息 + var usableOld, frozenOld decimal.Decimal + opInr, err := uo.GetBotUserStockOptionInrByUserIdAndStockId(session, userId, flags.OptionInrBasicUnit) + if err != nil || opInr == nil { + applogger.Error("%v OptionInrOrderWriteDB.INR:%v", common.ErrOptionInr, err) + return flags.SetNull, flags.ErrMySqlDB + } + usableOld = decimal.RequireFromString(opInr.UsableNum) + frozenOld = decimal.RequireFromString(opInr.FrozenNum) + // 检查用户期权印度股资产信息 + if usableOld.IsZero() || usableOld.IsNegative() || frozenOld.IsNegative() { + return flags.SetNull, flags.ErrShareOne + } + if !flags.CheckSetting { + applogger.Debug("下单可用资产:%v", usableOld) + applogger.Debug("下单冻结资产:%v", frozenOld) + } + // 用户期权印度股非资产信息 + var usableFOld, frozenFOld decimal.Decimal + stockFIdr, err := uo.GetBotUserStockOptionInrByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v OptionInrOrderWriteDB.FeiIDR:%v", common.ErrOptionInr, err) + return flags.SetNull, flags.ErrMySqlDB + } + if stockFIdr != nil { + usableFOld = decimal.RequireFromString(stockFIdr.UsableNum) + frozenFOld = decimal.RequireFromString(stockFIdr.FrozenNum) + } + if !flags.CheckSetting { + applogger.Debug("下单查询非资产账户:%v", stockFIdr) + applogger.Debug("下单可用非资产:%v", usableFOld) + applogger.Debug("下单冻结非资产:%v", frozenFOld) + } + // 检查期权-印度股订单ID是否存在,新增订单信息 + var orderId string + orderId, err = uo.VerifyBotStockOptionInrTradeOrderId(session) + if err != nil { + applogger.Error("%v OptionInrOrderWriteDB.VerifyBotStockOptionInrTradeOrderId:%v", common.ErrOptionInr, err) + return flags.SetNull, err + } + trade := orders.BotStockOptionInrTrade(ctx, userId, orderId, marginRatio.String(), order) + if err = uo.CreateBotStockOptionInrTrade(session, trade); err != nil { + applogger.Error("%v OptionInrOrderWriteDB.CreateBotStockOptionInrTrade:%v", common.ErrOptionInr, err) + return flags.SetNull, flags.ErrMySqlDB + } + // 检查用户下单资产信息 + orderMoney := marginRatio.Add(decimal.RequireFromString(order.ServiceCost)) // 订单总金额 = 保证金 + 手续费 + residue := usableOld.Sub(orderMoney).Div(usableOld) + if usableOld.Cmp(orderMoney) <= 0 || residue.Cmp(utils.DecimalsStrInt()) <= 0 { + return flags.SetNull, flags.ErrPublicTow + } + // 处理用户下单资产信息 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 订单数量 + var usableNew, frozenNew, usableFNew, frozenFNew decimal.Decimal + usableNew = usableOld.Sub(orderMoney) // 可用资产 + frozenNew = frozenOld.Add(orderMoney) // 冻结资产 + if order.StockId != flags.OptionInrBasicUnit { + usableFNew = usableFOld.Add(orderNumber) // 可用非资产 + frozenFNew = frozenFOld // 冻结非资产 + } + // 检查用户下单资产信息 + if usableNew.IsNegative() || frozenNew.IsNegative() { + return flags.SetNull, flags.ErrPublicTow + } + // 下单更新资产信息 + stockIdrModel := orders.UpdateBotUserStockOptionInr(ctx, usableNew.String(), frozenNew.String()) + err = uo.UpdateBotUserStockOptionInrByUserIdAndStockId(session, userId, flags.OptionInrBasicUnit, stockIdrModel) + if err != nil { + applogger.Error("%v OptionInrOrderWriteDB.UpdateBotUserStockOptionInrByUserIdAndStockId:%v", common.ErrOptionInr, err) + return flags.SetNull, flags.ErrMySqlDB + } + // 下单(新增|更新)非资产信息 + if stockFIdr == nil { + stockFIDRModel := orders.CreateBotUserStockOptionInr(ctx, userId, order.StockId, usableFNew.String(), frozenFNew.String()) + err = uo.CreateBotUserStockOptionInrFIRD(session, stockFIDRModel) + if err != nil { + applogger.Error("%v OptionInrOrderWriteDB.CreateBotUserStockOptionInrFIRD:%v", common.ErrOptionInr, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + stockFIDRModel := orders.UpdateBotUserStockOptionInr(ctx, usableFNew.String(), frozenFNew.String()) + err = uo.UpdateBotUserStockOptionInrByUserIdAndStockId(session, userId, order.StockId, stockFIDRModel) + if err != nil { + applogger.Error("%v OptionInrOrderWriteDB.UpdateBotUserStockOptionInrByUserIdAndStockId:%v", common.ErrOptionInr, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v OptionInrOrderWriteDB.Commit:%v", common.ErrOptionInr, err) + return flags.SetNull, flags.ErrMySqlDB + } + + return orderId, nil +} + +// OptionInrOpenOrder +// +// @Description: 期权-印度股系统开仓 +// @param ctx +// @param db +// @param userId +// @param orderId +// @param openPrice +// @param order +// @return error +func OptionInrOpenOrder(ctx context.Context, db *xorm.EngineGroup, userId int64, orderId, openPrice string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v OptionInrOpenOrder.NewSession:%v", common.ErrOptionInr, err) + return flags.ErrMySqlDB + } + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockIdr, err := Uo.GetBotUserStockOptionInrByUserIdAndStockId(session, userId, flags.OptionInrBasicUnit) + if err != nil || stockIdr == nil { + applogger.Error("%v OptionInrOpenOrder.GetBotUserStockOptionInrByUserIdAndStockId:%v", common.ErrOptionInr, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockIdr.UsableNum) // 用户可用资产 + frozen = decimal.RequireFromString(stockIdr.FrozenNum) // 用户冻结资产 + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + } + // 检查用户开仓资产信息 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrPublicThree + } + // 检查用户非资产信息 + if order.StockId != flags.OptionInrBasicUnit { + stockFIdr, err := Uo.GetBotUserStockOptionInrByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v OptionInrOpenOrder.GetBotUserStockOptionInrByUserIdAndStockId:%v", common.ErrOptionInr, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(stockFIdr.UsableNum) // 用户非可用资产 + frozenNo = decimal.RequireFromString(stockFIdr.FrozenNum) // 用户非冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + // 转换股票下单信息 + openOrderPrice := decimal.RequireFromString(openPrice) // 开盘价格 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 下单股数 + marketMoney := decimal.RequireFromString(order.MarketMoney) // 下单金额 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 下单手续费 + orderMoney := marketMoney.Add(serviceCost) // 下单总金额 = (下单手续费 + 下单金额) + if !flags.CheckSetting { + applogger.Debug("下单订单数量:%v", orderNumber) + applogger.Debug("下单订单金额:%v", marketMoney) + applogger.Debug("下单订单手续费:%v", serviceCost) + applogger.Debug("下单订单总金额:%v", orderMoney) + } + costOpenPrice, err := Uo.CalculateHandlingFeesOption(ctx, session, int(userId), flags.OptionInrMarketType, flags.OpenBrokType, orderId, openPrice, order.OrderNumber) + if err != nil { + applogger.Error("%v OptionInrOpenOrder.CalculateHandlingFeesOption:%v", common.ErrShareUs, err) + return err + } + openServiceCost := decimal.RequireFromString(costOpenPrice) // 期权-开仓手续费 + marginRatio := GetOptionInrCostPrice(openOrderPrice, order) // 期权-(开仓订单金额-开仓保证金) + openOrderMoney := marginRatio.Add(openServiceCost) // 期权-(订单总额 = 保证金 + 手续费) + floatPrice := orderMoney.Sub(openOrderMoney) // 期权-(计算容差 = 下单总额 - 开仓总额) + if !flags.CheckSetting { + applogger.Debug("开仓订单价格:%v", openOrderPrice) + applogger.Debug("开仓手续费:%v", openServiceCost) + applogger.Debug("开仓保证金:%v", marginRatio) + applogger.Debug("开仓总金额:%v", openOrderMoney) + applogger.Debug("下单->开仓总金额容差值:%v", floatPrice) + } + + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + usableNew = usable.Add(floatPrice) // 可用资产(处理容差值) = 可用余额 + 下单保证金 - 开仓保证金 + frozenNew = frozen.Sub(orderMoney).Add(marginRatio) // 冻结资产 = 冻结资产 - 下单总额 + 开仓保证金 + if order.StockId != flags.ShareInrBasicUnit { + usableNoNew = usableNo // 非可用资产 + frozenNoNew = frozenNo // 非冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("下单后用户可用资产:%v", usableNew) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + } + // 检查用户开仓资产 + if frozenNew.IsNegative() || usableNew.IsNegative() { + return flags.ErrPublicThree + } + // 处理资产信息 + userStockIdr := orders.UpdateBotUserStockOptionInr(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockOptionInrByUserIdAndStockId(session, userId, flags.OptionInrBasicUnit, userStockIdr); err != nil { + applogger.Error("%v OptionInrOpenOrder.UpdateBotUserStockOptionInrByUserIdAndStockId:%v", common.ErrOptionInr, err) + return flags.ErrMySqlDB + } + // 更新非资产信息 + if order.StockId != flags.OptionInrBasicUnit { + userStockFIdr := orders.UpdateBotUserStockOptionInr(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = Uo.UpdateBotUserStockOptionInrByUserIdAndStockId(session, userId, order.StockId, userStockFIdr); err != nil { + applogger.Error("%v OptionInrOpenOrder.OPI.UpdateBotUserStockOptionInrByUserIdAndStockId:%v", common.ErrOptionInr, err) + return flags.ErrMySqlDB + } + } + // 处理订单信息(成交价|仓位|开仓时间|订单总金额|手续费|持仓状态) + trade := orders.UpdateOpenBotStockOptionInrTrade(ctx, openPrice, order.OrderNumber, openOrderMoney.String(), order.ServiceCost, marginRatio.String()) + if err = Uo.UpdateBotStockOptionInrTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v OptionInrOpenOrder.UpdateBotStockOptionInrTradeByOrderId:%v", common.ErrOptionInr, err) + return flags.ErrMySqlDB + } + // 更改交易日志记录方式 + var list []models.BotUserStockOptionInrLog + qData1 := orders.CreatBotUserStockOptionInrLog(ctx, userId, flags.Freeze, flags.OptionInrBasicUnit, NegativeValue(marginRatio.String()), orderId) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockOptionInrLog(ctx, userId, flags.ChangeInto, order.StockId, order.OrderNumber, orderId) // 资金变动明细表(非资产) + qData3 := orders.CreatBotUserStockOptionInrLog(ctx, userId, flags.CostMoney, flags.OptionInrBasicUnit, NegativeValue(openServiceCost.String()), orderId) // 资金变动明细表(开仓手续费) + list = append(list, qData1, qData2, qData3) + // 批量写入数据信息 + if err = Uo.CreatBotUserStockOptionInrLogList(session, list); err != nil { + applogger.Error("%v OptionInrOpenOrder.CreatBotUserStockOptionInrLogList:%v", common.ErrOptionInr, err) + return flags.ErrMySqlDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v OptionInrOpenOrder.Commit:%v", common.ErrOptionInr, err) + return flags.ErrMySqlDB + } + + return nil +} + +// OptionInrClosingOrder +// +// @Description: 期权-印度股系统平仓 +// @param ctx +// @param db +// @param orderId +// @param price +// @param order +// @return error +func OptionInrClosingOrder(ctx context.Context, db *xorm.EngineGroup, orderId string, price string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v OptionInrClosingOrder.NewSession:%v", common.ErrOptionInr, err) + return flags.ErrMySqlDB + } + // 查询订单信息 + tread, err := Uo.GetBotStockOptionInrTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil { + applogger.Error("%v OptionInrClosingOrder.GetBotStockOptionInrTradeByOrderIdOrStatus:%v", common.ErrOptionInr, err) + return flags.ErrMySqlDB + } + var userId int64 + var openPrice, orderNumber, orderMoney, serviceCost, marketMoney, strikePrice decimal.Decimal + if tread != nil { + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 订单数量 + openPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + orderMoney = decimal.RequireFromString(tread.OrderMoney) // 订单总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + marketMoney = decimal.RequireFromString(tread.MarketMoney) // 保证金 + strikePrice = decimal.RequireFromString(tread.StrikePrice) // 行权价 + } + if !flags.CheckSetting { + applogger.Debug("下单开仓用户Id:%v", userId) + applogger.Debug("下单开仓开仓价格:%v", openPrice) + applogger.Debug("下单开仓订单数量:%v", orderNumber) + applogger.Debug("下单开仓总金额:%v", orderMoney) + applogger.Debug("下单开仓手续费:%v", serviceCost) + applogger.Debug("下单开仓订单金额:%v", marketMoney) + applogger.Debug("下单权利金:%v", strikePrice) + } + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + userStockIdr, err := Uo.GetBotUserStockOptionInrByUserIdAndStockId(session, userId, flags.OptionInrBasicUnit) + if err != nil { + applogger.Error("%v OptionInrClosingOrder.GetBotUserStockOptionInrByUserIdAndStockId:%v", common.ErrOptionInr, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(userStockIdr.UsableNum) // 用户可用资金 + frozen = decimal.RequireFromString(userStockIdr.FrozenNum) // 用户非冻结资金 + // 检查用户平仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrShareTow + } + // 查询当前下单用户可用非账户和冻结金额 + if order.StockId != flags.OptionInrBasicUnit { + userStockFIdr, err := Uo.GetBotUserStockOptionInrByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v OptionInrClosingOrder.GetBotUserStockOptionInrByUserIdAndStockId:%v", common.ErrOptionInr, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(userStockFIdr.UsableNum) // 用户非可用资金 + frozenNo = decimal.RequireFromString(userStockFIdr.FrozenNum) // 用户非冻结资金 + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + applogger.Debug("平仓价格:%v", price) + } + costClosePrice, err := Uo.CalculateHandlingFeesOption(ctx, session, int(userId), flags.OptionInrMarketType, flags.ClosingBrokType, orderId, price, order.OrderNumber) + if err != nil { + applogger.Error("%v OptionInrClosingOrder.CalculateHandlingFeesOption:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + closePrice := decimal.RequireFromString(price) // 期权-平仓价格 + closeServiceCost := decimal.RequireFromString(costClosePrice) // 期权-平仓手续费 + resultPrice := GetOptionInrFloatingPL(order, openPrice, closePrice, orderNumber) // 期权-浮动盈亏 + if !flags.CheckSetting { + applogger.Debug("平仓手续费手续费:%v", closeServiceCost) + applogger.Debug("平仓浮动盈亏:%v", resultPrice) + } + + // TODO: 判定亏损不能超过 = 保证金 + 平仓手续费 + if resultPrice.IsNegative() { + amountLoss := marketMoney.Sub(closeServiceCost) + if resultPrice.Abs().Cmp(amountLoss) >= 0 { + resultPrice = amountLoss.Neg() + } + } + + var usableNew, frozenNew, usableNewNo, frozenNewNo decimal.Decimal + usableNew = usable.Add(resultPrice).Add(marketMoney).Sub(closeServiceCost) // 可用资产 = 原可用资产 + ((正负)盈亏) + 开仓订单金额 - 平仓手续费 + if frozen.Cmp(marketMoney) == -1 { + frozenNew = frozen.Sub(frozen) // 冻结资产 + } else { + frozenNew = frozen.Sub(marketMoney) // 冻结资产 + } + if order.StockId != flags.OptionInrBasicUnit { + usableNewNo = usableNo.Sub(orderNumber) // 可用非资产 = 原可用非资产 - 下单股数 + frozenNewNo = frozenNo // 可用非冻结资产 + } + // 检查用户订单平仓资产 + if frozenNew.IsNegative() || usableNewNo.IsNegative() { + return flags.ErrShareTow + } + if !flags.CheckSetting { + applogger.Debug("可用资产:%v", usableNew) + applogger.Debug("冻结资产:%v", frozenNew) + applogger.Debug("可用非资产:%v", usableNewNo) + applogger.Debug("冻结非资产:%v", frozenNewNo) + } + // 平仓(处理资产表(资产)) + userStockIDR := orders.UpdateBotUserStockOptionInr(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockOptionInrByUserIdAndStockId(session, userId, flags.OptionInrBasicUnit, userStockIDR); err != nil { + applogger.Error("%v OptionInrClosingOrder.UpdateBotUserStockOptionInrByUserIdAndStockId:%v", common.ErrOptionInr, err) + return flags.ErrMySqlDB + } + // 平仓(处理资产表(非资产)) + if order.StockId != flags.OptionInrBasicUnit { + userStockFIDR := orders.UpdateBotUserStockOptionInr(ctx, usableNewNo.String(), frozenNewNo.String()) + if err = Uo.UpdateBotUserStockOptionInrByUserIdAndStockId(session, userId, order.StockId, userStockFIDR); err != nil { + applogger.Error("%v OptionInrClosingOrder.Opi.UpdateBotUserStockOptionInrByUserIdAndStockId:%v", common.ErrOptionInr, err) + return flags.ErrMySqlDB + } + } + // 平仓(处理订单信息(平仓价|平仓手续费|完成订单)) + trade := orders.UpdateCloseBotStockOptionInrTrade(ctx, price, closeServiceCost.String()) + if err = Uo.UpdateBotStockOptionInrTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v OptionInrClosingOrder.UpdateBotStockOptionInrTradeByOrderId:%v", common.ErrOptionInr, err) + return flags.ErrMySqlDB + } + // 更改交易日志记录方式 + var list []models.BotUserStockOptionInrLog + qData1 := orders.CreatBotUserStockOptionInrLog(ctx, userId, flags.Thaw, flags.OptionInrBasicUnit, marketMoney.String(), orderId) // 平仓(资金变动明细表(开仓保证金)) + qData2 := orders.CreatBotUserStockOptionInrLog(ctx, userId, flags.CostMoney, flags.OptionInrBasicUnit, NegativeValue(closeServiceCost.String()), orderId) // 平仓(资金变动明细表(平仓手续费)) + qData3 := orders.CreatBotUserStockOptionInrLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData1, qData2, qData3) + // 平仓(资金变动明细表(正负盈亏)) + if resultPrice.IsNegative() { + if resultPrice.Abs().Cmp(marketMoney) >= 0 { + resultPrice = marketMoney.Neg() + } + qData4 := orders.CreatBotUserStockOptionInrLog(ctx, userId, flags.TransferOut, flags.OptionInrBasicUnit, resultPrice.String(), orderId) + list = append(list, qData4) + } else { + qData5 := orders.CreatBotUserStockOptionInrLog(ctx, userId, flags.ChangeInto, flags.OptionInrBasicUnit, resultPrice.String(), orderId) + list = append(list, qData5) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockOptionInrLogList(session, list); err != nil { + applogger.Error("%v OptionInrClosingOrder.CreatBotUserStockOptionInrLogList:%v", common.ErrOptionInr, err) + return flags.ErrMySqlDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v OptionInrClosingOrder.Commit:%v", common.ErrOptionInr, err) + return flags.ErrMySqlDB + } + + return nil +} + +// UpdateBotStockOptionInrCancelByOrderId +// +// @Description: 期权-印度股撤单 +// @param ctx +// @param db +// @param orderId +// @return bool +// @return error +func UpdateBotStockOptionInrCancelByOrderId(ctx context.Context, db *xorm.EngineGroup, orderId string) (bool, error) { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.Begin:%v", common.ErrOptionInr, err) + return false, flags.ErrMySqlDB + } + // 订单信息 + stockTrade, err := Uo.GetBotStockOptionInrTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.GetBotStockOptionInrTradeByOrderId:%v", common.ErrOptionInr, err) + return false, flags.ErrMySqlDB + } + userId := int64(stockTrade.UserId) // 用户Id + stockId := stockTrade.StockId // 订单仓位量 + marketMoneyOld := decimal.RequireFromString(stockTrade.MarketMoney) // 订单保证金 + serviceCostOld := decimal.RequireFromString(stockTrade.ServiceCost) // 订单手续费 + orderNumber := decimal.RequireFromString(stockTrade.OrderNumber) // 订单仓位量 + // 用户资产信息 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockIdr, err := Uo.GetBotUserStockOptionInrByUserIdAndStockId(session, userId, flags.OptionInrBasicUnit) + if err != nil || stockIdr == nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.GetBotUserStockOptionInrByUserIdAndStockId:%v", common.ErrOptionInr, err) + return false, flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockIdr.UsableNum) // 用户账户可用资产 + frozen = decimal.RequireFromString(stockIdr.FrozenNum) // 用户账户冻结资产 + // 检查用户订单撤单资产 + if usable.IsNegative() || frozen.IsNegative() { + return false, flags.ErrShareThree + } + if stockId != flags.OptionInrBasicUnit { + stockFUsd, err := Uo.GetBotUserStockOptionInrByUserIdAndStockId(session, userId, stockId) + if err != nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.GetBotUserStockOptionInrByUserIdAndStockId:%v", common.ErrOptionInr, err) + return false, flags.ErrPublicFour + } + usableNo = decimal.RequireFromString(stockFUsd.UsableNum) // 用户非账户可用资产 + frozenNo = decimal.RequireFromString(stockFUsd.FrozenNum) // 用户非账户冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("用户原始可用资金:%v", usable) + applogger.Debug("用户原始冻结资金:%v", frozen) + applogger.Debug("用户原始可用非资金:%v", usableNo) + applogger.Debug("用户原始冻结非资金:%v", frozenNo) + } + // 更新订单信息 + botStockTrade := orders.BotStockOptionInrCancelByOrderId(ctx) + if err = Uo.UpdateBotStockOptionInrTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.UpdateBotStockOptionInrTradeByOrderId:%v", common.ErrOptionInr, err) + return false, flags.ErrMySqlDB + } + totalMoney := marketMoneyOld.Add(serviceCostOld) // 用户订单总金额 + usableNew := usable.Add(totalMoney) // 用户总资产 + frozenNew := frozen.Sub(totalMoney) // 用户冻结资产 + usableNoNew := usableNo.Sub(orderNumber) // 用户非可用资产 + frozenNoNew := frozenNo // 用户非冻结资产 + // 检查用户订单撤单资产 + if frozenNew.IsNegative() || usableNoNew.IsNegative() { + return false, flags.ErrShareThree + } + if !flags.CheckSetting { + applogger.Debug("用户撤单可用总资产:%v", usableNew) + applogger.Debug("用户撤单冻结总资产:%v", frozenNew) + applogger.Debug("用户非撤单可用总资产:%v", usableNoNew) + applogger.Debug("用户非撤单冻结总资产:%v", frozenNoNew) + } + // 更新资产信息和非资产信息 + userOptionInr := orders.UpdateBotUserStockOptionInr(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockOptionInrByUserIdAndStockId(session, userId, flags.OptionInrBasicUnit, userOptionInr); err != nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.OptionInrBasicUnit:%v", common.ErrOptionInr, err) + return false, flags.ErrMySqlDB + } + if stockId != flags.OptionInrBasicUnit { + userStockFIdn := orders.UpdateBotUserStockOptionInr(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = Uo.UpdateBotUserStockOptionInrByUserIdAndStockId(session, userId, stockId, userStockFIdn); err != nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.Opi.UpdateBotUserStockOptionInrByUserIdAndStockId:%v", common.ErrOptionInr, err) + return false, flags.ErrMySqlDB + } + } + // 删除订单缓存列表 + if err = Reds.HDel(context.Background(), setting.MarketOptionInrEntrust, orderId).Err(); err != nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.HDel:%v", common.ErrOptionInr, err) + return false, flags.ErrCacheDB + } + // 更新用户订阅订单缓存列表 + userSubKey := virtual.OrderIdListKey(setting.OptionInrSubscribe, userId) + if err = option.UpdateOptionInrHashByOrderId(Reds, orderId, userSubKey, flags.Cancel); err != nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.UpdateOptionInrHashByOrderId:%v", common.ErrOptionInr, err) + return false, flags.ErrCacheDB + } + // 更新管理员订阅订单缓存列表 + if err = UpdateOptionInrSubscribeHashStatusByOrderId(orderId, setting.AdminOptionInrSubscribe, flags.Cancel, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.AdminOptionInrSubscribe:%v", common.ErrOptionInr, err) + return false, flags.ErrCacheDB + } + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.Commit:%v", common.ErrOptionInr, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockOptionInrCancelByOrderId +// +// @Description: 期权-印度股撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockOptionInrCancelByOrderId(ctx context.Context, orderId string) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.Begin:%v", common.ErrOptionInr, err) + return false, flags.ErrMySqlDB + } + // 订单信息 + stockTrade, err := uo.GetBotStockOptionInrTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.GetBotStockOptionInrTradeByOrderId:%v", common.ErrOptionInr, err) + return false, flags.ErrMySqlDB + } + userId := int64(stockTrade.UserId) // 用户Id + stockId := stockTrade.StockId // 订单交易对 + marketMoneyOld := decimal.RequireFromString(stockTrade.MarketMoney) // 订单保证金 + serviceCostOld := decimal.RequireFromString(stockTrade.ServiceCost) // 订单手续费 + orderNumber := decimal.RequireFromString(stockTrade.OrderNumber) // 订单仓位量 + // 用户资产信息 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockIdr, err := uo.GetBotUserStockOptionInrByUserIdAndStockId(session, userId, flags.OptionInrBasicUnit) + if err != nil || stockIdr == nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.GetBotUserStockOptionInrByUserIdAndStockId:%v", common.ErrOptionInr, err) + return false, flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockIdr.UsableNum) // 用户账户可用资产 + frozen = decimal.RequireFromString(stockIdr.FrozenNum) // 用户账户冻结资产 + // 检查用户订单撤单资产 + if usable.IsNegative() || frozen.IsNegative() { + return false, flags.ErrShareThree + } + if stockId != flags.OptionInrBasicUnit { + stockFUsd, err := uo.GetBotUserStockOptionInrByUserIdAndStockId(session, userId, stockId) + if err != nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.GetBotUserStockOptionInrByUserIdAndStockId:%v", common.ErrOptionInr, err) + return false, flags.ErrPublicFour + } + usableNo = decimal.RequireFromString(stockFUsd.UsableNum) // 用户非账户可用资产 + frozenNo = decimal.RequireFromString(stockFUsd.FrozenNum) // 用户非账户冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("用户原始可用资金:%v", usable) + applogger.Debug("用户原始冻结资金:%v", frozen) + applogger.Debug("用户原始可用非资金:%v", usableNo) + applogger.Debug("用户原始冻结非资金:%v", frozenNo) + } + // 更新订单信息 + botStockTrade := orders.BotStockOptionInrCancelByOrderId(ctx) + if err = uo.UpdateBotStockOptionInrTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.UpdateBotStockOptionInrTradeByOrderId:%v", common.ErrOptionInr, err) + return false, flags.ErrMySqlDB + } + // Operational Spot Asset Table + totalMoney := marketMoneyOld.Add(serviceCostOld) // 订单总金额 + // update total asset data + usableNew := usable.Add(totalMoney) // 用户总资产 + frozenNew := frozen.Sub(totalMoney) // 用户冻结资产 + usableNoNew := usableNo.Sub(orderNumber) // 用户非可用资产 + frozenNoNew := frozenNo // 用户非冻结资产 + // 检查用户订单撤单资产 + if frozenNew.IsNegative() || usableNoNew.IsNegative() { + return false, flags.ErrShareThree + } + if !flags.CheckSetting { + applogger.Debug("用户撤单可用总资产:%v", usableNew) + applogger.Debug("用户撤单冻结总资产:%v", frozenNew) + applogger.Debug("用户非撤单可用总资产:%v", usableNoNew) + applogger.Debug("用户非撤单冻结总资产:%v", frozenNoNew) + } + // 更新资产信息和非资产信息 + userOptionInr := orders.UpdateBotUserStockOptionInr(ctx, usableNew.String(), frozenNew.String()) + if err = uo.UpdateBotUserStockOptionInrByUserIdAndStockId(session, userId, flags.OptionInrBasicUnit, userOptionInr); err != nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.OptionInrBasicUnit:%v", common.ErrOptionInr, err) + return false, flags.ErrMySqlDB + } + if stockId != flags.OptionInrBasicUnit { + userStockFIdn := orders.UpdateBotUserStockOptionInr(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = uo.UpdateBotUserStockOptionInrByUserIdAndStockId(session, userId, stockId, userStockFIdn); err != nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.Opi.UpdateBotUserStockOptionInrByUserIdAndStockId:%v", common.ErrOptionInr, err) + return false, flags.ErrMySqlDB + } + } + // 删除订单缓存列表 + if err = Reds.HDel(context.Background(), setting.MarketOptionInrEntrust, orderId).Err(); err != nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.HDel:%v", common.ErrOptionInr, err) + return false, flags.ErrCacheDB + } + // 更新用户订阅订单缓存列表 + userSubKey := virtual.OrderIdListKey(setting.OptionInrSubscribe, userId) + if err = option.UpdateOptionInrHashByOrderId(Reds, orderId, userSubKey, flags.Cancel); err != nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.UpdateOptionInrHashByOrderId:%v", common.ErrOptionInr, err) + return false, flags.ErrCacheDB + } + // 更新管理员订阅订单缓存列表 + if err = UpdateOptionInrSubscribeHashStatusByOrderId(orderId, setting.AdminOptionInrSubscribe, flags.Cancel, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.AdminOptionInrSubscribe:%v", common.ErrOptionInr, err) + return false, flags.ErrCacheDB + } + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockOptionInrCancelByOrderId.Commit:%v", common.ErrOptionInr, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockOptionInrStopByOrderId +// +// @Description: 期权-印度股设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockOptionInrStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockOptionInrStopByOrderId.NewSession:%v", common.ErrOptionInr, err) + return false, flags.ErrMySqlDB + } + + // 设置止盈止损 + var userId int64 + if order.StopType == 1 { + trade, err := uo.GetBotStockOptionInrTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockOptionInrStopByOrderId.GetBotStockOptionInrTradeByOrderIdOrStatus:%v", common.ErrOptionInr, err) + return false, flags.ErrShareFour + } + // 下单信息 + checkBool, stopWinPrice, stopLossPrice, err := uo.UpdateVoteStopType(order) + if err != nil { + applogger.Error("%v UpdateBotStockOptionInrStopByOrderId.UpdateVoteStopType:%v", common.ErrOptionInr, err) + return false, err + } + if !flags.CheckSetting { + applogger.Debug("当前止盈止损数据:%v,%v,%v", checkBool, stopWinPrice, stopLossPrice) + } + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err := uo.UpdateOptionInrVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockOptionInrStopByOrderId.UpdateOptionInrVoteDealType:%v", common.ErrOptionInr, err) + return false, err + } + if !flags.CheckSetting { + applogger.Debug("当前开仓价格:%v", limitOrMarketPrice) + } + // 下单判定设置(买涨|买跌) + bid := decimal.RequireFromString(trade.Bid) + ask := decimal.RequireFromString(trade.Ask) + userId = int64(trade.UserId) + if err = uo.VoteTradeTypeOption(int64(trade.DealType), int64(trade.TradeType), int64(trade.TradingType), stopWinPrice, stopLossPrice, limitOrMarketPrice, bid, ask, checkBool); err != nil { + applogger.Error("%v UpdateBotStockOptionInrStopByOrderId.VoteTradeType:%v", common.ErrOptionInr, err) + return false, err + } + } else { + order.StopLossPrice = decimal.Zero.String() + order.StopWinPrice = decimal.Zero.String() + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[userId] + if ok { + return false, flags.ErrPublicServe + } + + // 更新订单表 + botStockIdnTrade := orders.BotStockOptionInrStopByOrderId(ctx, order) + if err = uo.UpdateBotStockOptionInrTradeByOrderId(session, order.OrderId, botStockIdnTrade); err != nil { + applogger.Error("%v UpdateBotStockOptionInrStopByOrderId.UpdateBotStockOptionInrTradeByOrderId:%v", common.ErrOptionInr, err) + return false, flags.ErrMySqlDB + } + + // 修改挂单缓存队列 + if err = option.UpdateOptionInrStopByOrderId(Reds, order, setting.MarketOptionInrPosition, flags.Position); err != nil { + applogger.Error("%v UpdateBotStockOptionInrStopByOrderId.UpdateOptionInrStopByOrderId:%v", common.ErrOptionInr, err) + return false, flags.ErrCacheDB + } + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockOptionInrStopByOrderId.Commit:%v", common.ErrOptionInr, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockOptionInrClosingByOrderId +// +// @Description: 期权-印度股用户平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockOptionInrClosingByOrderId(ctx context.Context, orderId string) (bool, error) { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.OpiMarket) { + return false, flags.ErrStopTread + } + // 1、查询持仓缓存列表数据并清理对应缓存 + var entrustCache *option.OptionInrTallyCache + entrust, err := Reds.HGet(context.Background(), setting.MarketOptionInrPosition, orderId).Result() + if err != nil { + applogger.Error("%v UpdateBotStockOptionInrClosingByOrderId.HGet:%v", common.ErrOptionInr, err) + return false, flags.ErrShareFive + } + var entrustJson option.OptionInrTallyCache + if err = json.Unmarshal([]byte(entrust), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockOptionInrClosingByOrderId.Unmarshal:%v", common.ErrOptionInr, err) + return false, flags.ErrCacheDB + } + if orderId == entrustJson.OrderId { + entrustCache = &entrustJson + } + if entrustCache == nil { + return false, flags.ErrShareFive + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[entrustJson.UserId] + if isOk { + return false, flags.ErrPublicServe + } + + // 2、获取当前最新价格 + var closingPrice decimal.Decimal + closingPrice, err = uo.GetOptionInrTheLatestPrice(entrustJson) + if err != nil || closingPrice.IsZero() { + applogger.Error("%v UpdateBotStockOptionInrClosingByOrderId.GetOptionInrTheLatestPrice:%v", common.ErrOptionInr, err) + return false, flags.ErrStopTread + } + // 3、平仓处理 + if err = OptionInrClosingOrder(ctx, Msql, orderId, closingPrice.String(), entrustCache.Order); err != nil { + applogger.Error("%v UpdateBotStockOptionInrClosingByOrderId.OptionInrClosingOrder:%v", common.ErrOptionInr, err) + return false, err + } + // 4、清理持仓订单信息 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), setting.MarketOptionInrPosition, orderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockOptionInrClosingByOrderId.HDel:%v", common.ErrOptionInr, err) + return false, flags.ErrCacheDB + } + // 5、平仓更新订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(setting.OptionInrSubscribe, entrustCache.UserId) + if err = UpdateOptionInrSubscribeHashStatusByOrderId(orderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockOptionInrClosingByOrderId.OptionInrSubscribe:%v", common.ErrOptionInr, err) + return false, flags.ErrCacheDB + } + // 6、平仓更新管理订阅缓存订单状态 + if err = UpdateOptionInrSubscribeHashStatusByOrderId(orderId, setting.AdminOptionInrSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockOptionInrClosingByOrderId.AdminOptionInrSubscribe:%v", common.ErrOptionInr, err) + return false, flags.ErrCacheDB + } + + return true, nil +} + +// UpdateBotStockOptionInrAllClosingByOrderId +// +// @Description: 期权-印度股用户一键平仓 +// @receiver uo +// @param ctx +// @param userId +// @return error +func (uo *userOrderRepo) UpdateBotStockOptionInrAllClosingByOrderId(ctx context.Context, userId int64) error { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.OpiMarket) { + return flags.ErrStopTread + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe + } + + // 1、查询当前用户所有订单 + orderMap, err := uo.GetBotStockOptionInrTradeByUserId(userId) + if err != nil { + applogger.Error("%v UpdateBotStockOptionInrAllClosingByOrderId.GetBotStockOptionInrTradeByUserId:%v", common.ErrOptionInr, err) + return flags.ErrMySqlDB + } + // 2、查询持仓缓存列表数据-1、清理持仓列表缓存 2、处理平仓数据 3、清理订单ID缓存列表 + entrust, err := Reds.HGetAll(context.Background(), setting.MarketOptionInrPosition).Result() + if err != nil { + applogger.Error("%v UpdateBotStockOptionInrAllClosingByOrderId.HGetAll:%v", common.ErrOptionInr, err) + return flags.ErrShareFive + } + // 3、循环检查股票交易对最新价格(有一个查询不到既不能平仓) + var entrustList []option.OptionInrTallyCache + closePriceMap := make(map[string]decimal.Decimal) + for key, value := range entrust { + var entrustJson option.OptionInrTallyCache + if err = json.Unmarshal([]byte(value), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockOptionInrAllClosingByOrderId.Unmarshal:%v", common.ErrOptionInr, err) + return flags.ErrStopTread + } + _, ok := orderMap[entrustJson.OrderId] + if ok { + var closingPrice decimal.Decimal + closingPrice, err = uo.GetOptionInrTheLatestPrice(entrustJson) + if err != nil || closingPrice.IsZero() { + applogger.Error("%v UpdateBotStockOptionInrAllClosingByOrderId.GetOptionInrTheLatestPrice:%v", common.ErrOptionInr, err) + return flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("订阅Key:%v,最新价格:%v,订单ID:%v", entrustJson.Symbol, closingPrice, entrustJson.OrderId) + } + closePriceMap[key] = closingPrice + entrustList = append(entrustList, entrustJson) + } + } + // 4、股票一键平仓 + for _, value := range entrustList { + closePrice, ok := closePriceMap[value.OrderId] + if ok { + // 平仓 + if err = OptionInrClosingOrder(ctx, uo.data.mysqlDB, value.OrderId, closePrice.String(), value.Order); err != nil { + applogger.Error("%v UpdateBotStockOptionInrAllClosingByOrderId.OptionInrClosingOrder:%v", common.ErrOptionInr, err) + return err + } + // 清理持仓缓存列表 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), setting.MarketOptionInrPosition, value.OrderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockOptionInrAllClosingByOrderId.HDel:%v", common.ErrOptionInr, err) + return flags.ErrCacheDB + } + // 平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.OptionInrSubscribe, value.UserId) + if err = UpdateOptionInrSubscribeHashStatusByOrderId(value.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockOptionInrAllClosingByOrderId.OptionInrSubscribe:%v", common.ErrOptionInr, err) + return flags.ErrCacheDB + } + // 平仓更新管理员订阅订单状态 + if err = UpdateOptionInrSubscribeHashStatusByOrderId(value.OrderId, setting.AdminOptionInrSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockOptionInrAllClosingByOrderId.AdminShareInrSubscribe:%v", common.ErrOptionInr, err) + return flags.ErrCacheDB + } + } + } + + return nil +} + +// GetBotStockOptionInrTradeByUserId +// +// @Description: +// @receiver uo +// @param ctx +// @param userId +// @return map[string]string +// @return error +func (uo *userOrderRepo) GetBotStockOptionInrTradeByUserId(userId int64) (map[string]string, error) { + var botStockOptionInrTrade []models.BotStockOptionInrTrade + if err := uo.data.mysqlDB.Table(flags.BotStockOptionInrTrade). + Where("user_id = ?", userId). + Where("status = 1"). + Find(&botStockOptionInrTrade); err != nil { + return nil, err + } + + botMap := make(map[string]string) + for _, value := range botStockOptionInrTrade { + botMap[value.OrderId] = value.OrderId + } + + return botMap, nil +} + +// GetOptionInrTheLatestPrice +// +// @Description: +// @receiver uo +// @param subKey +// @param tradeType +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) GetOptionInrTheLatestPrice(order option.OptionInrTallyCache) (decimal.Decimal, error) { + closePrice := decimal.Zero + _, bid, ask, err := GetOptionInrPrice(order.Order.StockCode) + if err != nil { + return closePrice, err + } + + // 平仓 + // buy-call 和 buy-put 平仓价格以买一价(bid)成交 + // sell-call 和 sell-put 平仓价以卖一价(ask)成交 + switch order.Order.TradeType { + case flags.OptionCalls: // call + switch order.Order.TradingType { + case flags.OptionBuy: // call - buy + if !bid.IsZero() { + closePrice = bid + } + case flags.OptionSell: // call - sell + if !ask.IsZero() { + closePrice = ask + } + default: + + } + case flags.OptionPuts: // put + switch order.Order.TradingType { + case flags.OptionBuy: // put - buy + if !bid.IsZero() { + closePrice = bid + } + case flags.OptionSell: // put - sell + if !ask.IsZero() { + closePrice = ask + } + default: + + } + } + + return closePrice, nil +} + +// GetBotStockOptionInrTradeByOrderId +// +// @Description: +// @receiver uo +// @param session +// @param orderId +// @return *models.BotStockOptionInrTrade +// @return error +func (uo *userOrderRepo) GetBotStockOptionInrTradeByOrderId(session *xorm.Session, orderId string) (*models.BotStockOptionInrTrade, error) { + var botStockOptionInrTrade []models.BotStockOptionInrTrade + if err := session.Table(flags.BotStockOptionInrTrade). + Where("order_id = ?", orderId). + Find(&botStockOptionInrTrade); err != nil { + return nil, err + } + + for _, value := range botStockOptionInrTrade { + return &value, nil + } + + return nil, nil +} + +// GetBotUserStockOptionInrByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param session +// @param userId +// @param stockId +// @return *models.BotUserStockOptionInr +// @return error +func (uo *userOrderRepo) GetBotUserStockOptionInrByUserIdAndStockId(session *xorm.Session, userId int64, stockId string) (*models.BotUserStockOptionInr, error) { + var stockOptionInr []models.BotUserStockOptionInr + if err := session.Table(flags.BotUserStockOptionInr). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&stockOptionInr); err != nil || len(stockOptionInr) <= 0 { + return nil, err + } + + for _, value := range stockOptionInr { + return &value, nil + } + + return nil, nil +} + +// UpdateBotStockOptionInrTradeByOrderId +// +// @Description: +// @receiver uo +// @param session +// @param orderId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotStockOptionInrTradeByOrderId(session *xorm.Session, orderId string, stock models.BotStockOptionInrTrade) error { + checkInt, err := session.Table(flags.BotStockOptionInrTrade). + Where("order_id = ?", orderId). + Update(&stock) + if err != nil || checkInt < 0 { + return err + } + + return nil +} + +// CreateBotStockOptionInrTrade +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param trade +// @return error +func (uo *userOrderRepo) CreateBotStockOptionInrTrade(session *xorm.Session, trade models.BotStockOptionInrTrade) error { + _, err := session.Table(flags.BotStockOptionInrTrade).Insert(&trade) + if err != nil { + return err + } + + return nil +} + +// CreateBotUserStockOptionInrFIRD +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param stock +// @return error +func (uo *userOrderRepo) CreateBotUserStockOptionInrFIRD(session *xorm.Session, stock models.BotUserStockOptionInr) error { + _, err := session.Table(flags.BotUserStockOptionInr).Insert(&stock) + if err != nil { + return err + } + + return nil +} + +// UpdateBotUserStockOptionInrByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param session +// @param userId +// @param stockId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotUserStockOptionInrByUserIdAndStockId(session *xorm.Session, userId int64, stockId string, stock models.BotUserStockOptionInr) error { + checkNum, err := session.Table(flags.BotUserStockOptionInr). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&stock) + if err != nil || checkNum < 0 { + return err + } + + return nil +} + +// OptionInrVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) OptionInrVoteDealType(order structure.ShareOrder) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + return limitOrMarketPrice, nil +} + +// UpdateOptionInrVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) UpdateOptionInrVoteDealType(order *models.BotStockOptionInrTrade) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + if len(order.DealPrice) != 0 { + dealPrice := decimal.RequireFromString(order.DealPrice) + if !dealPrice.IsZero() { + limitOrMarketPrice = dealPrice + } + } + + return limitOrMarketPrice, nil +} + +// VerifyBotStockOptionInrTradeOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @return string +// @return error +func (uo *userOrderRepo) VerifyBotStockOptionInrTradeOrderId(session *xorm.Session) (string, error) { + var orderId string + for { + // 生成订单ID + orderId = orders.CreateRandCodeOrder(10) + + var orderList []models.BotStockOptionInrTrade + err := session.Table(flags.BotStockOptionInrTrade). + Where("order_id = ?", orderId). + Find(&orderList) + if err != nil || len(orderList) > 0 { + applogger.Warn("%v VerifyBotStockOptionInrTradeOrderId.Find:%v", common.ErrOptionInr, err) + continue + } + + break + } + + return orderId, nil +} + +// GetBotStockOptionInrTradeByOrderIdOrStatus +// +// @Description: +// @receiver uo +// @param session +// @param orderId +// @param status +// @return *models.BotStockOptionInrTrade +// @return error +func (uo *userOrderRepo) GetBotStockOptionInrTradeByOrderIdOrStatus(session *xorm.Session, orderId string, status int) (*models.BotStockOptionInrTrade, error) { + var botStockOptionInrTrade []models.BotStockOptionInrTrade + if err := session.Table(flags.BotStockOptionInrTrade). + Where("order_id = ?", orderId). + Where("`status` = ?", status). + Find(&botStockOptionInrTrade); err != nil { + return nil, err + } + + for _, value := range botStockOptionInrTrade { + return &value, nil + } + + return nil, nil +} diff --git a/internal/data/order_share_blk.go b/internal/data/order_share_blk.go new file mode 100644 index 0000000..502e59a --- /dev/null +++ b/internal/data/order_share_blk.go @@ -0,0 +1,90 @@ +package data + +import ( + "context" + "matchmaking-system/internal/pkg/flags" + models "matchmaking-system/internal/pkg/model" +) + +// GetBotStockBlockTradeList +// +// @Description: 大宗交易股订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param userId +// @param status +// @return []*models.BotStockBlockTrade +// @return int64 +// @return error +func (uo *userOrderRepo) GetBotStockBlockTradeList(ctx context.Context, pageSize, pageCount, userId, typeStatus, status int64) ([]*models.BotStockBlockTrade, int64, error) { + totalCount, err := uo.data.mysqlDB.Table(flags.BotStockBlockTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Where("type = ?", typeStatus). + Count() + if err != nil { + return nil, 0, flags.ErrMySqlDB + } + if totalCount == 0 { + return nil, 0, nil + } + var stockList []*models.BotStockBlockTrade + if err = uo.data.mysqlDB.Table(flags.BotStockBlockTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Where("type = ?", typeStatus). + Limit(int(pageSize), int(pageCount)). + Desc(GetOrderByStatusSort(status)). + Find(&stockList); err != nil { + return nil, 0, flags.ErrMySqlDB + } + + // 市场类型:3美股、4印尼股、5马股、6泰股、7印度股、9新加坡股、12港股 + var stockUpdateList []*models.BotStockBlockTrade + for _, value := range stockList { + switch value.Type { + case flags.ShareUsMarketType: // 美股 + value.KeepDecimal = GetKeepDecimal(flags.StockUsSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockUsSystemSetUpKey, value.StockId) + case flags.ShareThaMarketType: // 泰股 + value.KeepDecimal = GetKeepDecimal(flags.StockTGSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockTGSystemSetUpKey, value.StockId) + case flags.ShareMysMarketType: // 马股 + value.KeepDecimal = GetKeepDecimal(flags.StockMGSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockMGSystemSetUpKey, value.StockId) + case flags.ShareIdnMarketType: // 印尼股 + value.KeepDecimal = GetKeepDecimal(flags.StockYNSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockYNSystemSetUpKey, value.StockId) + case flags.ShareInrMarketType: // 印度股 + value.KeepDecimal = GetKeepDecimal(flags.StockYDSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockYDSystemSetUpKey, value.StockId) + case flags.ShareSgdMarketType: // 新加坡股 + value.KeepDecimal = GetKeepDecimal(flags.StockSGDSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockSGDSystemSetUpKey, value.StockId) + case flags.ShareHkdMarketType: // 港股 + value.KeepDecimal = GetKeepDecimal(flags.StockHKDSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockHKDSystemSetUpKey, value.StockId) + case flags.ShareGbxMarketType: // 英股 + value.KeepDecimal = GetKeepDecimal(flags.StockUkSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockUkSystemSetUpKey, value.StockId) + case flags.ShareEurMarketType: // 德股 + value.KeepDecimal = GetKeepDecimal(flags.StockEURSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockEURSystemSetUpKey, value.StockId) + case flags.ShareFurMarketType: // 法股 + value.KeepDecimal = GetKeepDecimal(flags.StockFURSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockFURSystemSetUpKey, value.StockId) + case flags.ShareBrlMarketType: // 巴西股 + value.KeepDecimal = GetKeepDecimal(flags.StockBRLSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockBRLSystemSetUpKey, value.StockId) + case flags.ShareJpyMarketType: // 日本股 + value.KeepDecimal = GetKeepDecimal(flags.StockJPYSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockJPYSystemSetUpKey, value.StockId) + default: + } + stockUpdateList = append(stockUpdateList, value) + } + + return stockUpdateList, totalCount, nil +} diff --git a/internal/data/order_share_brl.go b/internal/data/order_share_brl.go new file mode 100644 index 0000000..841e11f --- /dev/null +++ b/internal/data/order_share_brl.go @@ -0,0 +1,1507 @@ +package data + +import ( + "context" + "encoding/json" + "github.com/go-xorm/xorm" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" + + orders "matchmaking-system/internal/data/convert" + models "matchmaking-system/internal/pkg/model" +) + +// GetBotStockBrlTradeList +// +// @Description: 巴西股订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param userId +// @param status +// @return []*models.BotStockBrlTrade +// @return int64 +// @return error +func (uo *userOrderRepo) GetBotStockBrlTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockBrlTrade, int64, error) { + totalCount, err := uo.data.mysqlDB.Table(flags.BotStockBrlTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Count() + if err != nil { + return nil, 0, flags.ErrMySqlDB + } + if totalCount == 0 { + return nil, 0, nil + } + var stockList []*models.BotStockBrlTrade + if err = uo.data.mysqlDB.Table(flags.BotStockBrlTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Limit(int(pageSize), int(pageCount)). + Desc(GetOrderByStatusSort(status)). + Find(&stockList); err != nil { + return nil, 0, flags.ErrMySqlDB + } + + var stockUpdateList []*models.BotStockBrlTrade + for _, value := range stockList { + value.KeepDecimal = GetKeepDecimal(flags.StockBRLSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockBRLSystemSetUpKey, value.StockId) + stockUpdateList = append(stockUpdateList, value) + } + + return stockUpdateList, totalCount, nil +} + +// PlacingStockBrlOrders +// +// @Description: 巴西股下单 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) PlacingStockBrlOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) { + // 1、通知下单订阅 + symbol := order.StockId + timeValue := QuerySystemCache(flags.ShareBrlMarketType) // 市场开闭盘时间 + if !utils.CheckInPlateTime(timeValue) { + return flags.SetNull, flags.ErrStopTread + } + SubscribeBrlHSetCodeList(symbol, false) // 同步写入股票列表缓存 + SubscribeBrlCloseNewPrice(symbol) // 同步股票实时行情价 + + // 判定是否存在欠款订单 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe.Error(), nil + } + + order = PryNumInit(order) // 杠杆初始化 + subKey := publicData.SymbolCache(flags.Brl, symbol, flags.TradeTypePrice) + + // 市场系统设置 + if CheckGlobalTread(flags.BrlMarket) { + return flags.SetNull, flags.ErrStopTread + } + + // 全局设置停止交易操作 + var blockTime time.Time + var priceNew, userKey, adminKey string + if !CheckTypeStatus(order.Type) { + userKey = setting.ShareBrlSubscribe + adminKey = setting.AdminShareBrlSubscribe + } else { + // 判定:1、是否开启股票交易 2、是否在交易时间内 3、是否达到最小交易量 + check, openPrice, minNum, endTime := CheckBlockTread(flags.BrlBlk, symbol) + if check { + return flags.SetNull, flags.ErrShareSeven + } + if minNum > utils.StringToInt(order.OrderNumber) { + return flags.SetNull, flags.ErrShareSix + } + priceNew = openPrice // 开仓价格 + blockTime = endTime // 平仓时间 + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + flatRatio := GetCacheForcedClosure(flags.StockBRLSystemSetUpKey, symbol) // 设置强平阈值 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.BrlMarket, userId) // 股票市场系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), // 强平阈值 + Status: leverStatus.Status, // 股杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + order.System = system + + // 2、股票下单判定 + // 下单判定设置(false无设置|true止盈止损) + checkBool, stopWinPrice, stopLossPrice, err := StockBrlVoteStopType(order) + if err != nil { + applogger.Error("%v PlacingStockBrlOrders.StockBrlVoteStopType:%v", common.ErrShareBrl, err) + return flags.SetNull, err + } + // 下单判定设置(限价|市价) + limitOrMarketPrice, err := uo.StockBrlVoteDealType(order) + if err != nil { + applogger.Error("%v PlacingStockBrlOrders.StockBrlVoteDealType:%v", common.ErrShareBrl, err) + return flags.SetNull, err + } + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(order.TradeType, stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v PlacingStockBrlOrders.VoteTradeType:%v", common.ErrShareBrl, err) + return flags.SetNull, err + } + + // 3、订单持久化录入(并处理资产信息) + pryNum := SystemDealWithLever(order) + orderId, err := uo.StockBrlOrderWriteDB(ctx, userId, order, limitOrMarketPrice, pryNum) + if err != nil || len(orderId) == 0 { + applogger.Error("%v PlacingStockBrlOrders.StockBrlOrderWriteDB:%v", common.ErrShareBrl, err) + return flags.SetNull, err + } + + // 4、处理订单信息 + chg := GetShareChgBrl(flags.Brl, order.StockId) // 涨跌幅标识值 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.BrlMarket, time.Now()) // 开盘时间 + marketStatus, shareOrder, err := share.ShareBrlCacheDeal(ctx, userId, orderId, subKey, order, chg, priceNew, closingTime, blockTime) + if err != nil || shareOrder == nil { + applogger.Error("%v PlacingStockBrlOrders.ShareBrlCacheDeal:%v", common.ErrShareBrl, err) + return flags.SetNull, err + } + // 计算保证金 = 订单价格 * 订单数量 / 杠杆 + shareOrder.Order.MarketMoney = limitOrMarketPrice.Mul(decimal.RequireFromString(order.OrderNumber)).Div(pryNum).String() + if !flags.CheckSetting { + applogger.Debug("订单ID:%v", shareOrder.OrderId) + applogger.Debug("订单交易对:%v", shareOrder.Symbol) + applogger.Debug("订单状态:%v", shareOrder.Status) + applogger.Debug("订单用户ID:%v", shareOrder.UserId) + applogger.Debug("开盘价:%v", shareOrder.OpenPrice) + applogger.Debug("收盘价:%v", shareOrder.ClosingPrice) + applogger.Debug("下单信息:%v", shareOrder.Order) + } + + // 6、股票订单(挂单|持仓)缓存列表,等待队列计算 + if err = share.ShareBrlHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v PlacingStockBrlOrders.ShareBrlHashUserOrder:%v", common.ErrShareBrl, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 7、用户订阅股票订单信息 + orderIdKey := virtual.OrderIdListKey(userKey, userId) + if err = share.ShareBrlHashUserOrder(Reds, orderIdKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockBrlOrders.%v:%v", common.ErrShareBrl, userKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 8、管理员订阅订单信息 + if err = share.ShareBrlHashUserOrder(Reds, adminKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockBrlOrders.%v:%v", common.ErrShareBrl, adminKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + return orderId, nil +} + +// StockBrlOrderWriteDB +// +// @Description: 巴西股下单操作 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) StockBrlOrderWriteDB(ctx context.Context, userId int64, order structure.ShareOrder, limitOrMarketPrice, lever decimal.Decimal) (string, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockBrlOrderWriteDB.Begin:%v", common.ErrShareBrl, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 获取当前下单用户的资产 + var usableOld, frozenOld decimal.Decimal + stockSgd, err := uo.GetBotUserStockBrlByUserIdAndStockId(session, userId, flags.ShareBrlBasicUnit) + if err != nil || stockSgd == nil { + applogger.Error("%v StockBrlOrderWriteDB.GetBotUserStockBrlByUserIdAndStockId:%v", common.ErrShareBrl, err) + return flags.SetNull, flags.ErrMySqlDB + } + usableOld = decimal.RequireFromString(stockSgd.UsableNum) + frozenOld = decimal.RequireFromString(stockSgd.FrozenNum) + + // 检查用户订单下单资产 + if usableOld.IsZero() || usableOld.IsNegative() || frozenOld.IsNegative() { + return flags.SetNull, flags.ErrShareOne + } + + // 获取当前系统下单用户的非资产 + var usableFOld, frozenFOld decimal.Decimal + stockFSGD, err := uo.GetBotUserStockBrlByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockBrlOrderWriteDB.FeiSGD:%v", common.ErrShareBrl, err) + return flags.SetNull, flags.ErrMySqlDB + } + if stockFSGD != nil { + usableFOld = decimal.RequireFromString(stockFSGD.UsableNum) + frozenFOld = decimal.RequireFromString(stockFSGD.FrozenNum) + } + if !flags.CheckSetting { + applogger.Debug("下单可用资产:%v", usableOld) + applogger.Debug("下单冻结资产:%v", frozenOld) + applogger.Debug("下单查询非资产账户:%v", stockFSGD) + applogger.Debug("下单可用非资产:%v", usableFOld) + applogger.Debug("下单冻结非资产:%v", frozenFOld) + } + + // 整理当前下单信息 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 订单手续费 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 订单数量 + marketMoney := orderNumber.Mul(limitOrMarketPrice).Div(lever) // 订单金额(杠杆下单) = 订单数量 * 交易价格 / 杠杆 + totalMoney := marketMoney.Add(serviceCost) // 订单总金额 + order.MarketMoney = marketMoney.String() // 市值金额即为保证金 + + // 检查订单ID是否存在,新增下单信息 + var orderId string + if !CheckTypeStatus(order.Type) { + orderId, err = uo.VerifyBotStockBrlTradeOrderId(session) + if err != nil { + applogger.Error("%v StockBrlOrderWriteDB.VerifyBotStockBrlTradeOrderId:%v", common.ErrShareBrl, err) + return flags.SetNull, err + } + trade := orders.BotStockBrlTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockBrlTrade(session, trade); err != nil { + applogger.Error("%v StockBrlOrderWriteDB.CreateBotStockBrlTrade:%v", common.ErrShareBrl, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + orderId, err = uo.VerifyBotStockBlockTradeOrderId(session) + if err != nil { + applogger.Error("%v StockBrlOrderWriteDB.VerifyBotStockBlockTradeOrderId:%v", common.ErrShareBrl, err) + return flags.SetNull, err + } + trade := orders.BotStockBlockTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockBlockTrade(session, trade); err != nil { + applogger.Error("%v StockBrlOrderWriteDB.CreateBotStockBlockTrade:%v", common.ErrShareBrl, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + // 下单判定 + residue := usableOld.Sub(totalMoney).Div(usableOld) + if usableOld.Cmp(totalMoney) <= 0 || residue.Cmp(utils.DecimalsStrInt()) <= 0 { + return flags.SetNull, flags.ErrPublicTow + } + + var usableNew, frozenNew, usableFNew, frozenFNew decimal.Decimal + usableNew = usableOld.Sub(totalMoney) // 可用资产 + frozenNew = frozenOld.Add(totalMoney) // 冻结资产 + if order.StockId != flags.ShareBrlBasicUnit { + usableFNew = usableFOld.Add(orderNumber) // 可用非资产 + frozenFNew = frozenFOld // 冻结非资产 + } + // 检查用户订单下单资产 + if usableNew.IsNegative() { + return flags.SetNull, flags.ErrPublicTow + } + + // 下单更新资产信息 + stockSgdModel := orders.UpdateBotUserStockBrl(ctx, usableNew.String(), frozenNew.String()) + err = uo.UpdateBotUserStockBrlByUserIdAndStockId(session, userId, flags.ShareBrlBasicUnit, stockSgdModel) + if err != nil { + applogger.Error("%v StockBrlOrderWriteDB.UpdateBotUserStockBrlByUserIdAndStockId:%v", common.ErrShareBrl, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 下单(新增|更新)非资产信息 + if stockFSGD == nil { + stockFTHBModel := orders.CreateBotUserStockBrl(ctx, userId, order.StockId, usableFNew.String(), frozenFNew.String()) + err = uo.CreateBotUserStockBrlFTHB(session, stockFTHBModel) + if err != nil { + applogger.Error("%v StockBrlOrderWriteDB.CreateBotUserStockBrlFTHB:%v", common.ErrShareBrl, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + stockFTHBModel := orders.UpdateBotUserStockBrl(ctx, usableFNew.String(), frozenFNew.String()) + err = uo.UpdateBotUserStockBrlByUserIdAndStockId(session, userId, order.StockId, stockFTHBModel) + if err != nil { + applogger.Error("%v StockBrlOrderWriteDB.UpdateBotUserStockBrlByUserIdAndStockId:%v", common.ErrShareBrl, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockBrlOrderWriteDB.Commit:%v", common.ErrShareBrl, err) + return flags.SetNull, flags.ErrMySqlDB + } + + return orderId, nil +} + +// StockBrlOpenOrder +// +// @Description: 巴西股系统开仓 +// @param ctx +// @param db +// @param userId +// @param orderId +// @param openPrice +// @param order +// @return error +func StockBrlOpenOrder(ctx context.Context, db *xorm.EngineGroup, userId int64, orderId, openPrice string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockBrlOpenOrder.NewSession:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockThb, err := Uo.GetBotUserStockBrlByUserIdAndStockId(session, userId, flags.ShareBrlBasicUnit) + if err != nil || stockThb == nil { + applogger.Error("%v StockBrlOpenOrder.GetBotUserStockBrlByUserIdAndStockId:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockThb.UsableNum) // 用户可用资产 + frozen = decimal.RequireFromString(stockThb.FrozenNum) // 用户冻结资产 + + // 检查用户订单开仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrPublicThree + } + if order.StockId != flags.ShareBrlBasicUnit { + stockFThb, err := Uo.GetBotUserStockBrlByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockBrlOpenOrder.GetBotUserStockBrlByUserIdAndStockId:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(stockFThb.UsableNum) // 用户非可用资产 + frozenNo = decimal.RequireFromString(stockFThb.FrozenNum) // 用户非冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + + // 转换股票下单信息 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 下单股数 + markerMoney := decimal.RequireFromString(order.MarketMoney) // 下单金额 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 下单手续费 + totalMoney := markerMoney.Add(serviceCost) // 下单总金额 = (下单手续费 + 下单金额) + openOrderPrice := decimal.RequireFromString(openPrice) // 开盘价格 + if !flags.CheckSetting { + applogger.Debug("下单订单数量:%v", orderNumber) + applogger.Debug("下单订单金额:%v", markerMoney) + applogger.Debug("下单订单手续费:%v", serviceCost) + applogger.Debug("下单订单总金额:%v", totalMoney) + } + + // 手续费记录 + openPriceNew := openOrderPrice.Mul(orderNumber).String() // 开仓手续费 = 开仓价格 * 股数 * 开仓手续费 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareBrlMarketType, flags.OpenBrokType, orderId, openPriceNew) + if err != nil { + applogger.Error("%v StockBrlOpenOrder.CalculateHandlingFeesShare:%v", common.ErrShareBrl, err) + return err + } + openServiceCost := decimal.RequireFromString(cost) // 开仓手续费 + openMarkerMoney := openOrderPrice.Mul(orderNumber).Div(decimal.RequireFromString(order.PryNum)) // 开仓金额 = 开仓价格 * 股数 / 杠杆 + openTotalMoney := openMarkerMoney.Add(openServiceCost) // 开仓总金额 = 开仓金额 + 开仓手续费 + floatPrice := totalMoney.Sub(openTotalMoney) // 计算容差 = 下单总额 - 开仓总额 + if !flags.CheckSetting { + applogger.Debug("开仓订单价格:%v", openOrderPrice) + applogger.Debug("开仓手续费:%v", openServiceCost) + applogger.Debug("开仓总金额:%v", openTotalMoney) + applogger.Debug("下单开仓总金额容差值:%v", floatPrice) + } + + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + usableNew = usable.Add(floatPrice) // 可用资产(处理容差值) + frozenNew = frozen.Sub(totalMoney).Add(openMarkerMoney) // 冻结资产(处理容差值)---> 当前冻结金额 = 原冻结金额 - 下单总额 + if order.StockId != flags.ShareBrlBasicUnit { + usableNoNew = usableNo // 非可用资产 + frozenNoNew = frozenNo // 非冻结资产 + } + + // 检查用户订单开仓资产 + if frozenNew.IsNegative() || usableNew.IsNegative() { + return flags.ErrPublicThree + } + if !flags.CheckSetting { + applogger.Debug("下单后用户可用资产:%v", usableNew) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + } + + // 处理资产信息 + userStockThb := orders.UpdateBotUserStockBrl(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockBrlByUserIdAndStockId(session, userId, flags.ShareBrlBasicUnit, userStockThb); err != nil { + applogger.Error("%v StockBrlOpenOrder.UpdateBotUserStockBrlByUserIdAndStockId:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + + // 更新非资产信息 + if order.StockId != flags.ShareBrlBasicUnit { + userStockFThb := orders.UpdateBotUserStockBrl(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = Uo.UpdateBotUserStockBrlByUserIdAndStockId(session, userId, order.StockId, userStockFThb); err != nil { + applogger.Error("%v StockBrlOpenOrder.UpdateBotUserStockBrlByUserIdAndStockId:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + } + + // 返佣记录|资金信息|资金详情信息 + if err = Uo.ShareBrlRebateCalculation(ctx, session, int(userId), flags.ShareBrlMarketType, flags.OpenBrokType, flags.OpenMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockBrlOpenOrder.ShareBrlRebateCalculation:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + + // 处理订单信息(成交价|仓位|开仓时间|订单总金额|手续费|持仓状态) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateOpenBotStockBrlTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarkerMoney.String()) + if err = Uo.UpdateBotStockBrlTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockBrlOpenOrder.UpdateBotStockBrlTradeByOrderId:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + var list []models.BotUserStockBrlLog + qData0 := orders.CreatBotUserStockBrlLog(ctx, userId, flags.CostMoney, flags.ShareBrlBasicUnit, NegativeValue(openServiceCost.String()), orderId) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockBrlLog(ctx, userId, flags.Freeze, flags.ShareBrlBasicUnit, NegativeValue(openMarkerMoney.String()), orderId) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockBrlLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockBrlLogList(session, list); err != nil { + applogger.Error("%v StockBrlOpenOrder.CreatBotUserStockBrlLogList:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateOpenBotStockBlockTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarkerMoney.String()) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockBrlOpenOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareBrlBasicUnit, NegativeValue(openServiceCost.String()), orderId, order.Type) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Freeze, flags.ShareBrlBasicUnit, NegativeValue(openMarkerMoney.String()), orderId, order.Type) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId, order.Type) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockBrlOpenOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockBrlOpenOrder.Commit:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + + return nil +} + +// StockBrlClosingOrder +// +// @Description: 巴西股系统平仓 +// @param ctx +// @param db +// @param orderId +// @param price +// @param order +// @return error +func StockBrlClosingOrder(ctx context.Context, db *xorm.EngineGroup, orderId string, price string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockBrlClosingOrder.NewSession:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + + // 查询订单信息 + var userId int64 + var dealPrice, orderNumber, totalAmount, serviceCost, markerMoney decimal.Decimal + if !CheckTypeStatus(order.Type) { + tread, err := Uo.GetBotStockBrlTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockBrlClosingOrder.GetBotStockBrlTradeByOrderIdOrStatus:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + markerMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓下单金额 + } else { + tread, err := Uo.GetBotStockBlockTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockBrlClosingOrder.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + markerMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓下单金额 + } + + if !flags.CheckSetting { + applogger.Debug("下单开仓用户Id:%v", userId) + applogger.Debug("下单开仓开仓价格:%v", dealPrice) + applogger.Debug("下单开仓订单数量:%v", orderNumber) + applogger.Debug("下单开仓总金额:%v", totalAmount) + applogger.Debug("下单开仓手续费:%v", serviceCost) + applogger.Debug("下单开仓开仓金额:%v", markerMoney) + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + userStockThb, err := Uo.GetBotUserStockBrlByUserIdAndStockId(session, userId, flags.ShareBrlBasicUnit) + if err != nil { + applogger.Error("%v StockBrlClosingOrder.GetBotUserStockBrlByUserIdAndStockId:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(userStockThb.UsableNum) // 用户可用资金 + frozen = decimal.RequireFromString(userStockThb.FrozenNum) // 用户非冻结资金 + + // 检查用户订单平仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrShareTow + } + + // 查询当前下单用户可用非账户和冻结金额 + if order.StockId != flags.ShareBrlBasicUnit { + userStockFThb, err := Uo.GetBotUserStockBrlByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockBrlClosingOrder.GetBotUserStockBrlByUserIdAndStockId:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(userStockFThb.UsableNum) // 用户非可用资金 + frozenNo = decimal.RequireFromString(userStockFThb.FrozenNum) // 用户非冻结资金 + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + + // 手续费处理 + closePrice := decimal.RequireFromString(price) // 平仓价格 + cloePriceCost := closePrice.Mul(orderNumber).String() // 平仓手续费 = 平仓价格 * 股数 * 手续费比例 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareBrlMarketType, flags.ClosingBrokType, orderId, cloePriceCost) + if err != nil { + applogger.Error("%v StockBrlClosingOrder.CalculateHandlingFeesShare:%v", common.ErrShareBrl, err) + return err + } + closeServiceCost := decimal.RequireFromString(cost) + if !flags.CheckSetting { + applogger.Debug("平仓价格:%v", closePrice) + applogger.Debug("平仓手续费手续费:%v", closeServiceCost) + } + + //已经实现盈亏计算公式(已平仓结算方式) + //买涨 已经实现盈亏 = (平仓成交价-开仓成交价)*股数 + //买跌 已经实现盈亏 = (开仓成交价-平仓成交价)*股数 + var usableNew, frozenNew, usableNewNo, frozenNewNo, subPrice, resultPrice decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买涨 + subPrice = closePrice.Sub(dealPrice) + resultPrice = subPrice.Mul(orderNumber) + case flags.TradeTypeSell: // 买跌 + subPrice = dealPrice.Sub(closePrice) + resultPrice = subPrice.Mul(orderNumber) + default: + + } + + // 判定亏损不能超过 = 保证金 + 平仓手续费 + if resultPrice.IsNegative() { + amountLoss := markerMoney.Sub(closeServiceCost) + if resultPrice.Abs().Cmp(amountLoss) >= 0 { + resultPrice = amountLoss.Neg() + } + } + + // 用户资产账户 + usableNew = usable.Add(resultPrice).Sub(closeServiceCost).Add(markerMoney) // 可用资产 = 原可用资产 + ((正负)盈亏) - 平仓手续费 + 开仓下单金额 + if frozen.Cmp(markerMoney) == -1 { + frozenNew = frozen.Sub(frozen) // 冻结资产 + } else { + frozenNew = frozen.Sub(markerMoney) // 冻结资产 + } + + // 用户非资产账户 + if order.StockId != flags.ShareBrlBasicUnit { + usableNewNo = usableNo.Sub(orderNumber) // 可用非资产 = 原可用非资产 - 下单股数 + frozenNewNo = frozenNo // 可用非冻结资产 + } + + // 检查用户订单平仓资产 + if frozenNew.IsNegative() || usableNewNo.IsNegative() { + return flags.ErrShareTow + } + if !flags.CheckSetting { + applogger.Debug("可用资产:%v", usableNew) + applogger.Debug("冻结资产:%v", frozenNew) + applogger.Debug("可用非资产:%v", usableNewNo) + applogger.Debug("冻结非资产:%v", frozenNewNo) + } + + // 平仓(处理资产表(资产)) + userStockUTHB := orders.UpdateBotUserStockBrl(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockBrlByUserIdAndStockId(session, userId, flags.ShareBrlBasicUnit, userStockUTHB); err != nil { + applogger.Error("%v StockBrlClosingOrder.UpdateBotUserStockBrlByUserIdAndStockId:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + + // 平仓(处理资产表(非资产)) + if order.StockId != flags.ShareBrlBasicUnit { + userStockFTHB := orders.UpdateBotUserStockBrl(ctx, usableNewNo.String(), frozenNewNo.String()) + if err = Uo.UpdateBotUserStockBrlByUserIdAndStockId(session, userId, order.StockId, userStockFTHB); err != nil { + applogger.Error("%v StockBrlClosingOrder..UpdateBotUserStockBrlByUserIdAndStockId:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + } + + // 平仓(返佣记录表|资产表|资金变动表) + if err = Uo.ShareBrlRebateCalculation(ctx, session, int(userId), flags.ShareBrlMarketType, flags.ClosingBrokType, flags.CloseMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockBrlClosingOrder.ShareBrlRebateCalculation:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + + // 平仓(处理订单信息(平仓价|保证金|平仓|订单总金额|平仓手续费|完成订单)) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateCloseBotStockBrlTrade(ctx, price, cost) + if err = Uo.UpdateBotStockBrlTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockBrlClosingOrder.UpdateBotStockBrlTradeByOrderId:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockBrlLog + qData0 := orders.CreatBotUserStockBrlLog(ctx, userId, flags.Thaw, flags.ShareBrlBasicUnit, markerMoney.String(), orderId) // 平仓(资金变动明细表(开仓保证金)) + qData1 := orders.CreatBotUserStockBrlLog(ctx, userId, flags.CostMoney, flags.ShareBrlBasicUnit, NegativeValue(closeServiceCost.String()), orderId) // 平仓(资金变动明细表(-平仓手续费)) + qData2 := orders.CreatBotUserStockBrlLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockBrlLog(ctx, userId, flags.TransferOut, flags.ShareBrlBasicUnit, resultPrice.String(), orderId) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockBrlLog(ctx, userId, flags.ChangeInto, flags.ShareBrlBasicUnit, resultPrice.String(), orderId) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockBrlLogList(session, list); err != nil { + applogger.Error("%v StockBrlClosingOrder.CreatBotUserStockBrlLogList:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateCloseBotStockBlockTrade(ctx, price, cost) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockBrlClosingOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Thaw, flags.ShareBrlBasicUnit, markerMoney.String(), orderId, order.Type) // 平仓(资金变动明细表(开仓保证金)) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareBrlBasicUnit, NegativeValue(closeServiceCost.String()), orderId, order.Type) // 平仓(资金变动明细表(-平仓手续费)) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId, order.Type) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, flags.ShareBrlBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, flags.ShareBrlBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockBrlClosingOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockBrlClosingOrder.Commit:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + + return nil +} + +// UpdateBotStockBrlCancelByOrderId +// +// @Description: 巴西股撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockBrlCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockBrlCancelByOrderId.Begin:%v", common.ErrShareBrl, err) + return false, flags.ErrMySqlDB + } + + // 获取订单信息 + var userId int64 + var stockId string + var marketMoneyOld, serviceCostOld, orderNumber decimal.Decimal + if !CheckTypeStatus(typeStatus) { + stockTrade, err := uo.GetBotStockBrlTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockBrlCancelByOrderId.GetBotStockBrlTradeByOrderId:%v", common.ErrShareBrl, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } else { + stockTrade, err := uo.GetBotStockBlockTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockBrlCancelByOrderId.GetBotStockBlockTradeByOrderId:%v", common.ErrShareBrl, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } + + // 用户资产信息 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockThb, err := uo.GetBotUserStockBrlByUserIdAndStockId(session, userId, flags.ShareBrlBasicUnit) + if err != nil || stockThb == nil { + applogger.Error("%v UpdateBotStockBrlCancelByOrderId.GetBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareBrl, err) + return false, flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockThb.UsableNum) // 用户账户可用资产 + frozen = decimal.RequireFromString(stockThb.FrozenNum) // 用户账户冻结资产 + + // 检查用户订单撤单资产 + if usable.IsNegative() || frozen.IsNegative() { + return false, flags.ErrShareNine + } + if stockId != flags.ShareBrlBasicUnit { + stockFThb, err := uo.GetBotUserStockBrlByUserIdAndStockId(session, userId, stockId) + if err != nil { + applogger.Error("%v UpdateBotStockBrlCancelByOrderId.GetBotUserStockBrlByUserIdAndStockId:%v", common.ErrShareBrl, err) + return false, flags.ErrPublicFour + } + usableNo = decimal.RequireFromString(stockFThb.UsableNum) // 用户非账户可用资产 + frozenNo = decimal.RequireFromString(stockFThb.FrozenNum) // 用户非账户冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("用户原始可用资金:%v", usable) + applogger.Debug("用户原始冻结资金:%v", frozen) + applogger.Debug("用户原始可用非资金:%v", usableNo) + applogger.Debug("用户原始冻结非资金:%v", frozenNo) + } + + // 更新订单信息 + var entrustKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + botStockTrade := orders.BotStockBrlCancelByOrderId(ctx) + if err = uo.UpdateBotStockBrlTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockBrlCancelByOrderId.UpdateBotStockBrlTradeByOrderId:%v", common.ErrShareBrl, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareBrlEntrust + userKey = setting.ShareBrlSubscribe + adminKey = setting.AdminShareBrlSubscribe + } else { + botStockTrade := orders.BotStockBlockCancelByOrderId(ctx) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockBrlCancelByOrderId.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareBrl, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareBlkEntrust + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // Operational Spot Asset Table + totalMoney := marketMoneyOld.Add(serviceCostOld) // 订单总金额 + + // update total asset data + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + usableNew = usable.Add(totalMoney) // 用户总资产 + frozenNew = frozen.Sub(totalMoney) // 用户冻结资产 + if stockId != flags.ShareBrlBasicUnit { + usableNoNew = usableNo.Sub(orderNumber) // 用户非可用资产 + frozenNoNew = frozenNo // 用户非冻结资产 + } + + // 检查用户订单撤单资产 + if frozenNew.IsNegative() || usableNoNew.IsNegative() { + return false, flags.ErrShareNine + } + if !flags.CheckSetting { + applogger.Debug("用户撤单可用总资产:%v", usableNew) + applogger.Debug("用户撤单冻结总资产:%v", frozenNew) + applogger.Debug("用户非撤单可用总资产:%v", usableNoNew) + applogger.Debug("用户非撤单冻结总资产:%v", frozenNoNew) + } + + // 更新资产信息和非资产信息 + userStockTHB := orders.UpdateBotUserStockBrl(ctx, usableNew.String(), frozenNew.String()) + if err = uo.UpdateBotUserStockBrlByUserIdAndStockId(session, userId, flags.ShareBrlBasicUnit, userStockTHB); err != nil { + applogger.Error("%v UpdateBotStockBrlCancelByOrderId.SGD.UpdateBotUserStockBrlByUserIdAndStockId:%v", common.ErrShareBrl, err) + return false, flags.ErrMySqlDB + } + if stockId != flags.ShareBrlBasicUnit { + userStockFTHB := orders.UpdateBotUserStockBrl(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = uo.UpdateBotUserStockBrlByUserIdAndStockId(session, userId, stockId, userStockFTHB); err != nil { + applogger.Error("%v UpdateBotStockBrlCancelByOrderId.UpdateBotUserStockBrlByUserIdAndStockId:%v", common.ErrShareBrl, err) + return false, flags.ErrMySqlDB + } + } + + // 删除订单缓存列表 + if err = Reds.HDel(context.Background(), entrustKey, orderId).Err(); err != nil { + applogger.Error("%v UpdateBotStockBrlCancelByOrderId.HDel:%v", common.ErrShareBrl, err) + return false, flags.ErrCacheDB + } + + // 更新用户订阅订单缓存列表 + userSubKey := virtual.OrderIdListKey(userKey, userId) + if err = share.UpdateShareBrlHashByOrderId(Reds, orderId, userSubKey, flags.Cancel); err != nil { + applogger.Error("%v UpdateBotStockBrlCancelByOrderId.%v:%v", common.ErrShareBrl, userKey, err) + return false, flags.ErrCacheDB + } + + // 更新管理员订阅订单缓存列表 + if err = UpdateShareBrlSubscribeHashStatusByOrderId(orderId, adminKey, flags.Cancel, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockBrlCancelByOrderId.%v:%v", common.ErrShareBrl, adminKey, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockBrlCancelByOrderId.Commit:%v", common.ErrShareSgd, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockBrlStopByOrderId +// +// @Description: 巴西股设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockBrlStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockBrlStopByOrderId.NewSession:%v", common.ErrShareBrl, err) + return false, flags.ErrMySqlDB + } + + // 设置止盈止损 + var userId int64 + if order.StopType == 1 { + // 下单信息 + checkBool, stopWinPrice, stopLossPrice, err := uo.UpdateVoteStopType(order) + if err != nil { + applogger.Error("%v UpdateBotStockBrlStopByOrderId.UpdateVoteStopType:%v", common.ErrShareBrl, err) + return false, err + } + if !flags.CheckSetting { + applogger.Debug("当前止盈止损数据:%v,%v,%v", checkBool, stopWinPrice, stopLossPrice) + } + + // 止盈止损判定 + var tradeType int + var limitOrMarketPrice decimal.Decimal + if !CheckTypeStatus(order.Type) { + trade, err := uo.GetBotStockBrlTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockBrlStopByOrderId.GetBotStockBrlTradeByOrderIdOrStatus:%v", common.ErrShareBrl, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareBrlVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockBrlStopByOrderId.UpdateShareBrlVoteDealType:%v", common.ErrShareBrl, err) + return false, err + } + } else { + trade, err := uo.GetBotStockBlockTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockBrlStopByOrderId.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareBrl, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareBlockVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockBrlStopByOrderId.UpdateShareBlockVoteDealType:%v", common.ErrShareBrl, err) + return false, err + } + } + if !flags.CheckSetting { + applogger.Debug("当前开仓价格:%v", limitOrMarketPrice) + } + + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(int64(tradeType), stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v UpdateBotStockBrlStopByOrderId.VoteTradeType:%v", common.ErrShareBrl, err) + return false, err + } + } else { + order.StopLossPrice = decimal.Zero.String() + order.StopWinPrice = decimal.Zero.String() + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[userId] + if ok { + return false, flags.ErrPublicServe + } + + // 更新订单表 + var positionKey string + if !CheckTypeStatus(order.Type) { + botStockTrade := orders.BotStockBrlStopByOrderId(ctx, order) + if err = uo.UpdateBotStockBrlTradeByOrderId(session, order.OrderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockBrlStopByOrderId.UpdateBotStockBrlTradeByOrderId:%v", common.ErrShareBrl, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareBrlPosition + } else { + botStockTrade := orders.BotStockBlockStopByOrderId(ctx, order) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, order.OrderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockBrlStopByOrderId.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareBrl, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareBlkPosition + } + + // 挂单缓存队列 + if err = share.UpdateShareBrlStopByOrderId(Reds, order, positionKey, flags.Position); err != nil { + applogger.Error("%v UpdateBotStockBrlStopByOrderId.UpdateShareBrlStopByOrderId:%v", common.ErrShareBrl, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockBrlStopByOrderId.Commit:%v", common.ErrShareBrl, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockBrlClosingByOrderId +// +// @Description: 巴西股用户平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockBrlClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.BrlMarket) { + return false, flags.ErrStopTread + } + + // 1、查询持仓缓存列表数据并清理对应缓存 + var positionKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + positionKey = setting.MarketShareBrlPosition + userKey = setting.ShareBrlSubscribe + adminKey = setting.AdminShareBrlSubscribe + } else { + positionKey = setting.MarketShareBlkPosition + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + var entrustCache *share.ShareBrlTallyCache + entrust, err := Reds.HGet(context.Background(), positionKey, orderId).Result() + if err != nil { + applogger.Error("%v UpdateBotStockBrlClosingByOrderId.HGet:%v", common.ErrShareBrl, err) + return false, flags.ErrShareFive + } + var entrustJson share.ShareBrlTallyCache + if err = json.Unmarshal([]byte(entrust), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockBrlClosingByOrderId.Unmarshal:%v", common.ErrShareBrl, err) + return false, flags.ErrCacheDB + } + if orderId == entrustJson.OrderId { + entrustCache = &entrustJson + } + + // 2、判定是否存在平仓订单 + if entrustCache == nil { + return false, flags.ErrShareFive + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[entrustJson.UserId] + if ok { + return false, flags.ErrPublicServe + } + + // 市场设置交易时间(T+0,T+1,T+2s......) + if !CheckShareSystemTime(entrustCache.ClosingTime) { + return false, flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("手动平仓:%v", entrustCache) + } + + // 3、当前最新价格 + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Brl, entrustCache.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareBrlTheLatestPrice(subKey, entrustCache.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockBrlClosingByOrderId.GetShareBrlTheLatestPrice:%v", common.ErrShareBrl, err) + return false, flags.ErrStopTread + } + + // 4、平仓处理 + if err = StockBrlClosingOrder(ctx, Msql, orderId, closingPrice.String(), entrustCache.Order); err != nil { + applogger.Error("%v UpdateBotStockBrlClosingByOrderId.StockBrlClosingOrder:%v", common.ErrShareBrl, err) + return false, err + } + + // 5、清理持仓订单信息 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), positionKey, orderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockBrlClosingByOrderId.HDel:%v", common.ErrShareBrl, err) + return false, flags.ErrCacheDB + } + + // 6、平仓更新订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(userKey, entrustCache.UserId) + if err = UpdateShareBrlSubscribeHashStatusByOrderId(orderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockBrlClosingByOrderId.%v:%v", common.ErrShareBrl, userKey, err) + return false, flags.ErrCacheDB + } + + // 7、平仓更新管理员订阅缓存订单状态 + if err = UpdateShareBrlSubscribeHashStatusByOrderId(orderId, adminKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockBrlClosingByOrderId.%v:%v", common.ErrShareBrl, adminKey, err) + return false, flags.ErrCacheDB + } + + return true, nil +} + +// UpdateBotStockBrlAllClosingByOrderId +// +// @Description: 巴西股用户一键平仓 +// @receiver uo +// @param ctx +// @param userId +// @return error +func (uo *userOrderRepo) UpdateBotStockBrlAllClosingByOrderId(ctx context.Context, userId int64) error { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.BrlMarket) { + return flags.ErrStopTread + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe + } + + // 1、查询当前用户所有订单 + orderMap, err := uo.GetBotStockBrlTradeByUserId(userId) + if err != nil { + applogger.Error("%v UpdateBotStockBrlAllClosingByOrderId.GetBotStockBrlTradeByUserId:%v", common.ErrShareBrl, err) + return flags.ErrMySqlDB + } + + // 2、查询持仓缓存列表数据-1、清理持仓列表缓存 2、处理平仓数据 3、清理订单ID缓存列表 + entrust, err := Reds.HGetAll(context.Background(), setting.MarketShareBrlPosition).Result() + if err != nil { + applogger.Error("%v UpdateBotStockBrlAllClosingByOrderId.HGetAll:%v", common.ErrShareBrl, err) + return flags.ErrShareFive + } + + // 3、循环检查股票交易对最新价格(有一个查询不到既不能平仓) + var entrustList []share.ShareBrlTallyCache + closePriceMap := make(map[string]decimal.Decimal) + for key, value := range entrust { + var entrustJson share.ShareBrlTallyCache + if err = json.Unmarshal([]byte(value), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockBrlAllClosingByOrderId.Unmarshal:%v", common.ErrShareBrl, err) + return flags.ErrStopTread + } + _, ok := orderMap[entrustJson.OrderId] + if ok { + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Brl, entrustJson.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareBrlTheLatestPrice(subKey, entrustJson.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockBrlAllClosingByOrderId.GetShareSgdTheLatestPrice:%v", common.ErrShareBrl, err) + return flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("订阅Key:%v,最新价格:%v,订单ID:%v", subKey, closingPrice, entrustJson.OrderId) + } + + closePriceMap[key] = closingPrice + entrustList = append(entrustList, entrustJson) + } + } + + // 4、股票一键平仓 + for _, value := range entrustList { + closePrice, ok := closePriceMap[value.OrderId] + if ok { + // 平仓 + if err = StockBrlClosingOrder(ctx, uo.data.mysqlDB, value.OrderId, closePrice.String(), value.Order); err != nil { + applogger.Error("%v UpdateBotStockBrlAllClosingByOrderId.StockBrlClosingOrder:%v", common.ErrShareBrl, err) + return err + } + + // 清理持仓缓存列表 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), setting.MarketShareBrlPosition, value.OrderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockBrlAllClosingByOrderId.HDel:%v", common.ErrShareBrl, err) + return flags.ErrCacheDB + } + + // 平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareBrlSubscribe, value.UserId) + if err = UpdateShareBrlSubscribeHashStatusByOrderId(value.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockBrlAllClosingByOrderId.ShareBrlSubscribe:%v", common.ErrShareBrl, err) + return flags.ErrCacheDB + } + + // 平仓更新管理员订阅订单状态 + if err = UpdateShareBrlSubscribeHashStatusByOrderId(value.OrderId, setting.AdminShareBrlSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockBrlAllClosingByOrderId.AdminShareBrlSubscribe:%v", common.ErrShareBrl, err) + return flags.ErrCacheDB + } + } + } + + return nil +} + +// GetBotStockBrlTradeByUserId +// +// @Description: +// @receiver uo +// @param ctx +// @param userId +// @return map[string]string +// @return error +func (uo *userOrderRepo) GetBotStockBrlTradeByUserId(userId int64) (map[string]string, error) { + var botStockBrlTrade []models.BotStockBrlTrade + if err := uo.data.mysqlDB.Table(flags.BotStockBrlTrade). + Where("user_id = ?", userId). + Where("status = 1"). + Find(&botStockBrlTrade); err != nil { + return nil, err + } + + botMap := make(map[string]string) + for _, value := range botStockBrlTrade { + botMap[value.OrderId] = value.OrderId + } + + return botMap, nil +} + +// GetShareBrlTheLatestPrice +// +// @Description: +// @receiver uo +// @param ctx +// @param subKey +// @param tradeType +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) GetShareBrlTheLatestPrice(subKey string, tradeType int64) (decimal.Decimal, error) { + priceNew, err := share.ShareBrlSubMarketPrice(subKey) + if err != nil { + applogger.Error("%v GetShareBrlTheLatestPrice.ShareBrlSubMarketPrice:%v", common.ErrShareBrl, err) + return decimal.Decimal{}, err + } + + priceS := decimal.RequireFromString(priceNew) + + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tradeType { + case flags.TradeTypeBuy: // 买涨 + openPrice = priceS.Sub(difference) // 开仓价格 + case flags.TradeTypeSell: // 买跌 + openPrice = priceS.Add(difference) // 开仓价格 + default: + + } + + return openPrice, nil +} + +// GetBotStockBrlTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @return *models.BotStockBrlTrade +// @return error +func (uo *userOrderRepo) GetBotStockBrlTradeByOrderId(session *xorm.Session, orderId string) (*models.BotStockBrlTrade, error) { + var botStockBrlTrade []models.BotStockBrlTrade + if err := session.Table(flags.BotStockBrlTrade). + Where("order_id = ?", orderId). + Find(&botStockBrlTrade); err != nil { + return nil, err + } + + for _, value := range botStockBrlTrade { + return &value, nil + } + + return nil, nil +} + +// GetBotUserStockBrlByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @return *models.BotUserStockBrl +// @return error +func (uo *userOrderRepo) GetBotUserStockBrlByUserIdAndStockId(session *xorm.Session, userId int64, stockId string) (*models.BotUserStockBrl, error) { + var stockBrl []models.BotUserStockBrl + if err := session.Table(flags.BotUserStockBrl). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&stockBrl); err != nil || len(stockBrl) <= 0 { + return nil, err + } + + for _, value := range stockBrl { + return &value, nil + } + + return nil, nil +} + +// UpdateBotStockBrlTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotStockBrlTradeByOrderId(session *xorm.Session, orderId string, stock models.BotStockBrlTrade) error { + _, err := session.Table(flags.BotStockBrlTrade). + Where("order_id = ?", orderId). + Update(&stock) + + if err != nil { + return err + } + + return nil +} + +// CreateBotStockBrlTrade +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param trade +// @return error +func (uo *userOrderRepo) CreateBotStockBrlTrade(session *xorm.Session, trade models.BotStockBrlTrade) error { + _, err := session.Table(flags.BotStockBrlTrade).Insert(&trade) + if err != nil { + return err + } + + return nil +} + +// CreateBotUserStockBrlFTHB +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param stock +// @return error +func (uo *userOrderRepo) CreateBotUserStockBrlFTHB(session *xorm.Session, stock models.BotUserStockBrl) error { + _, err := session.Table(flags.BotUserStockBrl).Insert(&stock) + if err != nil { + return err + } + + return nil +} + +// UpdateBotUserStockBrlByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotUserStockBrlByUserIdAndStockId(session *xorm.Session, userId int64, stockId string, stock models.BotUserStockBrl) error { + _, err := session.Table(flags.BotUserStockBrl). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&stock) + if err != nil { + return err + } + + return nil +} + +// StockBrlVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) StockBrlVoteDealType(order structure.ShareOrder) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + return limitOrMarketPrice, nil +} + +// UpdateShareBrlVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) UpdateShareBrlVoteDealType(order *models.BotStockBrlTrade) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + if len(order.DealPrice) != 0 { + dealPrice := decimal.RequireFromString(order.DealPrice) + if !dealPrice.IsZero() { + limitOrMarketPrice = dealPrice + } + } + + return limitOrMarketPrice, nil +} + +// VerifyBotStockBrlTradeOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @return string +// @return error +func (uo *userOrderRepo) VerifyBotStockBrlTradeOrderId(session *xorm.Session) (string, error) { + var orderId string + for { + // 生成订单ID + orderId = orders.CreateRandCodeOrder(10) + + var orderList []models.BotStockBrlTrade + err := session.Table(flags.BotStockBrlTrade). + Where("order_id = ?", orderId). + Find(&orderList) + + if err != nil || len(orderList) > 0 { + applogger.Error("%v VerifyBotStockBrlTradeOrderId.Find:%v", common.ErrShareBrl, err) + continue + } + + break + } + + return orderId, nil +} + +// GetBotStockBrlTradeByOrderIdOrStatus +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param status +// @return *models.BotStockSgdTrade +// @return error +func (uo *userOrderRepo) GetBotStockBrlTradeByOrderIdOrStatus(session *xorm.Session, orderId string, status int) (*models.BotStockBrlTrade, error) { + var botStockBrlTrade []models.BotStockBrlTrade + if err := session.Table(flags.BotStockBrlTrade). + Where("order_id = ?", orderId). + Where("`status` = ?", status). + Find(&botStockBrlTrade); err != nil { + return nil, err + } + + for _, value := range botStockBrlTrade { + return &value, nil + } + + return nil, nil +} diff --git a/internal/data/order_share_eur.go b/internal/data/order_share_eur.go new file mode 100644 index 0000000..8a99f24 --- /dev/null +++ b/internal/data/order_share_eur.go @@ -0,0 +1,1507 @@ +package data + +import ( + "context" + "encoding/json" + "github.com/go-xorm/xorm" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" + + orders "matchmaking-system/internal/data/convert" + models "matchmaking-system/internal/pkg/model" +) + +// GetBotStockEurTradeList +// +// @Description: 德股订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param userId +// @param status +// @return []*models.BotStockEurTrade +// @return int64 +// @return error +func (uo *userOrderRepo) GetBotStockEurTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockEurTrade, int64, error) { + totalCount, err := uo.data.mysqlDB.Table(flags.BotStockEurTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Count() + if err != nil { + return nil, 0, flags.ErrMySqlDB + } + if totalCount == 0 { + return nil, 0, nil + } + var stockList []*models.BotStockEurTrade + if err = uo.data.mysqlDB.Table(flags.BotStockEurTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Limit(int(pageSize), int(pageCount)). + Desc(GetOrderByStatusSort(status)). + Find(&stockList); err != nil { + return nil, 0, flags.ErrMySqlDB + } + + var stockUpdateList []*models.BotStockEurTrade + for _, value := range stockList { + value.KeepDecimal = GetKeepDecimal(flags.StockEURSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockEURSystemSetUpKey, value.StockId) + stockUpdateList = append(stockUpdateList, value) + } + + return stockUpdateList, totalCount, nil +} + +// PlacingStockEurOrders +// +// @Description: 德股下单 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) PlacingStockEurOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) { + // 1、通知下单订阅 + symbol := order.StockId + timeValue := QuerySystemCache(flags.ShareEurMarketType) // 市场开闭盘时间 + if !utils.CheckInPlateTime(timeValue) { + return flags.SetNull, flags.ErrStopTread + } + SubscribeEurHSetCodeList(symbol, false) // 同步写入股票列表缓存 + SubscribeEurCloseNewPrice(symbol) // 同步股票实时行情价 + + // 判定是否存在欠款订单 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe.Error(), nil + } + + order = PryNumInit(order) // 杠杆初始化 + subKey := publicData.SymbolCache(flags.Eur, symbol, flags.TradeTypePrice) + + // 市场系统设置 + if CheckGlobalTread(flags.EurMarket) { + return flags.SetNull, flags.ErrStopTread + } + + // 全局设置停止交易操作 + var blockTime time.Time + var priceNew, userKey, adminKey string + if !CheckTypeStatus(order.Type) { + userKey = setting.ShareEurSubscribe + adminKey = setting.AdminShareEurSubscribe + } else { + // 判定:1、是否开启股票交易 2、是否在交易时间内 3、是否达到最小交易量 + check, openPrice, minNum, endTime := CheckBlockTread(flags.EurBlk, symbol) + if check { + return flags.SetNull, flags.ErrShareSeven + } + if minNum > utils.StringToInt(order.OrderNumber) { + return flags.SetNull, flags.ErrShareSix + } + priceNew = openPrice // 开仓价格 + blockTime = endTime // 平仓时间 + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + flatRatio := GetCacheForcedClosure(flags.StockEURSystemSetUpKey, symbol) // 设置强平阈值 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.EurMarket, userId) // 股票市场系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), // 强平阈值 + Status: leverStatus.Status, // 股杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + order.System = system + + // 2、股票下单判定 + // 下单判定设置(false无设置|true止盈止损) + checkBool, stopWinPrice, stopLossPrice, err := StockEurVoteStopType(order) + if err != nil { + applogger.Error("%v PlacingStockEurOrders.StockEurVoteStopType:%v", common.ErrShareEur, err) + return flags.SetNull, err + } + // 下单判定设置(限价|市价) + limitOrMarketPrice, err := uo.StockEurVoteDealType(order) + if err != nil { + applogger.Error("%v PlacingStockEurOrders.StockEurVoteDealType:%v", common.ErrShareEur, err) + return flags.SetNull, err + } + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(order.TradeType, stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v PlacingStockEurOrders.VoteTradeType:%v", common.ErrShareEur, err) + return flags.SetNull, err + } + + // 3、订单持久化录入(并处理资产信息) + pryNum := SystemDealWithLever(order) + orderId, err := uo.StockEurOrderWriteDB(ctx, userId, order, limitOrMarketPrice, pryNum) + if err != nil || len(orderId) == 0 { + applogger.Error("%v PlacingStockEurOrders.StockEurOrderWriteDB:%v", common.ErrShareEur, err) + return flags.SetNull, err + } + + // 4、处理订单信息 + chg := GetShareChgEur(flags.Eur, order.StockId) // 涨跌幅标识值 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.EurMarket, time.Now()) // 开盘时间 + marketStatus, shareOrder, err := share.ShareEurCacheDeal(ctx, userId, orderId, subKey, order, chg, priceNew, closingTime, blockTime) + if err != nil || shareOrder == nil { + applogger.Error("%v PlacingStockEurOrders.ShareEurCacheDeal:%v", common.ErrShareEur, err) + return flags.SetNull, err + } + // 计算保证金 = 订单价格 * 订单数量 / 杠杆 + shareOrder.Order.MarketMoney = limitOrMarketPrice.Mul(decimal.RequireFromString(order.OrderNumber)).Div(pryNum).String() + if !flags.CheckSetting { + applogger.Debug("订单ID:%v", shareOrder.OrderId) + applogger.Debug("订单交易对:%v", shareOrder.Symbol) + applogger.Debug("订单状态:%v", shareOrder.Status) + applogger.Debug("订单用户ID:%v", shareOrder.UserId) + applogger.Debug("开盘价:%v", shareOrder.OpenPrice) + applogger.Debug("收盘价:%v", shareOrder.ClosingPrice) + applogger.Debug("下单信息:%v", shareOrder.Order) + } + + // 6、股票订单(挂单|持仓)缓存列表,等待队列计算 + if err = share.ShareEurHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v PlacingStockEurOrders.ShareEurHashUserOrder:%v", common.ErrShareEur, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 7、用户订阅股票订单信息 + orderIdKey := virtual.OrderIdListKey(userKey, userId) + if err = share.ShareEurHashUserOrder(Reds, orderIdKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockEurOrders.%v:%v", common.ErrShareEur, userKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 8、管理员订阅订单信息 + if err = share.ShareEurHashUserOrder(Reds, adminKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockEurOrders.%v:%v", common.ErrShareEur, adminKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + return orderId, nil +} + +// StockEurOrderWriteDB +// +// @Description: 德股下单操作 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) StockEurOrderWriteDB(ctx context.Context, userId int64, order structure.ShareOrder, limitOrMarketPrice, lever decimal.Decimal) (string, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockEurOrderWriteDB.Begin:%v", common.ErrShareEur, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 获取当前下单用户的资产 + var usableOld, frozenOld decimal.Decimal + stockSgd, err := uo.GetBotUserStockEurByUserIdAndStockId(session, userId, flags.ShareEurBasicUnit) + if err != nil || stockSgd == nil { + applogger.Error("%v StockEurOrderWriteDB.GetBotUserStockEurByUserIdAndStockId:%v", common.ErrShareEur, err) + return flags.SetNull, flags.ErrMySqlDB + } + usableOld = decimal.RequireFromString(stockSgd.UsableNum) + frozenOld = decimal.RequireFromString(stockSgd.FrozenNum) + + // 检查用户订单下单资产 + if usableOld.IsZero() || usableOld.IsNegative() || frozenOld.IsNegative() { + return flags.SetNull, flags.ErrShareOne + } + + // 获取当前系统下单用户的非资产 + var usableFOld, frozenFOld decimal.Decimal + stockFSGD, err := uo.GetBotUserStockEurByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockEurOrderWriteDB.FeiSGD:%v", common.ErrShareEur, err) + return flags.SetNull, flags.ErrMySqlDB + } + if stockFSGD != nil { + usableFOld = decimal.RequireFromString(stockFSGD.UsableNum) + frozenFOld = decimal.RequireFromString(stockFSGD.FrozenNum) + } + if !flags.CheckSetting { + applogger.Debug("下单可用资产:%v", usableOld) + applogger.Debug("下单冻结资产:%v", frozenOld) + applogger.Debug("下单查询非资产账户:%v", stockFSGD) + applogger.Debug("下单可用非资产:%v", usableFOld) + applogger.Debug("下单冻结非资产:%v", frozenFOld) + } + + // 整理当前下单信息 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 订单手续费 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 订单数量 + marketMoney := orderNumber.Mul(limitOrMarketPrice).Div(lever) // 订单金额(杠杆下单) = 订单数量 * 交易价格 / 杠杆 + totalMoney := marketMoney.Add(serviceCost) // 订单总金额 + order.MarketMoney = marketMoney.String() // 市值金额即为保证金 + + // 检查订单ID是否存在,新增下单信息 + var orderId string + if !CheckTypeStatus(order.Type) { + orderId, err = uo.VerifyBotStockEurTradeOrderId(session) + if err != nil { + applogger.Error("%v StockEurOrderWriteDB.VerifyBotStockEurTradeOrderId:%v", common.ErrShareEur, err) + return flags.SetNull, err + } + trade := orders.BotStockEurTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockEurTrade(session, trade); err != nil { + applogger.Error("%v StockEurOrderWriteDB.CreateBotStockEurTrade:%v", common.ErrShareEur, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + orderId, err = uo.VerifyBotStockBlockTradeOrderId(session) + if err != nil { + applogger.Error("%v StockEurOrderWriteDB.VerifyBotStockBlockTradeOrderId:%v", common.ErrShareEur, err) + return flags.SetNull, err + } + trade := orders.BotStockBlockTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockBlockTrade(session, trade); err != nil { + applogger.Error("%v StockEurOrderWriteDB.CreateBotStockBlockTrade:%v", common.ErrShareEur, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + // 下单判定 + residue := usableOld.Sub(totalMoney).Div(usableOld) + if usableOld.Cmp(totalMoney) <= 0 || residue.Cmp(utils.DecimalsStrInt()) <= 0 { + return flags.SetNull, flags.ErrPublicTow + } + + var usableNew, frozenNew, usableFNew, frozenFNew decimal.Decimal + usableNew = usableOld.Sub(totalMoney) // 可用资产 + frozenNew = frozenOld.Add(totalMoney) // 冻结资产 + if order.StockId != flags.ShareEurBasicUnit { + usableFNew = usableFOld.Add(orderNumber) // 可用非资产 + frozenFNew = frozenFOld // 冻结非资产 + } + // 检查用户订单下单资产 + if usableNew.IsNegative() { + return flags.SetNull, flags.ErrPublicTow + } + + // 下单更新资产信息 + stockSgdModel := orders.UpdateBotUserStockEur(ctx, usableNew.String(), frozenNew.String()) + err = uo.UpdateBotUserStockEurByUserIdAndStockId(session, userId, flags.ShareEurBasicUnit, stockSgdModel) + if err != nil { + applogger.Error("%v StockEurOrderWriteDB.UpdateBotUserStockEurByUserIdAndStockId:%v", common.ErrShareEur, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 下单(新增|更新)非资产信息 + if stockFSGD == nil { + stockFTHBModel := orders.CreateBotUserStockEur(ctx, userId, order.StockId, usableFNew.String(), frozenFNew.String()) + err = uo.CreateBotUserStockEurFTHB(session, stockFTHBModel) + if err != nil { + applogger.Error("%v StockEurOrderWriteDB.CreateBotUserStockEurFTHB:%v", common.ErrShareEur, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + stockFTHBModel := orders.UpdateBotUserStockEur(ctx, usableFNew.String(), frozenFNew.String()) + err = uo.UpdateBotUserStockEurByUserIdAndStockId(session, userId, order.StockId, stockFTHBModel) + if err != nil { + applogger.Error("%v StockEurOrderWriteDB.UpdateBotUserStockEurByUserIdAndStockId:%v", common.ErrShareEur, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockEurOrderWriteDB.Commit:%v", common.ErrShareEur, err) + return flags.SetNull, flags.ErrMySqlDB + } + + return orderId, nil +} + +// StockEurOpenOrder +// +// @Description: 德股系统开仓 +// @param ctx +// @param db +// @param userId +// @param orderId +// @param openPrice +// @param order +// @return error +func StockEurOpenOrder(ctx context.Context, db *xorm.EngineGroup, userId int64, orderId, openPrice string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockEurOpenOrder.NewSession:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockThb, err := Uo.GetBotUserStockEurByUserIdAndStockId(session, userId, flags.ShareEurBasicUnit) + if err != nil || stockThb == nil { + applogger.Error("%v StockEurOpenOrder.GetBotUserStockEurByUserIdAndStockId:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockThb.UsableNum) // 用户可用资产 + frozen = decimal.RequireFromString(stockThb.FrozenNum) // 用户冻结资产 + + // 检查用户订单开仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrPublicThree + } + if order.StockId != flags.ShareEurBasicUnit { + stockFThb, err := Uo.GetBotUserStockEurByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockEurOpenOrder.GetBotUserStockEurByUserIdAndStockId:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(stockFThb.UsableNum) // 用户非可用资产 + frozenNo = decimal.RequireFromString(stockFThb.FrozenNum) // 用户非冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + + // 转换股票下单信息 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 下单股数 + markerMoney := decimal.RequireFromString(order.MarketMoney) // 下单金额 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 下单手续费 + totalMoney := markerMoney.Add(serviceCost) // 下单总金额 = (下单手续费 + 下单金额) + openOrderPrice := decimal.RequireFromString(openPrice) // 开盘价格 + if !flags.CheckSetting { + applogger.Debug("下单订单数量:%v", orderNumber) + applogger.Debug("下单订单金额:%v", markerMoney) + applogger.Debug("下单订单手续费:%v", serviceCost) + applogger.Debug("下单订单总金额:%v", totalMoney) + } + + // 手续费记录 + openPriceNew := openOrderPrice.Mul(orderNumber).String() // 开仓手续费 = 开仓价格 * 股数 * 开仓手续费 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareEurMarketType, flags.OpenBrokType, orderId, openPriceNew) + if err != nil { + applogger.Error("%v StockEurOpenOrder.CalculateHandlingFeesShare:%v", common.ErrShareEur, err) + return err + } + openServiceCost := decimal.RequireFromString(cost) // 开仓手续费 + openMarkerMoney := openOrderPrice.Mul(orderNumber).Div(decimal.RequireFromString(order.PryNum)) // 开仓金额 = 开仓价格 * 股数 / 杠杆 + openTotalMoney := openMarkerMoney.Add(openServiceCost) // 开仓总金额 = 开仓金额 + 开仓手续费 + floatPrice := totalMoney.Sub(openTotalMoney) // 计算容差 = 下单总额 - 开仓总额 + if !flags.CheckSetting { + applogger.Debug("开仓订单价格:%v", openOrderPrice) + applogger.Debug("开仓手续费:%v", openServiceCost) + applogger.Debug("开仓总金额:%v", openTotalMoney) + applogger.Debug("下单开仓总金额容差值:%v", floatPrice) + } + + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + usableNew = usable.Add(floatPrice) // 可用资产(处理容差值) + frozenNew = frozen.Sub(totalMoney).Add(openMarkerMoney) // 冻结资产(处理容差值)---> 当前冻结金额 = 原冻结金额 - 下单总额 + if order.StockId != flags.ShareEurBasicUnit { + usableNoNew = usableNo // 非可用资产 + frozenNoNew = frozenNo // 非冻结资产 + } + + // 检查用户订单开仓资产 + if frozenNew.IsNegative() || usableNew.IsNegative() { + return flags.ErrPublicThree + } + if !flags.CheckSetting { + applogger.Debug("下单后用户可用资产:%v", usableNew) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + } + + // 处理资产信息 + userStockThb := orders.UpdateBotUserStockEur(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockEurByUserIdAndStockId(session, userId, flags.ShareEurBasicUnit, userStockThb); err != nil { + applogger.Error("%v StockEurOpenOrder.UpdateBotUserStockEurByUserIdAndStockId:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + + // 更新非资产信息 + if order.StockId != flags.ShareEurBasicUnit { + userStockFThb := orders.UpdateBotUserStockEur(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = Uo.UpdateBotUserStockEurByUserIdAndStockId(session, userId, order.StockId, userStockFThb); err != nil { + applogger.Error("%v StockEurOpenOrder.UpdateBotUserStockEurByUserIdAndStockId:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + } + + // 返佣记录|资金信息|资金详情信息 + if err = Uo.ShareEurRebateCalculation(ctx, session, int(userId), flags.ShareEurMarketType, flags.OpenBrokType, flags.OpenMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockEurOpenOrder.ShareEurRebateCalculation:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + + // 处理订单信息(成交价|仓位|开仓时间|订单总金额|手续费|持仓状态) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateOpenBotStockEurTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarkerMoney.String()) + if err = Uo.UpdateBotStockEurTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockEurOpenOrder.UpdateBotStockEurTradeByOrderId:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + var list []models.BotUserStockEurLog + qData0 := orders.CreatBotUserStockEurLog(ctx, userId, flags.CostMoney, flags.ShareEurBasicUnit, NegativeValue(openServiceCost.String()), orderId) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockEurLog(ctx, userId, flags.Freeze, flags.ShareEurBasicUnit, NegativeValue(openMarkerMoney.String()), orderId) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockEurLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockEurLogList(session, list); err != nil { + applogger.Error("%v StockEurOpenOrder.CreatBotUserStockEurLogList:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateOpenBotStockBlockTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarkerMoney.String()) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockEurOpenOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareEurBasicUnit, NegativeValue(openServiceCost.String()), orderId, order.Type) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Freeze, flags.ShareEurBasicUnit, NegativeValue(openMarkerMoney.String()), orderId, order.Type) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId, order.Type) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockEurOpenOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockEurOpenOrder.Commit:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + + return nil +} + +// StockEurClosingOrder +// +// @Description: 德股系统平仓 +// @param ctx +// @param db +// @param orderId +// @param price +// @param order +// @return error +func StockEurClosingOrder(ctx context.Context, db *xorm.EngineGroup, orderId string, price string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockEurClosingOrder.NewSession:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + + // 查询订单信息 + var userId int64 + var dealPrice, orderNumber, totalAmount, serviceCost, markerMoney decimal.Decimal + if !CheckTypeStatus(order.Type) { + tread, err := Uo.GetBotStockEurTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockEurClosingOrder.GetBotStockEurTradeByOrderIdOrStatus:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + markerMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓下单金额 + } else { + tread, err := Uo.GetBotStockBlockTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockEurClosingOrder.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + markerMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓下单金额 + } + + if !flags.CheckSetting { + applogger.Debug("下单开仓用户Id:%v", userId) + applogger.Debug("下单开仓开仓价格:%v", dealPrice) + applogger.Debug("下单开仓订单数量:%v", orderNumber) + applogger.Debug("下单开仓总金额:%v", totalAmount) + applogger.Debug("下单开仓手续费:%v", serviceCost) + applogger.Debug("下单开仓开仓金额:%v", markerMoney) + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + userStockThb, err := Uo.GetBotUserStockEurByUserIdAndStockId(session, userId, flags.ShareEurBasicUnit) + if err != nil { + applogger.Error("%v StockEurClosingOrder.GetBotUserStockEurByUserIdAndStockId:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(userStockThb.UsableNum) // 用户可用资金 + frozen = decimal.RequireFromString(userStockThb.FrozenNum) // 用户非冻结资金 + + // 检查用户订单平仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrShareTow + } + + // 查询当前下单用户可用非账户和冻结金额 + if order.StockId != flags.ShareEurBasicUnit { + userStockFThb, err := Uo.GetBotUserStockEurByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockEurClosingOrder.GetBotUserStockEurByUserIdAndStockId:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(userStockFThb.UsableNum) // 用户非可用资金 + frozenNo = decimal.RequireFromString(userStockFThb.FrozenNum) // 用户非冻结资金 + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + + // 手续费处理 + closePrice := decimal.RequireFromString(price) // 平仓价格 + cloePriceCost := closePrice.Mul(orderNumber).String() // 平仓手续费 = 平仓价格 * 股数 * 手续费比例 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareEurMarketType, flags.ClosingBrokType, orderId, cloePriceCost) + if err != nil { + applogger.Error("%v StockEurClosingOrder.CalculateHandlingFeesShare:%v", common.ErrShareEur, err) + return err + } + closeServiceCost := decimal.RequireFromString(cost) + if !flags.CheckSetting { + applogger.Debug("平仓价格:%v", closePrice) + applogger.Debug("平仓手续费手续费:%v", closeServiceCost) + } + + //已经实现盈亏计算公式(已平仓结算方式) + //买涨 已经实现盈亏 = (平仓成交价-开仓成交价)*股数 + //买跌 已经实现盈亏 = (开仓成交价-平仓成交价)*股数 + var usableNew, frozenNew, usableNewNo, frozenNewNo, subPrice, resultPrice decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买涨 + subPrice = closePrice.Sub(dealPrice) + resultPrice = subPrice.Mul(orderNumber) + case flags.TradeTypeSell: // 买跌 + subPrice = dealPrice.Sub(closePrice) + resultPrice = subPrice.Mul(orderNumber) + default: + + } + + // 判定亏损不能超过 = 保证金 + 平仓手续费 + if resultPrice.IsNegative() { + amountLoss := markerMoney.Sub(closeServiceCost) + if resultPrice.Abs().Cmp(amountLoss) >= 0 { + resultPrice = amountLoss.Neg() + } + } + + // 用户资产账户 + usableNew = usable.Add(resultPrice).Sub(closeServiceCost).Add(markerMoney) // 可用资产 = 原可用资产 + ((正负)盈亏) - 平仓手续费 + 开仓下单金额 + if frozen.Cmp(markerMoney) == -1 { + frozenNew = frozen.Sub(frozen) // 冻结资产 + } else { + frozenNew = frozen.Sub(markerMoney) // 冻结资产 + } + + // 用户非资产账户 + if order.StockId != flags.ShareEurBasicUnit { + usableNewNo = usableNo.Sub(orderNumber) // 可用非资产 = 原可用非资产 - 下单股数 + frozenNewNo = frozenNo // 可用非冻结资产 + } + + // 检查用户订单平仓资产 + if frozenNew.IsNegative() || usableNewNo.IsNegative() { + return flags.ErrShareTow + } + if !flags.CheckSetting { + applogger.Debug("可用资产:%v", usableNew) + applogger.Debug("冻结资产:%v", frozenNew) + applogger.Debug("可用非资产:%v", usableNewNo) + applogger.Debug("冻结非资产:%v", frozenNewNo) + } + + // 平仓(处理资产表(资产)) + userStockUTHB := orders.UpdateBotUserStockEur(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockEurByUserIdAndStockId(session, userId, flags.ShareEurBasicUnit, userStockUTHB); err != nil { + applogger.Error("%v StockEurClosingOrder.UpdateBotUserStockEurByUserIdAndStockId:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + + // 平仓(处理资产表(非资产)) + if order.StockId != flags.ShareEurBasicUnit { + userStockFTHB := orders.UpdateBotUserStockEur(ctx, usableNewNo.String(), frozenNewNo.String()) + if err = Uo.UpdateBotUserStockEurByUserIdAndStockId(session, userId, order.StockId, userStockFTHB); err != nil { + applogger.Error("%v StockEurClosingOrder..UpdateBotUserStockEurByUserIdAndStockId:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + } + + // 平仓(返佣记录表|资产表|资金变动表) + if err = Uo.ShareEurRebateCalculation(ctx, session, int(userId), flags.ShareEurMarketType, flags.ClosingBrokType, flags.CloseMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockEurClosingOrder.ShareEurRebateCalculation:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + + // 平仓(处理订单信息(平仓价|保证金|平仓|订单总金额|平仓手续费|完成订单)) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateCloseBotStockEurTrade(ctx, price, cost) + if err = Uo.UpdateBotStockEurTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockEurClosingOrder.UpdateBotStockEurTradeByOrderId:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockEurLog + qData0 := orders.CreatBotUserStockEurLog(ctx, userId, flags.Thaw, flags.ShareEurBasicUnit, markerMoney.String(), orderId) // 平仓(资金变动明细表(开仓保证金)) + qData1 := orders.CreatBotUserStockEurLog(ctx, userId, flags.CostMoney, flags.ShareEurBasicUnit, NegativeValue(closeServiceCost.String()), orderId) // 平仓(资金变动明细表(-平仓手续费)) + qData2 := orders.CreatBotUserStockEurLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockEurLog(ctx, userId, flags.TransferOut, flags.ShareEurBasicUnit, resultPrice.String(), orderId) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockEurLog(ctx, userId, flags.ChangeInto, flags.ShareEurBasicUnit, resultPrice.String(), orderId) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockEurLogList(session, list); err != nil { + applogger.Error("%v StockEurClosingOrder.CreatBotUserStockEurLogList:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateCloseBotStockBlockTrade(ctx, price, cost) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockEurClosingOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Thaw, flags.ShareEurBasicUnit, markerMoney.String(), orderId, order.Type) // 平仓(资金变动明细表(开仓保证金)) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareEurBasicUnit, NegativeValue(closeServiceCost.String()), orderId, order.Type) // 平仓(资金变动明细表(-平仓手续费)) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId, order.Type) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, flags.ShareEurBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, flags.ShareEurBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockEurClosingOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockEurClosingOrder.Commit:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + + return nil +} + +// UpdateBotStockEurCancelByOrderId +// +// @Description: 德股撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockEurCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockEurCancelByOrderId.Begin:%v", common.ErrShareEur, err) + return false, flags.ErrMySqlDB + } + + // 获取订单信息 + var userId int64 + var stockId string + var marketMoneyOld, serviceCostOld, orderNumber decimal.Decimal + if !CheckTypeStatus(typeStatus) { + stockTrade, err := uo.GetBotStockEurTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockEurCancelByOrderId.GetBotStockEurTradeByOrderId:%v", common.ErrShareEur, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } else { + stockTrade, err := uo.GetBotStockBlockTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockEurCancelByOrderId.GetBotStockBlockTradeByOrderId:%v", common.ErrShareEur, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } + + // 用户资产信息 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockThb, err := uo.GetBotUserStockEurByUserIdAndStockId(session, userId, flags.ShareEurBasicUnit) + if err != nil || stockThb == nil { + applogger.Error("%v UpdateBotStockEurCancelByOrderId.GetBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareEur, err) + return false, flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockThb.UsableNum) // 用户账户可用资产 + frozen = decimal.RequireFromString(stockThb.FrozenNum) // 用户账户冻结资产 + + // 检查用户订单撤单资产 + if usable.IsNegative() || frozen.IsNegative() { + return false, flags.ErrShareNine + } + if stockId != flags.ShareEurBasicUnit { + stockFThb, err := uo.GetBotUserStockEurByUserIdAndStockId(session, userId, stockId) + if err != nil { + applogger.Error("%v UpdateBotStockEurCancelByOrderId.GetBotUserStockEurByUserIdAndStockId:%v", common.ErrShareEur, err) + return false, flags.ErrPublicFour + } + usableNo = decimal.RequireFromString(stockFThb.UsableNum) // 用户非账户可用资产 + frozenNo = decimal.RequireFromString(stockFThb.FrozenNum) // 用户非账户冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("用户原始可用资金:%v", usable) + applogger.Debug("用户原始冻结资金:%v", frozen) + applogger.Debug("用户原始可用非资金:%v", usableNo) + applogger.Debug("用户原始冻结非资金:%v", frozenNo) + } + + // 更新订单信息 + var entrustKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + botStockTrade := orders.BotStockEurCancelByOrderId(ctx) + if err = uo.UpdateBotStockEurTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockEurCancelByOrderId.UpdateBotStockEurTradeByOrderId:%v", common.ErrShareEur, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareEurEntrust + userKey = setting.ShareEurSubscribe + adminKey = setting.AdminShareEurSubscribe + } else { + botStockTrade := orders.BotStockBlockCancelByOrderId(ctx) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockEurCancelByOrderId.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareEur, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareBlkEntrust + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // Operational Spot Asset Table + totalMoney := marketMoneyOld.Add(serviceCostOld) // 订单总金额 + + // update total asset data + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + usableNew = usable.Add(totalMoney) // 用户总资产 + frozenNew = frozen.Sub(totalMoney) // 用户冻结资产 + if stockId != flags.ShareEurBasicUnit { + usableNoNew = usableNo.Sub(orderNumber) // 用户非可用资产 + frozenNoNew = frozenNo // 用户非冻结资产 + } + + // 检查用户订单撤单资产 + if frozenNew.IsNegative() || usableNoNew.IsNegative() { + return false, flags.ErrShareNine + } + if !flags.CheckSetting { + applogger.Debug("用户撤单可用总资产:%v", usableNew) + applogger.Debug("用户撤单冻结总资产:%v", frozenNew) + applogger.Debug("用户非撤单可用总资产:%v", usableNoNew) + applogger.Debug("用户非撤单冻结总资产:%v", frozenNoNew) + } + + // 更新资产信息和非资产信息 + userStockTHB := orders.UpdateBotUserStockEur(ctx, usableNew.String(), frozenNew.String()) + if err = uo.UpdateBotUserStockEurByUserIdAndStockId(session, userId, flags.ShareEurBasicUnit, userStockTHB); err != nil { + applogger.Error("%v UpdateBotStockEurCancelByOrderId.SGD.UpdateBotUserStockEurByUserIdAndStockId:%v", common.ErrShareEur, err) + return false, flags.ErrMySqlDB + } + if stockId != flags.ShareEurBasicUnit { + userStockFTHB := orders.UpdateBotUserStockEur(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = uo.UpdateBotUserStockEurByUserIdAndStockId(session, userId, stockId, userStockFTHB); err != nil { + applogger.Error("%v UpdateBotStockEurCancelByOrderId.UpdateBotUserStockEurByUserIdAndStockId:%v", common.ErrShareEur, err) + return false, flags.ErrMySqlDB + } + } + + // 删除订单缓存列表 + if err = Reds.HDel(context.Background(), entrustKey, orderId).Err(); err != nil { + applogger.Error("%v UpdateBotStockEurCancelByOrderId.HDel:%v", common.ErrShareEur, err) + return false, flags.ErrCacheDB + } + + // 更新用户订阅订单缓存列表 + userSubKey := virtual.OrderIdListKey(userKey, userId) + if err = share.UpdateShareEurHashByOrderId(Reds, orderId, userSubKey, flags.Cancel); err != nil { + applogger.Error("%v UpdateBotStockEurCancelByOrderId.%v:%v", common.ErrShareEur, userKey, err) + return false, flags.ErrCacheDB + } + + // 更新管理员订阅订单缓存列表 + if err = UpdateShareEurSubscribeHashStatusByOrderId(orderId, adminKey, flags.Cancel, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockEurCancelByOrderId.%v:%v", common.ErrShareEur, adminKey, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockEurCancelByOrderId.Commit:%v", common.ErrShareSgd, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockEurStopByOrderId +// +// @Description: 德股设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockEurStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockEurStopByOrderId.NewSession:%v", common.ErrShareEur, err) + return false, flags.ErrMySqlDB + } + + // 设置止盈止损 + var userId int64 + if order.StopType == 1 { + // 下单信息 + checkBool, stopWinPrice, stopLossPrice, err := uo.UpdateVoteStopType(order) + if err != nil { + applogger.Error("%v UpdateBotStockEurStopByOrderId.UpdateVoteStopType:%v", common.ErrShareEur, err) + return false, err + } + if !flags.CheckSetting { + applogger.Debug("当前止盈止损数据:%v,%v,%v", checkBool, stopWinPrice, stopLossPrice) + } + + // 止盈止损判定 + var tradeType int + var limitOrMarketPrice decimal.Decimal + if !CheckTypeStatus(order.Type) { + trade, err := uo.GetBotStockEurTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockEurStopByOrderId.GetBotStockEurTradeByOrderIdOrStatus:%v", common.ErrShareEur, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareEurVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockEurStopByOrderId.UpdateShareEurVoteDealType:%v", common.ErrShareEur, err) + return false, err + } + } else { + trade, err := uo.GetBotStockBlockTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockEurStopByOrderId.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareEur, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareBlockVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockEurStopByOrderId.UpdateShareBlockVoteDealType:%v", common.ErrShareEur, err) + return false, err + } + } + if !flags.CheckSetting { + applogger.Debug("当前开仓价格:%v", limitOrMarketPrice) + } + + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(int64(tradeType), stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v UpdateBotStockEurStopByOrderId.VoteTradeType:%v", common.ErrShareEur, err) + return false, err + } + } else { + order.StopLossPrice = decimal.Zero.String() + order.StopWinPrice = decimal.Zero.String() + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[userId] + if ok { + return false, flags.ErrPublicServe + } + + // 更新订单表 + var positionKey string + if !CheckTypeStatus(order.Type) { + botStockTrade := orders.BotStockEurStopByOrderId(ctx, order) + if err = uo.UpdateBotStockEurTradeByOrderId(session, order.OrderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockEurStopByOrderId.UpdateBotStockEurTradeByOrderId:%v", common.ErrShareEur, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareEurPosition + } else { + botStockTrade := orders.BotStockBlockStopByOrderId(ctx, order) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, order.OrderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockEurStopByOrderId.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareEur, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareBlkPosition + } + + // 挂单缓存队列 + if err = share.UpdateShareEurStopByOrderId(Reds, order, positionKey, flags.Position); err != nil { + applogger.Error("%v UpdateBotStockEurStopByOrderId.UpdateShareEurStopByOrderId:%v", common.ErrShareEur, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockEurStopByOrderId.Commit:%v", common.ErrShareEur, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockEurClosingByOrderId +// +// @Description: 德股用户平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockEurClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.EurMarket) { + return false, flags.ErrStopTread + } + + // 1、查询持仓缓存列表数据并清理对应缓存 + var positionKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + positionKey = setting.MarketShareEurPosition + userKey = setting.ShareEurSubscribe + adminKey = setting.AdminShareEurSubscribe + } else { + positionKey = setting.MarketShareBlkPosition + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + var entrustCache *share.ShareEurTallyCache + entrust, err := Reds.HGet(context.Background(), positionKey, orderId).Result() + if err != nil { + applogger.Error("%v UpdateBotStockEurClosingByOrderId.HGet:%v", common.ErrShareEur, err) + return false, flags.ErrShareFive + } + var entrustJson share.ShareEurTallyCache + if err = json.Unmarshal([]byte(entrust), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockEurClosingByOrderId.Unmarshal:%v", common.ErrShareEur, err) + return false, flags.ErrCacheDB + } + if orderId == entrustJson.OrderId { + entrustCache = &entrustJson + } + + // 2、判定是否存在平仓订单 + if entrustCache == nil { + return false, flags.ErrShareFive + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[entrustJson.UserId] + if ok { + return false, flags.ErrPublicServe + } + + // 市场设置交易时间(T+0,T+1,T+2s......) + if !CheckShareSystemTime(entrustCache.ClosingTime) { + return false, flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("手动平仓:%v", entrustCache) + } + + // 3、当前最新价格 + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Eur, entrustCache.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareEurTheLatestPrice(subKey, entrustCache.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockEurClosingByOrderId.GetShareEurTheLatestPrice:%v", common.ErrShareEur, err) + return false, flags.ErrStopTread + } + + // 4、平仓处理 + if err = StockEurClosingOrder(ctx, Msql, orderId, closingPrice.String(), entrustCache.Order); err != nil { + applogger.Error("%v UpdateBotStockEurClosingByOrderId.StockEurClosingOrder:%v", common.ErrShareEur, err) + return false, err + } + + // 5、清理持仓订单信息 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), positionKey, orderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockEurClosingByOrderId.HDel:%v", common.ErrShareEur, err) + return false, flags.ErrCacheDB + } + + // 6、平仓更新订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(userKey, entrustCache.UserId) + if err = UpdateShareEurSubscribeHashStatusByOrderId(orderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockEurClosingByOrderId.%v:%v", common.ErrShareEur, userKey, err) + return false, flags.ErrCacheDB + } + + // 7、平仓更新管理员订阅缓存订单状态 + if err = UpdateShareEurSubscribeHashStatusByOrderId(orderId, adminKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockEurClosingByOrderId.%v:%v", common.ErrShareEur, adminKey, err) + return false, flags.ErrCacheDB + } + + return true, nil +} + +// UpdateBotStockEurAllClosingByOrderId +// +// @Description: 德股用户一键平仓 +// @receiver uo +// @param ctx +// @param userId +// @return error +func (uo *userOrderRepo) UpdateBotStockEurAllClosingByOrderId(ctx context.Context, userId int64) error { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.EurMarket) { + return flags.ErrStopTread + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe + } + + // 1、查询当前用户所有订单 + orderMap, err := uo.GetBotStockEurTradeByUserId(userId) + if err != nil { + applogger.Error("%v UpdateBotStockEurAllClosingByOrderId.GetBotStockEurTradeByUserId:%v", common.ErrShareEur, err) + return flags.ErrMySqlDB + } + + // 2、查询持仓缓存列表数据-1、清理持仓列表缓存 2、处理平仓数据 3、清理订单ID缓存列表 + entrust, err := Reds.HGetAll(context.Background(), setting.MarketShareEurPosition).Result() + if err != nil { + applogger.Error("%v UpdateBotStockEurAllClosingByOrderId.HGetAll:%v", common.ErrShareEur, err) + return flags.ErrShareFive + } + + // 3、循环检查股票交易对最新价格(有一个查询不到既不能平仓) + var entrustList []share.ShareEurTallyCache + closePriceMap := make(map[string]decimal.Decimal) + for key, value := range entrust { + var entrustJson share.ShareEurTallyCache + if err = json.Unmarshal([]byte(value), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockEurAllClosingByOrderId.Unmarshal:%v", common.ErrShareEur, err) + return flags.ErrStopTread + } + _, ok := orderMap[entrustJson.OrderId] + if ok { + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Eur, entrustJson.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareEurTheLatestPrice(subKey, entrustJson.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockEurAllClosingByOrderId.GetShareSgdTheLatestPrice:%v", common.ErrShareEur, err) + return flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("订阅Key:%v,最新价格:%v,订单ID:%v", subKey, closingPrice, entrustJson.OrderId) + } + + closePriceMap[key] = closingPrice + entrustList = append(entrustList, entrustJson) + } + } + + // 4、股票一键平仓 + for _, value := range entrustList { + closePrice, ok := closePriceMap[value.OrderId] + if ok { + // 平仓 + if err = StockEurClosingOrder(ctx, uo.data.mysqlDB, value.OrderId, closePrice.String(), value.Order); err != nil { + applogger.Error("%v UpdateBotStockEurAllClosingByOrderId.StockEurClosingOrder:%v", common.ErrShareEur, err) + return err + } + + // 清理持仓缓存列表 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), setting.MarketShareEurPosition, value.OrderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockEurAllClosingByOrderId.HDel:%v", common.ErrShareEur, err) + return flags.ErrCacheDB + } + + // 平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareEurSubscribe, value.UserId) + if err = UpdateShareEurSubscribeHashStatusByOrderId(value.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockEurAllClosingByOrderId.ShareEurSubscribe:%v", common.ErrShareEur, err) + return flags.ErrCacheDB + } + + // 平仓更新管理员订阅订单状态 + if err = UpdateShareEurSubscribeHashStatusByOrderId(value.OrderId, setting.AdminShareEurSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockEurAllClosingByOrderId.AdminShareEurSubscribe:%v", common.ErrShareEur, err) + return flags.ErrCacheDB + } + } + } + + return nil +} + +// GetBotStockEurTradeByUserId +// +// @Description: +// @receiver uo +// @param ctx +// @param userId +// @return map[string]string +// @return error +func (uo *userOrderRepo) GetBotStockEurTradeByUserId(userId int64) (map[string]string, error) { + var botStockEurTrade []models.BotStockEurTrade + if err := uo.data.mysqlDB.Table(flags.BotStockEurTrade). + Where("user_id = ?", userId). + Where("status = 1"). + Find(&botStockEurTrade); err != nil { + return nil, err + } + + botMap := make(map[string]string) + for _, value := range botStockEurTrade { + botMap[value.OrderId] = value.OrderId + } + + return botMap, nil +} + +// GetShareEurTheLatestPrice +// +// @Description: +// @receiver uo +// @param ctx +// @param subKey +// @param tradeType +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) GetShareEurTheLatestPrice(subKey string, tradeType int64) (decimal.Decimal, error) { + priceNew, err := share.ShareEurSubMarketPrice(subKey) + if err != nil { + applogger.Error("%v GetShareEurTheLatestPrice.ShareEurSubMarketPrice:%v", common.ErrShareEur, err) + return decimal.Decimal{}, err + } + + priceS := decimal.RequireFromString(priceNew) + + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tradeType { + case flags.TradeTypeBuy: // 买涨 + openPrice = priceS.Sub(difference) // 开仓价格 + case flags.TradeTypeSell: // 买跌 + openPrice = priceS.Add(difference) // 开仓价格 + default: + + } + + return openPrice, nil +} + +// GetBotStockEurTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @return *models.BotStockEurTrade +// @return error +func (uo *userOrderRepo) GetBotStockEurTradeByOrderId(session *xorm.Session, orderId string) (*models.BotStockEurTrade, error) { + var botStockEurTrade []models.BotStockEurTrade + if err := session.Table(flags.BotStockEurTrade). + Where("order_id = ?", orderId). + Find(&botStockEurTrade); err != nil { + return nil, err + } + + for _, value := range botStockEurTrade { + return &value, nil + } + + return nil, nil +} + +// GetBotUserStockEurByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @return *models.BotUserStockEur +// @return error +func (uo *userOrderRepo) GetBotUserStockEurByUserIdAndStockId(session *xorm.Session, userId int64, stockId string) (*models.BotUserStockEur, error) { + var stockEur []models.BotUserStockEur + if err := session.Table(flags.BotUserStockEur). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&stockEur); err != nil || len(stockEur) <= 0 { + return nil, err + } + + for _, value := range stockEur { + return &value, nil + } + + return nil, nil +} + +// UpdateBotStockEurTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotStockEurTradeByOrderId(session *xorm.Session, orderId string, stock models.BotStockEurTrade) error { + _, err := session.Table(flags.BotStockEurTrade). + Where("order_id = ?", orderId). + Update(&stock) + + if err != nil { + return err + } + + return nil +} + +// CreateBotStockEurTrade +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param trade +// @return error +func (uo *userOrderRepo) CreateBotStockEurTrade(session *xorm.Session, trade models.BotStockEurTrade) error { + _, err := session.Table(flags.BotStockEurTrade).Insert(&trade) + if err != nil { + return err + } + + return nil +} + +// CreateBotUserStockEurFTHB +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param stock +// @return error +func (uo *userOrderRepo) CreateBotUserStockEurFTHB(session *xorm.Session, stock models.BotUserStockEur) error { + _, err := session.Table(flags.BotUserStockEur).Insert(&stock) + if err != nil { + return err + } + + return nil +} + +// UpdateBotUserStockEurByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotUserStockEurByUserIdAndStockId(session *xorm.Session, userId int64, stockId string, stock models.BotUserStockEur) error { + _, err := session.Table(flags.BotUserStockEur). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&stock) + if err != nil { + return err + } + + return nil +} + +// StockEurVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) StockEurVoteDealType(order structure.ShareOrder) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + return limitOrMarketPrice, nil +} + +// UpdateShareEurVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) UpdateShareEurVoteDealType(order *models.BotStockEurTrade) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + if len(order.DealPrice) != 0 { + dealPrice := decimal.RequireFromString(order.DealPrice) + if !dealPrice.IsZero() { + limitOrMarketPrice = dealPrice + } + } + + return limitOrMarketPrice, nil +} + +// VerifyBotStockEurTradeOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @return string +// @return error +func (uo *userOrderRepo) VerifyBotStockEurTradeOrderId(session *xorm.Session) (string, error) { + var orderId string + for { + // 生成订单ID + orderId = orders.CreateRandCodeOrder(10) + + var orderList []models.BotStockEurTrade + err := session.Table(flags.BotStockEurTrade). + Where("order_id = ?", orderId). + Find(&orderList) + + if err != nil || len(orderList) > 0 { + applogger.Error("%v VerifyBotStockEurTradeOrderId.Find:%v", common.ErrShareEur, err) + continue + } + + break + } + + return orderId, nil +} + +// GetBotStockEurTradeByOrderIdOrStatus +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param status +// @return *models.BotStockSgdTrade +// @return error +func (uo *userOrderRepo) GetBotStockEurTradeByOrderIdOrStatus(session *xorm.Session, orderId string, status int) (*models.BotStockEurTrade, error) { + var botStockEurTrade []models.BotStockEurTrade + if err := session.Table(flags.BotStockEurTrade). + Where("order_id = ?", orderId). + Where("`status` = ?", status). + Find(&botStockEurTrade); err != nil { + return nil, err + } + + for _, value := range botStockEurTrade { + return &value, nil + } + + return nil, nil +} diff --git a/internal/data/order_share_fur.go b/internal/data/order_share_fur.go new file mode 100644 index 0000000..cbcb983 --- /dev/null +++ b/internal/data/order_share_fur.go @@ -0,0 +1,1505 @@ +package data + +import ( + "context" + "encoding/json" + "github.com/go-xorm/xorm" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" + + orders "matchmaking-system/internal/data/convert" + models "matchmaking-system/internal/pkg/model" +) + +// GetBotStockFurTradeList +// +// @Description: 法股订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param userId +// @param status +// @return []*models.BotStockFurTrade +// @return int64 +// @return error +func (uo *userOrderRepo) GetBotStockFurTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockFurTrade, int64, error) { + totalCount, err := uo.data.mysqlDB.Table(flags.BotStockFurTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Count() + if err != nil { + return nil, 0, flags.ErrMySqlDB + } + if totalCount == 0 { + return nil, 0, nil + } + var stockList []*models.BotStockFurTrade + if err = uo.data.mysqlDB.Table(flags.BotStockFurTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Limit(int(pageSize), int(pageCount)). + Desc(GetOrderByStatusSort(status)). + Find(&stockList); err != nil { + return nil, 0, flags.ErrMySqlDB + } + + var stockUpdateList []*models.BotStockFurTrade + for _, value := range stockList { + value.KeepDecimal = GetKeepDecimal(flags.StockFURSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockFURSystemSetUpKey, value.StockId) + stockUpdateList = append(stockUpdateList, value) + } + + return stockUpdateList, totalCount, nil +} + +// PlacingStockFurOrders +// +// @Description: 法股下单 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) PlacingStockFurOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) { + // 1、通知下单订阅 + symbol := order.StockId + timeValue := QuerySystemCache(flags.ShareFurMarketType) // 市场开闭盘时间 + if !utils.CheckInPlateTime(timeValue) { + return flags.SetNull, flags.ErrStopTread + } + SubscribeFurHSetCodeList(symbol, false) // 同步写入股票列表缓存 + SubscribeFurCloseNewPrice(symbol) // 同步股票实时行情价 + + // 判定是否存在欠款订单 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe.Error(), nil + } + + order = PryNumInit(order) // 杠杆初始化 + subKey := publicData.SymbolCache(flags.Fur, symbol, flags.TradeTypePrice) + + // 市场系统设置 + if CheckGlobalTread(flags.FurMarket) { + return flags.SetNull, flags.ErrStopTread + } + + // 全局设置停止交易操作 + var blockTime time.Time + var priceNew, userKey, adminKey string + if !CheckTypeStatus(order.Type) { + userKey = setting.ShareFurSubscribe + adminKey = setting.AdminShareFurSubscribe + } else { + // 判定:1、是否开启股票交易 2、是否在交易时间内 3、是否达到最小交易量 + check, openPrice, minNum, endTime := CheckBlockTread(flags.FurBlk, symbol) + if check { + return flags.SetNull, flags.ErrShareSeven + } + if minNum > utils.StringToInt(order.OrderNumber) { + return flags.SetNull, flags.ErrShareSix + } + priceNew = openPrice // 开仓价格 + blockTime = endTime // 平仓时间 + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + flatRatio := GetCacheForcedClosure(flags.StockFURSystemSetUpKey, symbol) // 设置强平阈值 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.FurMarket, userId) // 股票市场系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), // 强平阈值 + Status: leverStatus.Status, // 股杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + order.System = system + + // 2、股票下单判定 + // 下单判定设置(false无设置|true止盈止损) + checkBool, stopWinPrice, stopLossPrice, err := StockFurVoteStopType(order) + if err != nil { + applogger.Error("%v PlacingStockFurOrders.StockEurVoteStopType:%v", common.ErrShareFur, err) + return flags.SetNull, err + } + // 下单判定设置(限价|市价) + limitOrMarketPrice, err := uo.StockFurVoteDealType(order) + if err != nil { + applogger.Error("%v PlacingStockFurOrders.StockFurVoteDealType:%v", common.ErrShareFur, err) + return flags.SetNull, err + } + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(order.TradeType, stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v PlacingStockFurOrders.VoteTradeType:%v", common.ErrShareFur, err) + return flags.SetNull, err + } + + // 3、订单持久化录入(并处理资产信息) + pryNum := SystemDealWithLever(order) + orderId, err := uo.StockFurOrderWriteDB(ctx, userId, order, limitOrMarketPrice, pryNum) + if err != nil || len(orderId) == 0 { + applogger.Error("%v PlacingStockFurOrders.StockFurOrderWriteDB:%v", common.ErrShareFur, err) + return flags.SetNull, err + } + + // 4、处理订单信息 + chg := GetShareChgFur(flags.Fur, order.StockId) // 涨跌幅标识值 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.FurMarket, time.Now()) // 开盘时间 + marketStatus, shareOrder, err := share.ShareFurCacheDeal(ctx, userId, orderId, subKey, order, chg, priceNew, closingTime, blockTime) + if err != nil || shareOrder == nil { + applogger.Error("%v PlacingStockFurOrders.ShareFurCacheDeal:%v", common.ErrShareFur, err) + return flags.SetNull, err + } + // 计算保证金 = 订单价格 * 订单数量 / 杠杆 + shareOrder.Order.MarketMoney = limitOrMarketPrice.Mul(decimal.RequireFromString(order.OrderNumber)).Div(pryNum).String() + if !flags.CheckSetting { + applogger.Debug("订单ID:%v", shareOrder.OrderId) + applogger.Debug("订单交易对:%v", shareOrder.Symbol) + applogger.Debug("订单状态:%v", shareOrder.Status) + applogger.Debug("订单用户ID:%v", shareOrder.UserId) + applogger.Debug("开盘价:%v", shareOrder.OpenPrice) + applogger.Debug("收盘价:%v", shareOrder.ClosingPrice) + applogger.Debug("下单信息:%v", shareOrder.Order) + } + + // 6、股票订单(挂单|持仓)缓存列表,等待队列计算 + if err = share.ShareFurHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v PlacingStockFurOrders.ShareFurHashUserOrder:%v", common.ErrShareFur, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 7、用户订阅股票订单信息 + orderIdKey := virtual.OrderIdListKey(userKey, userId) + if err = share.ShareFurHashUserOrder(Reds, orderIdKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockFurOrders.%v:%v", common.ErrShareFur, userKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 8、管理员订阅订单信息 + if err = share.ShareFurHashUserOrder(Reds, adminKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockFurOrders.%v:%v", common.ErrShareFur, adminKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + return orderId, nil +} + +// StockFurOrderWriteDB +// +// @Description: 法股下单操作 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) StockFurOrderWriteDB(ctx context.Context, userId int64, order structure.ShareOrder, limitOrMarketPrice, lever decimal.Decimal) (string, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockFurOrderWriteDB.Begin:%v", common.ErrShareFur, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 获取当前下单用户的资产 + var usableOld, frozenOld decimal.Decimal + stockSgd, err := uo.GetBotUserStockFurByUserIdAndStockId(session, userId, flags.ShareFurBasicUnit) + if err != nil || stockSgd == nil { + applogger.Error("%v StockFurOrderWriteDB.GetBotUserStockFurByUserIdAndStockId:%v", common.ErrShareFur, err) + return flags.SetNull, flags.ErrMySqlDB + } + usableOld = decimal.RequireFromString(stockSgd.UsableNum) + frozenOld = decimal.RequireFromString(stockSgd.FrozenNum) + + // 检查用户订单下单资产 + if usableOld.IsZero() || usableOld.IsNegative() || frozenOld.IsNegative() { + return flags.SetNull, flags.ErrShareOne + } + + // 获取当前系统下单用户的非资产 + var usableFOld, frozenFOld decimal.Decimal + stockFSGD, err := uo.GetBotUserStockFurByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockFurOrderWriteDB.FeiSGD:%v", common.ErrShareFur, err) + return flags.SetNull, flags.ErrMySqlDB + } + if stockFSGD != nil { + usableFOld = decimal.RequireFromString(stockFSGD.UsableNum) + frozenFOld = decimal.RequireFromString(stockFSGD.FrozenNum) + } + if !flags.CheckSetting { + applogger.Debug("下单可用资产:%v", usableOld) + applogger.Debug("下单冻结资产:%v", frozenOld) + applogger.Debug("下单查询非资产账户:%v", stockFSGD) + applogger.Debug("下单可用非资产:%v", usableFOld) + applogger.Debug("下单冻结非资产:%v", frozenFOld) + } + + // 整理当前下单信息 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 订单手续费 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 订单数量 + marketMoney := orderNumber.Mul(limitOrMarketPrice).Div(lever) // 订单金额(杠杆下单) = 订单数量 * 交易价格 / 杠杆 + totalMoney := marketMoney.Add(serviceCost) // 订单总金额 + order.MarketMoney = marketMoney.String() // 市值金额即为保证金 + + // 检查订单ID是否存在,新增下单信息 + var orderId string + if !CheckTypeStatus(order.Type) { + orderId, err = uo.VerifyBotStockFurTradeOrderId(session) + if err != nil { + applogger.Error("%v StockFurOrderWriteDB.VerifyBotStockFurTradeOrderId:%v", common.ErrShareFur, err) + return flags.SetNull, err + } + trade := orders.BotStockFurTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockFurTrade(session, trade); err != nil { + applogger.Error("%v StockFurOrderWriteDB.CreateBotStockFurTrade:%v", common.ErrShareFur, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + orderId, err = uo.VerifyBotStockBlockTradeOrderId(session) + if err != nil { + applogger.Error("%v StockFurOrderWriteDB.VerifyBotStockBlockTradeOrderId:%v", common.ErrShareFur, err) + return flags.SetNull, err + } + trade := orders.BotStockBlockTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockBlockTrade(session, trade); err != nil { + applogger.Error("%v StockFurOrderWriteDB.CreateBotStockBlockTrade:%v", common.ErrShareFur, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + // 下单判定 + residue := usableOld.Sub(totalMoney).Div(usableOld) + if usableOld.Cmp(totalMoney) <= 0 || residue.Cmp(utils.DecimalsStrInt()) <= 0 { + return flags.SetNull, flags.ErrPublicTow + } + + var usableNew, frozenNew, usableFNew, frozenFNew decimal.Decimal + usableNew = usableOld.Sub(totalMoney) // 可用资产 + frozenNew = frozenOld.Add(totalMoney) // 冻结资产 + if order.StockId != flags.ShareFurBasicUnit { + usableFNew = usableFOld.Add(orderNumber) // 可用非资产 + frozenFNew = frozenFOld // 冻结非资产 + } + // 检查用户订单下单资产 + if usableNew.IsNegative() { + return flags.SetNull, flags.ErrPublicTow + } + + // 下单更新资产信息 + stockSgdModel := orders.UpdateBotUserStockFur(ctx, usableNew.String(), frozenNew.String()) + err = uo.UpdateBotUserStockFurByUserIdAndStockId(session, userId, flags.ShareFurBasicUnit, stockSgdModel) + if err != nil { + applogger.Error("%v StockFurOrderWriteDB.UpdateBotUserStockFurByUserIdAndStockId:%v", common.ErrShareFur, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 下单(新增|更新)非资产信息 + if stockFSGD == nil { + stockFTHBModel := orders.CreateBotUserStockFur(ctx, userId, order.StockId, usableFNew.String(), frozenFNew.String()) + err = uo.CreateBotUserStockFurFTHB(session, stockFTHBModel) + if err != nil { + applogger.Error("%v StockFurOrderWriteDB.CreateBotUserStockFurFTHB:%v", common.ErrShareFur, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + stockFTHBModel := orders.UpdateBotUserStockFur(ctx, usableFNew.String(), frozenFNew.String()) + err = uo.UpdateBotUserStockFurByUserIdAndStockId(session, userId, order.StockId, stockFTHBModel) + if err != nil { + applogger.Error("%v StockFurOrderWriteDB.UpdateBotUserStockFurByUserIdAndStockId:%v", common.ErrShareFur, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockFurOrderWriteDB.Commit:%v", common.ErrShareFur, err) + return flags.SetNull, flags.ErrMySqlDB + } + + return orderId, nil +} + +// StockFurOpenOrder +// +// @Description: 法股系统开仓 +// @param ctx +// @param db +// @param userId +// @param orderId +// @param openPrice +// @param order +// @return error +func StockFurOpenOrder(ctx context.Context, db *xorm.EngineGroup, userId int64, orderId, openPrice string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockFurOpenOrder.NewSession:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockThb, err := Uo.GetBotUserStockFurByUserIdAndStockId(session, userId, flags.ShareFurBasicUnit) + if err != nil || stockThb == nil { + applogger.Error("%v StockFurOpenOrder.GetBotUserStockFurByUserIdAndStockId:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockThb.UsableNum) // 用户可用资产 + frozen = decimal.RequireFromString(stockThb.FrozenNum) // 用户冻结资产 + + // 检查用户订单开仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrPublicThree + } + if order.StockId != flags.ShareFurBasicUnit { + stockFThb, err := Uo.GetBotUserStockFurByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockFurOpenOrder.GetBotUserStockFurByUserIdAndStockId:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(stockFThb.UsableNum) // 用户非可用资产 + frozenNo = decimal.RequireFromString(stockFThb.FrozenNum) // 用户非冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + + // 转换股票下单信息 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 下单股数 + markerMoney := decimal.RequireFromString(order.MarketMoney) // 下单金额 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 下单手续费 + totalMoney := markerMoney.Add(serviceCost) // 下单总金额 = (下单手续费 + 下单金额) + openOrderPrice := decimal.RequireFromString(openPrice) // 开盘价格 + if !flags.CheckSetting { + applogger.Debug("下单订单数量:%v", orderNumber) + applogger.Debug("下单订单金额:%v", markerMoney) + applogger.Debug("下单订单手续费:%v", serviceCost) + applogger.Debug("下单订单总金额:%v", totalMoney) + } + + // 手续费记录 + openPriceNew := openOrderPrice.Mul(orderNumber).String() // 开仓手续费 = 开仓价格 * 股数 * 开仓手续费 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareFurMarketType, flags.OpenBrokType, orderId, openPriceNew) + if err != nil { + applogger.Error("%v StockFurOpenOrder.CalculateHandlingFeesShare:%v", common.ErrShareFur, err) + return err + } + openServiceCost := decimal.RequireFromString(cost) // 开仓手续费 + openMarkerMoney := openOrderPrice.Mul(orderNumber).Div(decimal.RequireFromString(order.PryNum)) // 开仓金额 = 开仓价格 * 股数 / 杠杆 + openTotalMoney := openMarkerMoney.Add(openServiceCost) // 开仓总金额 = 开仓金额 + 开仓手续费 + floatPrice := totalMoney.Sub(openTotalMoney) // 计算容差 = 下单总额 - 开仓总额 + if !flags.CheckSetting { + applogger.Debug("开仓订单价格:%v", openOrderPrice) + applogger.Debug("开仓手续费:%v", openServiceCost) + applogger.Debug("开仓总金额:%v", openTotalMoney) + applogger.Debug("下单开仓总金额容差值:%v", floatPrice) + } + + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + usableNew = usable.Add(floatPrice) // 可用资产(处理容差值) + frozenNew = frozen.Sub(totalMoney).Add(openMarkerMoney) // 冻结资产(处理容差值)---> 当前冻结金额 = 原冻结金额 - 下单总额 + if order.StockId != flags.ShareFurBasicUnit { + usableNoNew = usableNo // 非可用资产 + frozenNoNew = frozenNo // 非冻结资产 + } + + // 检查用户订单开仓资产 + if frozenNew.IsNegative() || usableNew.IsNegative() { + return flags.ErrPublicThree + } + if !flags.CheckSetting { + applogger.Debug("下单后用户可用资产:%v", usableNew) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + } + + // 处理资产信息 + userStockThb := orders.UpdateBotUserStockFur(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockFurByUserIdAndStockId(session, userId, flags.ShareFurBasicUnit, userStockThb); err != nil { + applogger.Error("%v StockFurOpenOrder.UpdateBotUserStockFurByUserIdAndStockId:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + + // 更新非资产信息 + if order.StockId != flags.ShareFurBasicUnit { + userStockFThb := orders.UpdateBotUserStockFur(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = Uo.UpdateBotUserStockFurByUserIdAndStockId(session, userId, order.StockId, userStockFThb); err != nil { + applogger.Error("%v StockFurOpenOrder.UpdateBotUserStockFurByUserIdAndStockId:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + } + + // 返佣记录|资金信息|资金详情信息 + if err = Uo.ShareFurRebateCalculation(ctx, session, int(userId), flags.ShareFurMarketType, flags.OpenBrokType, flags.OpenMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockFurOpenOrder.ShareFurRebateCalculation:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + + // 处理订单信息(成交价|仓位|开仓时间|订单总金额|手续费|持仓状态) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateOpenBotStockFurTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarkerMoney.String()) + if err = Uo.UpdateBotStockFurTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockFurOpenOrder.UpdateBotStockFurTradeByOrderId:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + var list []models.BotUserStockFurLog + qData0 := orders.CreatBotUserStockFurLog(ctx, userId, flags.CostMoney, flags.ShareFurBasicUnit, NegativeValue(openServiceCost.String()), orderId) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockFurLog(ctx, userId, flags.Freeze, flags.ShareFurBasicUnit, NegativeValue(openMarkerMoney.String()), orderId) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockFurLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockFurLogList(session, list); err != nil { + applogger.Error("%v StockFurOpenOrder.CreatBotUserStockFurLogList:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateOpenBotStockBlockTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarkerMoney.String()) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockFurOpenOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareFurBasicUnit, NegativeValue(openServiceCost.String()), orderId, order.Type) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Freeze, flags.ShareFurBasicUnit, NegativeValue(openMarkerMoney.String()), orderId, order.Type) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId, order.Type) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockFurOpenOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockFurOpenOrder.Commit:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + + return nil +} + +// StockFurClosingOrder +// +// @Description: 法股系统平仓 +// @param ctx +// @param db +// @param orderId +// @param price +// @param order +// @return error +func StockFurClosingOrder(ctx context.Context, db *xorm.EngineGroup, orderId string, price string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockFurClosingOrder.NewSession:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + + // 查询订单信息 + var userId int64 + var dealPrice, orderNumber, totalAmount, serviceCost, markerMoney decimal.Decimal + if !CheckTypeStatus(order.Type) { + tread, err := Uo.GetBotStockFurTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockFurClosingOrder.GetBotStockFurTradeByOrderIdOrStatus:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + markerMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓下单金额 + } else { + tread, err := Uo.GetBotStockBlockTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockFurClosingOrder.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + markerMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓下单金额 + } + + if !flags.CheckSetting { + applogger.Debug("下单开仓用户Id:%v", userId) + applogger.Debug("下单开仓开仓价格:%v", dealPrice) + applogger.Debug("下单开仓订单数量:%v", orderNumber) + applogger.Debug("下单开仓总金额:%v", totalAmount) + applogger.Debug("下单开仓手续费:%v", serviceCost) + applogger.Debug("下单开仓开仓金额:%v", markerMoney) + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + userStockThb, err := Uo.GetBotUserStockFurByUserIdAndStockId(session, userId, flags.ShareFurBasicUnit) + if err != nil { + applogger.Error("%v StockFurClosingOrder.GetBotUserStockFurByUserIdAndStockId:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(userStockThb.UsableNum) // 用户可用资金 + frozen = decimal.RequireFromString(userStockThb.FrozenNum) // 用户非冻结资金 + + // 检查用户订单平仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrShareTow + } + + // 查询当前下单用户可用非账户和冻结金额 + if order.StockId != flags.ShareFurBasicUnit { + userStockFThb, err := Uo.GetBotUserStockFurByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockFurClosingOrder.GetBotUserStockFurByUserIdAndStockId:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(userStockFThb.UsableNum) // 用户非可用资金 + frozenNo = decimal.RequireFromString(userStockFThb.FrozenNum) // 用户非冻结资金 + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + + // 手续费处理 + closePrice := decimal.RequireFromString(price) // 平仓价格 + cloePriceCost := closePrice.Mul(orderNumber).String() // 平仓手续费 = 平仓价格 * 股数 * 手续费比例 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareFurMarketType, flags.ClosingBrokType, orderId, cloePriceCost) + if err != nil { + applogger.Error("%v StockFurClosingOrder.CalculateHandlingFeesShare:%v", common.ErrShareFur, err) + return err + } + closeServiceCost := decimal.RequireFromString(cost) + if !flags.CheckSetting { + applogger.Debug("平仓价格:%v", closePrice) + applogger.Debug("平仓手续费手续费:%v", closeServiceCost) + } + + //已经实现盈亏计算公式(已平仓结算方式) + //买涨 已经实现盈亏 = (平仓成交价-开仓成交价)*股数 + //买跌 已经实现盈亏 = (开仓成交价-平仓成交价)*股数 + var usableNew, frozenNew, usableNewNo, frozenNewNo, subPrice, resultPrice decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买涨 + subPrice = closePrice.Sub(dealPrice) + resultPrice = subPrice.Mul(orderNumber) + case flags.TradeTypeSell: // 买跌 + subPrice = dealPrice.Sub(closePrice) + resultPrice = subPrice.Mul(orderNumber) + default: + + } + + // 判定亏损不能超过 = 保证金 + 平仓手续费 + if resultPrice.IsNegative() { + amountLoss := markerMoney.Sub(closeServiceCost) + if resultPrice.Abs().Cmp(amountLoss) >= 0 { + resultPrice = amountLoss.Neg() + } + } + + // 用户资产账户 + usableNew = usable.Add(resultPrice).Sub(closeServiceCost).Add(markerMoney) // 可用资产 = 原可用资产 + ((正负)盈亏) - 平仓手续费 + 开仓下单金额 + if frozen.Cmp(markerMoney) == -1 { + frozenNew = frozen.Sub(frozen) // 冻结资产 + } else { + frozenNew = frozen.Sub(markerMoney) // 冻结资产 + } + + // 用户非资产账户 + if order.StockId != flags.ShareFurBasicUnit { + usableNewNo = usableNo.Sub(orderNumber) // 可用非资产 = 原可用非资产 - 下单股数 + frozenNewNo = frozenNo // 可用非冻结资产 + } + + // 检查用户订单平仓资产 + if frozenNew.IsNegative() || usableNewNo.IsNegative() { + return flags.ErrShareTow + } + if !flags.CheckSetting { + applogger.Debug("可用资产:%v", usableNew) + applogger.Debug("冻结资产:%v", frozenNew) + applogger.Debug("可用非资产:%v", usableNewNo) + applogger.Debug("冻结非资产:%v", frozenNewNo) + } + + // 平仓(处理资产表(资产)) + userStockUTHB := orders.UpdateBotUserStockFur(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockFurByUserIdAndStockId(session, userId, flags.ShareFurBasicUnit, userStockUTHB); err != nil { + applogger.Error("%v StockFurClosingOrder.UpdateBotUserStockFurByUserIdAndStockId:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + + // 平仓(处理资产表(非资产)) + if order.StockId != flags.ShareFurBasicUnit { + userStockFTHB := orders.UpdateBotUserStockFur(ctx, usableNewNo.String(), frozenNewNo.String()) + if err = Uo.UpdateBotUserStockFurByUserIdAndStockId(session, userId, order.StockId, userStockFTHB); err != nil { + applogger.Error("%v StockFurClosingOrder..UpdateBotUserStockFurByUserIdAndStockId:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + } + + // 平仓(返佣记录表|资产表|资金变动表) + if err = Uo.ShareFurRebateCalculation(ctx, session, int(userId), flags.ShareFurMarketType, flags.ClosingBrokType, flags.CloseMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockFurClosingOrder.ShareFurRebateCalculation:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + + // 平仓(处理订单信息(平仓价|保证金|平仓|订单总金额|平仓手续费|完成订单)) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateCloseBotStockFurTrade(ctx, price, cost) + if err = Uo.UpdateBotStockFurTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockFurClosingOrder.UpdateBotStockFurTradeByOrderId:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockFurLog + qData0 := orders.CreatBotUserStockFurLog(ctx, userId, flags.Thaw, flags.ShareFurBasicUnit, markerMoney.String(), orderId) // 平仓(资金变动明细表(开仓保证金)) + qData1 := orders.CreatBotUserStockFurLog(ctx, userId, flags.CostMoney, flags.ShareFurBasicUnit, NegativeValue(closeServiceCost.String()), orderId) // 平仓(资金变动明细表(-平仓手续费)) + qData2 := orders.CreatBotUserStockFurLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockFurLog(ctx, userId, flags.TransferOut, flags.ShareFurBasicUnit, resultPrice.String(), orderId) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockFurLog(ctx, userId, flags.ChangeInto, flags.ShareFurBasicUnit, resultPrice.String(), orderId) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockFurLogList(session, list); err != nil { + applogger.Error("%v StockFurClosingOrder.CreatBotUserStockFurLogList:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateCloseBotStockBlockTrade(ctx, price, cost) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockFurClosingOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Thaw, flags.ShareFurBasicUnit, markerMoney.String(), orderId, order.Type) // 平仓(资金变动明细表(开仓保证金)) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareFurBasicUnit, NegativeValue(closeServiceCost.String()), orderId, order.Type) // 平仓(资金变动明细表(-平仓手续费)) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId, order.Type) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, flags.ShareFurBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, flags.ShareFurBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockFurClosingOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockFurClosingOrder.Commit:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + + return nil +} + +// UpdateBotStockFurCancelByOrderId +// +// @Description: 法股撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockFurCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockFurCancelByOrderId.Begin:%v", common.ErrShareFur, err) + return false, flags.ErrMySqlDB + } + + // 获取订单信息 + var userId int64 + var stockId string + var marketMoneyOld, serviceCostOld, orderNumber decimal.Decimal + if !CheckTypeStatus(typeStatus) { + stockTrade, err := uo.GetBotStockFurTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockFurCancelByOrderId.GetBotStockFurTradeByOrderId:%v", common.ErrShareFur, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } else { + stockTrade, err := uo.GetBotStockBlockTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockFurCancelByOrderId.GetBotStockBlockTradeByOrderId:%v", common.ErrShareFur, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } + + // 用户资产信息 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockThb, err := uo.GetBotUserStockFurByUserIdAndStockId(session, userId, flags.ShareFurBasicUnit) + if err != nil || stockThb == nil { + applogger.Error("%v UpdateBotStockFurCancelByOrderId.GetBotUserStockFurByUserIdAndStockId:%v", common.ErrShareFur, err) + return false, flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockThb.UsableNum) // 用户账户可用资产 + frozen = decimal.RequireFromString(stockThb.FrozenNum) // 用户账户冻结资产 + + // 检查用户订单撤单资产 + if usable.IsNegative() || frozen.IsNegative() { + return false, flags.ErrShareNine + } + if stockId != flags.ShareFurBasicUnit { + stockFThb, err := uo.GetBotUserStockFurByUserIdAndStockId(session, userId, stockId) + if err != nil { + applogger.Error("%v UpdateBotStockFurCancelByOrderId.GetBotUserStockEurByUserIdAndStockId:%v", common.ErrShareFur, err) + return false, flags.ErrPublicFour + } + usableNo = decimal.RequireFromString(stockFThb.UsableNum) // 用户非账户可用资产 + frozenNo = decimal.RequireFromString(stockFThb.FrozenNum) // 用户非账户冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("用户原始可用资金:%v", usable) + applogger.Debug("用户原始冻结资金:%v", frozen) + applogger.Debug("用户原始可用非资金:%v", usableNo) + applogger.Debug("用户原始冻结非资金:%v", frozenNo) + } + + // 更新订单信息 + var entrustKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + botStockTrade := orders.BotStockFurCancelByOrderId(ctx) + if err = uo.UpdateBotStockFurTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockFurCancelByOrderId.UpdateBotStockFurTradeByOrderId:%v", common.ErrShareFur, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareFurEntrust + userKey = setting.ShareFurSubscribe + adminKey = setting.AdminShareFurSubscribe + } else { + botStockTrade := orders.BotStockBlockCancelByOrderId(ctx) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockFurCancelByOrderId.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareFur, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareBlkEntrust + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // Operational Spot Asset Table + totalMoney := marketMoneyOld.Add(serviceCostOld) // 订单总金额 + + // update total asset data + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + usableNew = usable.Add(totalMoney) // 用户总资产 + frozenNew = frozen.Sub(totalMoney) // 用户冻结资产 + if stockId != flags.ShareFurBasicUnit { + usableNoNew = usableNo.Sub(orderNumber) // 用户非可用资产 + frozenNoNew = frozenNo // 用户非冻结资产 + } + + // 检查用户订单撤单资产 + if frozenNew.IsNegative() || usableNoNew.IsNegative() { + return false, flags.ErrShareNine + } + if !flags.CheckSetting { + applogger.Debug("用户撤单可用总资产:%v", usableNew) + applogger.Debug("用户撤单冻结总资产:%v", frozenNew) + applogger.Debug("用户非撤单可用总资产:%v", usableNoNew) + applogger.Debug("用户非撤单冻结总资产:%v", frozenNoNew) + } + + // 更新资产信息和非资产信息 + userStockTHB := orders.UpdateBotUserStockFur(ctx, usableNew.String(), frozenNew.String()) + if err = uo.UpdateBotUserStockFurByUserIdAndStockId(session, userId, flags.ShareFurBasicUnit, userStockTHB); err != nil { + applogger.Error("%v UpdateBotStockFurCancelByOrderId.UpdateBotUserStockFurByUserIdAndStockId:%v", common.ErrShareFur, err) + return false, flags.ErrMySqlDB + } + if stockId != flags.ShareFurBasicUnit { + userStockFTHB := orders.UpdateBotUserStockFur(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = uo.UpdateBotUserStockFurByUserIdAndStockId(session, userId, stockId, userStockFTHB); err != nil { + applogger.Error("%v UpdateBotStockFurCancelByOrderId.UpdateBotUserStockFurByUserIdAndStockId:%v", common.ErrShareFur, err) + return false, flags.ErrMySqlDB + } + } + + // 删除订单缓存列表 + if err = Reds.HDel(context.Background(), entrustKey, orderId).Err(); err != nil { + applogger.Error("%v UpdateBotStockFurCancelByOrderId.HDel:%v", common.ErrShareFur, err) + return false, flags.ErrCacheDB + } + + // 更新用户订阅订单缓存列表 + userSubKey := virtual.OrderIdListKey(userKey, userId) + if err = share.UpdateShareFurHashByOrderId(Reds, orderId, userSubKey, flags.Cancel); err != nil { + applogger.Error("%v UpdateBotStockFurCancelByOrderId.%v:%v", common.ErrShareFur, userKey, err) + return false, flags.ErrCacheDB + } + + // 更新管理员订阅订单缓存列表 + if err = UpdateShareFurSubscribeHashStatusByOrderId(orderId, adminKey, flags.Cancel, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockFurCancelByOrderId.%v:%v", common.ErrShareFur, adminKey, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockFurCancelByOrderId.Commit:%v", common.ErrShareFur, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockFurStopByOrderId +// +// @Description: 法股设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockFurStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockFurStopByOrderId.NewSession:%v", common.ErrShareFur, err) + return false, flags.ErrMySqlDB + } + + // 设置止盈止损 + var userId int64 + if order.StopType == 1 { + // 下单信息 + checkBool, stopWinPrice, stopLossPrice, err := uo.UpdateVoteStopType(order) + if err != nil { + applogger.Error("%v UpdateBotStockFurStopByOrderId.UpdateVoteStopType:%v", common.ErrShareFur, err) + return false, err + } + if !flags.CheckSetting { + applogger.Debug("当前止盈止损数据:%v,%v,%v", checkBool, stopWinPrice, stopLossPrice) + } + + // 止盈止损判定 + var tradeType int + var limitOrMarketPrice decimal.Decimal + if !CheckTypeStatus(order.Type) { + trade, err := uo.GetBotStockFurTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockFurStopByOrderId.GetBotStockFurTradeByOrderIdOrStatus:%v", common.ErrShareFur, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareFurVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockFurStopByOrderId.UpdateShareFurVoteDealType:%v", common.ErrShareFur, err) + return false, err + } + } else { + trade, err := uo.GetBotStockBlockTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockFurStopByOrderId.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareFur, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareBlockVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockFurStopByOrderId.UpdateShareBlockVoteDealType:%v", common.ErrShareFur, err) + return false, err + } + } + if !flags.CheckSetting { + applogger.Debug("当前开仓价格:%v", limitOrMarketPrice) + } + + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(int64(tradeType), stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v UpdateBotStockFurStopByOrderId.VoteTradeType:%v", common.ErrShareFur, err) + return false, err + } + } else { + order.StopLossPrice = decimal.Zero.String() + order.StopWinPrice = decimal.Zero.String() + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[userId] + if ok { + return false, flags.ErrPublicServe + } + + // 更新订单表 + var positionKey string + if !CheckTypeStatus(order.Type) { + botStockTrade := orders.BotStockFurStopByOrderId(ctx, order) + if err = uo.UpdateBotStockFurTradeByOrderId(session, order.OrderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockFurStopByOrderId.UpdateBotStockFurTradeByOrderId:%v", common.ErrShareFur, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareFurPosition + } else { + botStockTrade := orders.BotStockBlockStopByOrderId(ctx, order) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, order.OrderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockFurStopByOrderId.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareFur, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareBlkPosition + } + + // 挂单缓存队列 + if err = share.UpdateShareFurStopByOrderId(Reds, order, positionKey, flags.Position); err != nil { + applogger.Error("%v UpdateBotStockFurStopByOrderId.UpdateShareFurStopByOrderId:%v", common.ErrShareFur, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockFurStopByOrderId.Commit:%v", common.ErrShareFur, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockFurClosingByOrderId +// +// @Description: 法股用户平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockFurClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.FurMarket) { + return false, flags.ErrStopTread + } + + // 1、查询持仓缓存列表数据并清理对应缓存 + var positionKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + positionKey = setting.MarketShareFurPosition + userKey = setting.ShareFurSubscribe + adminKey = setting.AdminShareFurSubscribe + } else { + positionKey = setting.MarketShareBlkPosition + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + var entrustCache *share.ShareFurTallyCache + entrust, err := Reds.HGet(context.Background(), positionKey, orderId).Result() + if err != nil { + applogger.Error("%v UpdateBotStockFurClosingByOrderId.HGet:%v", common.ErrShareFur, err) + return false, flags.ErrShareFive + } + var entrustJson share.ShareFurTallyCache + if err = json.Unmarshal([]byte(entrust), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockFurClosingByOrderId.Unmarshal:%v", common.ErrShareFur, err) + return false, flags.ErrCacheDB + } + if orderId == entrustJson.OrderId { + entrustCache = &entrustJson + } + + // 2、判定是否存在平仓订单 + if entrustCache == nil { + return false, flags.ErrShareFive + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[entrustJson.UserId] + if ok { + return false, flags.ErrPublicServe + } + + // 市场设置交易时间(T+0,T+1,T+2s......) + if !CheckShareSystemTime(entrustCache.ClosingTime) { + return false, flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("手动平仓:%v", entrustCache) + } + + // 3、当前最新价格 + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Fur, entrustCache.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareFurTheLatestPrice(subKey, entrustCache.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockFurClosingByOrderId.GetShareFurTheLatestPrice:%v", common.ErrShareFur, err) + return false, flags.ErrStopTread + } + + // 4、平仓处理 + if err = StockFurClosingOrder(ctx, Msql, orderId, closingPrice.String(), entrustCache.Order); err != nil { + applogger.Error("%v UpdateBotStockFurClosingByOrderId.StockFurClosingOrder:%v", common.ErrShareFur, err) + return false, err + } + + // 5、清理持仓订单信息 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), positionKey, orderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockFurClosingByOrderId.HDel:%v", common.ErrShareFur, err) + return false, flags.ErrCacheDB + } + + // 6、平仓更新订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(userKey, entrustCache.UserId) + if err = UpdateShareFurSubscribeHashStatusByOrderId(orderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockFurClosingByOrderId.%v:%v", common.ErrShareFur, userKey, err) + return false, flags.ErrCacheDB + } + + // 7、平仓更新管理员订阅缓存订单状态 + if err = UpdateShareFurSubscribeHashStatusByOrderId(orderId, adminKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockFurClosingByOrderId.%v:%v", common.ErrShareFur, adminKey, err) + return false, flags.ErrCacheDB + } + + return true, nil +} + +// UpdateBotStockFurAllClosingByOrderId +// +// @Description: 德股用户一键平仓 +// @receiver uo +// @param ctx +// @param userId +// @return error +func (uo *userOrderRepo) UpdateBotStockFurAllClosingByOrderId(ctx context.Context, userId int64) error { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.FurMarket) { + return flags.ErrStopTread + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe + } + + // 1、查询当前用户所有订单 + orderMap, err := uo.GetBotStockFurTradeByUserId(userId) + if err != nil { + applogger.Error("%v UpdateBotStockFurAllClosingByOrderId.GetBotStockFurTradeByUserId:%v", common.ErrShareFur, err) + return flags.ErrMySqlDB + } + + // 2、查询持仓缓存列表数据-1、清理持仓列表缓存 2、处理平仓数据 3、清理订单ID缓存列表 + entrust, err := Reds.HGetAll(context.Background(), setting.MarketShareFurPosition).Result() + if err != nil { + applogger.Error("%v UpdateBotStockFurAllClosingByOrderId.HGetAll:%v", common.ErrShareFur, err) + return flags.ErrShareFive + } + + // 3、循环检查股票交易对最新价格(有一个查询不到既不能平仓) + var entrustList []share.ShareFurTallyCache + closePriceMap := make(map[string]decimal.Decimal) + for key, value := range entrust { + var entrustJson share.ShareFurTallyCache + if err = json.Unmarshal([]byte(value), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockFurAllClosingByOrderId.Unmarshal:%v", common.ErrShareFur, err) + return flags.ErrStopTread + } + _, ok := orderMap[entrustJson.OrderId] + if ok { + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Fur, entrustJson.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareFurTheLatestPrice(subKey, entrustJson.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockFurAllClosingByOrderId.GetShareSgdTheLatestPrice:%v", common.ErrShareFur, err) + return flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("订阅Key:%v,最新价格:%v,订单ID:%v", subKey, closingPrice, entrustJson.OrderId) + } + + closePriceMap[key] = closingPrice + entrustList = append(entrustList, entrustJson) + } + } + + // 4、股票一键平仓 + for _, value := range entrustList { + closePrice, ok := closePriceMap[value.OrderId] + if ok { + // 平仓 + if err = StockFurClosingOrder(ctx, uo.data.mysqlDB, value.OrderId, closePrice.String(), value.Order); err != nil { + applogger.Error("%v UpdateBotStockFurAllClosingByOrderId.StockFurClosingOrder:%v", common.ErrShareFur, err) + return err + } + + // 清理持仓缓存列表 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), setting.MarketShareFurPosition, value.OrderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockFurAllClosingByOrderId.HDel:%v", common.ErrShareFur, err) + return flags.ErrCacheDB + } + + // 平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareFurSubscribe, value.UserId) + if err = UpdateShareFurSubscribeHashStatusByOrderId(value.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockFurAllClosingByOrderId.ShareFurSubscribe:%v", common.ErrShareFur, err) + return flags.ErrCacheDB + } + + // 平仓更新管理员订阅订单状态 + if err = UpdateShareFurSubscribeHashStatusByOrderId(value.OrderId, setting.AdminShareFurSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockFurAllClosingByOrderId.AdminShareFurSubscribe:%v", common.ErrShareFur, err) + return flags.ErrCacheDB + } + } + } + + return nil +} + +// GetBotStockFurTradeByUserId +// +// @Description: +// @receiver uo +// @param ctx +// @param userId +// @return map[string]string +// @return error +func (uo *userOrderRepo) GetBotStockFurTradeByUserId(userId int64) (map[string]string, error) { + var botStockFurTrade []models.BotStockFurTrade + if err := uo.data.mysqlDB.Table(flags.BotStockFurTrade). + Where("user_id = ?", userId). + Where("status = 1"). + Find(&botStockFurTrade); err != nil { + return nil, err + } + + botMap := make(map[string]string) + for _, value := range botStockFurTrade { + botMap[value.OrderId] = value.OrderId + } + + return botMap, nil +} + +// GetShareFurTheLatestPrice +// +// @Description: +// @receiver uo +// @param ctx +// @param subKey +// @param tradeType +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) GetShareFurTheLatestPrice(subKey string, tradeType int64) (decimal.Decimal, error) { + priceNew, err := share.ShareFurSubMarketPrice(subKey) + if err != nil { + applogger.Error("%v GetShareFurTheLatestPrice.ShareFurSubMarketPrice:%v", common.ErrShareFur, err) + return decimal.Decimal{}, err + } + + priceS := decimal.RequireFromString(priceNew) + + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tradeType { + case flags.TradeTypeBuy: // 买涨 + openPrice = priceS.Sub(difference) // 开仓价格 + case flags.TradeTypeSell: // 买跌 + openPrice = priceS.Add(difference) // 开仓价格 + } + + return openPrice, nil +} + +// GetBotStockFurTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @return *models.BotStockFurTrade +// @return error +func (uo *userOrderRepo) GetBotStockFurTradeByOrderId(session *xorm.Session, orderId string) (*models.BotStockFurTrade, error) { + var botStockFurTrade []models.BotStockFurTrade + if err := session.Table(flags.BotStockFurTrade). + Where("order_id = ?", orderId). + Find(&botStockFurTrade); err != nil { + return nil, err + } + + for _, value := range botStockFurTrade { + return &value, nil + } + + return nil, nil +} + +// GetBotUserStockEurByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @return *models.BotUserStockFur +// @return error +func (uo *userOrderRepo) GetBotUserStockFurByUserIdAndStockId(session *xorm.Session, userId int64, stockId string) (*models.BotUserStockFur, error) { + var stockEur []models.BotUserStockFur + if err := session.Table(flags.BotUserStockFur). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&stockEur); err != nil || len(stockEur) <= 0 { + return nil, err + } + + for _, value := range stockEur { + return &value, nil + } + + return nil, nil +} + +// UpdateBotStockEurTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotStockFurTradeByOrderId(session *xorm.Session, orderId string, stock models.BotStockFurTrade) error { + _, err := session.Table(flags.BotStockFurTrade). + Where("order_id = ?", orderId). + Update(&stock) + + if err != nil { + return err + } + + return nil +} + +// CreateBotStockFurTrade +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param trade +// @return error +func (uo *userOrderRepo) CreateBotStockFurTrade(session *xorm.Session, trade models.BotStockFurTrade) error { + _, err := session.Table(flags.BotStockFurTrade).Insert(&trade) + if err != nil { + return err + } + + return nil +} + +// CreateBotUserStockFurFTHB +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param stock +// @return error +func (uo *userOrderRepo) CreateBotUserStockFurFTHB(session *xorm.Session, stock models.BotUserStockFur) error { + _, err := session.Table(flags.BotUserStockFur).Insert(&stock) + if err != nil { + return err + } + + return nil +} + +// UpdateBotUserStockFurByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotUserStockFurByUserIdAndStockId(session *xorm.Session, userId int64, stockId string, stock models.BotUserStockFur) error { + _, err := session.Table(flags.BotUserStockFur). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&stock) + if err != nil { + return err + } + + return nil +} + +// StockFurVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) StockFurVoteDealType(order structure.ShareOrder) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + return limitOrMarketPrice, nil +} + +// UpdateShareFurVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) UpdateShareFurVoteDealType(order *models.BotStockFurTrade) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + if len(order.DealPrice) != 0 { + dealPrice := decimal.RequireFromString(order.DealPrice) + if !dealPrice.IsZero() { + limitOrMarketPrice = dealPrice + } + } + + return limitOrMarketPrice, nil +} + +// VerifyBotStockFurTradeOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @return string +// @return error +func (uo *userOrderRepo) VerifyBotStockFurTradeOrderId(session *xorm.Session) (string, error) { + var orderId string + for { + // 生成订单ID + orderId = orders.CreateRandCodeOrder(10) + + var orderList []models.BotStockFurTrade + err := session.Table(flags.BotStockFurTrade). + Where("order_id = ?", orderId). + Find(&orderList) + + if err != nil || len(orderList) > 0 { + applogger.Error("%v VerifyBotStockFurTradeOrderId.Find:%v", common.ErrShareFur, err) + continue + } + + break + } + + return orderId, nil +} + +// GetBotStockFurTradeByOrderIdOrStatus +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param status +// @return *models.BotStockFurTrade +// @return error +func (uo *userOrderRepo) GetBotStockFurTradeByOrderIdOrStatus(session *xorm.Session, orderId string, status int) (*models.BotStockFurTrade, error) { + var botStockFurTrade []models.BotStockFurTrade + if err := session.Table(flags.BotStockFurTrade). + Where("order_id = ?", orderId). + Where("`status` = ?", status). + Find(&botStockFurTrade); err != nil { + return nil, err + } + + for _, value := range botStockFurTrade { + return &value, nil + } + + return nil, nil +} diff --git a/internal/data/order_share_gbx.go b/internal/data/order_share_gbx.go new file mode 100644 index 0000000..9b36368 --- /dev/null +++ b/internal/data/order_share_gbx.go @@ -0,0 +1,1486 @@ +package data + +import ( + "context" + "encoding/json" + "github.com/go-xorm/xorm" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" + + orders "matchmaking-system/internal/data/convert" + models "matchmaking-system/internal/pkg/model" +) + +// GetBotStockInTradeList +// +// @Description: 英股订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param userId +// @param status +// @return []*models.BotStockInTrade +// @return int64 +// @return error +func (uo *userOrderRepo) GetBotStockGbxTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockGbxTrade, int64, error) { + totalCount, err := uo.data.mysqlDB.Table(flags.BotStockGbxTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Count() + if err != nil { + return nil, 0, flags.ErrMySqlDB + } + if totalCount == 0 { + return nil, 0, nil + } + var stockList []*models.BotStockGbxTrade + if err = uo.data.mysqlDB.Table(flags.BotStockGbxTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Limit(int(pageSize), int(pageCount)). + Desc(GetOrderByStatusSort(status)). + Find(&stockList); err != nil { + return nil, 0, flags.ErrMySqlDB + } + + var stockUpdateList []*models.BotStockGbxTrade + for _, value := range stockList { + value.KeepDecimal = GetKeepDecimal(flags.StockUkSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockUkSystemSetUpKey, value.StockId) + stockUpdateList = append(stockUpdateList, value) + } + + return stockUpdateList, totalCount, nil +} + +// PlacingStockGbxOrders +// +// @Description: 英股下单 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) PlacingStockGbxOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) { + // 1、通知下单订阅 + symbol := order.StockId + timeValue := QuerySystemCache(flags.ShareGbxMarketType) // 市场开闭盘时间 + if !utils.CheckInPlateTime(timeValue) { + return flags.SetNull, flags.ErrStopTread + } + SubscribeGbxHSetCodeList(symbol, false) // 同步写入股票列表缓存 + SubscribeGbxCloseNewPrice(symbol) // 同步股票实时行情价 + + // 判定是否存在欠款订单 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe.Error(), nil + } + + order = PryNumInit(order) // 杠杆初始化 + subKey := publicData.SymbolCache(flags.Gbx, symbol, flags.TradeTypePrice) + + // 印度股市场系统设置 + if CheckGlobalTread(flags.GbxMarket) { + return flags.SetNull, flags.ErrStopTread + } + + // 股票系统设置(实时价格|全局设置停止交易操作) + var blockTime time.Time + var priceNew, userKey, adminKey string + if !CheckTypeStatus(order.Type) { + userKey = setting.ShareGbxSubscribe + adminKey = setting.AdminShareGbxSubscribe + } else { + // 判定:1、是否开启股票交易 2、是否在交易时间内 3、是否达到最小交易量 + check, openPrice, minNum, endTime := CheckBlockTread(flags.GbxBlk, symbol) + if check { + return flags.SetNull, flags.ErrShareSeven + } + if minNum > utils.StringToInt(order.OrderNumber) { + return flags.SetNull, flags.ErrShareSix + } + priceNew = openPrice // 开仓价格 + blockTime = endTime // 平仓时间 + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + flatRatio := GetCacheForcedClosure(flags.StockUkSystemSetUpKey, symbol) // 单个股票系统设置 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.GbxMarket, userId) // 股票市场系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), // 强平阈值 + Status: leverStatus.Status, // 杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + order.System = system + + // 2、股票下单判定 + // 下单判定设置(false无设置|true止盈止损) + checkBool, stopWinPrice, stopLossPrice, err := StockGbxVoteStopType(order) + if err != nil { + applogger.Error("%v PlacingStockGbxOrders.StockIdnVoteStopType:%v", common.ErrShareGbx, err) + return flags.SetNull, err + } + // 下单判定设置(限价|市价) + limitOrMarketPrice, err := uo.StockGbxVoteDealType(order) + if err != nil { + applogger.Error("%v PlacingStockGbxOrders.StockGbxVoteDealType:%v", common.ErrShareGbx, err) + return flags.SetNull, err + } + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(order.TradeType, stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v PlacingStockGbxOrders.StockVoteTradeType:%v", common.ErrShareGbx, err) + return flags.SetNull, err + } + + // 3、订单持久化录入(并处理资产信息) + pryNum := SystemDealWithLever(order) + orderId, err := uo.StockGbxOrderWriteDB(ctx, userId, order, limitOrMarketPrice, pryNum) + if err != nil || len(orderId) == 0 { + applogger.Error("%v PlacingStockGbxOrders.StockGbxOrderWriteDB:%v", common.ErrShareGbx, err) + return flags.SetNull, err + } + + // 4、处理订单信息 + chg := GetShareChgGbx(flags.Gbx, order.StockId) // 涨跌幅标识值 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.GbxMarket, time.Now()) // 开盘时间 + marketStatus, shareOrder, err := share.ShareGbxCacheDeal(ctx, userId, orderId, subKey, order, chg, priceNew, closingTime, blockTime) + if err != nil || shareOrder == nil { + applogger.Error("%v PlacingStockGbxOrders.ShareGbxCacheDeal:%v", common.ErrShareGbx, err) + return flags.SetNull, err + } + // 计算保证金 = 订单价格 * 订单数量 / 杠杆 + shareOrder.Order.MarketMoney = limitOrMarketPrice.Mul(decimal.RequireFromString(order.OrderNumber)).Div(pryNum).String() + // 测试校验信息 + if !flags.CheckSetting { + applogger.Debug("订单ID:%v", shareOrder.OrderId) + applogger.Debug("订单交易对:%v", shareOrder.Symbol) + applogger.Debug("订单状态:%v", shareOrder.Status) + applogger.Debug("订单用户ID:%v", shareOrder.UserId) + applogger.Debug("开盘价:%v", shareOrder.OpenPrice) + applogger.Debug("收盘价:%v", shareOrder.ClosingPrice) + applogger.Debug("下单信息:%v", shareOrder.Order) + } + + // 6、订单(挂单|持仓)缓存列表,等待队列计算 + if err = share.ShareGbxHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v PlacingStockGbxOrders.ShareGbxHashUserOrder:%v", common.ErrShareGbx, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 7、用户订阅股票订单信息 + orderIdKey := virtual.OrderIdListKey(userKey, userId) + if err = share.ShareGbxHashUserOrder(Reds, orderIdKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockGbxOrders.%v:%v", common.ErrShareGbx, userKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 8、管理员订阅订单信息 + if err = share.ShareGbxHashUserOrder(Reds, adminKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockGbxOrders.%v:%v", common.ErrShareGbx, adminKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + return orderId, nil +} + +// StockGbxOrderWriteDB +// +// @Description: 英股下单处理 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) StockGbxOrderWriteDB(ctx context.Context, userId int64, order structure.ShareOrder, limitOrMarketPrice, lever decimal.Decimal) (string, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockGbxOrderWriteDB.Begin:%v", common.ErrShareGbx, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 获取当前下单用户的资产 + var usableOld, frozenOld decimal.Decimal + stockIdr, err := uo.GetBotUserStockGbxByUserIdAndStockId(session, userId, flags.ShareGbxBasicUnit) + if err != nil || stockIdr == nil { + applogger.Error("%v StockGbxOrderWriteDB.IDR:%v", common.ErrShareGbx, err) + return flags.SetNull, flags.ErrMySqlDB + } + usableOld = decimal.RequireFromString(stockIdr.UsableNum) + frozenOld = decimal.RequireFromString(stockIdr.FrozenNum) + + // 检查用户订单下单资产 + if usableOld.IsZero() || usableOld.IsNegative() || frozenOld.IsNegative() { + return flags.SetNull, flags.ErrShareOne + } + + // 获取当前系统下单用户的非资产 + var usableFOld, frozenFOld decimal.Decimal + stockFIdr, err := uo.GetBotUserStockGbxByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockGbxOrderWriteDB.FeiIDR:%v", common.ErrShareGbx, err) + return flags.SetNull, flags.ErrMySqlDB + } + if stockFIdr != nil { + usableFOld = decimal.RequireFromString(stockFIdr.UsableNum) + frozenFOld = decimal.RequireFromString(stockFIdr.FrozenNum) + } + if !flags.CheckSetting { + applogger.Debug("下单可用资产:%v", usableOld) + applogger.Debug("下单冻结资产:%v", frozenOld) + applogger.Debug("下单查询非资产账户:%v", stockFIdr) + applogger.Debug("下单可用非资产:%v", usableFOld) + applogger.Debug("下单冻结非资产:%v", frozenFOld) + } + + // 校验订单信息 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 订单数量 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 订单手续费 + marketMoney := limitOrMarketPrice.Mul(orderNumber).Div(lever) // 订单金额(杠杆下单) = 订单数量 * 交易价格 / 杠杆 + totalMoney := marketMoney.Add(serviceCost) // 订单总金额 + order.MarketMoney = marketMoney.String() // 市值金额即为保证金 + + // 检查订单Id是否存在,新增下单信息 + var orderId string + if !CheckTypeStatus(order.Type) { + orderId, err = uo.VerifyBotStockGbxTradeOrderId(session) + if err != nil { + applogger.Error("%v StockGbxOrderWriteDB.VerifyBotStockGbxTradeOrderId:%v", common.ErrShareGbx, err) + return flags.SetNull, err + } + trade := orders.BotStockGbxTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockGbxTrade(session, trade); err != nil { + applogger.Error("%v StockGbxOrderWriteDB.CreateBotStockGbxTrade:%v", common.ErrShareGbx, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + orderId, err = uo.VerifyBotStockBlockTradeOrderId(session) + if err != nil { + applogger.Error("%v StockGbxOrderWriteDB.VerifyBotStockBlockTradeOrderId:%v", common.ErrShareGbx, err) + return flags.SetNull, err + } + trade := orders.BotStockBlockTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockBlockTrade(session, trade); err != nil { + applogger.Error("%v StockGbxOrderWriteDB.CreateBotStockBlockTrade:%v", common.ErrShareGbx, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + // 下单判定 + residue := usableOld.Sub(totalMoney).Div(usableOld) + if usableOld.Cmp(totalMoney) <= 0 || residue.Cmp(utils.DecimalsStrInt()) <= 0 { + return flags.SetNull, flags.ErrPublicTow + } + + var usableNew, frozenNew, usableFNew, frozenFNew decimal.Decimal + usableNew = usableOld.Sub(totalMoney) // 可用资产 + frozenNew = frozenOld.Add(totalMoney) // 冻结资产 + if order.StockId != flags.ShareGbxBasicUnit { + usableFNew = usableFOld.Add(orderNumber) // 可用非资产 + frozenFNew = frozenFOld // 冻结非资产 + } + + // 检查用户下单资产信息 + if usableNew.IsNegative() || frozenNew.IsNegative() { + return flags.SetNull, flags.ErrPublicTow + } + + // 下单更新资产信息 + stockIdrModel := orders.UpdateBotUserStockGbx(ctx, usableNew.String(), frozenNew.String()) + err = uo.UpdateBotUserStockGbxByUserIdAndStockId(session, userId, flags.ShareGbxBasicUnit, stockIdrModel) + if err != nil { + applogger.Error("%v StockGbxOrderWriteDB.UpdateBotUserStockGbxByUserIdAndStockId:%v", common.ErrShareGbx, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 下单(新增|更新)非资产信息 + if stockFIdr == nil { + stockFIDRModel := orders.CreateBotUserStockGbx(ctx, userId, order.StockId, usableFNew.String(), frozenFNew.String()) + err = uo.CreateBotUserStockGbxFIRD(session, stockFIDRModel) + if err != nil { + applogger.Error("%v StockGbxOrderWriteDB.CreateBotUserStockGbxFIRD:%v", common.ErrShareGbx, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + stockFIDRModel := orders.UpdateBotUserStockGbx(ctx, usableFNew.String(), frozenFNew.String()) + err = uo.UpdateBotUserStockGbxByUserIdAndStockId(session, userId, order.StockId, stockFIDRModel) + if err != nil { + applogger.Error("%v StockGbxOrderWriteDB.UpdateBotUserStockGbxByUserIdAndStockId:%v", common.ErrShareGbx, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockGbxOrderWriteDB.Commit:%v", common.ErrShareGbx, err) + return flags.SetNull, flags.ErrMySqlDB + } + + return orderId, nil +} + +// StockGbxOpenOrder +// +// @Description: 英股系统开仓 +// @param ctx +// @param db +// @param userId +// @param orderId +// @param openPrice +// @param order +// @return error +func StockGbxOpenOrder(ctx context.Context, db *xorm.EngineGroup, userId int64, orderId, openPrice string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockGbxOpenOrder.NewSession:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockIdr, err := Uo.GetBotUserStockGbxByUserIdAndStockId(session, userId, flags.ShareGbxBasicUnit) + if err != nil || stockIdr == nil { + applogger.Error("%v StockGbxOpenOrder.GetBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockIdr.UsableNum) // 用户可用资产 + frozen = decimal.RequireFromString(stockIdr.FrozenNum) // 用户冻结资产 + + // 检查用户开仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrPublicThree + } + if order.StockId != flags.ShareGbxBasicUnit { + stockFIdr, err := Uo.GetBotUserStockGbxByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockGbxOpenOrder.GetBotUserStockInByUserIdAndStockId:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(stockFIdr.UsableNum) // 用户非可用资产 + frozenNo = decimal.RequireFromString(stockFIdr.FrozenNum) // 用户非冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + + // 转换股票下单信息 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 下单股数 + orderMoney := decimal.RequireFromString(order.MarketMoney) // 下单金额 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 下单手续费 + totalMoney := orderMoney.Add(serviceCost) // 下单总金额 = (下单手续费 + 下单金额) + openOrderPrice := decimal.RequireFromString(openPrice) // 开盘价格 + if !flags.CheckSetting { + applogger.Debug("下单订单数量:%v", orderNumber) + applogger.Debug("下单订单金额:%v", orderMoney) + applogger.Debug("下单订单手续费:%v", serviceCost) + applogger.Debug("下单订单总金额:%v", totalMoney) + } + + // 手续费记录 + openPriceNew := openOrderPrice.Mul(orderNumber).String() // 开仓手续费 = 开仓价格 * 股数 * 开仓手续费 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareGbxMarketType, flags.OpenBrokType, orderId, openPriceNew) + if err != nil { + applogger.Error("%v StockGbxOpenOrder.CalculateHandlingFeesShare:%v", common.ErrShareGbx, err) + return err + } + openServiceCost := decimal.RequireFromString(cost) // 开仓手续费 + openMarkerMoney := openOrderPrice.Mul(orderNumber).Div(decimal.RequireFromString(order.PryNum)) // 开仓订单金额 = 开仓价格 * 股数 / 杠杆 + openTotalMoney := openMarkerMoney.Add(openServiceCost) // 开仓总金额 = 开仓订单金额 + 开仓手续费 + floatPrice := totalMoney.Sub(openTotalMoney) // 计算容差 = 下单总额 - 开仓总额 + if !flags.CheckSetting { + applogger.Debug("开仓订单价格:%v", openOrderPrice) + applogger.Debug("开仓手续费:%v", openServiceCost) + applogger.Debug("开仓总金额:%v", openTotalMoney) + applogger.Debug("开仓订单金额:%v", openMarkerMoney) + applogger.Debug("下单->开仓总金额容差值:%v", floatPrice) + } + + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + usableNew = usable.Add(floatPrice) // 可用资产(处理容差值) + frozenNew = frozen.Sub(totalMoney).Add(openMarkerMoney) // 冻结资产 + if order.StockId != flags.ShareGbxBasicUnit { + usableNoNew = usableNo // 非可用资产 + frozenNoNew = frozenNo // 非冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("下单后用户可用资产:%v", usableNew) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + } + + // 检查用户开仓资产 + if frozenNew.IsNegative() || usableNew.IsNegative() { + return flags.ErrPublicThree + } + + // 处理资产信息 + userStockIdr := orders.UpdateBotUserStockGbx(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockGbxByUserIdAndStockId(session, userId, flags.ShareGbxBasicUnit, userStockIdr); err != nil { + applogger.Error("%v StockGbxOpenOrder.UpdateBotUserStockGbxByUserIdAndStockId:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + + // 更新非资产信息 + if order.StockId != flags.ShareGbxBasicUnit { + userStockFIdr := orders.UpdateBotUserStockGbx(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = Uo.UpdateBotUserStockGbxByUserIdAndStockId(session, userId, order.StockId, userStockFIdr); err != nil { + applogger.Error("%v StockGbxOpenOrder.UpdateBotUserStockGbxByUserIdAndStockId:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + } + + // 返佣记录|资金信息|资金详情信息 + if err = Uo.ShareGbxRebateCalculation(ctx, session, int(userId), flags.ShareGbxMarketType, flags.OpenBrokType, flags.OpenMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockGbxOpenOrder.ShareGbxRebateCalculation:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + + // 处理订单信息(成交价|仓位|开仓时间|订单总金额|手续费|持仓状态) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateOpenBotStockGbxTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarkerMoney.String()) + if err = Uo.UpdateBotStockGbxTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockGbxOpenOrder.UpdateBotStockGbxTradeByOrderId:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + var list []models.BotUserStockGbxLog + qData0 := orders.CreatBotUserStockGbxLog(ctx, userId, flags.CostMoney, flags.ShareGbxBasicUnit, NegativeValue(openServiceCost.String()), orderId) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockGbxLog(ctx, userId, flags.Freeze, flags.ShareGbxBasicUnit, NegativeValue(openMarkerMoney.String()), orderId) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockGbxLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockGbxLogList(session, list); err != nil { + applogger.Error("%v StockGbxOpenOrder.CreatBotUserStockGbxLogList:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateOpenBotStockBlockTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarkerMoney.String()) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockGbxOpenOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareGbxBasicUnit, NegativeValue(openServiceCost.String()), orderId, order.Type) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Freeze, flags.ShareGbxBasicUnit, NegativeValue(openMarkerMoney.String()), orderId, order.Type) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId, order.Type) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockGbxOpenOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockGbxOpenOrder.Commit:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + + return nil +} + +// StockGbxClosingOrder +// +// @Description: 英股系统平仓 +// @param ctx +// @param db +// @param orderId +// @param price +// @param order +// @return error +func StockGbxClosingOrder(ctx context.Context, db *xorm.EngineGroup, orderId string, price string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockGbxClosingOrder.NewSession:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + + // 查询订单信息 + var userId int64 + var dealPrice, orderNumber, totalAmount, serviceCost, marketMoney decimal.Decimal + if !CheckTypeStatus(order.Type) { + tread, err := Uo.GetBotStockGbxTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockGbxClosingOrder.GetBotStockGbxTradeByOrderIdOrStatus:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + marketMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓订单金额 + } else { + tread, err := Uo.GetBotStockBlockTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockGbxClosingOrder.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + marketMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓订单金额 + } + if !flags.CheckSetting { + applogger.Debug("下单开仓用户Id:%v", userId) + applogger.Debug("下单开仓开仓价格:%v", dealPrice) + applogger.Debug("下单开仓订单数量:%v", orderNumber) + applogger.Debug("下单开仓总金额:%v", totalAmount) + applogger.Debug("下单开仓手续费:%v", serviceCost) + applogger.Debug("下单开仓订单金额:%v", marketMoney) + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + userStockIdr, err := Uo.GetBotUserStockGbxByUserIdAndStockId(session, userId, flags.ShareGbxBasicUnit) + if err != nil { + applogger.Error("%v StockGbxClosingOrder.GetBotUserStockGbxByUserIdAndStockId:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(userStockIdr.UsableNum) // 用户可用资金 + frozen = decimal.RequireFromString(userStockIdr.FrozenNum) // 用户非冻结资金 + + // 检查用户平仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrShareTow + } + // 查询当前下单用户可用非账户和冻结金额 + if order.StockId != flags.ShareGbxBasicUnit { + userStockFIdr, err := Uo.GetBotUserStockGbxByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockGbxClosingOrder.GetBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(userStockFIdr.UsableNum) // 用户非可用资金 + frozenNo = decimal.RequireFromString(userStockFIdr.FrozenNum) // 用户非冻结资金 + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + + // 手续费处理 + closePrice := decimal.RequireFromString(price) // 平仓价格 + cloePriceCost := closePrice.Mul(orderNumber).String() // 平仓手续费 = 平仓价格 * 股数 * 手续费比例 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareGbxMarketType, flags.ClosingBrokType, orderId, cloePriceCost) + if err != nil { + applogger.Error("%v StockGbxClosingOrder.CalculateHandlingFeesShare:%v", common.ErrShareGbx, err) + return err + } + closeServiceCost := decimal.RequireFromString(cost) + if !flags.CheckSetting { + applogger.Debug("平仓价格:%v", closePrice) + applogger.Debug("平仓手续费手续费:%v", closeServiceCost) + } + + //已经实现盈亏计算公式(已平仓结算方式) + //买涨 已经实现盈亏 = (平仓成交价-开仓成交价)*股数 + //买跌 已经实现盈亏 = (开仓成交价-平仓成交价)*股数 + var usableNew, frozenNew, usableNewNo, frozenNewNo, subPrice, resultPrice decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买涨 + subPrice = closePrice.Sub(dealPrice) + resultPrice = subPrice.Mul(orderNumber) + case flags.TradeTypeSell: // 买跌 + subPrice = dealPrice.Sub(closePrice) + resultPrice = subPrice.Mul(orderNumber) + default: + } + + // TODO: 判定亏损不能超过 = 保证金 + 平仓手续费 + if resultPrice.IsNegative() { + amountLoss := marketMoney.Sub(closeServiceCost) + if resultPrice.Abs().Cmp(amountLoss) >= 0 { + resultPrice = amountLoss.Neg() + } + } + + // 用户资产账户 + usableNew = usable.Add(resultPrice).Sub(closeServiceCost).Add(marketMoney) // 可用资产 = 原可用资产 + ((正负)盈亏) - 平仓手续费 + 开仓订单金额 + if frozen.Cmp(marketMoney) == -1 { + frozenNew = frozen.Sub(frozen) // 冻结资产 + } else { + frozenNew = frozen.Sub(marketMoney) + } + + // 用户非资产账户 + if order.StockId != flags.ShareGbxBasicUnit { + usableNewNo = usableNo.Sub(orderNumber) // 可用非资产 = 原可用非资产 - 下单股数 + frozenNewNo = frozenNo // 可用非冻结资产 + } + + // 检查用户订单平仓资产 + if frozenNew.IsNegative() || usableNewNo.IsNegative() { + return flags.ErrShareTow + } + if !flags.CheckSetting { + applogger.Debug("可用资产:%v", usableNew) + applogger.Debug("冻结资产:%v", frozenNew) + applogger.Debug("可用非资产:%v", usableNewNo) + applogger.Debug("冻结非资产:%v", frozenNewNo) + } + + // 平仓(处理资产表(资产)) + userStockIDR := orders.UpdateBotUserStockGbx(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockGbxByUserIdAndStockId(session, userId, flags.ShareGbxBasicUnit, userStockIDR); err != nil { + applogger.Error("%v StockGbxClosingOrder.UpdateBotUserStockGbxByUserIdAndStockId:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + + // 平仓(处理资产表(非资产)) + if order.StockId != flags.ShareGbxBasicUnit { + userStockFIDR := orders.UpdateBotUserStockGbx(ctx, usableNewNo.String(), frozenNewNo.String()) + if err = Uo.UpdateBotUserStockGbxByUserIdAndStockId(session, userId, order.StockId, userStockFIDR); err != nil { + applogger.Error("%v StockGbxClosingOrder.UpdateBotUserStockGbxByUserIdAndStockId:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + } + + // 平仓(返佣记录表|资产表|资金变动表) + if err = Uo.ShareGbxRebateCalculation(ctx, session, int(userId), flags.ShareGbxMarketType, flags.ClosingBrokType, flags.CloseMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockGbxClosingOrder.ShareGbxRebateCalculation:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + + // 大宗(印度股)交易平仓(处理订单信息(平仓价|保证金|平仓|订单总金额|平仓手续费|完成订单)) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateCloseBotStockGbxTrade(ctx, price, cost) + if err = Uo.UpdateBotStockGbxTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockGbxClosingOrder.UpdateBotStockGbxTradeByOrderId:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockGbxLog + qData0 := orders.CreatBotUserStockGbxLog(ctx, userId, flags.Thaw, flags.ShareGbxBasicUnit, marketMoney.String(), orderId) // 平仓(资金变动明细表(开仓保证金)) + qData1 := orders.CreatBotUserStockGbxLog(ctx, userId, flags.CostMoney, flags.ShareGbxBasicUnit, NegativeValue(closeServiceCost.String()), orderId) // 平仓(资金变动明细表(-平仓手续费)) + qData2 := orders.CreatBotUserStockGbxLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏)) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockGbxLog(ctx, userId, flags.TransferOut, flags.ShareGbxBasicUnit, resultPrice.String(), orderId) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockGbxLog(ctx, userId, flags.ChangeInto, flags.ShareGbxBasicUnit, resultPrice.String(), orderId) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockGbxLogList(session, list); err != nil { + applogger.Error("%v StockGbxClosingOrder.CreatBotUserStockGbxLogList:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateCloseBotStockBlockTrade(ctx, price, cost) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockGbxClosingOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Thaw, flags.ShareGbxBasicUnit, marketMoney.String(), orderId, order.Type) // 平仓(资金变动明细表(开仓保证金)) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareGbxBasicUnit, NegativeValue(closeServiceCost.String()), orderId, order.Type) // 平仓(资金变动明细表(-平仓手续费)) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId, order.Type) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏)) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, flags.ShareGbxBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, flags.ShareGbxBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockGbxClosingOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockGbxClosingOrder.Commit:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + + return nil +} + +// UpdateBotStockGbxCancelByOrderId +// +// @Description: 英股撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockGbxCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockGbxCancelByOrderId.Begin:%v", common.ErrShareGbx, err) + return false, flags.ErrMySqlDB + } + + // 获取订单信息 + var userId int64 + var stockId string + var marketMoneyOld, serviceCostOld, orderNumber decimal.Decimal + if !CheckTypeStatus(typeStatus) { + stockTrade, err := uo.GetBotStockGbxTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockGbxCancelByOrderId.GetBotStockGbxTradeByOrderId:%v", common.ErrShareGbx, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } else { + stockTrade, err := uo.GetBotStockBlockTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockGbxCancelByOrderId.GetBotStockBlockTradeByOrderId:%v", common.ErrShareGbx, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } + + // 获取用户资产信息 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockIdr, err := uo.GetBotUserStockGbxByUserIdAndStockId(session, userId, flags.ShareGbxBasicUnit) + if err != nil || stockIdr == nil { + applogger.Error("%v UpdateBotStockGbxCancelByOrderId.GetBotUserStockGbxByUserIdAndStockId:%v", common.ErrShareGbx, err) + return false, flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockIdr.UsableNum) // 用户账户可用资产 + frozen = decimal.RequireFromString(stockIdr.FrozenNum) // 用户账户冻结资产 + + // 检查用户订单撤单资产 + if usable.IsNegative() || frozen.IsNegative() { + return false, flags.ErrShareThree + } + if stockId != flags.ShareGbxBasicUnit { + stockFUsd, err := uo.GetBotUserStockGbxByUserIdAndStockId(session, userId, stockId) + if err != nil { + applogger.Error("%v UpdateBotStockGbxCancelByOrderId.GetBotUserStockGbxByUserIdAndStockId:%v", common.ErrShareGbx, err) + return false, flags.ErrPublicFour + } + usableNo = decimal.RequireFromString(stockFUsd.UsableNum) // 用户非账户可用资产 + frozenNo = decimal.RequireFromString(stockFUsd.FrozenNum) // 用户非账户冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("用户原始可用资金:%v", usable) + applogger.Debug("用户原始冻结资金:%v", frozen) + applogger.Debug("用户原始可用非资金:%v", usableNo) + applogger.Debug("用户原始冻结非资金:%v", frozenNo) + } + + // 更新订单信息 + var entrustKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + botStockTrade := orders.BotStockGbxCancelByOrderId(ctx) + if err = uo.UpdateBotStockGbxTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockGbxCancelByOrderId.UpdateBotStockGbxTradeByOrderId:%v", common.ErrShareGbx, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareGbxEntrust + userKey = setting.ShareGbxSubscribe + adminKey = setting.AdminShareGbxSubscribe + } else { + botStockTrade := orders.BotStockBlockCancelByOrderId(ctx) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockGbxCancelByOrderId.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareGbx, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareBlkEntrust + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // Operational Spot Asset Table + totalMoney := marketMoneyOld.Add(serviceCostOld) // 订单总金额 + // update total asset data + usableNew := usable.Add(totalMoney) // 用户总资产 + frozenNew := frozen.Sub(totalMoney) // 用户冻结资产 + usableNoNew := usableNo.Sub(orderNumber) // 用户非可用资产 + frozenNoNew := frozenNo // 用户非冻结资产 + + // 检查用户订单撤单资产 + if frozenNew.IsNegative() || usableNoNew.IsNegative() { + return false, flags.ErrShareThree + } + if !flags.CheckSetting { + applogger.Debug("用户撤单可用总资产:%v", usableNew) + applogger.Debug("用户撤单冻结总资产:%v", frozenNew) + applogger.Debug("用户非撤单可用总资产:%v", usableNoNew) + applogger.Debug("用户非撤单冻结总资产:%v", frozenNoNew) + } + + // 更新资产信息和非资产信息 + userStockIDR := orders.UpdateBotUserStockGbx(ctx, usableNew.String(), frozenNew.String()) + if err = uo.UpdateBotUserStockGbxByUserIdAndStockId(session, userId, flags.ShareGbxBasicUnit, userStockIDR); err != nil { + applogger.Error("%v UpdateBotStockGbxCancelByOrderId.UpdateBotUserStockGbxByUserIdAndStockId:%v", common.ErrShareGbx, err) + return false, flags.ErrMySqlDB + } + if stockId != flags.ShareGbxBasicUnit { + userStockFIdn := orders.UpdateBotUserStockGbx(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = uo.UpdateBotUserStockGbxByUserIdAndStockId(session, userId, stockId, userStockFIdn); err != nil { + applogger.Error("%v UpdateBotStockGbxCancelByOrderId.UpdateBotUserStockGbxByUserIdAndStockId:%v", common.ErrShareGbx, err) + return false, flags.ErrMySqlDB + } + } + + // 删除订单缓存列表 + if err = Reds.HDel(context.Background(), entrustKey, orderId).Err(); err != nil { + applogger.Error("%v UpdateBotStockGbxCancelByOrderId.HDel:%v", common.ErrShareGbx, err) + return false, flags.ErrCacheDB + } + + // 更新用户订阅订单缓存列表 + userSubKey := virtual.OrderIdListKey(userKey, userId) + if err = share.UpdateShareGbxHashByOrderId(Reds, orderId, userSubKey, flags.Cancel); err != nil { + applogger.Error("%v UpdateBotStockGbxCancelByOrderId.%v:%v", common.ErrShareGbx, userKey, err) + return false, flags.ErrCacheDB + } + + // 更新管理员订阅订单缓存列表 + if err = UpdateShareGbxSubscribeHashStatusByOrderId(orderId, adminKey, flags.Cancel, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockGbxCancelByOrderId.%v:%v", common.ErrShareGbx, adminKey, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockGbxCancelByOrderId.Commit:%v", common.ErrShareGbx, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockGbxStopByOrderId +// +// @Description: 英股设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockGbxStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockGbxStopByOrderId.NewSession:%v", common.ErrShareGbx, err) + return false, flags.ErrMySqlDB + } + + // 设置止盈止损 + var userId int64 + if order.StopType == 1 { + // 下单信息 + checkBool, stopWinPrice, stopLossPrice, err := uo.UpdateVoteStopType(order) + if err != nil { + applogger.Error("%v UpdateBotStockGbxStopByOrderId.UpdateVoteStopType:%v", common.ErrShareGbx, err) + return false, err + } + if !flags.CheckSetting { + applogger.Debug("当前止盈止损数据:%v,%v,%v", checkBool, stopWinPrice, stopLossPrice) + } + + // 设置止盈止损判定 + var tradeType int + var limitOrMarketPrice decimal.Decimal + if !CheckTypeStatus(order.Type) { + trade, err := uo.GetBotStockGbxTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockGbxStopByOrderId.GetBotStockGbxTradeByOrderIdOrStatus:%v", common.ErrShareGbx, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareGbxVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockGbxStopByOrderId.UpdateShareGbxVoteDealType:%v", common.ErrShareGbx, err) + return false, err + } + } else { + trade, err := uo.GetBotStockBlockTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockGbxStopByOrderId.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareGbx, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareBlockVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockGbxStopByOrderId.UpdateShareBlockVoteDealType:%v", common.ErrShareGbx, err) + return false, err + } + } + if !flags.CheckSetting { + applogger.Debug("当前开仓价格:%v", limitOrMarketPrice) + } + + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(int64(tradeType), stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v UpdateBotStockGbxStopByOrderId.VoteTradeType:%v", common.ErrShareGbx, err) + return false, err + } + } else { + order.StopLossPrice = decimal.Zero.String() + order.StopWinPrice = decimal.Zero.String() + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[userId] + if ok { + return false, flags.ErrPublicServe + } + + // 更新订单表 + var positionKey string + if !CheckTypeStatus(order.Type) { + botStockIdnTrade := orders.BotStockGbxStopByOrderId(ctx, order) + if err = uo.UpdateBotStockGbxTradeByOrderId(session, order.OrderId, botStockIdnTrade); err != nil { + applogger.Error("%v UpdateBotStockGbxStopByOrderId.UpdateBotStockInTradeByOrderId:%v", common.ErrShareGbx, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareGbxPosition + } else { + botStockIdnTrade := orders.BotStockBlockStopByOrderId(ctx, order) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, order.OrderId, botStockIdnTrade); err != nil { + applogger.Error("%v UpdateBotStockGbxStopByOrderId.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareGbx, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareBlkPosition + } + + // 修改挂单缓存队列 + if err = share.UpdateShareGbxStopByOrderId(Reds, order, positionKey, flags.Position); err != nil { + applogger.Error("%v UpdateBotStockGbxStopByOrderId.UpdateShareGbxStopByOrderId:%v", common.ErrShareGbx, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockGbxStopByOrderId.Commit:%v", common.ErrShareGbx, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockGbxClosingByOrderId +// +// @Description: 英股用户平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockGbxClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.GbxMarket) { + return false, flags.ErrStopTread + } + + // 1、查询持仓缓存列表数据并清理对应缓存 + var positionKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + positionKey = setting.MarketShareGbxPosition + userKey = setting.ShareGbxSubscribe + adminKey = setting.AdminShareGbxSubscribe + } else { + positionKey = setting.MarketShareBlkPosition + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + var entrustCache *share.ShareGbxTallyCache + entrust, err := Reds.HGet(context.Background(), positionKey, orderId).Result() + if err != nil { + applogger.Error("%v UpdateBotStockGbxClosingByOrderId.HGet:%v", common.ErrShareGbx, err) + return false, flags.ErrShareFive + } + var entrustJson share.ShareGbxTallyCache + if err = json.Unmarshal([]byte(entrust), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockGbxClosingByOrderId.Unmarshal:%v", common.ErrShareGbx, err) + return false, flags.ErrCacheDB + } + if orderId == entrustJson.OrderId { + entrustCache = &entrustJson + } + if entrustCache == nil { + return false, flags.ErrShareFive + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[entrustJson.UserId] + if ok { + return false, flags.ErrPublicServe + } + + // 市场设置交易时间(T+0,T+1,T+2s......) + if !CheckShareSystemTime(entrustCache.ClosingTime) { + return false, flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("手动平仓:%v", entrustCache) + } + // 2、获取当前最新价格 + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Gbx, entrustCache.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareGbxTheLatestPrice(subKey, entrustCache.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockGbxClosingByOrderId.GetShareGbxTheLatestPrice:%v", common.ErrShareGbx, err) + return false, flags.ErrStopTread + } + // 3、平仓处理 + if err = StockGbxClosingOrder(ctx, Msql, orderId, closingPrice.String(), entrustCache.Order); err != nil { + applogger.Error("%v UpdateBotStockGbxClosingByOrderId.StockGbxClosingOrder:%v", common.ErrShareGbx, err) + return false, err + } + // 4、清理持仓订单信息 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), positionKey, orderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockGbxClosingByOrderId.HDel:%v", common.ErrShareGbx, err) + return false, flags.ErrCacheDB + } + // 5、平仓更新订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(userKey, entrustCache.UserId) + if err = UpdateShareGbxSubscribeHashStatusByOrderId(orderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockGbxClosingByOrderId.%v:%v", common.ErrShareGbx, userKey, err) + return false, flags.ErrCacheDB + } + // 6、平仓更新管理订阅缓存订单状态 + if err = UpdateShareGbxSubscribeHashStatusByOrderId(orderId, adminKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockGbxClosingByOrderId.%v:%v", common.ErrShareGbx, adminKey, err) + return false, flags.ErrCacheDB + } + + return true, nil +} + +// UpdateBotStockGbxAllClosingByOrderId +// +// @Description: 英股用户一键平仓 +// @receiver uo +// @param ctx +// @param userId +// @return error +func (uo *userOrderRepo) UpdateBotStockGbxAllClosingByOrderId(ctx context.Context, userId int64) error { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.GbxMarket) { + return flags.ErrStopTread + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe + } + + // 1、查询当前用户所有订单 + orderMap, err := uo.GetBotStockGbxTradeByUserId(userId) + if err != nil { + applogger.Error("%v UpdateBotStockGbxAllClosingByOrderId.GetBotStockGbxTradeByUserId:%v", common.ErrShareGbx, err) + return flags.ErrMySqlDB + } + // 2、查询持仓缓存列表数据-1、清理持仓列表缓存 2、处理平仓数据 3、清理订单ID缓存列表 + entrust, err := Reds.HGetAll(context.Background(), setting.MarketShareGbxPosition).Result() + if err != nil { + applogger.Error("%v UpdateBotStockGbxAllClosingByOrderId.HGetAll:%v", common.ErrShareGbx, err) + return flags.ErrShareFive + } + // 3、循环检查股票交易对最新价格(有一个查询不到既不能平仓) + var entrustList []share.ShareGbxTallyCache + closePriceMap := make(map[string]decimal.Decimal) + for key, value := range entrust { + var entrustJson share.ShareGbxTallyCache + if err = json.Unmarshal([]byte(value), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockGbxAllClosingByOrderId.Unmarshal:%v", common.ErrShareGbx, err) + return flags.ErrStopTread + } + _, ok := orderMap[entrustJson.OrderId] + if ok { + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Gbx, entrustJson.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareGbxTheLatestPrice(subKey, entrustJson.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockGbxAllClosingByOrderId.GetShareGbxTheLatestPrice:%v", common.ErrShareGbx, err) + return flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("订阅Key:%v,最新价格:%v,订单ID:%v", subKey, closingPrice, entrustJson.OrderId) + } + closePriceMap[key] = closingPrice + entrustList = append(entrustList, entrustJson) + } + } + // 4、股票一键平仓 + for _, value := range entrustList { + closePrice, ok := closePriceMap[value.OrderId] + if ok { + // 平仓 + if err = StockGbxClosingOrder(ctx, uo.data.mysqlDB, value.OrderId, closePrice.String(), value.Order); err != nil { + applogger.Error("%v UpdateBotStockGbxAllClosingByOrderId.StockGbxClosingOrder:%v", common.ErrShareGbx, err) + return err + } + // 清理持仓缓存列表 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), setting.MarketShareGbxPosition, value.OrderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockGbxAllClosingByOrderId.HDel:%v", common.ErrShareGbx, err) + return flags.ErrCacheDB + } + // 平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareGbxSubscribe, value.UserId) + if err = UpdateShareGbxSubscribeHashStatusByOrderId(value.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockGbxAllClosingByOrderId.ShareGbxSubscribe:%v", common.ErrShareGbx, err) + return flags.ErrCacheDB + } + // 平仓更新管理员订阅订单状态 + if err = UpdateShareGbxSubscribeHashStatusByOrderId(value.OrderId, setting.AdminShareGbxSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockGbxAllClosingByOrderId.AdminShareGbxSubscribe:%v", common.ErrShareGbx, err) + return flags.ErrCacheDB + } + } + } + + return nil +} + +// GetBotStockGbxTradeByUserId +// +// @Description: +// @receiver uo +// @param ctx +// @param userId +// @return map[string]string +// @return error +func (uo *userOrderRepo) GetBotStockGbxTradeByUserId(userId int64) (map[string]string, error) { + var botStockGbxTrade []models.BotStockGbxTrade + if err := uo.data.mysqlDB.Table(flags.BotStockGbxTrade). + Where("user_id = ?", userId). + Where("status = 1"). + Find(&botStockGbxTrade); err != nil { + return nil, err + } + + botMap := make(map[string]string) + for _, value := range botStockGbxTrade { + botMap[value.OrderId] = value.OrderId + } + + return botMap, nil +} + +// GetShareGbxTheLatestPrice +// +// @Description: +// @receiver uo +// @param ctx +// @param subKey +// @param tradeType +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) GetShareGbxTheLatestPrice(subKey string, tradeType int64) (decimal.Decimal, error) { + priceNew, err := share.ShareGbxSubMarketPrice(subKey) + if err != nil { + applogger.Error("%v GetShareGbxTheLatestPrice.ShareGbxSubMarketPrice:%v", common.ErrShareGbx, err) + return decimal.Decimal{}, err + } + + priceS := decimal.RequireFromString(priceNew) + + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tradeType { + case flags.TradeTypeBuy: // 买涨 + openPrice = priceS.Sub(difference) // 开仓价格 + case flags.TradeTypeSell: // 买跌 + openPrice = priceS.Add(difference) // 开仓价格 + default: + } + + return openPrice, nil +} + +// GetBotStockGbxTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @return *models.BotStockGbxTrade +// @return error +func (uo *userOrderRepo) GetBotStockGbxTradeByOrderId(session *xorm.Session, orderId string) (*models.BotStockGbxTrade, error) { + var botStockGbxTrade []models.BotStockGbxTrade + if err := session.Table(flags.BotStockGbxTrade). + Where("order_id = ?", orderId). + Find(&botStockGbxTrade); err != nil { + return nil, err + } + + for _, value := range botStockGbxTrade { + return &value, nil + } + + return nil, nil +} + +// GetBotUserStockGbxByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @return *models.BotUserStockGbx +// @return error +func (uo *userOrderRepo) GetBotUserStockGbxByUserIdAndStockId(session *xorm.Session, userId int64, stockId string) (*models.BotUserStockGbx, error) { + var stockGbx []models.BotUserStockGbx + if err := session.Table(flags.BotUserStockGbx). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&stockGbx); err != nil || len(stockGbx) <= 0 { + return nil, err + } + + for _, value := range stockGbx { + return &value, nil + } + + return nil, nil +} + +// UpdateBotStockGbxTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotStockGbxTradeByOrderId(session *xorm.Session, orderId string, stock models.BotStockGbxTrade) error { + checkInt, err := session.Table(flags.BotStockGbxTrade). + Where("order_id = ?", orderId). + Update(&stock) + if err != nil || checkInt < 0 { + return err + } + + return nil +} + +// CreateBotStockInTrade +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param trade +// @return error +func (uo *userOrderRepo) CreateBotStockGbxTrade(session *xorm.Session, trade models.BotStockGbxTrade) error { + _, err := session.Table(flags.BotStockGbxTrade).Insert(&trade) + if err != nil { + return err + } + + return nil +} + +// CreateBotUserStockGbxFIRD +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param stock +// @return error +func (uo *userOrderRepo) CreateBotUserStockGbxFIRD(session *xorm.Session, stock models.BotUserStockGbx) error { + _, err := session.Table(flags.BotUserStockGbx).Insert(&stock) + if err != nil { + return err + } + + return nil +} + +// UpdateBotUserStockGbxByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotUserStockGbxByUserIdAndStockId(session *xorm.Session, userId int64, stockId string, stock models.BotUserStockGbx) error { + checkNum, err := session.Table(flags.BotUserStockGbx). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&stock) + if err != nil || checkNum < 0 { + return err + } + + return nil +} + +// StockGbxVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) StockGbxVoteDealType(order structure.ShareOrder) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + return limitOrMarketPrice, nil +} + +// UpdateShareGbxVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) UpdateShareGbxVoteDealType(order *models.BotStockGbxTrade) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + if len(order.DealPrice) != 0 { + dealPrice := decimal.RequireFromString(order.DealPrice) + if !dealPrice.IsZero() { + limitOrMarketPrice = dealPrice + } + } + + return limitOrMarketPrice, nil +} + +// VerifyBotStockGbxTradeOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @return string +// @return error +func (uo *userOrderRepo) VerifyBotStockGbxTradeOrderId(session *xorm.Session) (string, error) { + var orderId string + for { + // 生成订单ID + orderId = orders.CreateRandCodeOrder(10) + + var orderList []models.BotStockGbxTrade + err := session.Table(flags.BotStockGbxTrade). + Where("order_id = ?", orderId). + Find(&orderList) + if err != nil || len(orderList) > 0 { + applogger.Warn("%v VerifyBotStockGbxTradeOrderId.Find:%v", common.ErrShareGbx, err) + continue + } + + break + } + + return orderId, nil +} + +// GetBotStockGbxTradeByOrderIdOrStatus +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param status +// @return *models.BotStockGbxTrade +// @return error +func (uo *userOrderRepo) GetBotStockGbxTradeByOrderIdOrStatus(session *xorm.Session, orderId string, status int) (*models.BotStockGbxTrade, error) { + var botStockGbxTrade []models.BotStockGbxTrade + if err := session.Table(flags.BotStockGbxTrade). + Where("order_id = ?", orderId). + Where("`status` = ?", status). + Find(&botStockGbxTrade); err != nil { + return nil, err + } + + for _, value := range botStockGbxTrade { + return &value, nil + } + + return nil, nil +} diff --git a/internal/data/order_share_hkd.go b/internal/data/order_share_hkd.go new file mode 100644 index 0000000..8c9bc2c --- /dev/null +++ b/internal/data/order_share_hkd.go @@ -0,0 +1,1506 @@ +package data + +import ( + "context" + "encoding/json" + "github.com/go-xorm/xorm" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" + + orders "matchmaking-system/internal/data/convert" + models "matchmaking-system/internal/pkg/model" +) + +// GetBotStockHkdTradeList +// +// @Description: 港股订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param userId +// @param status +// @return []*models.BotStockHkdTrade +// @return int64 +// @return error +func (uo *userOrderRepo) GetBotStockHkdTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockHkdTrade, int64, error) { + totalCount, err := uo.data.mysqlDB.Table(flags.BotStockHkdTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Count() + if err != nil { + return nil, 0, flags.ErrMySqlDB + } + if totalCount == 0 { + return nil, 0, nil + } + var stockList []*models.BotStockHkdTrade + if err = uo.data.mysqlDB.Table(flags.BotStockHkdTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Limit(int(pageSize), int(pageCount)). + Desc(GetOrderByStatusSort(status)). + Find(&stockList); err != nil { + return nil, 0, flags.ErrMySqlDB + } + + var stockUpdateList []*models.BotStockHkdTrade + for _, value := range stockList { + value.KeepDecimal = GetKeepDecimal(flags.StockHKDSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockHKDSystemSetUpKey, value.StockId) + stockUpdateList = append(stockUpdateList, value) + } + + return stockUpdateList, totalCount, nil +} + +// PlacingStockHkdOrders +// +// @Description: 港股下单 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) PlacingStockHkdOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) { + // 1、通知下单订阅 + symbol := order.StockId + timeValue := QuerySystemCache(flags.ShareHkdMarketType) // 市场开闭盘时间 + if !utils.CheckInPlateTime(timeValue) { + return flags.SetNull, flags.ErrStopTread + } + SubscribeHkdHSetCodeList(symbol, false) // 同步写入股票列表缓存 + SubscribeHkdCloseNewPrice(symbol) // 同步股票实时行情价 + + // 判定是否存在欠款订单 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe.Error(), nil + } + + order = PryNumInit(order) // 杠杆初始化 + subKey := publicData.SymbolCache(flags.Hkd, symbol, flags.TradeTypePrice) + + // 港股市场系统设置 + if CheckGlobalTread(flags.HkdMarket) { + return flags.SetNull, flags.ErrShareSeven + } + + // 全局设置停止交易操作 + var blockTime time.Time + var userKey, adminKey, priceNew string + if !CheckTypeStatus(order.Type) { + userKey = setting.ShareHkdSubscribe + adminKey = setting.AdminShareHkdSubscribe + } else { + // 判定:1、是否开启股票交易 2、是否在交易时间内 3、是否达到最小交易量 + check, openPrice, minNum, endTime := CheckBlockTread(flags.HkdBlk, symbol) + if check { + return flags.SetNull, flags.ErrShareSeven + } + if minNum > utils.StringToInt(order.OrderNumber) { + return flags.SetNull, flags.ErrShareSix + } + priceNew = openPrice // 开仓价格 + blockTime = endTime // 平仓时间 + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + flatRatio := GetCacheForcedClosure(flags.StockHKDSystemSetUpKey, symbol) // 设置强平阈值 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.HkdMarket, userId) // 股票市场系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), // 强平阈值 + Status: leverStatus.Status, // 杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + order.System = system + + // 2、股票下单判定 + // 下单判定设置(false无设置|true止盈止损) + checkBool, stopWinPrice, stopLossPrice, err := StockHkdVoteStopType(order) + if err != nil { + applogger.Error("%v PlacingStockHkdOrders.StockVoteStopType:%v", common.ErrShareHkd, err) + return flags.SetNull, err + } + // 下单判定设置(限价|市价) + limitOrMarketPrice, err := uo.StockHkdVoteDealType(order) + if err != nil { + applogger.Error("%v PlacingStockHkdOrders.StockVoteDealType:%v", common.ErrShareHkd, err) + return flags.SetNull, err + } + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(order.TradeType, stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v PlacingStockHkdOrders.VoteTradeType:%v", common.ErrShareHkd, err) + return flags.SetNull, err + } + + // 3、订单持久化录入(并处理资产信息) + pryNum := SystemDealWithLever(order) + orderId, err := uo.StockOrderHkdWriteDB(ctx, userId, order, limitOrMarketPrice, pryNum) + if err != nil || len(orderId) == 0 { + applogger.Error("%v PlacingStockHkdOrders.StockOrderHkdWriteDB:%v", common.ErrShareHkd, err) + return flags.SetNull, err + } + + // 4、处理订单信息 + chg := GetShareChgHkd(flags.Hkd, order.StockId) // 涨跌幅标识值 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.HkdMarket, time.Now()) // 开盘时间 + marketStatus, shareOrder, err := share.ShareHkdCacheDeal(ctx, userId, orderId, subKey, order, chg, priceNew, closingTime, blockTime) + if err != nil || shareOrder == nil { + applogger.Error("%v PlacingStockHkdOrders.ShareHkdCacheDeal:%v", common.ErrShareHkd, err) + return flags.SetNull, err + } + // 计算保证金 = 订单价格 * 订单数量 / 杠杆 + shareOrder.Order.MarketMoney = limitOrMarketPrice.Mul(decimal.RequireFromString(order.OrderNumber)).Div(pryNum).String() + if !flags.CheckSetting { + applogger.Debug("订单ID:%v", shareOrder.OrderId) + applogger.Debug("订单交易对:%v", shareOrder.Symbol) + applogger.Debug("订单状态:%v", shareOrder.Status) + applogger.Debug("订单用户ID:%v", shareOrder.UserId) + applogger.Debug("开盘价:%v", shareOrder.OpenPrice) + applogger.Debug("收盘价:%v", shareOrder.ClosingPrice) + applogger.Debug("下单信息:%v", shareOrder.Order) + } + + // 6、订单(挂单|持仓)缓存列表,等待队列计算 + if err = share.ShareHkdHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v PlacingStockHkdOrders.ShareHkdHashUserOrder:%v", common.ErrShareHkd, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 7、用户订阅股票订单信息 + orderIdKey := virtual.OrderIdListKey(userKey, userId) + if err = share.ShareHkdHashUserOrder(Reds, orderIdKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockHkdOrders.%v:%v", common.ErrShareHkd, userKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 8、管理员订阅订单信息 + if err = share.ShareHkdHashUserOrder(Reds, adminKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockHkdOrders.%v:%v", common.ErrShareHkd, adminKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + return orderId, nil +} + +// StockOrderHkdWriteDB +// +// @Description: 港股处理下单操作 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) StockOrderHkdWriteDB(ctx context.Context, userId int64, order structure.ShareOrder, limitOrMarketPrice, lever decimal.Decimal) (string, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockOrderHkdWriteDB.Begin:%v", common.ErrShareHkd, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 获取当前下单用户的资产 + var usableOld, frozenOld decimal.Decimal + stockUsd, err := uo.GetBotUserStockHkdByUserIdAndStockId(session, userId, flags.ShareHkdBasicUnit) + if err != nil || stockUsd == nil { + applogger.Error("%v StockOrderHkdWriteDB.Hkd:%v", common.ErrShareHkd, err) + return flags.SetNull, flags.ErrMySqlDB + } + usableOld = decimal.RequireFromString(stockUsd.UsableNum) + frozenOld = decimal.RequireFromString(stockUsd.FrozenNum) + + // 检查用户订单下单资产 + if usableOld.IsNegative() || frozenOld.IsNegative() { + return flags.SetNull, flags.ErrShareOne + } + + // 获取当前系统下单用户的非资产 + var usableFOld, frozenFOld decimal.Decimal + stockFUsd, err := uo.GetBotUserStockHkdByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockOrderHkdWriteDB.FeiHkd:%v", common.ErrShareHkd, err) + return flags.SetNull, flags.ErrMySqlDB + } + if stockFUsd != nil { + usableFOld = decimal.RequireFromString(stockFUsd.UsableNum) + frozenFOld = decimal.RequireFromString(stockFUsd.FrozenNum) + } + if !flags.CheckSetting { + applogger.Debug("下单可用资产:%v", usableOld) + applogger.Debug("下单冻结资产:%v", frozenOld) + applogger.Debug("下单查询非资产账户:%v", stockFUsd) + applogger.Debug("下单可用非资产:%v", usableFOld) + applogger.Debug("下单冻结非资产:%v", frozenFOld) + } + + // 整理当前下单信息 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 订单手续费 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 订单数量 + marketMoney := limitOrMarketPrice.Mul(orderNumber).Div(lever) // 订单金额(杠杆下单) = 订单数量 * 交易价格 / 杠杆 + totalMoney := marketMoney.Add(serviceCost) // 订单总金额 + order.MarketMoney = marketMoney.String() // 市值金额即为保证金 + + // 检查订单ID是否存在,新增下单信息 + var orderId string + if !CheckTypeStatus(order.Type) { + orderId, err = uo.VerifyBotStockHkdTradeOrderId(session) + if err != nil { + applogger.Error("%v StockOrderHkdWriteDB.VerifyBotStockHkdTradeOrderId:%v", common.ErrShareHkd, err) + return flags.SetNull, err + } + trade := orders.BotStockHkdTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockHkdTrade(session, trade); err != nil { + applogger.Error("%v StockOrderHkdWriteDB.CreateBotStockHkdTrade:%v", common.ErrShareHkd, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + orderId, err = uo.VerifyBotStockBlockTradeOrderId(session) + if err != nil { + applogger.Error("%v StockOrderHkdWriteDB.VerifyBotStockBlockTradeOrderId:%v", common.ErrShareHkd, err) + return flags.SetNull, err + } + trade := orders.BotStockBlockTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockBlockTrade(session, trade); err != nil { + applogger.Error("%v StockOrderHkdWriteDB.CreateBotStockBlockTrade:%v", common.ErrShareHkd, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + // 下单判定 + residue := usableOld.Sub(totalMoney).Div(usableOld) + if usableOld.Cmp(totalMoney) <= 0 || residue.Cmp(utils.DecimalsStrInt()) <= 0 { + return flags.SetNull, flags.ErrPublicTow + } + var usableNew, frozenNew, usableFNew, frozenFNew decimal.Decimal + usableNew = usableOld.Sub(totalMoney) // 可用资产 + frozenNew = frozenOld.Add(totalMoney) // 冻结资产 + if order.StockId != flags.ShareHkdBasicUnit { + usableFNew = usableFOld.Add(orderNumber) // 可用非资产 + frozenFNew = frozenFOld // 冻结非资产 + } + + // 检查用户订单下单资产 + if usableNew.IsNegative() { + return flags.SetNull, flags.ErrPublicTow + } + + // 下单更新资产信息 + stockUSDModel := orders.UpdateBotUserStockHkd(ctx, usableNew.String(), frozenNew.String()) + err = uo.UpdateBotUserStockHkdByUserIdAndStockId(session, userId, flags.ShareHkdBasicUnit, stockUSDModel) + if err != nil { + applogger.Error("%v StockOrderHkdWriteDB.UpdateBotUserStockHkdByUserIdAndStockId:%v", common.ErrShareHkd, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 下单(新增|更新)非资产信息 + if stockFUsd == nil { + stockHKDModel := orders.CreateBotUserStockHkd(ctx, userId, order.StockId, usableFNew.String(), frozenFNew.String()) + err = uo.CreateBotUserStockHkd(session, stockHKDModel) + if err != nil { + applogger.Error("%v StockOrderHkdWriteDB.CreateBotUserStockHkd:%v", common.ErrShareHkd, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + stockHKDModel := orders.UpdateBotUserStockHkd(ctx, usableFNew.String(), frozenFNew.String()) + err = uo.UpdateBotUserStockHkdByUserIdAndStockId(session, userId, order.StockId, stockHKDModel) + if err != nil { + applogger.Error("%v StockOrderHkdWriteDB.UpdateHKD:%v", common.ErrShareHkd, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockOrderHkdWriteDB.Commit:%v", common.ErrShareHkd, err) + return flags.SetNull, flags.ErrMySqlDB + } + + return orderId, nil +} + +// StockHkdOpenOrder +// +// @Description: 港股系统开仓 +// @param ctx +// @param db +// @param userId +// @param orderId +// @param openPrice +// @param order +// @return error +func StockHkdOpenOrder(ctx context.Context, db *xorm.EngineGroup, userId int64, orderId, openPrice string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockHkdOpenOrder.NewSession:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockUsd, err := Uo.GetBotUserStockHkdByUserIdAndStockId(session, userId, flags.ShareHkdBasicUnit) + if err != nil || stockUsd == nil { + applogger.Error("%v StockHkdOpenOrder.GetBotUserStockHkdByUserIdAndStockId:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockUsd.UsableNum) // 用户可用资产 + frozen = decimal.RequireFromString(stockUsd.FrozenNum) // 用户冻结资产 + + // 检查用户订单开仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrPublicThree + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + } + + if order.StockId != flags.ShareHkdBasicUnit { + stockFUsd, err := Uo.GetBotUserStockHkdByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockHkdOpenOrder.GetBotUserStockHkdByUserIdAndStockId:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(stockFUsd.UsableNum) // 用户非可用资产 + frozenNo = decimal.RequireFromString(stockFUsd.FrozenNum) // 用户非冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + + // 转换股票下单信息 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 下单股数 + marketMoney := decimal.RequireFromString(order.MarketMoney) // 下单金额 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 下单手续费 + totalMoney := marketMoney.Add(serviceCost) // 下单总金额 = (下单手续费 + 下单金额) + openOrderPrice := decimal.RequireFromString(openPrice) // 开盘价格 + if !flags.CheckSetting { + applogger.Debug("下单订单数量:%v", orderNumber) + applogger.Debug("下单订单金额:%v", marketMoney) + applogger.Debug("下单订单手续费:%v", serviceCost) + applogger.Debug("下单订单总金额:%v", totalMoney) + } + + // 手续费记录 + openPriceNew := openOrderPrice.Mul(orderNumber).String() // 开仓手续费 = 开仓价格 * 股数 * 开仓手续费 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareHkdMarketType, flags.OpenBrokType, orderId, openPriceNew) + if err != nil { + applogger.Error("%v StockHkdOpenOrder.CalculateHandlingFeesShare:%v", common.ErrShareHkd, err) + return err + } + openServiceCost := decimal.RequireFromString(cost) // 开仓手续费 + openMarketMoney := openOrderPrice.Mul(orderNumber).Div(decimal.RequireFromString(order.PryNum)) // 开仓订单金额 = 开仓价格 * 开仓数量 / 杠杆 + openTotalMoney := openMarketMoney.Add(openServiceCost) // 开仓总金额 = (开仓订单金额 + 开仓手续费) + floatPrice := totalMoney.Sub(openTotalMoney) // 计算可用金额容差 = 下单总额 - 开仓总额 + if !flags.CheckSetting { + applogger.Debug("开仓订单价格:%v", openOrderPrice) + applogger.Debug("开仓手续费:%v", openServiceCost) + applogger.Debug("开仓总金额:%v", openTotalMoney) + applogger.Debug("下单->开仓总金额容差值:%v", floatPrice) + } + + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + usableNew = usable.Add(floatPrice) // 可用资产(处理容差值) + frozenNew = frozen.Sub(totalMoney).Add(openMarketMoney) // 冻结资产 + if order.StockId != flags.ShareHkdBasicUnit { + usableNoNew = usableNo // 非可用资产 + frozenNoNew = frozenNo // 非冻结资产 + } + + // 检查用户订单开仓资产 + if frozenNew.IsNegative() || usableNew.IsNegative() { + return flags.ErrPublicThree + } + if !flags.CheckSetting { + applogger.Debug("下单后用户可用资产:%v", usableNew) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + } + + // 处理资产信息 + userStockUsd := orders.UpdateBotUserStockHkd(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockHkdByUserIdAndStockId(session, userId, flags.ShareHkdBasicUnit, userStockUsd); err != nil { + applogger.Error("%v StockHkdOpenOrder.HKD.UpdateBotUserStockHkdByUserIdAndStockId:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + + // 更新非资产信息 + if order.StockId != flags.ShareHkdBasicUnit { + userStockFUsd := orders.UpdateBotUserStockHkd(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = Uo.UpdateBotUserStockHkdByUserIdAndStockId(session, userId, order.StockId, userStockFUsd); err != nil { + applogger.Error("%v StockHkdOpenOrder.HKD.UpdateBotUserStockHkdByUserIdAndStockId:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + } + + // 返佣记录|资金信息|资金详情信息 + if err = Uo.ShareHkdRebateCalculation(ctx, session, int(userId), flags.ShareHkdMarketType, flags.OpenBrokType, flags.OpenMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockHkdOpenOrder.ShareHkdRebateCalculation:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + + // 处理订单信息(成交价|仓位|开仓时间|订单总金额|手续费|持仓状态) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateOpenBotStockHkdTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarketMoney.String()) + if err = Uo.UpdateBotStockHkdTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockHkdOpenOrder.UpdateBotStockHkdTradeByOrderId:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockHkdLog + qData0 := orders.CreatBotUserStockHkdLog(ctx, userId, flags.CostMoney, flags.ShareHkdBasicUnit, NegativeValue(openServiceCost.String()), orderId) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockHkdLog(ctx, userId, flags.Freeze, flags.ShareHkdBasicUnit, NegativeValue(openMarketMoney.String()), orderId) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockHkdLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + // 批量写入数据信息 + if err = Uo.CreatBotUserStockHkdLogList(session, list); err != nil { + applogger.Error("%v StockHkdOpenOrder.CreatBotUserStockHkdLogList:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateOpenBotStockBlockTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarketMoney.String()) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockHkdOpenOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareHkdBasicUnit, NegativeValue(openServiceCost.String()), orderId, order.Type) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Freeze, flags.ShareHkdBasicUnit, NegativeValue(openMarketMoney.String()), orderId, order.Type) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId, order.Type) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + // 批量写入数据信息 + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockHkdOpenOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockHkdOpenOrder.Commit:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + + return nil +} + +// StockHkdClosingOrder +// +// @Description: 港股系统平仓 +// @param ctx +// @param db +// @param orderId +// @param price +// @param order +// @return error +func StockHkdClosingOrder(ctx context.Context, db *xorm.EngineGroup, orderId string, price string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockHkdClosingOrder.NewSession:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + + // 查询订单信息 + var userId int64 + var dealPrice, orderNumber, totalAmount, serviceCost, marketMoney decimal.Decimal + if !CheckTypeStatus(order.Type) { + tread, err := Uo.GetBotStockHkdTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockHkdClosingOrder.GetBotStockHkdTradeByOrderIdOrStatus:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + marketMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓订单金额 + } else { + tread, err := Uo.GetBotStockBlockTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockHkdClosingOrder.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + marketMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓订单金额 + } + if !flags.CheckSetting { + applogger.Debug("下单开仓用户Id:%v", userId) + applogger.Debug("下单开仓开仓价格:%v", dealPrice) + applogger.Debug("下单开仓订单数量:%v", orderNumber) + applogger.Debug("下单开仓总金额:%v", totalAmount) + applogger.Debug("下单开仓手续费:%v", serviceCost) + applogger.Debug("下单开仓订单金额:%v", marketMoney) + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + userStockUsd, err := Uo.GetBotUserStockHkdByUserIdAndStockId(session, userId, flags.ShareHkdBasicUnit) + if err != nil { + applogger.Error("%v StockHkdClosingOrder.GetBotUserStockHkdByUserIdAndStockId:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(userStockUsd.UsableNum) // 用户可用资金 + frozen = decimal.RequireFromString(userStockUsd.FrozenNum) // 用户冻结资金 + + // 检查用户订单平仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrShareTow + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + } + + // 查询当前下单用户可用非账户和冻结金额 + if order.StockId != flags.ShareHkdBasicUnit { + userStockFUsd, err := Uo.GetBotUserStockHkdByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockHkdClosingOrder.GetBotUserStockHkdByUserIdAndStockId:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(userStockFUsd.UsableNum) // 用户非可用资金 + frozenNo = decimal.RequireFromString(userStockFUsd.FrozenNum) // 用户非冻结资金 + if !flags.CheckSetting { + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + } + + // 手续费处理 + closePrice := decimal.RequireFromString(price) // 平仓价格 + cloePriceCost := closePrice.Mul(orderNumber).String() // 平仓手续费 = 平仓价格 * 股数 * 手续费比例 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareHkdMarketType, flags.ClosingBrokType, orderId, cloePriceCost) + if err != nil { + applogger.Error("%v StockHkdClosingOrder.CalculateHandlingFeesShare:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + closeServiceCost := decimal.RequireFromString(cost) + if !flags.CheckSetting { + applogger.Debug("平仓价格:%v", closePrice) + applogger.Debug("平仓手续费手续费:%v", closeServiceCost) + } + + //已经实现盈亏计算公式(已平仓结算方式) + //买涨 已经实现盈亏 = (平仓成交价-开仓成交价)*股数 + //买跌 已经实现盈亏 = (开仓成交价-平仓成交价)*股数 + var usableNew, frozenNew, usableNewNo, frozenNewNo, subPrice, resultPrice decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买涨 + subPrice = closePrice.Sub(dealPrice) + resultPrice = subPrice.Mul(orderNumber) + case flags.TradeTypeSell: // 买跌 + subPrice = dealPrice.Sub(closePrice) + resultPrice = subPrice.Mul(orderNumber) + default: + + } + + // TODO: 判定亏损不能超过 = 保证金 + 平仓手续费 + if resultPrice.IsNegative() { + amountLoss := marketMoney.Sub(closeServiceCost) + if resultPrice.Abs().Cmp(amountLoss) >= 0 { + resultPrice = amountLoss.Neg() + } + } + + // 用户资产账户 + usableNew = usable.Add(resultPrice).Sub(closeServiceCost).Add(marketMoney) // 可用资产 = 原可用资产 + ((正负)盈亏) - 平仓手续费 + 保证金 + if frozen.Cmp(marketMoney) == -1 { + frozenNew = frozen.Sub(frozen) // 冻结资产 = 原冻结资产 - 保证金 + } else { + frozenNew = frozen.Sub(marketMoney) // 冻结资产 = 原冻结资产 - 保证金 + } + + // 用户非资产账户 + if order.StockId != flags.ShareHkdBasicUnit { + usableNewNo = usableNo.Sub(orderNumber) // 非可用资产 = 原非可用资产 + frozenNewNo = frozenNo // 非冻结资产 = 原非冻结资产 - 订单数量 + } + + // 检查用户订单平仓资产 + if frozenNew.IsNegative() || usableNewNo.IsNegative() { + return flags.ErrShareTow + } + if !flags.CheckSetting { + applogger.Debug("可用资产:%v", usableNew) + applogger.Debug("冻结资产:%v", frozenNew) + applogger.Debug("可用非资产:%v", usableNewNo) + applogger.Debug("冻结非资产:%v", frozenNewNo) + } + + // 平仓(处理资产表(资产)) + userStockUSDT := orders.UpdateBotUserStockHkd(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockHkdByUserIdAndStockId(session, userId, flags.ShareHkdBasicUnit, userStockUSDT); err != nil { + applogger.Error("%v StockHkdClosingOrder.UpdateBotUserStockHkd:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + + // 平仓(处理资产表(非资产)) + if order.StockId != flags.ShareHkdBasicUnit { + userStockFHKD := orders.UpdateBotUserStockHkd(ctx, usableNewNo.String(), frozenNewNo.String()) + if err = Uo.UpdateBotUserStockHkdByUserIdAndStockId(session, userId, order.StockId, userStockFHKD); err != nil { + applogger.Error("%v StockHkdClosingOrder.UpdateBotUserStockHkd:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + } + + // 平仓(返佣记录表|资产表|资金变动表) + if err = Uo.ShareHkdRebateCalculation(ctx, session, int(userId), flags.ShareHkdMarketType, flags.ClosingBrokType, flags.CloseMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockHkdClosingOrder.ShareHkdRebateCalculation:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + + // 平仓(处理订单信息(平仓价|保证金|平仓|订单总金额|平仓手续费|完成订单)) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateCloseBotStockHkdTrade(ctx, price, cost) + if err = Uo.UpdateBotStockHkdTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockHkdClosingOrder.UpdateBotStockHkdTradeByOrderId:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockHkdLog + qData0 := orders.CreatBotUserStockHkdLog(ctx, userId, flags.Thaw, flags.ShareHkdBasicUnit, marketMoney.String(), orderId) // 平仓(资金变动明细(平仓保证金)) + qData1 := orders.CreatBotUserStockHkdLog(ctx, userId, flags.CostMoney, flags.ShareHkdBasicUnit, NegativeValue(closeServiceCost.String()), orderId) // 平仓(资金变动明细表(平仓手续费)) + qData2 := orders.CreatBotUserStockHkdLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId) // 平仓(资金变动明细表(非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏)) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockHkdLog(ctx, userId, flags.TransferOut, flags.ShareHkdBasicUnit, resultPrice.String(), orderId) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockHkdLog(ctx, userId, flags.ChangeInto, flags.ShareHkdBasicUnit, resultPrice.String(), orderId) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockHkdLogList(session, list); err != nil { + applogger.Error("%v StockHkdClosingOrder.CreatBotUserStockHkdLogList:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateCloseBotStockBlockTrade(ctx, price, cost) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockHkdClosingOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Thaw, flags.ShareHkdBasicUnit, marketMoney.String(), orderId, order.Type) // 平仓(资金变动明细(平仓保证金)) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareHkdBasicUnit, NegativeValue(closeServiceCost.String()), orderId, order.Type) // 平仓(资金变动明细表(平仓手续费)) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId, order.Type) // 平仓(资金变动明细表(非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏)) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, flags.ShareHkdBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, flags.ShareHkdBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockHkdClosingOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockHkdClosingOrder.Commit:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + + return nil +} + +// UpdateBotStockHkdCancelByOrderId +// +// @Description: 港股撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockHkdCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockHkdCancelByOrderId.Begin:%v", common.ErrShareHkd, err) + return false, flags.ErrMySqlDB + } + + // 获取订单信息 + var userId int64 + var stockId string + var marketMoneyOld, serviceCostOld, orderNumber decimal.Decimal + if !CheckTypeStatus(typeStatus) { + stockTrade, err := uo.GetBotStockHkdTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockHkdCancelByOrderId.GetBotStockHkdTradeByOrderId:%v", common.ErrShareHkd, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } else { + stockTrade, err := uo.GetBotStockBlockTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockHkdCancelByOrderId.GetBotStockBlockTradeByOrderId:%v", common.ErrShareHkd, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } + + // 获取用户资产信息 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockUsd, err := uo.GetBotUserStockHkdByUserIdAndStockId(session, userId, flags.ShareHkdBasicUnit) + if err != nil || stockUsd == nil { + applogger.Error("%v UpdateBotStockHkdCancelByOrderId.HKD.GetBotUserStockHkdByUserIdAndStockId:%v", common.ErrShareHkd, err) + return false, err + } + usable = decimal.RequireFromString(stockUsd.UsableNum) // 用户账户可用资产 + frozen = decimal.RequireFromString(stockUsd.FrozenNum) // 用户账户冻结资产 + + // 检查用户订单撤单资产 + if usable.IsNegative() || frozen.IsNegative() { + return false, flags.ErrShareNine + } + + if stockId != flags.ShareHkdBasicUnit { + stockFUsd, err := uo.GetBotUserStockHkdByUserIdAndStockId(session, userId, stockId) + if err != nil { + applogger.Error("%v UpdateBotStockHkdCancelByOrderId.GetBotUserStockHkdByUserIdAndStockId:%v", common.ErrShareHkd, err) + return false, flags.ErrPublicFour + } + usableNo = decimal.RequireFromString(stockFUsd.UsableNum) // 用户非账户可用资产 + frozenNo = decimal.RequireFromString(stockFUsd.FrozenNum) // 用户非账户冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("用户原始可用资金:%v", usable) + applogger.Debug("用户原始冻结资金:%v", frozen) + applogger.Debug("用户原始可用非资金:%v", usableNo) + applogger.Debug("用户原始冻结非资金:%v", frozenNo) + } + + // 更新订单信息 + var entrustKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + botStockTrade := orders.BotStockHkdCancelByOrderId(ctx) + if err = uo.UpdateBotStockHkdTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockHkdCancelByOrderId.HKD.UpdateBotStockHkdTradeByOrderId:%v", common.ErrShareHkd, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareHkdEntrust + userKey = setting.ShareHkdSubscribe + adminKey = setting.AdminShareHkdSubscribe + } else { + botStockTrade := orders.BotStockBlockCancelByOrderId(ctx) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockHkdCancelByOrderId.HKD.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareHkd, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareBlkEntrust + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // Operational Spot Asset Table + totalMoney := marketMoneyOld.Add(serviceCostOld) // 订单总金额 + // update total asset data + usableNew := usable.Add(totalMoney) // 用户总资产 + frozenNew := frozen.Sub(totalMoney) // 用户冻结资产 + usableNoNew := usableNo.Sub(orderNumber) // 用户非可用资产 + frozenNoNew := frozenNo // 用户非冻结资产 + + // 检查用户订单撤单资产 + if frozenNew.IsNegative() || usableNoNew.IsNegative() { + return false, flags.ErrShareNine + } + if !flags.CheckSetting { + applogger.Debug("用户撤单可用总资产:%v", usableNew) + applogger.Debug("用户撤单冻结总资产:%v", frozenNew) + applogger.Debug("用户非撤单可用总资产:%v", usableNoNew) + applogger.Debug("用户非撤单冻结总资产:%v", frozenNoNew) + } + + // 更新资产信息和非资产信息 + userStockUSD := orders.UpdateBotUserStockHkd(ctx, usableNew.String(), frozenNew.String()) + if err = uo.UpdateBotUserStockHkdByUserIdAndStockId(session, userId, flags.ShareHkdBasicUnit, userStockUSD); err != nil { + applogger.Error("%v UpdateBotStockHkdCancelByOrderId.UpdateBotUserStockHkdByUserIdAndStockId:%v", common.ErrShareHkd, err) + return false, flags.ErrMySqlDB + } + if stockId != flags.ShareHkdBasicUnit { + userStockFHKD := orders.UpdateBotUserStockHkd(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = uo.UpdateBotUserStockHkdByUserIdAndStockId(session, userId, stockId, userStockFHKD); err != nil { + applogger.Error("%v UpdateBotStockHkdCancelByOrderId.UpdateBotUserStockHkdByUserIdAndStockId:%v", common.ErrShareHkd, err) + return false, flags.ErrMySqlDB + } + } + + // 删除订单缓存列表 + if err = Reds.HDel(context.Background(), entrustKey, orderId).Err(); err != nil { + applogger.Error("%v UpdateBotStockHkdCancelByOrderId.HDel:%v", common.ErrShareHkd, err) + return false, flags.ErrCacheDB + } + + // 更新用户订阅订单缓存列表 + userSubKey := virtual.OrderIdListKey(userKey, userId) + if err = share.UpdateShareHkdHashByOrderId(Reds, orderId, userSubKey, flags.Cancel); err != nil { + applogger.Error("%v UpdateBotStockHkdCancelByOrderId.%v:%v", common.ErrShareHkd, userKey, err) + return false, flags.ErrCacheDB + } + + // 更新管理员订阅订单缓存列表 + if err = UpdateShareHkdSubscribeHashStatusByOrderId(orderId, adminKey, flags.Cancel, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockHkdCancelByOrderId.%v:%v", common.ErrShareHkd, adminKey, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockHkdCancelByOrderId.Commit:%v", common.ErrShareHkd, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockHkdStopByOrderId +// +// @Description: 港股设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockHkdStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockHkdStopByOrderId.NewSession:%v", common.ErrShareHkd, err) + return false, flags.ErrMySqlDB + } + + // 设置止盈止损 + var userId int64 + if order.StopType == 1 { + // 股票下单信息 + checkBool, stopWinPrice, stopLossPrice, err := uo.UpdateVoteStopType(order) + if err != nil { + applogger.Error("%v UpdateBotStockHkdStopByOrderId.UpdateVoteStopType:%v", common.ErrShareHkd, err) + return false, err + } + if !flags.CheckSetting { + applogger.Debug("当前止盈止损数据:%v,%v,%v", checkBool, stopWinPrice, stopLossPrice) + } + + // 设置止盈止损判定 + var tradeType int + var limitOrMarketPrice decimal.Decimal + if !CheckTypeStatus(order.Type) { + trade, err := uo.GetBotStockHkdTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockHkdStopByOrderId.GetBotStockHkdTradeByOrderIdOrStatus:%v", common.ErrShareHkd, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareHkdVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockHkdStopByOrderId.UpdateShareHkdVoteDealType:%v", common.ErrShareHkd, err) + return false, err + } + } else { + trade, err := uo.GetBotStockBlockTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockHkdStopByOrderId.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareHkd, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareBlockVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockHkdStopByOrderId.UpdateShareBlockVoteDealType:%v", common.ErrShareHkd, err) + return false, err + } + } + if !flags.CheckSetting { + applogger.Debug("当前开仓价格:%v", limitOrMarketPrice) + } + + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(int64(tradeType), stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v UpdateBotStockHkdStopByOrderId.VoteTradeType:%v", common.ErrShareHkd, err) + return false, err + } + } else { + order.StopLossPrice = decimal.Zero.String() + order.StopWinPrice = decimal.Zero.String() + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[userId] + if ok { + return false, flags.ErrPublicServe + } + + // 更新订单表 + var positionKey string + if !CheckTypeStatus(order.Type) { + botStockTrade := orders.BotStockStopHkdByOrderId(ctx, order) + if err = uo.UpdateBotStockHkdTradeByOrderId(session, order.OrderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockHkdStopByOrderId.UpdateBotStockHkdTradeByOrderId:%v", common.ErrShareHkd, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareHkdPosition + } else { + botStockTrade := orders.BotStockBlockStopByOrderId(ctx, order) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, order.OrderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockHkdStopByOrderId.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareHkd, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareBlkPosition + } + + // 修改止損止盈持仓缓存队列数据 + if err = share.UpdateShareHkdStopByOrderId(Reds, order, positionKey, flags.Position); err != nil { + applogger.Error("%v UpdateBotStockHkdStopByOrderId.UpdateShareHkdStopByOrderId:%v", common.ErrShareHkd, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockHkdStopByOrderId.Commit:%v", common.ErrShareHkd, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockHkdClosingByOrderId +// +// @Description: 港股用户平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockHkdClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.HkdMarket) { + return false, flags.ErrStopTread + } + + // 1、查询持仓缓存列表数据并清理对应缓存 + var positionKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + positionKey = setting.MarketShareHkdPosition + userKey = setting.ShareHkdSubscribe + adminKey = setting.AdminShareHkdSubscribe + } else { + positionKey = setting.MarketShareBlkPosition + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + var entrustCache *share.ShareHkdTallyCache + entrust, err := Reds.HGet(context.Background(), positionKey, orderId).Result() + if err != nil { + applogger.Error("%v UpdateBotStockHkdClosingByOrderId.HGet:%v", common.ErrShareHkd, err) + return false, flags.ErrShareFive + } + var entrustJson share.ShareHkdTallyCache + if err = json.Unmarshal([]byte(entrust), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockHkdClosingByOrderId.Unmarshal:%v", common.ErrShareHkd, err) + return false, flags.ErrCacheDB + } + if orderId == entrustJson.OrderId { + entrustCache = &entrustJson + } + + // 3、判定是否存在平仓订单 + if entrustCache == nil { + return false, flags.ErrShareFive + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[entrustJson.UserId] + if ok { + return false, flags.ErrPublicServe + } + + // 市场设置交易时间(T+0,T+1,T+2s......) + if !CheckShareSystemTime(entrustCache.ClosingTime) { + return false, flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("手动平仓:%v", entrustCache) + } + + // 2、获取当前最新价格 + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Hkd, entrustCache.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareHkdTheLatestPrice(subKey, entrustCache.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockHkdClosingByOrderId.GetShareHkdTheLatestPrice:%v", common.ErrShareHkd, err) + return false, flags.ErrStopTread + } + + // 4、平仓处理 + if err = StockHkdClosingOrder(ctx, Msql, orderId, closingPrice.String(), entrustCache.Order); err != nil { + applogger.Error("%v UpdateBotStockHkdClosingByOrderId.StockHkdClosingOrder:%v", common.ErrShareHkd, err) + return false, err + } + + // 5、清理持仓订单信息 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), positionKey, orderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockHkdClosingByOrderId.HDel:%v", common.ErrShareHkd, err) + return false, flags.ErrCacheDB + } + + // 6、平仓更新订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(userKey, entrustCache.UserId) + if err = UpdateShareHkdSubscribeHashStatusByOrderId(orderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockHkdClosingByOrderId.ShareHkdSubscribe:%v", common.ErrShareHkd, err) + return false, flags.ErrCacheDB + } + + // 7、平仓更新管理员订阅缓存订单状态 + if err = UpdateShareHkdSubscribeHashStatusByOrderId(orderId, adminKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockHkdClosingByOrderId.%v:%v", common.ErrShareHkd, adminKey, err) + return false, flags.ErrCacheDB + } + + return true, nil +} + +// UpdateBotStockHkdAllClosingByOrderId +// +// @Description: 港股用户一键平仓 +// @receiver uo +// @param ctx +// @param userId +// @return error +func (uo *userOrderRepo) UpdateBotStockHkdAllClosingByOrderId(ctx context.Context, userId int64) error { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.HkdMarket) { + return flags.ErrStopTread + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe + } + + // 1、查询当前用户所有订单 + orderMap, err := uo.GetBotStockHkdTradeByUserId(userId) + if err != nil { + applogger.Error("%v UpdateBotStockHkdAllClosingByOrderId.GetBotStockHkdTradeByUserId:%v", common.ErrShareHkd, err) + return flags.ErrMySqlDB + } + + // 2、查询持仓缓存列表数据-1、清理持仓列表缓存 2、处理平仓数据 3、清理订单ID缓存列表 + entrust, err := Reds.HGetAll(context.Background(), setting.MarketShareHkdPosition).Result() + if err != nil { + applogger.Error("%v UpdateBotStockHkdAllClosingByOrderId.HGetAll:%v", common.ErrShareHkd, err) + return flags.ErrShareFive + } + + // 3、循环检查股票交易对最新价格(有一个查询不到既不能平仓) + var entrustList []share.ShareHkdTallyCache + closePriceMap := make(map[string]decimal.Decimal) + for key, value := range entrust { + var entrustJson share.ShareHkdTallyCache + if err = json.Unmarshal([]byte(value), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockHkdAllClosingByOrderId.Unmarshal:%v", common.ErrShareHkd, err) + return flags.ErrStopTread + } + _, ok := orderMap[entrustJson.OrderId] + if ok { + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Hkd, entrustJson.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareHkdTheLatestPrice(subKey, entrustJson.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockHkdAllClosingByOrderId.GetShareHkdTheLatestPrice:%v", common.ErrShareHkd, err) + return flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("订阅Key:%v,最新价格:%v,订单ID:%v", subKey, closingPrice, entrustJson.OrderId) + } + + closePriceMap[key] = closingPrice + entrustList = append(entrustList, entrustJson) + } + } + + // 4、股票一键平仓 + for _, value := range entrustList { + closePrice, ok := closePriceMap[value.OrderId] + if ok { + // 平仓 + if err = StockHkdClosingOrder(ctx, uo.data.mysqlDB, value.OrderId, closePrice.String(), value.Order); err != nil { + applogger.Error("%v UpdateBotStockHkdAllClosingByOrderId.StockHkdClosingOrder:%v", common.ErrShareHkd, err) + return err + } + + // 清理持仓缓存列表 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), setting.MarketShareHkdPosition, value.OrderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockHkdAllClosingByOrderId.HDel:%v", common.ErrShareHkd, err) + return flags.ErrCacheDB + } + + // 平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareHkdSubscribe, value.UserId) + if err = UpdateShareHkdSubscribeHashStatusByOrderId(value.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockHkdAllClosingByOrderId.ShareHkdSubscribe:%v", common.ErrShareHkd, err) + return flags.ErrCacheDB + } + + // 平仓更新管理员订阅订单状态 + if err = UpdateShareHkdSubscribeHashStatusByOrderId(value.OrderId, setting.AdminShareHkdSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockHkdAllClosingByOrderId.AdminShareHkdSubscribe:%v", common.ErrShareHkd, err) + return flags.ErrCacheDB + } + } + } + + return nil +} + +// GetBotStockHkdTradeByUserId +// +// @Description: +// @receiver uo +// @param ctx +// @param userId +// @return map[string]string +// @return error +func (uo *userOrderRepo) GetBotStockHkdTradeByUserId(userId int64) (map[string]string, error) { + var botStockHkdTrade []models.BotStockHkdTrade + if err := uo.data.mysqlDB.Table(flags.BotStockHkdTrade). + Where("user_id = ?", userId). + Where("status = 1"). + Find(&botStockHkdTrade); err != nil { + return nil, err + } + + botMap := make(map[string]string) + for _, value := range botStockHkdTrade { + botMap[value.OrderId] = value.OrderId + } + + return botMap, nil +} + +// GetShareHkdTheLatestPrice +// +// @Description: +// @receiver uo +// @param ctx +// @param subKey +// @param tradeType +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) GetShareHkdTheLatestPrice(subKey string, tradeType int64) (decimal.Decimal, error) { + priceNew, err := share.ShareHkdSubMarketPrice(subKey) + if err != nil { + applogger.Error("%v GetShareHkdTheLatestPrice.ShareHkdSubMarketPrice:%v", common.ErrShareHkd, err) + return decimal.Decimal{}, err + } + + priceS := decimal.RequireFromString(priceNew) + + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tradeType { + case flags.TradeTypeBuy: // 买涨 + openPrice = priceS.Sub(difference) // 开仓价格 + case flags.TradeTypeSell: // 买跌 + openPrice = priceS.Add(difference) // 开仓价格 + default: + + } + + return openPrice, nil +} + +// GetBotStockHkdTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @return *models.BotStockHkdTrade +// @return error +func (uo *userOrderRepo) GetBotStockHkdTradeByOrderId(session *xorm.Session, orderId string) (*models.BotStockHkdTrade, error) { + var botStockHkdTrade []models.BotStockHkdTrade + if err := session.Table(flags.BotStockHkdTrade). + Where("order_id = ?", orderId). + Find(&botStockHkdTrade); err != nil { + return nil, err + } + + for _, value := range botStockHkdTrade { + return &value, nil + } + + return nil, nil +} + +// GetBotUserStockHkdByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @return *models.BotUserStock +// @return error +func (uo *userOrderRepo) GetBotUserStockHkdByUserIdAndStockId(session *xorm.Session, userId int64, stockId string) (*models.BotUserStockHkd, error) { + var stockUSD []models.BotUserStockHkd + if err := session.Table(flags.BotUserStockHkd). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&stockUSD); err != nil || len(stockUSD) < 0 { + return nil, err + } + + for _, value := range stockUSD { + return &value, nil + } + + return nil, nil +} + +// UpdateBotStockHkdTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotStockHkdTradeByOrderId(session *xorm.Session, orderId string, stock models.BotStockHkdTrade) error { + checkInt, err := session.Table(flags.BotStockHkdTrade). + Where("order_id = ?", orderId). + Update(&stock) + if err != nil || checkInt < 0 { + return err + } + + return nil +} + +// CreateBotStockHkdTrade +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param trade +// @return error +func (uo *userOrderRepo) CreateBotStockHkdTrade(session *xorm.Session, trade models.BotStockHkdTrade) error { + _, err := session.Table(flags.BotStockHkdTrade).Insert(&trade) + if err != nil { + return err + } + + return nil +} + +// CreateBotUserStockHkd +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param stock +// @return error +func (uo *userOrderRepo) CreateBotUserStockHkd(session *xorm.Session, stock models.BotUserStockHkd) error { + _, err := session.Table(flags.BotUserStockHkd).Insert(&stock) + if err != nil { + return err + } + + return nil +} + +// UpdateBotUserStockHkdByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotUserStockHkdByUserIdAndStockId(session *xorm.Session, userId int64, stockId string, stock models.BotUserStockHkd) error { + checkNum, err := session.Table(flags.BotUserStockHkd). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&stock) + if err != nil || checkNum < 0 { + return err + } + + return nil +} + +// StockHkdVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) StockHkdVoteDealType(order structure.ShareOrder) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + return limitOrMarketPrice, nil +} + +// UpdateShareHkdVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) UpdateShareHkdVoteDealType(order *models.BotStockHkdTrade) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + if len(order.DealPrice) != 0 { + dealPrice := decimal.RequireFromString(order.DealPrice) + if !dealPrice.IsZero() { + limitOrMarketPrice = dealPrice + } + } + + return limitOrMarketPrice, nil +} + +// VerifyBotStockHkdTradeOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @return string +// @return error +func (uo *userOrderRepo) VerifyBotStockHkdTradeOrderId(session *xorm.Session) (string, error) { + var orderId string + for { + // 生成订单ID + orderId = orders.CreateRandCodeOrder(10) + + var orderList []models.BotStockHkdTrade + err := session.Table(flags.BotStockHkdTrade). + Where("order_id = ?", orderId). + Find(&orderList) + if err != nil || len(orderList) > 0 { + applogger.Error("%v VerifyBotStockHkdTradeOrderId.Find:%v", common.ErrShareHkd, err) + continue + } + + break + } + + return orderId, nil +} + +// GetBotStockHkdTradeByOrderIdOrStatus +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param status +// @return *models.BotStockTrade +// @return error +func (uo *userOrderRepo) GetBotStockHkdTradeByOrderIdOrStatus(session *xorm.Session, orderId string, status int) (*models.BotStockHkdTrade, error) { + var botStockHkdTrade []models.BotStockHkdTrade + if err := session.Table(flags.BotStockHkdTrade). + Where("order_id = ?", orderId). + Where("`status` = ?", status). + Find(&botStockHkdTrade); err != nil { + return nil, err + } + + for _, value := range botStockHkdTrade { + return &value, nil + } + + return nil, nil +} diff --git a/internal/data/order_share_idn.go b/internal/data/order_share_idn.go new file mode 100644 index 0000000..d5af225 --- /dev/null +++ b/internal/data/order_share_idn.go @@ -0,0 +1,1498 @@ +package data + +import ( + "context" + "encoding/json" + "github.com/go-xorm/xorm" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" + + orders "matchmaking-system/internal/data/convert" + models "matchmaking-system/internal/pkg/model" +) + +// GetBotStockIdnTradeList +// +// @Description: 印尼股订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param userId +// @param status +// @return []*models.BotStockIdnTrade +// @return int64 +// @return error +func (uo *userOrderRepo) GetBotStockIdnTradeList(pageSize, pageCount, userId, status int64) ([]*models.BotStockIdnTrade, int64, error) { + totalCount, err := uo.data.mysqlDB.Table(flags.BotStockIdnTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Count() + if err != nil { + return nil, 0, flags.ErrMySqlDB + } + if totalCount == 0 { + return nil, 0, nil + } + var stockList []*models.BotStockIdnTrade + if err = uo.data.mysqlDB.Table(flags.BotStockIdnTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Limit(int(pageSize), int(pageCount)). + Desc(GetOrderByStatusSort(status)). + Find(&stockList); err != nil { + return nil, 0, flags.ErrMySqlDB + } + + var stockUpdateList []*models.BotStockIdnTrade + for _, value := range stockList { + value.KeepDecimal = GetKeepDecimal(flags.StockYNSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockYNSystemSetUpKey, value.StockId) + stockUpdateList = append(stockUpdateList, value) + } + + return stockUpdateList, totalCount, nil +} + +// PlacingStockIdnOrders +// +// @Description: 印尼股下单 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) PlacingStockIdnOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) { + // 1、通知股下单订阅 + symbol := order.StockId + timeValue := QuerySystemCache(flags.ShareIdnMarketType) // 市场开闭盘时间 + if !utils.CheckInPlateTime(timeValue) { + return flags.SetNull, flags.ErrStopTread + } + SubscribeIdnHSetCodeList(symbol, false) // 同步写入股票列表缓存 + SubscribeIdnCloseNewPrice(symbol) // 同步股票实时行情价 + + // 判定是否存在欠款订单 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe.Error(), nil + } + + order = PryNumInit(order) // 杠杆初始化 + subKey := publicData.SymbolCache(flags.Idn, symbol, flags.TradeTypePrice) + + // 印尼股市场系统设置 + if CheckGlobalTread(flags.IdnMarket) { + return flags.SetNull, flags.ErrStopTread + } + + // 全局设置交易操作 + var blockTime time.Time + var priceNew, userKey, adminKey string + if !CheckTypeStatus(order.Type) { + userKey = setting.ShareIdnSubscribe + adminKey = setting.AdminShareIdnSubscribe + } else { + // 判定:1、是否开启股票交易 2、是否在交易时间内 3、是否达到最小交易量 + check, openPrice, minNum, endTime := CheckBlockTread(flags.IdnBlk, symbol) + if check { + return flags.SetNull, flags.ErrShareSeven + } + if minNum > utils.StringToInt(order.OrderNumber) { + return flags.SetNull, flags.ErrShareSix + } + priceNew = openPrice // 开仓价格 + blockTime = endTime // 平仓时间 + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + flatRatio := GetCacheForcedClosure(flags.StockYNSystemSetUpKey, symbol) // 单个股票系统设置 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.IdnMarket, userId) // 股票市场系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), // 强平阈值 + Status: leverStatus.Status, // 杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + order.System = system + + // 2、股票下单判定 + // 下单判定设置(false无设置|true止盈止损) + checkBool, stopWinPrice, stopLossPrice, err := StockIdnVoteStopType(order) + if err != nil { + applogger.Error("%v PlacingStockIdnOrders.StockIdnVoteStopType:%v", common.ErrShareIdn, err) + return flags.SetNull, err + } + // 下单判定设置(限价|市价) + limitOrMarketPrice, err := uo.StockIdnVoteDealType(order) + if err != nil { + applogger.Error("%v PlacingStockIdnOrders.StockVoteDealType:%v", common.ErrShareIdn, err) + return flags.SetNull, err + } + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(order.TradeType, stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v PlacingStockIdnOrders.StockVoteTradeType:%v", common.ErrShareIdn, err) + return flags.SetNull, err + } + + // 3、订单持久化录入(并处理资产信息) + pryNum := SystemDealWithLever(order) + orderId, err := uo.StockIdnOrderWriteDB(ctx, userId, order, limitOrMarketPrice, pryNum) + if err != nil || len(orderId) == 0 { + applogger.Error("%v PlacingStockIdnOrders.StockIdnOrderWriteDB:%v", common.ErrShareIdn, err) + return flags.SetNull, err + } + + // 4、处理订单信息 + chg := GetShareChgIdn(flags.Idn, order.StockId) // 涨跌幅标识值 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.IdnMarket, time.Now()) // 开盘时间 + marketStatus, shareOrder, err := share.ShareIdnCacheDeal(ctx, userId, orderId, subKey, order, chg, priceNew, closingTime, blockTime) + if err != nil || shareOrder == nil { + applogger.Error("%v PlacingStockIdnOrders.ShareIdnCacheDeal:%v", common.ErrShareIdn, err) + return flags.SetNull, err + } + // 计算保证金 = 订单价格 * 订单数量 / 杠杆 + shareOrder.Order.MarketMoney = limitOrMarketPrice.Mul(decimal.RequireFromString(order.OrderNumber)).Div(pryNum).String() + if !flags.CheckSetting { + applogger.Debug("订单ID:%v", shareOrder.OrderId) + applogger.Debug("订单交易对:%v", shareOrder.Symbol) + applogger.Debug("订单状态:%v", shareOrder.Status) + applogger.Debug("订单用户ID:%v", shareOrder.UserId) + applogger.Debug("开盘价:%v", shareOrder.OpenPrice) + applogger.Debug("收盘价:%v", shareOrder.ClosingPrice) + applogger.Debug("下单信息:%v", shareOrder.Order) + } + + // 6、订单(挂单|持仓)缓存列表,等待队列计算 + if err = share.ShareIdnHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v PlacingStockIdnOrders.ShareIdnHashUserOrder:%v", common.ErrShareIdn, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 7、用户订阅股票订单信息 + orderIdKey := virtual.OrderIdListKey(userKey, userId) + if err = share.ShareIdnHashUserOrder(Reds, orderIdKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockIdnOrders.%v:%v", common.ErrShareIdn, userKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 8、管理员订阅订单信息 + if err = share.ShareIdnHashUserOrder(Reds, adminKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockIdnOrders.%v:%v", common.ErrShareIdn, adminKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + return orderId, nil +} + +// StockIdnOrderWriteDB +// +// @Description: 印尼股下单处理 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) StockIdnOrderWriteDB(ctx context.Context, userId int64, order structure.ShareOrder, limitOrMarketPrice, lever decimal.Decimal) (string, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockIdnOrderWriteDB.Begin:%v", common.ErrShareIdn, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 当前下单用户的资产 + var usableOld, frozenOld decimal.Decimal + stockIdr, err := uo.GetBotUserStockIdnByUserIdAndStockId(session, userId, flags.ShareIdnBasicUnit) + if err != nil || stockIdr == nil { + applogger.Error("%v StockIdnOrderWriteDB.IDR:%v", common.ErrShareIdn, err) + return flags.SetNull, flags.ErrMySqlDB + } + usableOld = decimal.RequireFromString(stockIdr.UsableNum) + frozenOld = decimal.RequireFromString(stockIdr.FrozenNum) + + // 检查用户下单资产 + if usableOld.IsZero() || usableOld.IsNegative() || frozenOld.IsNegative() { + return flags.SetNull, flags.ErrShareOne + } + + // 当前系统下单用户的非资产 + var usableFOld, frozenFOld decimal.Decimal + stockFIdr, err := uo.GetBotUserStockIdnByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockIdnOrderWriteDB.FeiIDR:%v", common.ErrShareIdn, err) + return flags.SetNull, flags.ErrMySqlDB + } + if stockFIdr != nil { + usableFOld = decimal.RequireFromString(stockFIdr.UsableNum) + frozenFOld = decimal.RequireFromString(stockFIdr.FrozenNum) + } + if !flags.CheckSetting { + applogger.Debug("下单可用资产:%v", usableOld) + applogger.Debug("下单冻结资产:%v", frozenOld) + applogger.Debug("下单可用非资产:%v", usableFOld) + applogger.Debug("下单冻结非资产:%v", frozenFOld) + } + + // 整理当前下单信息 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 订单手续费 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 订单数量 + marketMoney := limitOrMarketPrice.Mul(orderNumber).Div(lever) // 订单金额(杠杆下单) = 订单数量 * 交易价格 / 杠杆 + totalMoney := marketMoney.Add(serviceCost) // 订单总金额 + order.MarketMoney = marketMoney.String() // 市值金额即为保证金 + + // TODO: 大宗(印尼股)交易检查订单ID是否存在,新增下单信息 + var orderId string + if !CheckTypeStatus(order.Type) { + orderId, err = uo.VerifyBotStockIdnTradeOrderId(session) + if err != nil { + applogger.Error("%v StockIdnOrderWriteDB.VerifyBotStockIdnTradeOrderId:%v", common.ErrShareIdn, err) + return flags.SetNull, err + } + trade := orders.BotStockIdnTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockIdnTrade(session, trade); err != nil { + applogger.Error("%v StockIdnOrderWriteDB.CreateBotStockIdnTrade:%v", common.ErrShareIdn, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + orderId, err = uo.VerifyBotStockBlockTradeOrderId(session) + if err != nil { + applogger.Error("%v StockIdnOrderWriteDB.VerifyBotStockBlockTradeOrderId:%v", common.ErrShareIdn, err) + return flags.SetNull, err + } + trade := orders.BotStockBlockTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockBlockTrade(session, trade); err != nil { + applogger.Error("%v StockIdnOrderWriteDB.CreateBotStockBlockTrade:%v", common.ErrShareIdn, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + // 下单判定 + residue := usableOld.Sub(totalMoney).Div(usableOld) + if usableOld.Cmp(totalMoney) <= 0 || residue.Cmp(utils.DecimalsStrInt()) <= 0 { + return flags.SetNull, flags.ErrPublicTow + } + + var usableNew, frozenNew, usableFNew, frozenFNew decimal.Decimal + usableNew = usableOld.Sub(totalMoney) // 可用资产 + frozenNew = frozenOld.Add(totalMoney) // 冻结资产 + if order.StockId != flags.ShareIdnBasicUnit { + usableFNew = usableFOld.Add(orderNumber) // 可用非资产 + frozenFNew = frozenFOld // 冻结非资产 + } + + // 检查用户订单下单资产 + if usableNew.IsNegative() || usableNew.IsZero() { + return flags.SetNull, flags.ErrPublicTow + } + + // 下单更新资产信息 + stockIdrModel := orders.UpdateBotUserStockIdn(ctx, usableNew.String(), frozenNew.String()) + err = uo.UpdateBotUserStockIdnByUserIdAndStockId(session, userId, flags.ShareIdnBasicUnit, stockIdrModel) + if err != nil { + applogger.Error("%v StockIdnOrderWriteDB.UpdateBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareIdn, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 下单(新增|更新)非资产信息 + if stockFIdr == nil { + stockFIDRModel := orders.CreateBotUserStockIdn(ctx, userId, order.StockId, usableFNew.String(), frozenFNew.String()) + err = uo.CreateBotUserStockIdnFIRD(session, stockFIDRModel) + if err != nil { + applogger.Error("%v StockIdnOrderWriteDB.CreateBotUserStockIdnFIRD:%v", common.ErrShareIdn, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + stockFIDRModel := orders.UpdateBotUserStockIdn(ctx, usableFNew.String(), frozenFNew.String()) + err = uo.UpdateBotUserStockIdnByUserIdAndStockId(session, userId, order.StockId, stockFIDRModel) + if err != nil { + applogger.Error("%v StockIdnOrderWriteDB.UpdateBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareIdn, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockIdnOrderWriteDB.Commit:%v", common.ErrShareIdn, err) + return flags.SetNull, flags.ErrMySqlDB + } + + return orderId, nil +} + +// StockIdnOpenOrder +// +// @Description: 印尼股系统开仓 +// @param ctx +// @param db +// @param userId +// @param orderId +// @param openPrice +// @param order +// @return error +func StockIdnOpenOrder(ctx context.Context, db *xorm.EngineGroup, userId int64, orderId, openPrice string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockIdnOpenOrder.NewSession:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockIdr, err := Uo.GetBotUserStockIdnByUserIdAndStockId(session, userId, flags.ShareIdnBasicUnit) + if err != nil || stockIdr == nil { + applogger.Error("%v StockIdnOpenOrder.GetBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockIdr.UsableNum) // 用户可用资产 + frozen = decimal.RequireFromString(stockIdr.FrozenNum) // 用户冻结资产 + + // 检查用户开仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrPublicThree + } + if order.StockId != flags.ShareIdnBasicUnit { + stockFIdr, err := Uo.GetBotUserStockIdnByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockIdnOpenOrder.GetBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(stockFIdr.UsableNum) // 用户非可用资产 + frozenNo = decimal.RequireFromString(stockFIdr.FrozenNum) // 用户非冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + + // 转换股票下单信息 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 下单股数 + orderMoney := decimal.RequireFromString(order.MarketMoney) // 下单金额 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 下单手续费 + totalMoney := orderMoney.Add(serviceCost) // 下单总金额 = (下单手续费 + 下单金额) + openOrderPrice := decimal.RequireFromString(openPrice) // 开盘价格 + if !flags.CheckSetting { + applogger.Debug("下单订单数量:%v", orderNumber) + applogger.Debug("下单订单金额:%v", orderMoney) + applogger.Debug("下单订单手续费:%v", serviceCost) + applogger.Debug("下单订单总金额:%v", totalMoney) + } + + // 手续费记录 + openPriceNew := openOrderPrice.Mul(orderNumber).String() // 开仓手续费 = 开仓价格 * 股数 * 开仓手续费 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareIdnMarketType, flags.OpenBrokType, orderId, openPriceNew) + if err != nil { + applogger.Error("%v StockIdnOpenOrder.CalculateHandlingFeesShare:%v", common.ErrShareIdn, err) + return err + } + openServiceCost := decimal.RequireFromString(cost) // 开仓手续费 + openMarkerMoney := openOrderPrice.Mul(orderNumber).Div(decimal.RequireFromString(order.PryNum)) // 开仓订单金额 = 开仓价格 * 股数 / 杠杠 + openTotalMoney := openMarkerMoney.Add(openServiceCost) // 开仓总金额 = 开仓订单金额 + 开仓手续费 + floatPrice := totalMoney.Sub(openTotalMoney) // 计算容差 = 下单总额 - 开仓总额 + if !flags.CheckSetting { + applogger.Debug("开仓订单价格:%v", openOrderPrice) + applogger.Debug("开仓手续费:%v", openServiceCost) + applogger.Debug("开仓总金额:%v", openTotalMoney) + applogger.Debug("开仓订单金额:%v", openMarkerMoney) + applogger.Debug("下单->开仓总金额容差值:%v", floatPrice) + } + + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + usableNew = usable.Add(floatPrice) // 可用资产(处理容差值) + frozenNew = frozen.Sub(totalMoney).Add(openMarkerMoney) // 冻结资产 + if order.StockId != flags.ShareIdnBasicUnit { + usableNoNew = usableNo // 非可用资产 + frozenNoNew = frozenNo // 非冻结资产 + } + + // 检查用户开仓资产 + if frozenNew.IsNegative() || usableNew.IsNegative() { + return flags.ErrPublicThree + } + if !flags.CheckSetting { + applogger.Debug("下单后用户可用资产:%v", usableNew) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + } + + // 处理资产信息 + userStockIdr := orders.UpdateBotUserStockIdn(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockIdnByUserIdAndStockId(session, userId, flags.ShareIdnBasicUnit, userStockIdr); err != nil { + applogger.Error("%v StockIdnOpenOrder.IDR.UpdateBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + + // 更新非资产信息 + if order.StockId != flags.ShareIdnBasicUnit { + userStockFIdr := orders.UpdateBotUserStockIdn(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = Uo.UpdateBotUserStockIdnByUserIdAndStockId(session, userId, order.StockId, userStockFIdr); err != nil { + applogger.Error("%v StockIdnOpenOrder.UpdateBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + } + + // 返佣记录|资金信息|资金详情信息 + if err = Uo.ShareIdnRebateCalculation(ctx, session, int(userId), flags.ShareIdnMarketType, flags.OpenBrokType, flags.OpenMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockIdnOpenOrder.ShareIdnRebateCalculation:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + + // 处理订单信息(成交价|仓位|开仓时间|订单总金额|手续费|持仓状态) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateOpenBotStockIdnTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarkerMoney.String()) + if err = Uo.UpdateBotStockIdnTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockIdnOpenOrder.UpdateBotStockIdnTradeByOrderId:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + var list []models.BotUserStockIdnLog + qData0 := orders.CreatBotUserStockIdnLog(ctx, userId, flags.CostMoney, flags.ShareIdnBasicUnit, NegativeValue(openServiceCost.String()), orderId) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockIdnLog(ctx, userId, flags.Freeze, flags.ShareIdnBasicUnit, NegativeValue(openMarkerMoney.String()), orderId) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockIdnLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockIdnLogList(session, list); err != nil { + applogger.Error("%v StockIdnOpenOrder.CreatBotUserStockIdnLogList:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateOpenBotStockBlockTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarkerMoney.String()) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockIdnOpenOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareIdnBasicUnit, NegativeValue(openServiceCost.String()), orderId, order.Type) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Freeze, flags.ShareIdnBasicUnit, NegativeValue(openMarkerMoney.String()), orderId, order.Type) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId, order.Type) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockIdnOpenOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockIdnOpenOrder.Commit:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + + return nil +} + +// StockIdnClosingOrder +// +// @Description: 印尼股系统平仓 +// @param ctx +// @param db +// @param orderId +// @param price +// @param order +// @return error +func StockIdnClosingOrder(ctx context.Context, db *xorm.EngineGroup, orderId string, price string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockIdnClosingOrder.NewSession:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + + // 查询订单信息 + var userId int64 + var dealPrice, orderNumber, totalAmount, serviceCost, marketMoney decimal.Decimal + if !CheckTypeStatus(order.Type) { + tread, err := Uo.GetBotStockIdnTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockIdnClosingOrder.GetBotStockIdnTradeByOrderIdOrStatus:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + marketMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓订单金额 + } else { + tread, err := Uo.GetBotStockBlockTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockIdnClosingOrder.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + marketMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓订单金额 + } + + if !flags.CheckSetting { + applogger.Debug("下单开仓用户Id:%v", userId) + applogger.Debug("下单开仓开仓价格:%v", dealPrice) + applogger.Debug("下单开仓订单数量:%v", orderNumber) + applogger.Debug("下单开仓总金额:%v", totalAmount) + applogger.Debug("下单开仓手续费:%v", serviceCost) + applogger.Debug("下单开仓订单金额:%v", marketMoney) + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + userStockIdr, err := Uo.GetBotUserStockIdnByUserIdAndStockId(session, userId, flags.ShareIdnBasicUnit) + if err != nil { + applogger.Error("%v StockIdnClosingOrder.GetBotUserStockByUserIdAndStockId:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(userStockIdr.UsableNum) // 用户可用资金 + frozen = decimal.RequireFromString(userStockIdr.FrozenNum) // 用户非冻结资金 + + // 检查用户订单平仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrShareTow + } + + // 查询当前下单用户可用非账户和冻结金额 + if order.StockId != flags.ShareIdnBasicUnit { + userStockFIdr, err := Uo.GetBotUserStockIdnByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockIdnClosingOrder.GetBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(userStockFIdr.UsableNum) // 用户非可用资金 + frozenNo = decimal.RequireFromString(userStockFIdr.FrozenNum) // 用户非冻结资金 + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + + // 手续费处理 + closePrice := decimal.RequireFromString(price) // 平仓价格 + cloePriceCost := closePrice.Mul(orderNumber).String() // 平仓手续费 = 平仓价格 * 股数 * 手续费比例 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareIdnMarketType, flags.ClosingBrokType, orderId, cloePriceCost) + if err != nil { + applogger.Error("%v StockIdnClosingOrder.CalculateHandlingFeesShare:%v", common.ErrShareIdn, err) + return err + } + closeServiceCost := decimal.RequireFromString(cost) + if !flags.CheckSetting { + applogger.Debug("平仓价格:%v", closePrice) + applogger.Debug("平仓手续费手续费:%v", closeServiceCost) + } + + //已经实现盈亏计算公式(已平仓结算方式) + //买涨 已经实现盈亏 = (平仓成交价-开仓成交价)*股数 + //买跌 已经实现盈亏 = (开仓成交价-平仓成交价)*股数 + var usableNew, frozenNew, usableNewNo, frozenNewNo, subPrice, resultPrice decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买涨 + subPrice = closePrice.Sub(dealPrice) + resultPrice = subPrice.Mul(orderNumber) + case flags.TradeTypeSell: // 买跌 + subPrice = dealPrice.Sub(closePrice) + resultPrice = subPrice.Mul(orderNumber) + default: + } + + // TODO: 判定亏损不能超过 = 保证金 + 平仓手续费 + if resultPrice.IsNegative() { + amountLoss := marketMoney.Sub(closeServiceCost) + if resultPrice.Abs().Cmp(amountLoss) >= 0 { + resultPrice = amountLoss.Neg() + } + } + + // 用户资产账户 + usableNew = usable.Add(resultPrice).Sub(closeServiceCost).Add(marketMoney) // 可用资产 = 原可用资产 + ((正负)盈亏) - 平仓手续费 + 开仓订单金额 + if frozen.Cmp(marketMoney) == -1 { + frozenNew = frozen.Sub(frozen) // 冻结资产 + } else { + frozenNew = frozen.Sub(marketMoney) // 冻结资产 + } + + // 用户非资产账户 + if order.StockId != flags.ShareIdnBasicUnit { + usableNewNo = usableNo.Sub(orderNumber) // 可用非资产 = 原可用非资产 - 下单股数 + frozenNewNo = frozenNo // 可用非冻结资产 + } + + // 检查用户平仓资产 + if frozenNew.IsNegative() || usableNewNo.IsNegative() { + return flags.ErrShareTow + } + if !flags.CheckSetting { + applogger.Debug("可用资产:%v", usableNew) + applogger.Debug("冻结资产:%v", frozenNew) + applogger.Debug("可用非资产:%v", usableNewNo) + applogger.Debug("冻结非资产:%v", frozenNewNo) + } + + // 平仓(处理资产表(资产)) + userStockIDR := orders.UpdateBotUserStockIdn(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockIdnByUserIdAndStockId(session, userId, flags.ShareIdnBasicUnit, userStockIDR); err != nil { + applogger.Error("%v StockIdnClosingOrder.USD.UpdateBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + + // 平仓(处理资产表(非资产)) + if order.StockId != flags.ShareIdnBasicUnit { + userStockFIDR := orders.UpdateBotUserStockIdn(ctx, usableNewNo.String(), frozenNewNo.String()) + if err = Uo.UpdateBotUserStockIdnByUserIdAndStockId(session, userId, order.StockId, userStockFIDR); err != nil { + applogger.Error("%v StockIdnClosingOrder.UpdateBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + } + + // 平仓(返佣记录表|资产表|资金变动表) + if err = Uo.ShareIdnRebateCalculation(ctx, session, int(userId), flags.ShareIdnMarketType, flags.ClosingBrokType, flags.CloseMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockIdnClosingOrder.ShareIdnRebateCalculation:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + + // 平仓(处理订单信息(平仓价|保证金|平仓|订单总金额|平仓手续费|完成订单)) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateCloseBotStockIdnTrade(ctx, price, cost) + if err = Uo.UpdateBotStockIdnTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockIdnClosingOrder.UpdateBotStockIdnTradeByOrderId:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockIdnLog + qData0 := orders.CreatBotUserStockIdnLog(ctx, userId, flags.Thaw, flags.ShareIdnBasicUnit, marketMoney.String(), orderId) // 平仓(资金变动明细表(开仓保证金)) + qData1 := orders.CreatBotUserStockIdnLog(ctx, userId, flags.CostMoney, flags.ShareIdnBasicUnit, NegativeValue(closeServiceCost.String()), orderId) // 平仓(资金变动明细表(平仓手续费)) + qData2 := orders.CreatBotUserStockIdnLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId) // 平仓(资金变动明细表(非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏)) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockIdnLog(ctx, userId, flags.TransferOut, flags.ShareIdnBasicUnit, resultPrice.String(), orderId) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockIdnLog(ctx, userId, flags.ChangeInto, flags.ShareIdnBasicUnit, resultPrice.String(), orderId) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockIdnLogList(session, list); err != nil { + applogger.Error("%v StockIdnClosingOrder.CreatBotUserStockIdnLogList:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateCloseBotStockBlockTrade(ctx, price, cost) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockIdnClosingOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Thaw, flags.ShareIdnBasicUnit, marketMoney.String(), orderId, order.Type) // 平仓(资金变动明细表(开仓保证金)) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareIdnBasicUnit, NegativeValue(closeServiceCost.String()), orderId, order.Type) // 平仓(资金变动明细表(平仓手续费)) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId, order.Type) // 平仓(资金变动明细表(非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏)) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, flags.ShareIdnBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, flags.ShareIdnBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockIdnClosingOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockClosingOrder.Commit:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + + return nil +} + +// UpdateBotStockIdnCancelByOrderId +// +// @Description: 印尼股撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockIdnCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockIdnCancelByOrderId.Begin:%v", common.ErrShareIdn, err) + return false, flags.ErrMySqlDB + } + + // 获取订单信息 + var userId int64 + var stockId string + var marketMoneyOld, serviceCostOld, orderNumber decimal.Decimal + if !CheckTypeStatus(typeStatus) { + stockTrade, err := uo.GetBotStockIdnTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockIdnCancelByOrderId.GetBotStockIdnTradeByOrderId:%v", common.ErrShareIdn, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } else { + stockTrade, err := uo.GetBotStockBlockTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockIdnCancelByOrderId.GetBotStockBlockTradeByOrderId:%v", common.ErrShareIdn, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } + + // 获取用户资产信息 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockIdr, err := uo.GetBotUserStockIdnByUserIdAndStockId(session, userId, flags.ShareIdnBasicUnit) + if err != nil || stockIdr == nil { + applogger.Error("%v UpdateBotStockIdnCancelByOrderId.IDR.GetBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareIdn, err) + return false, flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockIdr.UsableNum) // 用户账户可用资产 + frozen = decimal.RequireFromString(stockIdr.FrozenNum) // 用户账户冻结资产 + + // 检查用户订单撤单资产 + if frozen.IsNegative() || usable.IsNegative() { + return false, flags.ErrShareThree + } + if stockId != flags.ShareIdnBasicUnit { + stockFUsd, err := uo.GetBotUserStockIdnByUserIdAndStockId(session, userId, stockId) + if err != nil { + applogger.Error("%v UpdateBotStockIdnCancelByOrderId.GetBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareIdn, err) + return false, flags.ErrPublicFour + } + usableNo = decimal.RequireFromString(stockFUsd.UsableNum) // 用户非账户可用资产 + frozenNo = decimal.RequireFromString(stockFUsd.FrozenNum) // 用户非账户冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("用户原始可用资金:%v", usable) + applogger.Debug("用户原始冻结资金:%v", frozen) + applogger.Debug("用户原始可用非资金:%v", usableNo) + applogger.Debug("用户原始冻结非资金:%v", frozenNo) + } + + // 更新订单信息 + var entrustKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + botStockTrade := orders.BotStockIdnCancelByOrderId(ctx) + if err = uo.UpdateBotStockIdnTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockIdnCancelByOrderId.IDR.UpdateBotStockIdnTradeByOrderId:%v", common.ErrShareIdn, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareIdnEntrust + userKey = setting.ShareIdnSubscribe + adminKey = setting.AdminShareIdnSubscribe + } else { + botStockTrade := orders.BotStockBlockCancelByOrderId(ctx) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockIdnCancelByOrderId.IDR.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareIdn, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareBlkEntrust + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // Operational Spot Asset Table + totalMoney := marketMoneyOld.Add(serviceCostOld) // 订单总金额 + // update total asset data + usableNew := usable.Add(totalMoney) // 用户总资产 + frozenNew := frozen.Sub(totalMoney) // 用户冻结资产 + usableNoNew := usableNo.Sub(orderNumber) // 用户非可用资产 + frozenNoNew := frozenNo // 用户非冻结资产 + if !flags.CheckSetting { + applogger.Debug("用户撤单可用总资产:%v", usableNew) + applogger.Debug("用户撤单冻结总资产:%v", frozenNew) + applogger.Debug("用户非撤单可用总资产:%v", usableNoNew) + applogger.Debug("用户非撤单冻结总资产:%v", frozenNoNew) + } + + // 检查用户订单撤单资产 + if frozenNew.IsNegative() || usableNoNew.IsNegative() { + return false, flags.ErrShareThree + } + + // 更新资产信息和非资产信息 + userStockIDR := orders.UpdateBotUserStockIdn(ctx, usableNew.String(), frozenNew.String()) + if err = uo.UpdateBotUserStockIdnByUserIdAndStockId(session, userId, flags.ShareIdnBasicUnit, userStockIDR); err != nil { + applogger.Error("%v UpdateBotStockIdnCancelByOrderId.UpdateBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareIdn, err) + return false, flags.ErrMySqlDB + } + if stockId != flags.ShareIdnBasicUnit { + userStockFIdn := orders.UpdateBotUserStockIdn(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = uo.UpdateBotUserStockIdnByUserIdAndStockId(session, userId, stockId, userStockFIdn); err != nil { + applogger.Error("%v UpdateBotStockIdnCancelByOrderId.UpdateBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareIdn, err) + return false, flags.ErrMySqlDB + } + } + + // 删除订单缓存列表 + if err = Reds.HDel(context.Background(), entrustKey, orderId).Err(); err != nil { + applogger.Error("%v UpdateBotStockIdnCancelByOrderId.HDel:%v", common.ErrShareIdn, err) + return false, flags.ErrCacheDB + } + + // 更新用户订阅订单缓存列表 + userSubKey := virtual.OrderIdListKey(userKey, userId) + if err = share.UpdateShareIdnHashByOrderId(Reds, orderId, userSubKey, flags.Cancel); err != nil { + applogger.Error("%v UpdateBotStockIdnCancelByOrderId.%v:%v", common.ErrShareIdn, userKey, err) + return false, flags.ErrCacheDB + } + + // 更新管理员订阅订单缓存列表 + if err = UpdateShareIdnSubscribeHashStatusByOrderId(orderId, adminKey, flags.Cancel, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotContractCancelByOrderId.%v:%v", common.ErrShareIdn, adminKey, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotContractCancelByOrderId.Commit:%v", common.ErrShareIdn, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockIdnStopByOrderId +// +// @Description: 印尼股设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockIdnStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockIdnStopByOrderId.NewSession:%v", common.ErrShareIdn, err) + return false, flags.ErrMySqlDB + } + + // 设置止盈止损 + var userId int64 + if order.StopType == 1 { + // 股票下单信息 + checkBool, stopWinPrice, stopLossPrice, err := uo.UpdateVoteStopType(order) + if err != nil { + applogger.Error("%v UpdateBotStockIdnStopByOrderId.UpdateVoteStopType:%v", common.ErrShareIdn, err) + return false, err + } + if !flags.CheckSetting { + applogger.Debug("当前止盈止损数据:%v,%v,%v", checkBool, stopWinPrice, stopLossPrice) + } + + // 设置止盈止损判定 + var tradeType int + var limitOrMarketPrice decimal.Decimal + if !CheckTypeStatus(order.Type) { + trade, err := uo.GetBotStockIdnTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockIdnStopByOrderId.GetBotStockIdnTradeByOrderIdOrStatus:%v", common.ErrShareIdn, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareIdnVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockIdnStopByOrderId.UpdateShareIdnVoteDealType:%v", common.ErrShareIdn, err) + return false, err + } + } else { + trade, err := uo.GetBotStockBlockTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockIdnStopByOrderId.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareIdn, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareBlockVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockIdnStopByOrderId.UpdateShareBlockVoteDealType:%v", common.ErrShareIdn, err) + return false, err + } + } + if !flags.CheckSetting { + applogger.Debug("当前开仓价格:%v", limitOrMarketPrice) + } + + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(int64(tradeType), stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v UpdateBotStockIdnStopByOrderId.VoteTradeType:%v", common.ErrShareIdn, err) + return false, err + } + } else { + order.StopLossPrice = decimal.Zero.String() + order.StopWinPrice = decimal.Zero.String() + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[userId] + if ok { + return false, flags.ErrPublicServe + } + + // 更新订单表 + var positionKey string + if !CheckTypeStatus(order.Type) { + botStockIdnTrade := orders.BotStockIdnStopByOrderId(ctx, order) + if err = uo.UpdateBotStockIdnTradeByOrderId(session, order.OrderId, botStockIdnTrade); err != nil { + applogger.Error("%v UpdateBotStockIdnStopByOrderId.UpdateBotStockIdnTradeByOrderId:%v", common.ErrShareIdn, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareIdnPosition + } else { + botStockIdnTrade := orders.BotStockBlockStopByOrderId(ctx, order) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, order.OrderId, botStockIdnTrade); err != nil { + applogger.Error("%v UpdateBotStockIdnStopByOrderId.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareIdn, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareBlkPosition + } + + // 修改挂单缓存队列 + if err = share.UpdateShareIdnStopByOrderId(Reds, order, positionKey, flags.Position); err != nil { + applogger.Error("%v UpdateBotStockIdnStopByOrderId.UpdateShareIdnStopByOrderId:%v", common.ErrShareIdn, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockIdnStopByOrderId.Commit:%v", common.ErrShareIdn, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockIdnClosingByOrderId +// +// @Description: 印尼股用户平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockIdnClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.IdnMarket) { + return false, flags.ErrStopTread + } + + // 1、查询持仓缓存列表数据并清理对应缓存 + var positionKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + positionKey = setting.MarketShareIdnPosition + userKey = setting.ShareIdnSubscribe + adminKey = setting.AdminShareIdnSubscribe + } else { + positionKey = setting.MarketShareBlkPosition + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + var entrustCache *share.ShareIdnTallyCache + entrust, err := Reds.HGet(context.Background(), positionKey, orderId).Result() + if err != nil { + applogger.Error("%v UpdateBotStockIdnClosingByOrderId.HGet:%v", common.ErrShareIdn, err) + return false, flags.ErrShareFive + } + var entrustJson share.ShareIdnTallyCache + if err = json.Unmarshal([]byte(entrust), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockIdnClosingByOrderId.Unmarshal:%v", common.ErrShareIdn, err) + return false, flags.ErrCacheDB + } + + if orderId == entrustJson.OrderId { + entrustCache = &entrustJson + } + + if entrustCache == nil { + return false, flags.ErrShareFive + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[entrustJson.UserId] + if ok { + return false, flags.ErrPublicServe + } + + // 市场设置交易时间(T+0,T+1,T+2s......) + if !CheckShareSystemTime(entrustCache.ClosingTime) { + return false, flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("手动平仓:%v", entrustCache) + } + + // 2、获取当前最新价格 + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Idn, entrustCache.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareIdnTheLatestPrice(subKey, entrustCache.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockIdnClosingByOrderId.GetShareIdnTheLatestPrice:%v", common.ErrShareIdn, err) + return false, flags.ErrStopTread + } + + // 3、平仓处理 + if err = StockIdnClosingOrder(ctx, Msql, orderId, closingPrice.String(), entrustCache.Order); err != nil { + applogger.Error("%v UpdateBotStockIdnClosingByOrderId.StockIdnClosingOrder:%v", common.ErrShareIdn, err) + return false, err + } + + // 4、清理持仓订单信息 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), positionKey, orderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockIdnClosingByOrderId.HDel:%v", common.ErrShareIdn, err) + return false, flags.ErrCacheDB + } + + // 5、平仓更新订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(userKey, entrustCache.UserId) + if err = UpdateShareIdnSubscribeHashStatusByOrderId(orderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockIdnClosingByOrderId.%v:%v", common.ErrShareIdn, userKey, err) + return false, flags.ErrCacheDB + } + + // 6、平仓更新管理员订阅缓存订单状态 + if err = UpdateShareIdnSubscribeHashStatusByOrderId(orderId, adminKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockIdnClosingByOrderId.%v:%v", common.ErrShareIdn, adminKey, err) + return false, flags.ErrCacheDB + } + + return true, nil +} + +// UpdateBotStockIdnAllClosingByOrderId +// +// @Description: 印尼股用户一键平仓 +// @receiver uo +// @param ctx +// @param userId +// @return error +func (uo *userOrderRepo) UpdateBotStockIdnAllClosingByOrderId(ctx context.Context, userId int64) error { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.IdnMarket) { + return flags.ErrStopTread + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe + } + + // 1、查询当前用户所有订单 + orderMap, err := uo.GetBotStockIdnTradeByUserId(userId) + if err != nil { + applogger.Error("%v UpdateBotStockIdnAllClosingByOrderId.GetBotStockIdnTradeByUserId:%v", common.ErrShareIdn, err) + return flags.ErrMySqlDB + } + + // 2、查询持仓缓存列表数据-1、清理持仓列表缓存 2、处理平仓数据 3、清理订单ID缓存列表 + entrust, err := Reds.HGetAll(context.Background(), setting.MarketShareIdnPosition).Result() + if err != nil { + applogger.Error("%v UpdateBotStockIdnAllClosingByOrderId.HGetAll:%v", common.ErrShareIdn, err) + return flags.ErrShareFive + } + + // 3、循环检查股票交易对最新价格(有一个查询不到既不能平仓) + var entrustList []share.ShareIdnTallyCache + closePriceMap := make(map[string]decimal.Decimal) + for key, value := range entrust { + var entrustJson share.ShareIdnTallyCache + if err = json.Unmarshal([]byte(value), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockIdnAllClosingByOrderId.Unmarshal:%v", common.ErrShareIdn, err) + return flags.ErrStopTread + } + _, ok := orderMap[entrustJson.OrderId] + if ok { + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Idn, entrustJson.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareIdnTheLatestPrice(subKey, entrustJson.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockIdnAllClosingByOrderId.GetShareIdnTheLatestPrice:%v", common.ErrShareIdn, err) + return flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("订阅Key:%v,最新价格:%v,订单ID:%v", subKey, closingPrice, entrustJson.OrderId) + } + + closePriceMap[key] = closingPrice + entrustList = append(entrustList, entrustJson) + } + } + + // 4、股票一键平仓 + for _, value := range entrustList { + closePrice, ok := closePriceMap[value.OrderId] + if ok { + // 平仓 + if err = StockIdnClosingOrder(ctx, uo.data.mysqlDB, value.OrderId, closePrice.String(), value.Order); err != nil { + applogger.Error("%v UpdateBotStockIdnAllClosingByOrderId.StockIdnClosingOrder:%v", common.ErrShareIdn, err) + return err + } + + // 清理持仓缓存列表 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), setting.MarketShareIdnPosition, value.OrderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockIdnAllClosingByOrderId.HDel:%v", common.ErrShareIdn, err) + return flags.ErrCacheDB + } + + // 平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareIdnSubscribe, value.UserId) + if err = UpdateShareIdnSubscribeHashStatusByOrderId(value.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockIdnAllClosingByOrderId.UpdateShareIdnSubscribeHashStatusByOrderId:%v", common.ErrShareIdn, err) + return flags.ErrCacheDB + } + + // 平仓更新管理员订阅订单状态 + if err = UpdateShareIdnSubscribeHashStatusByOrderId(value.OrderId, setting.AdminShareIdnSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockIdnAllClosingByOrderId.UpdateShareIdnSubscribeHashStatusByOrderId:%v", common.ErrShareIdn, err) + return flags.ErrCacheDB + } + } + } + + return nil +} + +// GetBotStockIdnTradeByUserId +// +// @Description: +// @receiver uo +// @param ctx +// @param userId +// @return map[string]string +// @return error +func (uo *userOrderRepo) GetBotStockIdnTradeByUserId(userId int64) (map[string]string, error) { + var botStockIdnTrade []models.BotStockIdnTrade + if err := uo.data.mysqlDB.Table(flags.BotStockIdnTrade). + Where("user_id = ?", userId). + Where("status = 1"). + Find(&botStockIdnTrade); err != nil { + return nil, err + } + + botMap := make(map[string]string) + for _, value := range botStockIdnTrade { + botMap[value.OrderId] = value.OrderId + } + + return botMap, nil +} + +// GetShareIdnTheLatestPrice +// +// @Description: +// @receiver uo +// @param ctx +// @param subKey +// @param tradeType +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) GetShareIdnTheLatestPrice(subKey string, tradeType int64) (decimal.Decimal, error) { + priceNew, err := share.ShareIdnSubMarketPrice(subKey) + if err != nil { + applogger.Error("%v GetShareIdnTheLatestPrice.ShareIdnSubMarketPrice:%v", common.ErrShareIdn, err) + return decimal.Decimal{}, err + } + + priceS := decimal.RequireFromString(priceNew) + + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tradeType { + case flags.TradeTypeBuy: // 买涨 + openPrice = priceS.Sub(difference) // 开仓价格 + case flags.TradeTypeSell: // 买跌 + openPrice = priceS.Add(difference) // 开仓价格 + default: + } + + return openPrice, nil +} + +// GetBotStockIdnTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @return *models.BotStockIdnTrade +// @return error +func (uo *userOrderRepo) GetBotStockIdnTradeByOrderId(session *xorm.Session, orderId string) (*models.BotStockIdnTrade, error) { + var botStockIdnTrade []models.BotStockIdnTrade + if err := session.Table(flags.BotStockIdnTrade). + Where("order_id = ?", orderId). + Find(&botStockIdnTrade); err != nil { + return nil, err + } + + for _, value := range botStockIdnTrade { + return &value, nil + } + + return nil, nil +} + +// GetBotUserStockIdnByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @return *models.BotUserStockIdn +// @return error +func (uo *userOrderRepo) GetBotUserStockIdnByUserIdAndStockId(session *xorm.Session, userId int64, stockId string) (*models.BotUserStockIdn, error) { + var stockIDR []models.BotUserStockIdn + if err := session.Table(flags.BotUserStockIdn). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&stockIDR); err != nil || len(stockIDR) <= 0 { + return nil, err + } + + for _, value := range stockIDR { + return &value, nil + } + + return nil, nil +} + +// UpdateBotStockIdnTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotStockIdnTradeByOrderId(session *xorm.Session, orderId string, stock models.BotStockIdnTrade) error { + checkInt, err := session.Table(flags.BotStockIdnTrade). + Where("order_id = ?", orderId). + Update(&stock) + if err != nil || checkInt < 0 { + return err + } + + return nil +} + +// CreateBotStockIdnTrade +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param trade +// @return error +func (uo *userOrderRepo) CreateBotStockIdnTrade(session *xorm.Session, trade models.BotStockIdnTrade) error { + _, err := session.Table(flags.BotStockIdnTrade).Insert(&trade) + if err != nil { + return err + } + + return nil +} + +// CreateBotUserStockIdnFIRD +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param stock +// @return error +func (uo *userOrderRepo) CreateBotUserStockIdnFIRD(session *xorm.Session, stock models.BotUserStockIdn) error { + _, err := session.Table(flags.BotUserStockIdn).Insert(&stock) + if err != nil { + return err + } + + return nil +} + +// UpdateBotUserStockIdnByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotUserStockIdnByUserIdAndStockId(session *xorm.Session, userId int64, stockId string, stock models.BotUserStockIdn) error { + checkNum, err := session.Table(flags.BotUserStockIdn). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&stock) + if err != nil || checkNum < 0 { + return err + } + + return nil +} + +// StockIdnVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) StockIdnVoteDealType(order structure.ShareOrder) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + return limitOrMarketPrice, nil +} + +// UpdateShareIdnVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) UpdateShareIdnVoteDealType(order *models.BotStockIdnTrade) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + if len(order.DealPrice) != 0 { + dealPrice := decimal.RequireFromString(order.DealPrice) + if !dealPrice.IsZero() { + limitOrMarketPrice = dealPrice + } + } + + return limitOrMarketPrice, nil +} + +// VerifyBotStockIdnTradeOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @return string +// @return error +func (uo *userOrderRepo) VerifyBotStockIdnTradeOrderId(session *xorm.Session) (string, error) { + var orderId string + for { + // 生成订单ID + orderId = orders.CreateRandCodeOrder(10) + + var orderList []models.BotStockIdnTrade + err := session.Table(flags.BotStockIdnTrade).Where("order_id = ?", orderId).Find(&orderList) + if err != nil || len(orderList) > 0 { + applogger.Error("%v VerifyBotStockIdnTradeOrderId.Find:%v", common.ErrShareIdn, err) + continue + } + + break + } + + return orderId, nil +} + +// GetBotStockIdnTradeByOrderIdOrStatus +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param status +// @return *models.BotStockIdnTrade +// @return error +func (uo *userOrderRepo) GetBotStockIdnTradeByOrderIdOrStatus(session *xorm.Session, orderId string, status int) (*models.BotStockIdnTrade, error) { + var botStockIdnTrade []models.BotStockIdnTrade + if err := session.Table(flags.BotStockIdnTrade). + Where("order_id = ?", orderId). + Where("`status` = ?", status). + Find(&botStockIdnTrade); err != nil { + return nil, err + } + + for _, value := range botStockIdnTrade { + return &value, nil + } + + return nil, nil +} diff --git a/internal/data/order_share_inr.go b/internal/data/order_share_inr.go new file mode 100644 index 0000000..f63f1a6 --- /dev/null +++ b/internal/data/order_share_inr.go @@ -0,0 +1,1501 @@ +package data + +import ( + "context" + "encoding/json" + "github.com/go-xorm/xorm" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" + + orders "matchmaking-system/internal/data/convert" + models "matchmaking-system/internal/pkg/model" +) + +// GetBotStockInTradeList +// +// @Description: 印度股订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param userId +// @param status +// @return []*models.BotStockInTrade +// @return int64 +// @return error +func (uo *userOrderRepo) GetBotStockInTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockInTrade, int64, error) { + totalCount, err := uo.data.mysqlDB.Table(flags.BotStockInTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Count() + if err != nil { + return nil, 0, flags.ErrMySqlDB + } + if totalCount == 0 { + return nil, 0, nil + } + var stockList []*models.BotStockInTrade + if err = uo.data.mysqlDB.Table(flags.BotStockInTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Limit(int(pageSize), int(pageCount)). + Desc(GetOrderByStatusSort(status)). + Find(&stockList); err != nil { + return nil, 0, flags.ErrMySqlDB + } + + var stockUpdateList []*models.BotStockInTrade + for _, value := range stockList { + value.KeepDecimal = GetKeepDecimal(flags.StockYDSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockYDSystemSetUpKey, value.StockId) + stockUpdateList = append(stockUpdateList, value) + } + + return stockUpdateList, totalCount, nil +} + +// PlacingStockInOrders +// +// @Description: 印度股下单 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) PlacingStockInOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) { + // 1、通知下单订阅 + symbol := order.StockId + timeValue := QuerySystemCache(flags.ShareInrMarketType) // 市场开闭盘时间 + if !utils.CheckInPlateTime(timeValue) { + return flags.SetNull, flags.ErrStopTread + } + SubscribeInrHSetCodeList(symbol, false) // 同步写入股票列表缓存 + SubscribeInrCloseNewPrice(symbol) // 同步股票实时行情价 + + // 判定是否存在欠款订单 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe.Error(), nil + } + + order = PryNumInit(order) // 杠杆初始化 + subKey := publicData.SymbolCache(flags.Inr, symbol, flags.TradeTypePrice) + + // 印度股市场系统设置 + if CheckGlobalTread(flags.InrMarket) { + return flags.SetNull, flags.ErrStopTread + } + + // 股票系统设置(实时价格|全局设置停止交易操作) + var blockTime time.Time + var priceNew, userKey, adminKey string + if !CheckTypeStatus(order.Type) { + userKey = setting.ShareInrSubscribe + adminKey = setting.AdminShareInrSubscribe + } else { + // 判定:1、是否开启股票交易 2、是否在交易时间内 3、是否达到最小交易量 + check, openPrice, minNum, endTime := CheckBlockTread(flags.InBlk, symbol) + if check { + return flags.SetNull, flags.ErrShareSeven + } + if minNum > utils.StringToInt(order.OrderNumber) { + return flags.SetNull, flags.ErrShareSix + } + priceNew = openPrice // 开仓价格 + blockTime = endTime // 平仓时间 + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + flatRatio := GetCacheForcedClosure(flags.StockYDSystemSetUpKey, symbol) // 单个股票系统设置 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.InrMarket, userId) // 股票市场系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), // 强平阈值 + Status: leverStatus.Status, // 杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + order.System = system + + // 2、股票下单判定 + // 下单判定设置(false无设置|true止盈止损) + checkBool, stopWinPrice, stopLossPrice, err := StockInrVoteStopType(order) + if err != nil { + applogger.Error("%v PlacingStockInrOrders.StockIdnVoteStopType:%v", common.ErrShareInr, err) + return flags.SetNull, err + } + // 下单判定设置(限价|市价) + limitOrMarketPrice, err := uo.StockInVoteDealType(order) + if err != nil { + applogger.Error("%v PlacingStockInrOrders.StockVoteDealType:%v", common.ErrShareInr, err) + return flags.SetNull, err + } + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(order.TradeType, stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v PlacingStockInrOrders.StockVoteTradeType:%v", common.ErrShareInr, err) + return flags.SetNull, err + } + + // 3、订单持久化录入(并处理资产信息) + pryNum := SystemDealWithLever(order) + orderId, err := uo.StockInrOrderWriteDB(ctx, userId, order, limitOrMarketPrice, pryNum) + if err != nil || len(orderId) == 0 { + applogger.Error("%v PlacingStockInrOrders.StockIdnOrderWriteDB:%v", common.ErrShareInr, err) + return flags.SetNull, err + } + + // 4、处理订单信息 + chg := GetShareChgInr(flags.Inr, order.StockId) // 涨跌幅标识值 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.InrMarket, time.Now()) // 开盘时间 + marketStatus, shareOrder, err := share.ShareInrCacheDeal(ctx, userId, orderId, subKey, order, chg, priceNew, closingTime, blockTime) + if err != nil || shareOrder == nil { + applogger.Error("%v PlacingStockInrOrders.ShareIdnCacheDeal:%v", common.ErrShareInr, err) + return flags.SetNull, err + } + // 计算保证金 = 订单价格 * 订单数量 / 杠杆 + shareOrder.Order.MarketMoney = limitOrMarketPrice.Mul(decimal.RequireFromString(order.OrderNumber)).Div(pryNum).String() + // 测试校验信息 + if !flags.CheckSetting { + applogger.Debug("订单ID:%v", shareOrder.OrderId) + applogger.Debug("订单交易对:%v", shareOrder.Symbol) + applogger.Debug("订单状态:%v", shareOrder.Status) + applogger.Debug("订单用户ID:%v", shareOrder.UserId) + applogger.Debug("开盘价:%v", shareOrder.OpenPrice) + applogger.Debug("收盘价:%v", shareOrder.ClosingPrice) + applogger.Debug("下单信息:%v", shareOrder.Order) + } + + // 6、订单(挂单|持仓)缓存列表,等待队列计算 + if err = share.ShareInrHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v PlacingStockInrOrders.ShareIdnHashUserOrder:%v", common.ErrShareInr, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 7、用户订阅股票订单信息 + orderIdKey := virtual.OrderIdListKey(userKey, userId) + if err = share.ShareInrHashUserOrder(Reds, orderIdKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockInrOrders.%v:%v", common.ErrShareInr, userKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 8、管理员订阅订单信息 + if err = share.ShareInrHashUserOrder(Reds, adminKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockInrOrders.%v:%v", common.ErrShareInr, adminKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + return orderId, nil +} + +// StockInrOrderWriteDB +// +// @Description: 印度股下单处理 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) StockInrOrderWriteDB(ctx context.Context, userId int64, order structure.ShareOrder, limitOrMarketPrice, lever decimal.Decimal) (string, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockInrOrderWriteDB.Begin:%v", common.ErrShareInr, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 获取当前下单用户的资产 + var usableOld, frozenOld decimal.Decimal + stockIdr, err := uo.GetBotUserStockInByUserIdAndStockId(session, userId, flags.ShareInrBasicUnit) + if err != nil || stockIdr == nil { + applogger.Error("%v StockInrOrderWriteDB.IDR:%v", common.ErrShareInr, err) + return flags.SetNull, flags.ErrMySqlDB + } + usableOld = decimal.RequireFromString(stockIdr.UsableNum) + frozenOld = decimal.RequireFromString(stockIdr.FrozenNum) + + // 检查用户订单下单资产 + if usableOld.IsZero() || usableOld.IsNegative() || frozenOld.IsNegative() { + return flags.SetNull, flags.ErrShareOne + } + + // 获取当前系统下单用户的非资产 + var usableFOld, frozenFOld decimal.Decimal + stockFIdr, err := uo.GetBotUserStockInByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockInrOrderWriteDB.FeiIDR:%v", common.ErrShareInr, err) + return flags.SetNull, flags.ErrMySqlDB + } + if stockFIdr != nil { + usableFOld = decimal.RequireFromString(stockFIdr.UsableNum) + frozenFOld = decimal.RequireFromString(stockFIdr.FrozenNum) + } + if !flags.CheckSetting { + applogger.Debug("下单可用资产:%v", usableOld) + applogger.Debug("下单冻结资产:%v", frozenOld) + applogger.Debug("下单查询非资产账户:%v", stockFIdr) + applogger.Debug("下单可用非资产:%v", usableFOld) + applogger.Debug("下单冻结非资产:%v", frozenFOld) + } + + // 校验订单信息 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 订单数量 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 订单手续费 + marketMoney := limitOrMarketPrice.Mul(orderNumber).Div(lever) // 订单金额(杠杆下单) = 订单数量 * 交易价格 / 杠杆 + totalMoney := marketMoney.Add(serviceCost) // 订单总金额 + order.MarketMoney = marketMoney.String() // 市值金额即为保证金 + + // 检查订单Id是否存在,新增下单信息 + var orderId string + if !CheckTypeStatus(order.Type) { + orderId, err = uo.VerifyBotStockInTradeOrderId(session) + if err != nil { + applogger.Error("%v StockInrOrderWriteDB.VerifyBotStockInTradeOrderId:%v", common.ErrShareInr, err) + return flags.SetNull, err + } + trade := orders.BotStockInrTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockInTrade(session, trade); err != nil { + applogger.Error("%v StockInrOrderWriteDB.CreateBotStockInTrade:%v", common.ErrShareInr, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + orderId, err = uo.VerifyBotStockBlockTradeOrderId(session) + if err != nil { + applogger.Error("%v StockInrOrderWriteDB.VerifyBotStockBlockTradeOrderId:%v", common.ErrShareInr, err) + return flags.SetNull, err + } + trade := orders.BotStockBlockTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockBlockTrade(session, trade); err != nil { + applogger.Error("%v StockInrOrderWriteDB.CreateBotStockBlockTrade:%v", common.ErrShareInr, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + // 下单判定 + residue := usableOld.Sub(totalMoney).Div(usableOld) + if usableOld.Cmp(totalMoney) <= 0 || residue.Cmp(utils.DecimalsStrInt()) <= 0 { + return flags.SetNull, flags.ErrPublicTow + } + + var usableNew, frozenNew, usableFNew, frozenFNew decimal.Decimal + usableNew = usableOld.Sub(totalMoney) // 可用资产 + frozenNew = frozenOld.Add(totalMoney) // 冻结资产 + if order.StockId != flags.ShareInrBasicUnit { + usableFNew = usableFOld.Add(orderNumber) // 可用非资产 + frozenFNew = frozenFOld // 冻结非资产 + } + + // 检查用户下单资产信息 + if usableNew.IsNegative() || frozenNew.IsNegative() { + return flags.SetNull, flags.ErrPublicTow + } + + // 下单更新资产信息 + stockIdrModel := orders.UpdateBotUserStockIn(ctx, usableNew.String(), frozenNew.String()) + err = uo.UpdateBotUserStockInByUserIdAndStockId(session, userId, flags.ShareInrBasicUnit, stockIdrModel) + if err != nil { + applogger.Error("%v StockInrOrderWriteDB.UpdateBotUserStockInByUserIdAndStockId:%v", common.ErrShareInr, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 下单(新增|更新)非资产信息 + if stockFIdr == nil { + stockFIDRModel := orders.CreateBotUserStockIn(ctx, userId, order.StockId, usableFNew.String(), frozenFNew.String()) + err = uo.CreateBotUserStockInFIRD(session, stockFIDRModel) + if err != nil { + applogger.Error("%v StockInrOrderWriteDB.CreateBotUserStockInFIRD:%v", common.ErrShareInr, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + stockFIDRModel := orders.UpdateBotUserStockIn(ctx, usableFNew.String(), frozenFNew.String()) + err = uo.UpdateBotUserStockInByUserIdAndStockId(session, userId, order.StockId, stockFIDRModel) + if err != nil { + applogger.Error("%v StockInrOrderWriteDB.UpdateBotUserStockInByUserIdAndStockId:%v", common.ErrShareInr, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockInrOrderWriteDB.Commit:%v", common.ErrShareInr, err) + return flags.SetNull, flags.ErrMySqlDB + } + + return orderId, nil +} + +// StockInrOpenOrder +// +// @Description: 印度股系统开仓 +// @param ctx +// @param db +// @param userId +// @param orderId +// @param openPrice +// @param order +// @return error +func StockInrOpenOrder(ctx context.Context, db *xorm.EngineGroup, userId int64, orderId, openPrice string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockInrOpenOrder.NewSession:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockIdr, err := Uo.GetBotUserStockInByUserIdAndStockId(session, userId, flags.ShareInrBasicUnit) + if err != nil || stockIdr == nil { + applogger.Error("%v StockInrOpenOrder.GetBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockIdr.UsableNum) // 用户可用资产 + frozen = decimal.RequireFromString(stockIdr.FrozenNum) // 用户冻结资产 + + // 检查用户开仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrPublicThree + } + if order.StockId != flags.ShareInrBasicUnit { + stockFIdr, err := Uo.GetBotUserStockInByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockInrOpenOrder.GetBotUserStockInByUserIdAndStockId:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(stockFIdr.UsableNum) // 用户非可用资产 + frozenNo = decimal.RequireFromString(stockFIdr.FrozenNum) // 用户非冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + + // 转换股票下单信息 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 下单股数 + orderMoney := decimal.RequireFromString(order.MarketMoney) // 下单金额 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 下单手续费 + totalMoney := orderMoney.Add(serviceCost) // 下单总金额 = (下单手续费 + 下单金额) + openOrderPrice := decimal.RequireFromString(openPrice) // 开盘价格 + if !flags.CheckSetting { + applogger.Debug("下单订单数量:%v", orderNumber) + applogger.Debug("下单订单金额:%v", orderMoney) + applogger.Debug("下单订单手续费:%v", serviceCost) + applogger.Debug("下单订单总金额:%v", totalMoney) + } + + // 手续费记录 + openPriceNew := openOrderPrice.Mul(orderNumber).String() // 开仓手续费 = 开仓价格 * 股数 * 开仓手续费 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareInrMarketType, flags.OpenBrokType, orderId, openPriceNew) + if err != nil { + applogger.Error("%v StockInrOpenOrder.CalculateHandlingFeesShare:%v", common.ErrShareInr, err) + return err + } + openServiceCost := decimal.RequireFromString(cost) // 开仓手续费 + openMarkerMoney := openOrderPrice.Mul(orderNumber).Div(decimal.RequireFromString(order.PryNum)) // 开仓订单金额 = 开仓价格 * 股数 / 杠杆 + openTotalMoney := openMarkerMoney.Add(openServiceCost) // 开仓总金额 = 开仓订单金额 + 开仓手续费 + floatPrice := totalMoney.Sub(openTotalMoney) // 计算容差 = 下单总额 - 开仓总额 + if !flags.CheckSetting { + applogger.Debug("开仓订单价格:%v", openOrderPrice) + applogger.Debug("开仓手续费:%v", openServiceCost) + applogger.Debug("开仓总金额:%v", openTotalMoney) + applogger.Debug("开仓订单金额:%v", openMarkerMoney) + applogger.Debug("下单->开仓总金额容差值:%v", floatPrice) + } + + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + usableNew = usable.Add(floatPrice) // 可用资产(处理容差值) + frozenNew = frozen.Sub(totalMoney).Add(openMarkerMoney) // 冻结资产 + if order.StockId != flags.ShareInrBasicUnit { + usableNoNew = usableNo // 非可用资产 + frozenNoNew = frozenNo // 非冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("下单后用户可用资产:%v", usableNew) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + } + + // 检查用户开仓资产 + if frozenNew.IsNegative() || usableNew.IsNegative() { + return flags.ErrPublicThree + } + + // 处理资产信息 + userStockIdr := orders.UpdateBotUserStockIn(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockInByUserIdAndStockId(session, userId, flags.ShareInrBasicUnit, userStockIdr); err != nil { + applogger.Error("%v StockInrOpenOrder.IDR.UpdateBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + + // 更新非资产信息 + if order.StockId != flags.ShareInrBasicUnit { + userStockFIdr := orders.UpdateBotUserStockIn(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = Uo.UpdateBotUserStockInByUserIdAndStockId(session, userId, order.StockId, userStockFIdr); err != nil { + applogger.Error("%v StockInrOpenOrder.UpdateBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + } + + // 返佣记录|资金信息|资金详情信息 + if err = Uo.ShareInrRebateCalculation(ctx, session, int(userId), flags.ShareInrMarketType, flags.OpenBrokType, flags.OpenMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockInrOpenOrder.ShareIdnRebateCalculation:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + + // 处理订单信息(成交价|仓位|开仓时间|订单总金额|手续费|持仓状态) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateOpenBotStockInTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarkerMoney.String()) + if err = Uo.UpdateBotStockInTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockInrOpenOrder.UpdateBotStockInTradeByOrderId:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + var list []models.BotUserStockInLog + qData0 := orders.CreatBotUserStockInLog(ctx, userId, flags.CostMoney, flags.ShareInrBasicUnit, NegativeValue(openServiceCost.String()), orderId) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockInLog(ctx, userId, flags.Freeze, flags.ShareInrBasicUnit, NegativeValue(openMarkerMoney.String()), orderId) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockInLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockInLogList(session, list); err != nil { + applogger.Error("%v StockInrOpenOrder.CreatBotUserStockInLogList:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateOpenBotStockBlockTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarkerMoney.String()) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockInrOpenOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareInrBasicUnit, NegativeValue(openServiceCost.String()), orderId, order.Type) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Freeze, flags.ShareInrBasicUnit, NegativeValue(openMarkerMoney.String()), orderId, order.Type) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId, order.Type) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockInrOpenOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockInrOpenOrder.Commit:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + + return nil +} + +// StockInrClosingOrder +// +// @Description: 印度股系统平仓 +// @param ctx +// @param db +// @param orderId +// @param price +// @param order +// @return error +func StockInrClosingOrder(ctx context.Context, db *xorm.EngineGroup, orderId string, price string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockInrClosingOrder.NewSession:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + + // 查询订单信息 + var userId int64 + var dealPrice, orderNumber, totalAmount, serviceCost, marketMoney decimal.Decimal + if !CheckTypeStatus(order.Type) { + tread, err := Uo.GetBotStockInTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockInrClosingOrder.GetBotStockInTradeByOrderIdOrStatus:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + marketMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓订单金额 + } else { + tread, err := Uo.GetBotStockBlockTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockInrClosingOrder.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + marketMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓订单金额 + } + if !flags.CheckSetting { + applogger.Debug("下单开仓用户Id:%v", userId) + applogger.Debug("下单开仓开仓价格:%v", dealPrice) + applogger.Debug("下单开仓订单数量:%v", orderNumber) + applogger.Debug("下单开仓总金额:%v", totalAmount) + applogger.Debug("下单开仓手续费:%v", serviceCost) + applogger.Debug("下单开仓订单金额:%v", marketMoney) + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + userStockIdr, err := Uo.GetBotUserStockInByUserIdAndStockId(session, userId, flags.ShareInrBasicUnit) + if err != nil { + applogger.Error("%v StockInrClosingOrder.GetBotUserStockInByUserIdAndStockId:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(userStockIdr.UsableNum) // 用户可用资金 + frozen = decimal.RequireFromString(userStockIdr.FrozenNum) // 用户非冻结资金 + + // 检查用户平仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrShareTow + } + // 查询当前下单用户可用非账户和冻结金额 + if order.StockId != flags.ShareInrBasicUnit { + userStockFIdr, err := Uo.GetBotUserStockInByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockIdnClosingOrder.GetBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(userStockFIdr.UsableNum) // 用户非可用资金 + frozenNo = decimal.RequireFromString(userStockFIdr.FrozenNum) // 用户非冻结资金 + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + + // 手续费处理 + closePrice := decimal.RequireFromString(price) // 平仓价格 + cloePriceCost := closePrice.Mul(orderNumber).String() // 平仓手续费 = 平仓价格 * 股数 * 手续费比例 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareInrMarketType, flags.ClosingBrokType, orderId, cloePriceCost) + if err != nil { + applogger.Error("%v StockInrClosingOrder.CalculateHandlingFeesShare:%v", common.ErrShareInr, err) + return err + } + closeServiceCost := decimal.RequireFromString(cost) + if !flags.CheckSetting { + applogger.Debug("平仓价格:%v", closePrice) + applogger.Debug("平仓手续费手续费:%v", closeServiceCost) + } + + //已经实现盈亏计算公式(已平仓结算方式) + //买涨 已经实现盈亏 = (平仓成交价-开仓成交价)*股数 + //买跌 已经实现盈亏 = (开仓成交价-平仓成交价)*股数 + var usableNew, frozenNew, usableNewNo, frozenNewNo, subPrice, resultPrice decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买涨 + subPrice = closePrice.Sub(dealPrice) + resultPrice = subPrice.Mul(orderNumber) + case flags.TradeTypeSell: // 买跌 + subPrice = dealPrice.Sub(closePrice) + resultPrice = subPrice.Mul(orderNumber) + default: + } + + // TODO: 判定亏损不能超过 = 保证金 + 平仓手续费 + if resultPrice.IsNegative() { + amountLoss := marketMoney.Sub(closeServiceCost) + if resultPrice.Abs().Cmp(amountLoss) >= 0 { + resultPrice = amountLoss.Neg() + } + } + + // 用户资产账户 + usableNew = usable.Add(resultPrice).Sub(closeServiceCost).Add(marketMoney) // 可用资产 = 原可用资产 + ((正负)盈亏) - 平仓手续费 + 开仓订单金额 + if frozen.Cmp(marketMoney) == -1 { + frozenNew = frozen.Sub(frozen) // 冻结资产 + } else { + frozenNew = frozen.Sub(marketMoney) + } + + // 用户非资产账户 + if order.StockId != flags.ShareInrBasicUnit { + usableNewNo = usableNo.Sub(orderNumber) // 可用非资产 = 原可用非资产 - 下单股数 + frozenNewNo = frozenNo // 可用非冻结资产 + } + + // 检查用户订单平仓资产 + if frozenNew.IsNegative() || usableNewNo.IsNegative() { + return flags.ErrShareTow + } + if !flags.CheckSetting { + applogger.Debug("可用资产:%v", usableNew) + applogger.Debug("冻结资产:%v", frozenNew) + applogger.Debug("可用非资产:%v", usableNewNo) + applogger.Debug("冻结非资产:%v", frozenNewNo) + } + + // 平仓(处理资产表(资产)) + userStockIDR := orders.UpdateBotUserStockIn(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockInByUserIdAndStockId(session, userId, flags.ShareInrBasicUnit, userStockIDR); err != nil { + applogger.Error("%v StockInrClosingOrder.USD.UpdateBotUserStockInByUserIdAndStockId:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + + // 平仓(处理资产表(非资产)) + if order.StockId != flags.ShareInrBasicUnit { + userStockFIDR := orders.UpdateBotUserStockIn(ctx, usableNewNo.String(), frozenNewNo.String()) + if err = Uo.UpdateBotUserStockInByUserIdAndStockId(session, userId, order.StockId, userStockFIDR); err != nil { + applogger.Error("%v StockInrClosingOrder.UpdateBotUserStockInByUserIdAndStockId:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + } + + // 平仓(返佣记录表|资产表|资金变动表) + if err = Uo.ShareInrRebateCalculation(ctx, session, int(userId), flags.ShareInrMarketType, flags.ClosingBrokType, flags.CloseMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockInrClosingOrder.ShareIdnRebateCalculation:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + + // 大宗(印度股)交易平仓(处理订单信息(平仓价|保证金|平仓|订单总金额|平仓手续费|完成订单)) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateCloseBotStockInTrade(ctx, price, cost) + if err = Uo.UpdateBotStockInTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockInrClosingOrder.UpdateBotStockInTradeByOrderId:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockInLog + qData0 := orders.CreatBotUserStockInLog(ctx, userId, flags.Thaw, flags.ShareInrBasicUnit, marketMoney.String(), orderId) // 平仓(资金变动明细表(开仓保证金)) + qData1 := orders.CreatBotUserStockInLog(ctx, userId, flags.CostMoney, flags.ShareInrBasicUnit, NegativeValue(closeServiceCost.String()), orderId) // 平仓(资金变动明细表(-平仓手续费)) + qData2 := orders.CreatBotUserStockInLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏)) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockInLog(ctx, userId, flags.TransferOut, flags.ShareInrBasicUnit, resultPrice.String(), orderId) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockInLog(ctx, userId, flags.ChangeInto, flags.ShareInrBasicUnit, resultPrice.String(), orderId) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockInLogList(session, list); err != nil { + applogger.Error("%v StockInrClosingOrder.CreatBotUserStockInLogList:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateCloseBotStockBlockTrade(ctx, price, cost) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockInrClosingOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Thaw, flags.ShareInrBasicUnit, marketMoney.String(), orderId, order.Type) // 平仓(资金变动明细表(开仓保证金)) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareInrBasicUnit, NegativeValue(closeServiceCost.String()), orderId, order.Type) // 平仓(资金变动明细表(-平仓手续费)) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId, order.Type) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏)) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, flags.ShareInrBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, flags.ShareInrBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockInrClosingOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockInrClosingOrder.Commit:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + + return nil +} + +// UpdateBotStockInCancelByOrderId +// +// @Description: 印度股撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockInCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockInCancelByOrderId.Begin:%v", common.ErrShareInr, err) + return false, flags.ErrMySqlDB + } + + // 获取订单信息 + var userId int64 + var stockId string + var marketMoneyOld, serviceCostOld, orderNumber decimal.Decimal + if !CheckTypeStatus(typeStatus) { + stockTrade, err := uo.GetBotStockInTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockInCancelByOrderId.GetBotStockIdnTradeByOrderId:%v", common.ErrShareInr, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } else { + stockTrade, err := uo.GetBotStockBlockTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockInCancelByOrderId.GetBotStockBlockTradeByOrderId:%v", common.ErrShareInr, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } + + // 获取用户资产信息 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockIdr, err := uo.GetBotUserStockInByUserIdAndStockId(session, userId, flags.ShareInrBasicUnit) + if err != nil || stockIdr == nil { + applogger.Error("%v UpdateBotStockIdnCancelByOrderId.IDR.GetBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareInr, err) + return false, flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockIdr.UsableNum) // 用户账户可用资产 + frozen = decimal.RequireFromString(stockIdr.FrozenNum) // 用户账户冻结资产 + + // 检查用户订单撤单资产 + if usable.IsNegative() || frozen.IsNegative() { + return false, flags.ErrShareThree + } + if stockId != flags.ShareInrBasicUnit { + stockFUsd, err := uo.GetBotUserStockInByUserIdAndStockId(session, userId, stockId) + if err != nil { + applogger.Error("%v UpdateBotStockIdnCancelByOrderId.GetBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareInr, err) + return false, flags.ErrPublicFour + } + usableNo = decimal.RequireFromString(stockFUsd.UsableNum) // 用户非账户可用资产 + frozenNo = decimal.RequireFromString(stockFUsd.FrozenNum) // 用户非账户冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("用户原始可用资金:%v", usable) + applogger.Debug("用户原始冻结资金:%v", frozen) + applogger.Debug("用户原始可用非资金:%v", usableNo) + applogger.Debug("用户原始冻结非资金:%v", frozenNo) + } + + // 更新订单信息 + var entrustKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + botStockTrade := orders.BotStockInCancelByOrderId(ctx) + if err = uo.UpdateBotStockInTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockIdnCancelByOrderId.INR.UpdateBotStockIdnTradeByOrderId:%v", common.ErrShareInr, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareInrEntrust + userKey = setting.ShareInrSubscribe + adminKey = setting.AdminShareInrSubscribe + } else { + botStockTrade := orders.BotStockBlockCancelByOrderId(ctx) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockIdnCancelByOrderId.INR.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareInr, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareBlkEntrust + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // Operational Spot Asset Table + totalMoney := marketMoneyOld.Add(serviceCostOld) // 订单总金额 + // update total asset data + usableNew := usable.Add(totalMoney) // 用户总资产 + frozenNew := frozen.Sub(totalMoney) // 用户冻结资产 + usableNoNew := usableNo.Sub(orderNumber) // 用户非可用资产 + frozenNoNew := frozenNo // 用户非冻结资产 + + // 检查用户订单撤单资产 + if frozenNew.IsNegative() || usableNoNew.IsNegative() { + return false, flags.ErrShareThree + } + if !flags.CheckSetting { + applogger.Debug("用户撤单可用总资产:%v", usableNew) + applogger.Debug("用户撤单冻结总资产:%v", frozenNew) + applogger.Debug("用户非撤单可用总资产:%v", usableNoNew) + applogger.Debug("用户非撤单冻结总资产:%v", frozenNoNew) + } + + // 更新资产信息和非资产信息 + userStockIDR := orders.UpdateBotUserStockIn(ctx, usableNew.String(), frozenNew.String()) + if err = uo.UpdateBotUserStockInByUserIdAndStockId(session, userId, flags.ShareInrBasicUnit, userStockIDR); err != nil { + applogger.Error("%v UpdateBotStockIdnCancelByOrderId.UpdateBotUserStockInByUserIdAndStockId:%v", common.ErrShareInr, err) + return false, flags.ErrMySqlDB + } + if stockId != flags.ShareInrBasicUnit { + userStockFIdn := orders.UpdateBotUserStockIn(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = uo.UpdateBotUserStockInByUserIdAndStockId(session, userId, stockId, userStockFIdn); err != nil { + applogger.Error("%v UpdateBotStockIdnCancelByOrderId.UpdateBotUserStockInByUserIdAndStockId:%v", common.ErrShareInr, err) + return false, flags.ErrMySqlDB + } + } + + // 删除订单缓存列表 + if err = Reds.HDel(context.Background(), entrustKey, orderId).Err(); err != nil { + applogger.Error("%v UpdateBotStockIdnCancelByOrderId.HDel:%v", common.ErrShareInr, err) + return false, flags.ErrCacheDB + } + + // 更新用户订阅订单缓存列表 + userSubKey := virtual.OrderIdListKey(userKey, userId) + if err = share.UpdateShareInHashByOrderId(Reds, orderId, userSubKey, flags.Cancel); err != nil { + applogger.Error("%v UpdateBotStockIdnCancelByOrderId.%v:%v", common.ErrShareInr, userKey, err) + return false, flags.ErrCacheDB + } + + // 更新管理员订阅订单缓存列表 + if err = UpdateShareInrSubscribeHashStatusByOrderId(orderId, adminKey, flags.Cancel, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotContractCancelByOrderId.%v:%v", common.ErrShareInr, adminKey, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotContractCancelByOrderId.Commit:%v", common.ErrShareInr, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockInStopByOrderId +// +// @Description: 印度股设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockInStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockInStopByOrderId.NewSession:%v", common.ErrShareInr, err) + return false, flags.ErrMySqlDB + } + + // 设置止盈止损 + var userId int64 + if order.StopType == 1 { + // 下单信息 + checkBool, stopWinPrice, stopLossPrice, err := uo.UpdateVoteStopType(order) + if err != nil { + applogger.Error("%v UpdateBotStockInStopByOrderId.UpdateVoteStopType:%v", common.ErrShareInr, err) + return false, err + } + if !flags.CheckSetting { + applogger.Debug("当前止盈止损数据:%v,%v,%v", checkBool, stopWinPrice, stopLossPrice) + } + + // 设置止盈止损判定 + var tradeType int + var limitOrMarketPrice decimal.Decimal + if !CheckTypeStatus(order.Type) { + trade, err := uo.GetBotStockInTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockInStopByOrderId.GetBotStockInTradeByOrderIdOrStatus:%v", common.ErrShareInr, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareInVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockInStopByOrderId.UpdateShareInVoteDealType:%v", common.ErrShareInr, err) + return false, err + } + } else { + trade, err := uo.GetBotStockBlockTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockInStopByOrderId.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareInr, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareBlockVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockInStopByOrderId.UpdateShareBlockVoteDealType:%v", common.ErrShareInr, err) + return false, err + } + } + if !flags.CheckSetting { + applogger.Debug("当前开仓价格:%v", limitOrMarketPrice) + } + + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(int64(tradeType), stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v UpdateBotStockInStopByOrderId.VoteTradeType:%v", common.ErrShareInr, err) + return false, err + } + } else { + order.StopLossPrice = decimal.Zero.String() + order.StopWinPrice = decimal.Zero.String() + } + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[userId] + if ok { + return false, flags.ErrPublicServe + } + + // 更新订单表 + var positionKey string + if !CheckTypeStatus(order.Type) { + botStockIdnTrade := orders.BotStockInStopByOrderId(ctx, order) + if err = uo.UpdateBotStockInTradeByOrderId(session, order.OrderId, botStockIdnTrade); err != nil { + applogger.Error("%v UpdateBotStockInStopByOrderId.UpdateBotStockInTradeByOrderId:%v", common.ErrShareInr, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareInrPosition + } else { + botStockIdnTrade := orders.BotStockBlockStopByOrderId(ctx, order) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, order.OrderId, botStockIdnTrade); err != nil { + applogger.Error("%v UpdateBotStockInStopByOrderId.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareInr, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareBlkPosition + } + + // 修改挂单缓存队列 + if err = share.UpdateShareInrStopByOrderId(Reds, order, positionKey, flags.Position); err != nil { + applogger.Error("%v UpdateBotStockInStopByOrderId.UpdateShareInrStopByOrderId:%v", common.ErrShareInr, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockInStopByOrderId.Commit:%v", common.ErrShareInr, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockInClosingByOrderId +// +// @Description: 印度股用户平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockInClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.InrMarket) { + return false, flags.ErrStopTread + } + + // 1、查询持仓缓存列表数据并清理对应缓存 + var positionKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + positionKey = setting.MarketShareInrPosition + userKey = setting.ShareInrSubscribe + adminKey = setting.AdminShareInrSubscribe + } else { + positionKey = setting.MarketShareBlkPosition + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + var entrustCache *share.ShareInrTallyCache + entrust, err := Reds.HGet(context.Background(), positionKey, orderId).Result() + if err != nil { + applogger.Error("%v UpdateBotStockInClosingByOrderId.HGet:%v", common.ErrShareInr, err) + return false, flags.ErrShareFive + } + + var entrustJson share.ShareInrTallyCache + if err = json.Unmarshal([]byte(entrust), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockInClosingByOrderId.Unmarshal:%v", common.ErrShareInr, err) + return false, flags.ErrCacheDB + } + if orderId == entrustJson.OrderId { + entrustCache = &entrustJson + } + + if entrustCache == nil { + return false, flags.ErrShareFive + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[entrustJson.UserId] + if ok { + return false, flags.ErrPublicServe + } + + // 市场设置交易时间(T+0,T+1,T+2s......) + if !CheckShareSystemTime(entrustCache.ClosingTime) { + return false, flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("手动平仓:%v", entrustCache) + } + + // 2、获取当前最新价格 + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Inr, entrustCache.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareInTheLatestPrice(subKey, entrustCache.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockInClosingByOrderId.GetShareIdnTheLatestPrice:%v", common.ErrShareInr, err) + return false, flags.ErrStopTread + } + + // 3、平仓处理 + if err = StockInrClosingOrder(ctx, Msql, orderId, closingPrice.String(), entrustCache.Order); err != nil { + applogger.Error("%v UpdateBotStockInClosingByOrderId.StockIdnClosingOrder:%v", common.ErrShareInr, err) + return false, err + } + + // 4、清理持仓订单信息 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), positionKey, orderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockInClosingByOrderId.HDel:%v", common.ErrShareInr, err) + return false, flags.ErrCacheDB + } + + // 5、平仓更新订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(userKey, entrustCache.UserId) + if err = UpdateShareInrSubscribeHashStatusByOrderId(orderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockInClosingByOrderId.%v:%v", common.ErrShareInr, userKey, err) + return false, flags.ErrCacheDB + } + + // 6、平仓更新管理订阅缓存订单状态 + if err = UpdateShareInrSubscribeHashStatusByOrderId(orderId, adminKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockInClosingByOrderId.%v:%v", common.ErrShareInr, adminKey, err) + return false, flags.ErrCacheDB + } + + return true, nil +} + +// UpdateBotStockInAllClosingByOrderId +// +// @Description: 印度股用户一键平仓 +// @receiver uo +// @param ctx +// @param userId +// @return error +func (uo *userOrderRepo) UpdateBotStockInAllClosingByOrderId(ctx context.Context, userId int64) error { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.InrMarket) { + return flags.ErrStopTread + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe + } + + // 1、查询当前用户所有订单 + orderMap, err := uo.GetBotStockInTradeByUserId(userId) + if err != nil { + applogger.Error("%v UpdateBotStockInAllClosingByOrderId.GetBotStockIdnTradeByUserId:%v", common.ErrShareInr, err) + return flags.ErrMySqlDB + } + + // 2、查询持仓缓存列表数据-1、清理持仓列表缓存 2、处理平仓数据 3、清理订单ID缓存列表 + entrust, err := Reds.HGetAll(context.Background(), setting.MarketShareInrPosition).Result() + if err != nil { + applogger.Error("%v UpdateBotStockInAllClosingByOrderId.HGetAll:%v", common.ErrShareInr, err) + return flags.ErrShareFive + } + + // 3、循环检查股票交易对最新价格(有一个查询不到既不能平仓) + var entrustList []share.ShareInrTallyCache + closePriceMap := make(map[string]decimal.Decimal) + for key, value := range entrust { + var entrustJson share.ShareInrTallyCache + if err = json.Unmarshal([]byte(value), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockInAllClosingByOrderId.Unmarshal:%v", common.ErrShareInr, err) + return flags.ErrStopTread + } + + _, ok := orderMap[entrustJson.OrderId] + if ok { + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Inr, entrustJson.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareInTheLatestPrice(subKey, entrustJson.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockInAllClosingByOrderId.GetShareInTheLatestPrice:%v", common.ErrShareInr, err) + return flags.ErrStopTread + } + + if !flags.CheckSetting { + applogger.Debug("订阅Key:%v,最新价格:%v,订单ID:%v", subKey, closingPrice, entrustJson.OrderId) + } + + closePriceMap[key] = closingPrice + entrustList = append(entrustList, entrustJson) + } + } + + // 4、股票一键平仓 + for _, value := range entrustList { + closePrice, ok := closePriceMap[value.OrderId] + if ok { + // 平仓 + if err = StockInrClosingOrder(ctx, uo.data.mysqlDB, value.OrderId, closePrice.String(), value.Order); err != nil { + applogger.Error("%v UpdateBotStockInAllClosingByOrderId.StockInrClosingOrder:%v", common.ErrShareInr, err) + return err + } + + // 清理持仓缓存列表 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), setting.MarketShareInrPosition, value.OrderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockInAllClosingByOrderId.HDel:%v", common.ErrShareInr, err) + return flags.ErrCacheDB + } + + // 平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareInrSubscribe, value.UserId) + if err = UpdateShareInrSubscribeHashStatusByOrderId(value.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockInAllClosingByOrderId.ShareInrSubscribe:%v", common.ErrShareInr, err) + return flags.ErrCacheDB + } + + // 平仓更新管理员订阅订单状态 + if err = UpdateShareInrSubscribeHashStatusByOrderId(value.OrderId, setting.AdminShareInrSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockInAllClosingByOrderId.AdminShareInrSubscribe:%v", common.ErrShareInr, err) + return flags.ErrCacheDB + } + } + } + + return nil +} + +// GetBotStockInTradeByUserId +// +// @Description: +// @receiver uo +// @param ctx +// @param userId +// @return map[string]string +// @return error +func (uo *userOrderRepo) GetBotStockInTradeByUserId(userId int64) (map[string]string, error) { + var botStockInTrade []models.BotStockInTrade + if err := uo.data.mysqlDB.Table(flags.BotStockInTrade). + Where("user_id = ?", userId). + Where("status = 1"). + Find(&botStockInTrade); err != nil { + return nil, err + } + + botMap := make(map[string]string) + for _, value := range botStockInTrade { + botMap[value.OrderId] = value.OrderId + } + + return botMap, nil +} + +// GetShareInTheLatestPrice +// +// @Description: +// @receiver uo +// @param ctx +// @param subKey +// @param tradeType +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) GetShareInTheLatestPrice(subKey string, tradeType int64) (decimal.Decimal, error) { + priceNew, err := share.ShareInrSubMarketPrice(subKey) + if err != nil { + applogger.Error("%v GetShareInTheLatestPrice.ShareInrSubMarketPrice:%v", common.ErrShareInr, err) + return decimal.Decimal{}, err + } + + priceS := decimal.RequireFromString(priceNew) + + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tradeType { + case flags.TradeTypeBuy: // 买涨 + openPrice = priceS.Sub(difference) // 开仓价格 + case flags.TradeTypeSell: // 买跌 + openPrice = priceS.Add(difference) // 开仓价格 + default: + } + + return openPrice, nil +} + +// GetBotStockInTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @return *models.BotStockIdnTrade +// @return error +func (uo *userOrderRepo) GetBotStockInTradeByOrderId(session *xorm.Session, orderId string) (*models.BotStockInTrade, error) { + var botStockInTrade []models.BotStockInTrade + if err := session.Table(flags.BotStockInTrade). + Where("order_id = ?", orderId). + Find(&botStockInTrade); err != nil { + return nil, err + } + + for _, value := range botStockInTrade { + return &value, nil + } + + return nil, nil +} + +// GetBotUserStockInByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @return *models.BotUserStockIdn +// @return error +func (uo *userOrderRepo) GetBotUserStockInByUserIdAndStockId(session *xorm.Session, userId int64, stockId string) (*models.BotUserStockIn, error) { + var stockInr []models.BotUserStockIn + if err := session.Table(flags.BotUserStockIn). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&stockInr); err != nil || len(stockInr) <= 0 { + return nil, err + } + + for _, value := range stockInr { + return &value, nil + } + + return nil, nil +} + +// UpdateBotStockInTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotStockInTradeByOrderId(session *xorm.Session, orderId string, stock models.BotStockInTrade) error { + checkInt, err := session.Table(flags.BotStockInTrade). + Where("order_id = ?", orderId). + Update(&stock) + if err != nil || checkInt < 0 { + return err + } + + return nil +} + +// CreateBotStockInTrade +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param trade +// @return error +func (uo *userOrderRepo) CreateBotStockInTrade(session *xorm.Session, trade models.BotStockInTrade) error { + _, err := session.Table(flags.BotStockInTrade).Insert(&trade) + if err != nil { + return err + } + + return nil +} + +// CreateBotUserStockInFIRD +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param stock +// @return error +func (uo *userOrderRepo) CreateBotUserStockInFIRD(session *xorm.Session, stock models.BotUserStockIn) error { + _, err := session.Table(flags.BotUserStockIn).Insert(&stock) + if err != nil { + return err + } + + return nil +} + +// UpdateBotUserStockInByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotUserStockInByUserIdAndStockId(session *xorm.Session, userId int64, stockId string, stock models.BotUserStockIn) error { + checkNum, err := session.Table(flags.BotUserStockIn). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&stock) + if err != nil || checkNum < 0 { + return err + } + + return nil +} + +// StockInVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) StockInVoteDealType(order structure.ShareOrder) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + return limitOrMarketPrice, nil +} + +// UpdateShareInVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) UpdateShareInVoteDealType(order *models.BotStockInTrade) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + if len(order.DealPrice) != 0 { + dealPrice := decimal.RequireFromString(order.DealPrice) + if !dealPrice.IsZero() { + limitOrMarketPrice = dealPrice + } + } + + return limitOrMarketPrice, nil +} + +// VerifyBotStockInTradeOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @return string +// @return error +func (uo *userOrderRepo) VerifyBotStockInTradeOrderId(session *xorm.Session) (string, error) { + var orderId string + for { + // 生成订单ID + orderId = orders.CreateRandCodeOrder(10) + + var orderList []models.BotStockInTrade + err := session.Table(flags.BotStockInTrade). + Where("order_id = ?", orderId). + Find(&orderList) + if err != nil || len(orderList) > 0 { + applogger.Warn("%v VerifyBotStockInTradeOrderId.Find:%v", common.ErrShareInr, err) + continue + } + + break + } + + return orderId, nil +} + +// GetBotStockInTradeByOrderIdOrStatus +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param status +// @return *models.BotStockIdnTrade +// @return error +func (uo *userOrderRepo) GetBotStockInTradeByOrderIdOrStatus(session *xorm.Session, orderId string, status int) (*models.BotStockInTrade, error) { + var botStockInTrade []models.BotStockInTrade + if err := session.Table(flags.BotStockInTrade). + Where("order_id = ?", orderId). + Where("`status` = ?", status). + Find(&botStockInTrade); err != nil { + return nil, err + } + + for _, value := range botStockInTrade { + return &value, nil + } + + return nil, nil +} diff --git a/internal/data/order_share_jpy.go b/internal/data/order_share_jpy.go new file mode 100644 index 0000000..b850857 --- /dev/null +++ b/internal/data/order_share_jpy.go @@ -0,0 +1,1505 @@ +package data + +import ( + "context" + "encoding/json" + "github.com/go-xorm/xorm" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" + + orders "matchmaking-system/internal/data/convert" + models "matchmaking-system/internal/pkg/model" +) + +// GetBotStockJpyTradeList +// +// @Description: 日股订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param userId +// @param status +// @return []*models.BotStockJpyTrade +// @return int64 +// @return error +func (uo *userOrderRepo) GetBotStockJpyTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockJpTrade, int64, error) { + totalCount, err := uo.data.mysqlDB.Table(flags.BotStockJpyTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Count() + if err != nil { + return nil, 0, flags.ErrMySqlDB + } + if totalCount == 0 { + return nil, 0, nil + } + var stockList []*models.BotStockJpTrade + if err = uo.data.mysqlDB.Table(flags.BotStockJpyTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Limit(int(pageSize), int(pageCount)). + Desc(GetOrderByStatusSort(status)). + Find(&stockList); err != nil { + return nil, 0, flags.ErrMySqlDB + } + + var stockUpdateList []*models.BotStockJpTrade + for _, value := range stockList { + value.KeepDecimal = GetKeepDecimal(flags.StockFURSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockFURSystemSetUpKey, value.StockId) + stockUpdateList = append(stockUpdateList, value) + } + + return stockUpdateList, totalCount, nil +} + +// PlacingStockJpyOrders +// +// @Description: 日股下单 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) PlacingStockJpyOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) { + // 1、通知下单订阅 + symbol := order.StockId + timeValue := QuerySystemCache(flags.ShareJpyMarketType) // 市场开闭盘时间 + if !utils.CheckInPlateTime(timeValue) { + return flags.SetNull, flags.ErrStopTread + } + SubscribeJpyHSetCodeList(symbol, false) // 同步写入股票列表缓存 + SubscribeJpyCloseNewPrice(symbol) // 同步股票实时行情价 + + // 判定是否存在欠款订单 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe.Error(), nil + } + + order = PryNumInit(order) // 杠杆初始化 + subKey := publicData.SymbolCache(flags.Jpy, symbol, flags.TradeTypePrice) + + // 市场系统设置 + if CheckGlobalTread(flags.JpyMarket) { + return flags.SetNull, flags.ErrStopTread + } + + // 全局设置停止交易操作 + var blockTime time.Time + var priceNew, userKey, adminKey string + if !CheckTypeStatus(order.Type) { + userKey = setting.ShareJpySubscribe + adminKey = setting.AdminShareJpySubscribe + } else { + // 判定:1、是否开启股票交易 2、是否在交易时间内 3、是否达到最小交易量 + check, openPrice, minNum, endTime := CheckBlockTread(flags.JpyBlk, symbol) + if check { + return flags.SetNull, flags.ErrShareSeven + } + if minNum > utils.StringToInt(order.OrderNumber) { + return flags.SetNull, flags.ErrShareSix + } + priceNew = openPrice // 开仓价格 + blockTime = endTime // 平仓时间 + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + flatRatio := GetCacheForcedClosure(flags.StockFURSystemSetUpKey, symbol) // 设置强平阈值 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.JpyMarket, userId) // 股票市场系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), // 强平阈值 + Status: leverStatus.Status, // 股杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + order.System = system + + // 2、股票下单判定 + // 下单判定设置(false无设置|true止盈止损) + checkBool, stopWinPrice, stopLossPrice, err := StockJpyVoteStopType(order) + if err != nil { + applogger.Error("%v PlacingStockJpyOrders.StockEurVoteStopType:%v", common.ErrShareJpy, err) + return flags.SetNull, err + } + // 下单判定设置(限价|市价) + limitOrMarketPrice, err := uo.StockJpyVoteDealType(order) + if err != nil { + applogger.Error("%v PlacingStockJpyOrders.StockJpyVoteDealType:%v", common.ErrShareJpy, err) + return flags.SetNull, err + } + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(order.TradeType, stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v PlacingStockJpyOrders.VoteTradeType:%v", common.ErrShareJpy, err) + return flags.SetNull, err + } + + // 3、订单持久化录入(并处理资产信息) + pryNum := SystemDealWithLever(order) + orderId, err := uo.StockJpyOrderWriteDB(ctx, userId, order, limitOrMarketPrice, pryNum) + if err != nil || len(orderId) == 0 { + applogger.Error("%v PlacingStockJpyOrders.StockJpyOrderWriteDB:%v", common.ErrShareJpy, err) + return flags.SetNull, err + } + + // 4、处理订单信息 + chg := GetShareChgJpy(flags.Jpy, order.StockId) // 涨跌幅标识值 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.JpyMarket, time.Now()) // 开盘时间 + marketStatus, shareOrder, err := share.ShareJpyCacheDeal(ctx, userId, orderId, subKey, order, chg, priceNew, closingTime, blockTime) + if err != nil || shareOrder == nil { + applogger.Error("%v PlacingStockJpyOrders.ShareJpyCacheDeal:%v", common.ErrShareJpy, err) + return flags.SetNull, err + } + // 计算保证金 = 订单价格 * 订单数量 / 杠杆 + shareOrder.Order.MarketMoney = limitOrMarketPrice.Mul(decimal.RequireFromString(order.OrderNumber)).Div(pryNum).String() + if !flags.CheckSetting { + applogger.Debug("订单ID:%v", shareOrder.OrderId) + applogger.Debug("订单交易对:%v", shareOrder.Symbol) + applogger.Debug("订单状态:%v", shareOrder.Status) + applogger.Debug("订单用户ID:%v", shareOrder.UserId) + applogger.Debug("开盘价:%v", shareOrder.OpenPrice) + applogger.Debug("收盘价:%v", shareOrder.ClosingPrice) + applogger.Debug("下单信息:%v", shareOrder.Order) + } + + // 6、股票订单(挂单|持仓)缓存列表,等待队列计算 + if err = share.ShareJpyHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v PlacingStockJpyOrders.ShareJpyHashUserOrder:%v", common.ErrShareJpy, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 7、用户订阅股票订单信息 + orderIdKey := virtual.OrderIdListKey(userKey, userId) + if err = share.ShareJpyHashUserOrder(Reds, orderIdKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockJpyOrders.%v:%v", common.ErrShareJpy, userKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 8、管理员订阅订单信息 + if err = share.ShareJpyHashUserOrder(Reds, adminKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockJpyOrders.%v:%v", common.ErrShareJpy, adminKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + return orderId, nil +} + +// StockJpyOrderWriteDB +// +// @Description: 日股下单操作 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) StockJpyOrderWriteDB(ctx context.Context, userId int64, order structure.ShareOrder, limitOrMarketPrice, lever decimal.Decimal) (string, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockJpyOrderWriteDB.Begin:%v", common.ErrShareJpy, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 获取当前下单用户的资产 + var usableOld, frozenOld decimal.Decimal + stockSgd, err := uo.GetBotUserStockJpyByUserIdAndStockId(session, userId, flags.ShareJpyBasicUnit) + if err != nil || stockSgd == nil { + applogger.Error("%v StockJpyOrderWriteDB.GetBotUserStockJpyByUserIdAndStockId:%v", common.ErrShareJpy, err) + return flags.SetNull, flags.ErrMySqlDB + } + usableOld = decimal.RequireFromString(stockSgd.UsableNum) + frozenOld = decimal.RequireFromString(stockSgd.FrozenNum) + + // 检查用户订单下单资产 + if usableOld.IsZero() || usableOld.IsNegative() || frozenOld.IsNegative() { + return flags.SetNull, flags.ErrShareOne + } + + // 获取当前系统下单用户的非资产 + var usableFOld, frozenFOld decimal.Decimal + stockFSGD, err := uo.GetBotUserStockJpyByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockJpyOrderWriteDB.FeiSGD:%v", common.ErrShareJpy, err) + return flags.SetNull, flags.ErrMySqlDB + } + if stockFSGD != nil { + usableFOld = decimal.RequireFromString(stockFSGD.UsableNum) + frozenFOld = decimal.RequireFromString(stockFSGD.FrozenNum) + } + if !flags.CheckSetting { + applogger.Debug("下单可用资产:%v", usableOld) + applogger.Debug("下单冻结资产:%v", frozenOld) + applogger.Debug("下单查询非资产账户:%v", stockFSGD) + applogger.Debug("下单可用非资产:%v", usableFOld) + applogger.Debug("下单冻结非资产:%v", frozenFOld) + } + + // 整理当前下单信息 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 订单手续费 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 订单数量 + marketMoney := orderNumber.Mul(limitOrMarketPrice).Div(lever) // 订单金额(杠杆下单) = 订单数量 * 交易价格 / 杠杆 + totalMoney := marketMoney.Add(serviceCost) // 订单总金额 + order.MarketMoney = marketMoney.String() // 市值金额即为保证金 + + // 检查订单ID是否存在,新增下单信息 + var orderId string + if !CheckTypeStatus(order.Type) { + orderId, err = uo.VerifyBotStockJpyTradeOrderId(session) + if err != nil { + applogger.Error("%v StockJpyOrderWriteDB.VerifyBotStockJpyTradeOrderId:%v", common.ErrShareJpy, err) + return flags.SetNull, err + } + trade := orders.BotStockJpyTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockJpyTrade(session, trade); err != nil { + applogger.Error("%v StockJpyOrderWriteDB.CreateBotStockJpyTrade:%v", common.ErrShareJpy, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + orderId, err = uo.VerifyBotStockBlockTradeOrderId(session) + if err != nil { + applogger.Error("%v StockJpyOrderWriteDB.VerifyBotStockBlockTradeOrderId:%v", common.ErrShareJpy, err) + return flags.SetNull, err + } + trade := orders.BotStockBlockTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockBlockTrade(session, trade); err != nil { + applogger.Error("%v StockJpyOrderWriteDB.CreateBotStockBlockTrade:%v", common.ErrShareJpy, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + // 下单判定 + residue := usableOld.Sub(totalMoney).Div(usableOld) + if usableOld.Cmp(totalMoney) <= 0 || residue.Cmp(utils.DecimalsStrInt()) <= 0 { + return flags.SetNull, flags.ErrPublicTow + } + + var usableNew, frozenNew, usableFNew, frozenFNew decimal.Decimal + usableNew = usableOld.Sub(totalMoney) // 可用资产 + frozenNew = frozenOld.Add(totalMoney) // 冻结资产 + if order.StockId != flags.ShareJpyBasicUnit { + usableFNew = usableFOld.Add(orderNumber) // 可用非资产 + frozenFNew = frozenFOld // 冻结非资产 + } + // 检查用户订单下单资产 + if usableNew.IsNegative() { + return flags.SetNull, flags.ErrPublicTow + } + + // 下单更新资产信息 + stockSgdModel := orders.UpdateBotUserStockJpy(ctx, usableNew.String(), frozenNew.String()) + err = uo.UpdateBotUserStockJpyByUserIdAndStockId(session, userId, flags.ShareJpyBasicUnit, stockSgdModel) + if err != nil { + applogger.Error("%v StockJpyOrderWriteDB.UpdateBotUserStockJpyByUserIdAndStockId:%v", common.ErrShareJpy, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 下单(新增|更新)非资产信息 + if stockFSGD == nil { + stockFTHBModel := orders.CreateBotUserStockJpy(ctx, userId, order.StockId, usableFNew.String(), frozenFNew.String()) + err = uo.CreateBotUserStockJpyFTHB(session, stockFTHBModel) + if err != nil { + applogger.Error("%v StockJpyOrderWriteDB.CreateBotUserStockJpyFTHB:%v", common.ErrShareJpy, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + stockFTHBModel := orders.UpdateBotUserStockJpy(ctx, usableFNew.String(), frozenFNew.String()) + err = uo.UpdateBotUserStockJpyByUserIdAndStockId(session, userId, order.StockId, stockFTHBModel) + if err != nil { + applogger.Error("%v StockJpyOrderWriteDB.UpdateBotUserStockJpyByUserIdAndStockId:%v", common.ErrShareJpy, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockJpyOrderWriteDB.Commit:%v", common.ErrShareJpy, err) + return flags.SetNull, flags.ErrMySqlDB + } + + return orderId, nil +} + +// StockJpyOpenOrder +// +// @Description: 日股系统开仓 +// @param ctx +// @param db +// @param userId +// @param orderId +// @param openPrice +// @param order +// @return error +func StockJpyOpenOrder(ctx context.Context, db *xorm.EngineGroup, userId int64, orderId, openPrice string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockJpyOpenOrder.NewSession:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockThb, err := Uo.GetBotUserStockJpyByUserIdAndStockId(session, userId, flags.ShareJpyBasicUnit) + if err != nil || stockThb == nil { + applogger.Error("%v StockJpyOpenOrder.GetBotUserStockJpyByUserIdAndStockId:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockThb.UsableNum) // 用户可用资产 + frozen = decimal.RequireFromString(stockThb.FrozenNum) // 用户冻结资产 + + // 检查用户订单开仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrPublicThree + } + if order.StockId != flags.ShareJpyBasicUnit { + stockFThb, err := Uo.GetBotUserStockJpyByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockJpyOpenOrder.GetBotUserStockJpyByUserIdAndStockId:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(stockFThb.UsableNum) // 用户非可用资产 + frozenNo = decimal.RequireFromString(stockFThb.FrozenNum) // 用户非冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + + // 转换股票下单信息 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 下单股数 + markerMoney := decimal.RequireFromString(order.MarketMoney) // 下单金额 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 下单手续费 + totalMoney := markerMoney.Add(serviceCost) // 下单总金额 = (下单手续费 + 下单金额) + openOrderPrice := decimal.RequireFromString(openPrice) // 开盘价格 + if !flags.CheckSetting { + applogger.Debug("下单订单数量:%v", orderNumber) + applogger.Debug("下单订单金额:%v", markerMoney) + applogger.Debug("下单订单手续费:%v", serviceCost) + applogger.Debug("下单订单总金额:%v", totalMoney) + } + + // 手续费记录 + openPriceNew := openOrderPrice.Mul(orderNumber).String() // 开仓手续费 = 开仓价格 * 股数 * 开仓手续费 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareJpyMarketType, flags.OpenBrokType, orderId, openPriceNew) + if err != nil { + applogger.Error("%v StockJpyOpenOrder.CalculateHandlingFeesShare:%v", common.ErrShareJpy, err) + return err + } + openServiceCost := decimal.RequireFromString(cost) // 开仓手续费 + openMarkerMoney := openOrderPrice.Mul(orderNumber).Div(decimal.RequireFromString(order.PryNum)) // 开仓金额 = 开仓价格 * 股数 / 杠杆 + openTotalMoney := openMarkerMoney.Add(openServiceCost) // 开仓总金额 = 开仓金额 + 开仓手续费 + floatPrice := totalMoney.Sub(openTotalMoney) // 计算容差 = 下单总额 - 开仓总额 + if !flags.CheckSetting { + applogger.Debug("开仓订单价格:%v", openOrderPrice) + applogger.Debug("开仓手续费:%v", openServiceCost) + applogger.Debug("开仓总金额:%v", openTotalMoney) + applogger.Debug("下单开仓总金额容差值:%v", floatPrice) + } + + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + usableNew = usable.Add(floatPrice) // 可用资产(处理容差值) + frozenNew = frozen.Sub(totalMoney).Add(openMarkerMoney) // 冻结资产(处理容差值)---> 当前冻结金额 = 原冻结金额 - 下单总额 + if order.StockId != flags.ShareJpyBasicUnit { + usableNoNew = usableNo // 非可用资产 + frozenNoNew = frozenNo // 非冻结资产 + } + + // 检查用户订单开仓资产 + if frozenNew.IsNegative() || usableNew.IsNegative() { + return flags.ErrPublicThree + } + if !flags.CheckSetting { + applogger.Debug("下单后用户可用资产:%v", usableNew) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + } + + // 处理资产信息 + userStockThb := orders.UpdateBotUserStockJpy(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockJpyByUserIdAndStockId(session, userId, flags.ShareJpyBasicUnit, userStockThb); err != nil { + applogger.Error("%v StockJpyOpenOrder.UpdateBotUserStockJpyByUserIdAndStockId:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + + // 更新非资产信息 + if order.StockId != flags.ShareJpyBasicUnit { + userStockFThb := orders.UpdateBotUserStockJpy(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = Uo.UpdateBotUserStockJpyByUserIdAndStockId(session, userId, order.StockId, userStockFThb); err != nil { + applogger.Error("%v StockJpyOpenOrder.UpdateBotUserStockJpyByUserIdAndStockId:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + } + + // 返佣记录|资金信息|资金详情信息 + if err = Uo.ShareJpyRebateCalculation(ctx, session, int(userId), flags.ShareJpyMarketType, flags.OpenBrokType, flags.OpenMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockJpyOpenOrder.ShareJpyRebateCalculation:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + + // 处理订单信息(成交价|仓位|开仓时间|订单总金额|手续费|持仓状态) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateOpenBotStockJpyTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarkerMoney.String()) + if err = Uo.UpdateBotStockJpyTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockJpyOpenOrder.UpdateBotStockJpyTradeByOrderId:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + var list []models.BotUserStockJpLog + qData0 := orders.CreatBotUserStockJpyLog(ctx, userId, flags.CostMoney, flags.ShareJpyBasicUnit, NegativeValue(openServiceCost.String()), orderId) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockJpyLog(ctx, userId, flags.Freeze, flags.ShareJpyBasicUnit, NegativeValue(openMarkerMoney.String()), orderId) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockJpyLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockJpyLogList(session, list); err != nil { + applogger.Error("%v StockJpyOpenOrder.CreatBotUserStockJpyLogList:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateOpenBotStockBlockTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarkerMoney.String()) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockJpyOpenOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareJpyBasicUnit, NegativeValue(openServiceCost.String()), orderId, order.Type) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Freeze, flags.ShareJpyBasicUnit, NegativeValue(openMarkerMoney.String()), orderId, order.Type) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId, order.Type) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockJpyOpenOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockJpyOpenOrder.Commit:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + + return nil +} + +// StockJpyClosingOrder +// +// @Description: 日股系统平仓 +// @param ctx +// @param db +// @param orderId +// @param price +// @param order +// @return error +func StockJpyClosingOrder(ctx context.Context, db *xorm.EngineGroup, orderId string, price string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockJpyClosingOrder.NewSession:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + + // 查询订单信息 + var userId int64 + var dealPrice, orderNumber, totalAmount, serviceCost, markerMoney decimal.Decimal + if !CheckTypeStatus(order.Type) { + tread, err := Uo.GetBotStockJpyTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockJpyClosingOrder.GetBotStockJpyTradeByOrderIdOrStatus:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + markerMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓下单金额 + } else { + tread, err := Uo.GetBotStockBlockTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockJpyClosingOrder.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + markerMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓下单金额 + } + + if !flags.CheckSetting { + applogger.Debug("下单开仓用户Id:%v", userId) + applogger.Debug("下单开仓开仓价格:%v", dealPrice) + applogger.Debug("下单开仓订单数量:%v", orderNumber) + applogger.Debug("下单开仓总金额:%v", totalAmount) + applogger.Debug("下单开仓手续费:%v", serviceCost) + applogger.Debug("下单开仓开仓金额:%v", markerMoney) + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + userStockThb, err := Uo.GetBotUserStockJpyByUserIdAndStockId(session, userId, flags.ShareJpyBasicUnit) + if err != nil { + applogger.Error("%v StockJpyClosingOrder.GetBotUserStockJpyByUserIdAndStockId:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(userStockThb.UsableNum) // 用户可用资金 + frozen = decimal.RequireFromString(userStockThb.FrozenNum) // 用户非冻结资金 + + // 检查用户订单平仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrShareTow + } + + // 查询当前下单用户可用非账户和冻结金额 + if order.StockId != flags.ShareJpyBasicUnit { + userStockFThb, err := Uo.GetBotUserStockJpyByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockJpyClosingOrder.GetBotUserStockJpyByUserIdAndStockId:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(userStockFThb.UsableNum) // 用户非可用资金 + frozenNo = decimal.RequireFromString(userStockFThb.FrozenNum) // 用户非冻结资金 + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + + // 手续费处理 + closePrice := decimal.RequireFromString(price) // 平仓价格 + cloePriceCost := closePrice.Mul(orderNumber).String() // 平仓手续费 = 平仓价格 * 股数 * 手续费比例 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareJpyMarketType, flags.ClosingBrokType, orderId, cloePriceCost) + if err != nil { + applogger.Error("%v StockJpyClosingOrder.CalculateHandlingFeesShare:%v", common.ErrShareJpy, err) + return err + } + closeServiceCost := decimal.RequireFromString(cost) + if !flags.CheckSetting { + applogger.Debug("平仓价格:%v", closePrice) + applogger.Debug("平仓手续费手续费:%v", closeServiceCost) + } + + //已经实现盈亏计算公式(已平仓结算方式) + //买涨 已经实现盈亏 = (平仓成交价-开仓成交价)*股数 + //买跌 已经实现盈亏 = (开仓成交价-平仓成交价)*股数 + var usableNew, frozenNew, usableNewNo, frozenNewNo, subPrice, resultPrice decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买涨 + subPrice = closePrice.Sub(dealPrice) + resultPrice = subPrice.Mul(orderNumber) + case flags.TradeTypeSell: // 买跌 + subPrice = dealPrice.Sub(closePrice) + resultPrice = subPrice.Mul(orderNumber) + default: + + } + + // 判定亏损不能超过 = 保证金 + 平仓手续费 + if resultPrice.IsNegative() { + amountLoss := markerMoney.Sub(closeServiceCost) + if resultPrice.Abs().Cmp(amountLoss) >= 0 { + resultPrice = amountLoss.Neg() + } + } + + // 用户资产账户 + usableNew = usable.Add(resultPrice).Sub(closeServiceCost).Add(markerMoney) // 可用资产 = 原可用资产 + ((正负)盈亏) - 平仓手续费 + 开仓下单金额 + if frozen.Cmp(markerMoney) == -1 { + frozenNew = frozen.Sub(frozen) // 冻结资产 + } else { + frozenNew = frozen.Sub(markerMoney) // 冻结资产 + } + + // 用户非资产账户 + if order.StockId != flags.ShareJpyBasicUnit { + usableNewNo = usableNo.Sub(orderNumber) // 可用非资产 = 原可用非资产 - 下单股数 + frozenNewNo = frozenNo // 可用非冻结资产 + } + + // 检查用户订单平仓资产 + if frozenNew.IsNegative() || usableNewNo.IsNegative() { + return flags.ErrShareTow + } + if !flags.CheckSetting { + applogger.Debug("可用资产:%v", usableNew) + applogger.Debug("冻结资产:%v", frozenNew) + applogger.Debug("可用非资产:%v", usableNewNo) + applogger.Debug("冻结非资产:%v", frozenNewNo) + } + + // 平仓(处理资产表(资产)) + userStockUTHB := orders.UpdateBotUserStockJpy(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockJpyByUserIdAndStockId(session, userId, flags.ShareJpyBasicUnit, userStockUTHB); err != nil { + applogger.Error("%v StockJpyClosingOrder.UpdateBotUserStockJpyByUserIdAndStockId:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + + // 平仓(处理资产表(非资产)) + if order.StockId != flags.ShareJpyBasicUnit { + userStockFTHB := orders.UpdateBotUserStockJpy(ctx, usableNewNo.String(), frozenNewNo.String()) + if err = Uo.UpdateBotUserStockJpyByUserIdAndStockId(session, userId, order.StockId, userStockFTHB); err != nil { + applogger.Error("%v StockJpyClosingOrder..UpdateBotUserStockJpyByUserIdAndStockId:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + } + + // 平仓(返佣记录表|资产表|资金变动表) + if err = Uo.ShareJpyRebateCalculation(ctx, session, int(userId), flags.ShareJpyMarketType, flags.ClosingBrokType, flags.CloseMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockJpyClosingOrder.ShareJpyRebateCalculation:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + + // 平仓(处理订单信息(平仓价|保证金|平仓|订单总金额|平仓手续费|完成订单)) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateCloseBotStockJpyTrade(ctx, price, cost) + if err = Uo.UpdateBotStockJpyTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockJpyClosingOrder.UpdateBotStockJpyTradeByOrderId:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockJpLog + qData0 := orders.CreatBotUserStockJpyLog(ctx, userId, flags.Thaw, flags.ShareJpyBasicUnit, markerMoney.String(), orderId) // 平仓(资金变动明细表(开仓保证金)) + qData1 := orders.CreatBotUserStockJpyLog(ctx, userId, flags.CostMoney, flags.ShareJpyBasicUnit, NegativeValue(closeServiceCost.String()), orderId) // 平仓(资金变动明细表(-平仓手续费)) + qData2 := orders.CreatBotUserStockJpyLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockJpyLog(ctx, userId, flags.TransferOut, flags.ShareJpyBasicUnit, resultPrice.String(), orderId) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockJpyLog(ctx, userId, flags.ChangeInto, flags.ShareJpyBasicUnit, resultPrice.String(), orderId) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockJpyLogList(session, list); err != nil { + applogger.Error("%v StockJpyClosingOrder.CreatBotUserStockJpyLogList:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateCloseBotStockBlockTrade(ctx, price, cost) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockJpyClosingOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Thaw, flags.ShareJpyBasicUnit, markerMoney.String(), orderId, order.Type) // 平仓(资金变动明细表(开仓保证金)) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareJpyBasicUnit, NegativeValue(closeServiceCost.String()), orderId, order.Type) // 平仓(资金变动明细表(-平仓手续费)) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId, order.Type) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, flags.ShareJpyBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, flags.ShareJpyBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockJpyClosingOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockJpyClosingOrder.Commit:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + + return nil +} + +// UpdateBotStockJpyCancelByOrderId +// +// @Description: 日股撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockJpyCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockJpyCancelByOrderId.Begin:%v", common.ErrShareJpy, err) + return false, flags.ErrMySqlDB + } + + // 获取订单信息 + var userId int64 + var stockId string + var marketMoneyOld, serviceCostOld, orderNumber decimal.Decimal + if !CheckTypeStatus(typeStatus) { + stockTrade, err := uo.GetBotStockJpyTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockJpyCancelByOrderId.GetBotStockJpyTradeByOrderId:%v", common.ErrShareJpy, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } else { + stockTrade, err := uo.GetBotStockBlockTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockJpyCancelByOrderId.GetBotStockBlockTradeByOrderId:%v", common.ErrShareJpy, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } + + // 用户资产信息 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockThb, err := uo.GetBotUserStockJpyByUserIdAndStockId(session, userId, flags.ShareJpyBasicUnit) + if err != nil || stockThb == nil { + applogger.Error("%v UpdateBotStockJpyCancelByOrderId.GetBotUserStockJpyByUserIdAndStockId:%v", common.ErrShareJpy, err) + return false, flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockThb.UsableNum) // 用户账户可用资产 + frozen = decimal.RequireFromString(stockThb.FrozenNum) // 用户账户冻结资产 + + // 检查用户订单撤单资产 + if usable.IsNegative() || frozen.IsNegative() { + return false, flags.ErrShareNine + } + if stockId != flags.ShareJpyBasicUnit { + stockFThb, err := uo.GetBotUserStockJpyByUserIdAndStockId(session, userId, stockId) + if err != nil { + applogger.Error("%v UpdateBotStockJpyCancelByOrderId.GetBotUserStockEurByUserIdAndStockId:%v", common.ErrShareJpy, err) + return false, flags.ErrPublicFour + } + usableNo = decimal.RequireFromString(stockFThb.UsableNum) // 用户非账户可用资产 + frozenNo = decimal.RequireFromString(stockFThb.FrozenNum) // 用户非账户冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("用户原始可用资金:%v", usable) + applogger.Debug("用户原始冻结资金:%v", frozen) + applogger.Debug("用户原始可用非资金:%v", usableNo) + applogger.Debug("用户原始冻结非资金:%v", frozenNo) + } + + // 更新订单信息 + var entrustKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + botStockTrade := orders.BotStockJpyCancelByOrderId(ctx) + if err = uo.UpdateBotStockJpyTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockJpyCancelByOrderId.UpdateBotStockJpyTradeByOrderId:%v", common.ErrShareJpy, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareJpyEntrust + userKey = setting.ShareJpySubscribe + adminKey = setting.AdminShareJpySubscribe + } else { + botStockTrade := orders.BotStockBlockCancelByOrderId(ctx) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockJpyCancelByOrderId.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareJpy, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareBlkEntrust + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // Operational Spot Asset Table + totalMoney := marketMoneyOld.Add(serviceCostOld) // 订单总金额 + + // update total asset data + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + usableNew = usable.Add(totalMoney) // 用户总资产 + frozenNew = frozen.Sub(totalMoney) // 用户冻结资产 + if stockId != flags.ShareJpyBasicUnit { + usableNoNew = usableNo.Sub(orderNumber) // 用户非可用资产 + frozenNoNew = frozenNo // 用户非冻结资产 + } + + // 检查用户订单撤单资产 + if frozenNew.IsNegative() || usableNoNew.IsNegative() { + return false, flags.ErrShareNine + } + if !flags.CheckSetting { + applogger.Debug("用户撤单可用总资产:%v", usableNew) + applogger.Debug("用户撤单冻结总资产:%v", frozenNew) + applogger.Debug("用户非撤单可用总资产:%v", usableNoNew) + applogger.Debug("用户非撤单冻结总资产:%v", frozenNoNew) + } + + // 更新资产信息和非资产信息 + userStockTHB := orders.UpdateBotUserStockJpy(ctx, usableNew.String(), frozenNew.String()) + if err = uo.UpdateBotUserStockJpyByUserIdAndStockId(session, userId, flags.ShareJpyBasicUnit, userStockTHB); err != nil { + applogger.Error("%v UpdateBotStockJpyCancelByOrderId.UpdateBotUserStockJpyByUserIdAndStockId:%v", common.ErrShareJpy, err) + return false, flags.ErrMySqlDB + } + if stockId != flags.ShareJpyBasicUnit { + userStockFTHB := orders.UpdateBotUserStockJpy(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = uo.UpdateBotUserStockJpyByUserIdAndStockId(session, userId, stockId, userStockFTHB); err != nil { + applogger.Error("%v UpdateBotStockJpyCancelByOrderId.UpdateBotUserStockJpyByUserIdAndStockId:%v", common.ErrShareJpy, err) + return false, flags.ErrMySqlDB + } + } + + // 删除订单缓存列表 + if err = Reds.HDel(context.Background(), entrustKey, orderId).Err(); err != nil { + applogger.Error("%v UpdateBotStockJpyCancelByOrderId.HDel:%v", common.ErrShareJpy, err) + return false, flags.ErrCacheDB + } + + // 更新用户订阅订单缓存列表 + userSubKey := virtual.OrderIdListKey(userKey, userId) + if err = share.UpdateShareJpyHashByOrderId(Reds, orderId, userSubKey, flags.Cancel); err != nil { + applogger.Error("%v UpdateBotStockJpyCancelByOrderId.%v:%v", common.ErrShareJpy, userKey, err) + return false, flags.ErrCacheDB + } + + // 更新管理员订阅订单缓存列表 + if err = UpdateShareFurSubscribeHashStatusByOrderId(orderId, adminKey, flags.Cancel, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockJpyCancelByOrderId.%v:%v", common.ErrShareJpy, adminKey, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockJpyCancelByOrderId.Commit:%v", common.ErrShareJpy, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockJpyStopByOrderId +// +// @Description: 日股设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockJpyStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockJpyStopByOrderId.NewSession:%v", common.ErrShareJpy, err) + return false, flags.ErrMySqlDB + } + + // 设置止盈止损 + var userId int64 + if order.StopType == 1 { + // 下单信息 + checkBool, stopWinPrice, stopLossPrice, err := uo.UpdateVoteStopType(order) + if err != nil { + applogger.Error("%v UpdateBotStockJpyStopByOrderId.UpdateVoteStopType:%v", common.ErrShareJpy, err) + return false, err + } + if !flags.CheckSetting { + applogger.Debug("当前止盈止损数据:%v,%v,%v", checkBool, stopWinPrice, stopLossPrice) + } + + // 止盈止损判定 + var tradeType int + var limitOrMarketPrice decimal.Decimal + if !CheckTypeStatus(order.Type) { + trade, err := uo.GetBotStockJpyTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockJpyStopByOrderId.GetBotStockJpyTradeByOrderIdOrStatus:%v", common.ErrShareJpy, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareJpyVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockJpyStopByOrderId.UpdateShareJpyVoteDealType:%v", common.ErrShareJpy, err) + return false, err + } + } else { + trade, err := uo.GetBotStockBlockTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockJpyStopByOrderId.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareJpy, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareBlockVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockJpyStopByOrderId.UpdateShareBlockVoteDealType:%v", common.ErrShareJpy, err) + return false, err + } + } + if !flags.CheckSetting { + applogger.Debug("当前开仓价格:%v", limitOrMarketPrice) + } + + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(int64(tradeType), stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v UpdateBotStockJpyStopByOrderId.VoteTradeType:%v", common.ErrShareJpy, err) + return false, err + } + } else { + order.StopLossPrice = decimal.Zero.String() + order.StopWinPrice = decimal.Zero.String() + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[userId] + if ok { + return false, flags.ErrPublicServe + } + + // 更新订单表 + var positionKey string + if !CheckTypeStatus(order.Type) { + botStockTrade := orders.BotStockJpyStopByOrderId(ctx, order) + if err = uo.UpdateBotStockJpyTradeByOrderId(session, order.OrderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockJpyStopByOrderId.UpdateBotStockJpyTradeByOrderId:%v", common.ErrShareJpy, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareJpyPosition + } else { + botStockTrade := orders.BotStockBlockStopByOrderId(ctx, order) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, order.OrderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockJpyStopByOrderId.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareJpy, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareBlkPosition + } + + // 挂单缓存队列 + if err = share.UpdateShareJpyStopByOrderId(Reds, order, positionKey, flags.Position); err != nil { + applogger.Error("%v UpdateBotStockJpyStopByOrderId.UpdateShareJpyStopByOrderId:%v", common.ErrShareJpy, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockJpyStopByOrderId.Commit:%v", common.ErrShareJpy, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockJpyClosingByOrderId +// +// @Description: 日股用户平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockJpyClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.JpyMarket) { + return false, flags.ErrStopTread + } + + // 1、查询持仓缓存列表数据并清理对应缓存 + var positionKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + positionKey = setting.MarketShareJpyPosition + userKey = setting.ShareJpySubscribe + adminKey = setting.AdminShareJpySubscribe + } else { + positionKey = setting.MarketShareBlkPosition + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + var entrustCache *share.ShareJpyTallyCache + entrust, err := Reds.HGet(context.Background(), positionKey, orderId).Result() + if err != nil { + applogger.Error("%v UpdateBotStockJpyClosingByOrderId.HGet:%v", common.ErrShareJpy, err) + return false, flags.ErrShareFive + } + var entrustJson share.ShareJpyTallyCache + if err = json.Unmarshal([]byte(entrust), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockJpyClosingByOrderId.Unmarshal:%v", common.ErrShareJpy, err) + return false, flags.ErrCacheDB + } + if orderId == entrustJson.OrderId { + entrustCache = &entrustJson + } + + // 2、判定是否存在平仓订单 + if entrustCache == nil { + return false, flags.ErrShareFive + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[entrustJson.UserId] + if ok { + return false, flags.ErrPublicServe + } + + // 市场设置交易时间(T+0,T+1,T+2s......) + if !CheckShareSystemTime(entrustCache.ClosingTime) { + return false, flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("手动平仓:%v", entrustCache) + } + + // 3、当前最新价格 + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Jpy, entrustCache.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareJpyTheLatestPrice(subKey, entrustCache.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockJpyClosingByOrderId.GetShareJpyTheLatestPrice:%v", common.ErrShareJpy, err) + return false, flags.ErrStopTread + } + + // 4、平仓处理 + if err = StockJpyClosingOrder(ctx, Msql, orderId, closingPrice.String(), entrustCache.Order); err != nil { + applogger.Error("%v UpdateBotStockJpyClosingByOrderId.StockJpyClosingOrder:%v", common.ErrShareJpy, err) + return false, err + } + + // 5、清理持仓订单信息 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), positionKey, orderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockJpyClosingByOrderId.HDel:%v", common.ErrShareJpy, err) + return false, flags.ErrCacheDB + } + + // 6、平仓更新订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(userKey, entrustCache.UserId) + if err = UpdateShareJpySubscribeHashStatusByOrderId(orderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockJpyClosingByOrderId.%v:%v", common.ErrShareJpy, userKey, err) + return false, flags.ErrCacheDB + } + + // 7、平仓更新管理员订阅缓存订单状态 + if err = UpdateShareJpySubscribeHashStatusByOrderId(orderId, adminKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockJpyClosingByOrderId.%v:%v", common.ErrShareJpy, adminKey, err) + return false, flags.ErrCacheDB + } + + return true, nil +} + +// UpdateBotStockJpyAllClosingByOrderId +// +// @Description: 德股用户一键平仓 +// @receiver uo +// @param ctx +// @param userId +// @return error +func (uo *userOrderRepo) UpdateBotStockJpyAllClosingByOrderId(ctx context.Context, userId int64) error { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.JpyMarket) { + return flags.ErrStopTread + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe + } + + // 1、查询当前用户所有订单 + orderMap, err := uo.GetBotStockJpyTradeByUserId(userId) + if err != nil { + applogger.Error("%v UpdateBotStockJpyAllClosingByOrderId.GetBotStockJpyTradeByUserId:%v", common.ErrShareJpy, err) + return flags.ErrMySqlDB + } + + // 2、查询持仓缓存列表数据-1、清理持仓列表缓存 2、处理平仓数据 3、清理订单ID缓存列表 + entrust, err := Reds.HGetAll(context.Background(), setting.MarketShareJpyPosition).Result() + if err != nil { + applogger.Error("%v UpdateBotStockJpyAllClosingByOrderId.HGetAll:%v", common.ErrShareJpy, err) + return flags.ErrShareFive + } + + // 3、循环检查股票交易对最新价格(有一个查询不到既不能平仓) + var entrustList []share.ShareJpyTallyCache + closePriceMap := make(map[string]decimal.Decimal) + for key, value := range entrust { + var entrustJson share.ShareJpyTallyCache + if err = json.Unmarshal([]byte(value), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockJpyAllClosingByOrderId.Unmarshal:%v", common.ErrShareJpy, err) + return flags.ErrStopTread + } + _, ok := orderMap[entrustJson.OrderId] + if ok { + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Jpy, entrustJson.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareJpyTheLatestPrice(subKey, entrustJson.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockJpyAllClosingByOrderId.GetShareSgdTheLatestPrice:%v", common.ErrShareJpy, err) + return flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("订阅Key:%v,最新价格:%v,订单ID:%v", subKey, closingPrice, entrustJson.OrderId) + } + + closePriceMap[key] = closingPrice + entrustList = append(entrustList, entrustJson) + } + } + + // 4、股票一键平仓 + for _, value := range entrustList { + closePrice, ok := closePriceMap[value.OrderId] + if ok { + // 平仓 + if err = StockJpyClosingOrder(ctx, uo.data.mysqlDB, value.OrderId, closePrice.String(), value.Order); err != nil { + applogger.Error("%v UpdateBotStockJpyAllClosingByOrderId.StockJpyClosingOrder:%v", common.ErrShareJpy, err) + return err + } + + // 清理持仓缓存列表 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), setting.MarketShareJpyPosition, value.OrderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockJpyAllClosingByOrderId.HDel:%v", common.ErrShareJpy, err) + return flags.ErrCacheDB + } + + // 平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareJpySubscribe, value.UserId) + if err = UpdateShareJpySubscribeHashStatusByOrderId(value.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockJpyAllClosingByOrderId.ShareJpySubscribe:%v", common.ErrShareJpy, err) + return flags.ErrCacheDB + } + + // 平仓更新管理员订阅订单状态 + if err = UpdateShareJpySubscribeHashStatusByOrderId(value.OrderId, setting.AdminShareJpySubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockJpyAllClosingByOrderId.AdminShareJpySubscribe:%v", common.ErrShareJpy, err) + return flags.ErrCacheDB + } + } + } + + return nil +} + +// GetBotStockJpyTradeByUserId +// +// @Description: +// @receiver uo +// @param ctx +// @param userId +// @return map[string]string +// @return error +func (uo *userOrderRepo) GetBotStockJpyTradeByUserId(userId int64) (map[string]string, error) { + var botStockJpyTrade []models.BotStockJpTrade + if err := uo.data.mysqlDB.Table(flags.BotStockJpyTrade). + Where("user_id = ?", userId). + Where("status = 1"). + Find(&botStockJpyTrade); err != nil { + return nil, err + } + + botMap := make(map[string]string) + for _, value := range botStockJpyTrade { + botMap[value.OrderId] = value.OrderId + } + + return botMap, nil +} + +// GetShareJpyTheLatestPrice +// +// @Description: +// @receiver uo +// @param ctx +// @param subKey +// @param tradeType +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) GetShareJpyTheLatestPrice(subKey string, tradeType int64) (decimal.Decimal, error) { + priceNew, err := share.ShareJpySubMarketPrice(subKey) + if err != nil { + applogger.Error("%v GetShareJpyTheLatestPrice.ShareJpySubMarketPrice:%v", common.ErrShareJpy, err) + return decimal.Decimal{}, err + } + + priceS := decimal.RequireFromString(priceNew) + + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tradeType { + case flags.TradeTypeBuy: // 买涨 + openPrice = priceS.Sub(difference) // 开仓价格 + case flags.TradeTypeSell: // 买跌 + openPrice = priceS.Add(difference) // 开仓价格 + } + + return openPrice, nil +} + +// GetBotStockJpyTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @return *models.BotStockJpTrade +// @return error +func (uo *userOrderRepo) GetBotStockJpyTradeByOrderId(session *xorm.Session, orderId string) (*models.BotStockJpTrade, error) { + var botStockJpyTrade []models.BotStockJpTrade + if err := session.Table(flags.BotStockJpyTrade). + Where("order_id = ?", orderId). + Find(&botStockJpyTrade); err != nil { + return nil, err + } + + for _, value := range botStockJpyTrade { + return &value, nil + } + + return nil, nil +} + +// GetBotUserStockEurByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @return *models.BotUserStockJpy +// @return error +func (uo *userOrderRepo) GetBotUserStockJpyByUserIdAndStockId(session *xorm.Session, userId int64, stockId string) (*models.BotUserStockJp, error) { + var stockEur []models.BotUserStockJp + if err := session.Table(flags.BotUserStockJpy). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&stockEur); err != nil || len(stockEur) <= 0 { + return nil, err + } + + for _, value := range stockEur { + return &value, nil + } + + return nil, nil +} + +// UpdateBotStockEurTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotStockJpyTradeByOrderId(session *xorm.Session, orderId string, stock models.BotStockJpTrade) error { + _, err := session.Table(flags.BotStockJpyTrade). + Where("order_id = ?", orderId). + Update(&stock) + + if err != nil { + return err + } + + return nil +} + +// CreateBotStockJpyTrade +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param trade +// @return error +func (uo *userOrderRepo) CreateBotStockJpyTrade(session *xorm.Session, trade models.BotStockJpTrade) error { + _, err := session.Table(flags.BotStockJpyTrade).Insert(&trade) + if err != nil { + return err + } + + return nil +} + +// CreateBotUserStockJpyFTHB +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param stock +// @return error +func (uo *userOrderRepo) CreateBotUserStockJpyFTHB(session *xorm.Session, stock models.BotUserStockJp) error { + _, err := session.Table(flags.BotUserStockJpy).Insert(&stock) + if err != nil { + return err + } + + return nil +} + +// UpdateBotUserStockJpyByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotUserStockJpyByUserIdAndStockId(session *xorm.Session, userId int64, stockId string, stock models.BotUserStockJp) error { + _, err := session.Table(flags.BotUserStockJpy). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&stock) + if err != nil { + return err + } + + return nil +} + +// StockJpyVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) StockJpyVoteDealType(order structure.ShareOrder) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + return limitOrMarketPrice, nil +} + +// UpdateShareJpyVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) UpdateShareJpyVoteDealType(order *models.BotStockJpTrade) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + if len(order.DealPrice) != 0 { + dealPrice := decimal.RequireFromString(order.DealPrice) + if !dealPrice.IsZero() { + limitOrMarketPrice = dealPrice + } + } + + return limitOrMarketPrice, nil +} + +// VerifyBotStockJpyTradeOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @return string +// @return error +func (uo *userOrderRepo) VerifyBotStockJpyTradeOrderId(session *xorm.Session) (string, error) { + var orderId string + for { + // 生成订单ID + orderId = orders.CreateRandCodeOrder(10) + + var orderList []models.BotStockJpTrade + err := session.Table(flags.BotStockJpyTrade). + Where("order_id = ?", orderId). + Find(&orderList) + + if err != nil || len(orderList) > 0 { + applogger.Error("%v VerifyBotStockJpyTradeOrderId.Find:%v", common.ErrShareJpy, err) + continue + } + + break + } + + return orderId, nil +} + +// GetBotStockJpyTradeByOrderIdOrStatus +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param status +// @return *models.BotStockJpyTrade +// @return error +func (uo *userOrderRepo) GetBotStockJpyTradeByOrderIdOrStatus(session *xorm.Session, orderId string, status int) (*models.BotStockJpTrade, error) { + var botStockJpyTrade []models.BotStockJpTrade + if err := session.Table(flags.BotStockJpyTrade). + Where("order_id = ?", orderId). + Where("`status` = ?", status). + Find(&botStockJpyTrade); err != nil { + return nil, err + } + + for _, value := range botStockJpyTrade { + return &value, nil + } + + return nil, nil +} diff --git a/internal/data/order_share_mys.go b/internal/data/order_share_mys.go new file mode 100644 index 0000000..c775f2f --- /dev/null +++ b/internal/data/order_share_mys.go @@ -0,0 +1,1534 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/go-xorm/xorm" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" + + orders "matchmaking-system/internal/data/convert" + models "matchmaking-system/internal/pkg/model" +) + +// GetBotStockMysTradeList +// +// @Description: 马股订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param userId +// @param status +// @return []*models.BotStockMysTrade +// @return int64 +// @return error +func (uo *userOrderRepo) GetBotStockMysTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockMysTrade, int64, error) { + totalCount, err := uo.data.mysqlDB.Table(flags.BotStockMysTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Count() + if err != nil { + return nil, 0, flags.ErrMySqlDB + } + + if totalCount == 0 { + return nil, 0, nil + } + + var stockList []*models.BotStockMysTrade + if err = uo.data.mysqlDB.Table(flags.BotStockMysTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Limit(int(pageSize), int(pageCount)). + Desc(GetOrderByStatusSort(status)). + Find(&stockList); err != nil { + return nil, 0, flags.ErrMySqlDB + } + + var stockUpdateList []*models.BotStockMysTrade + for _, value := range stockList { + value.NumericCode = GetCacheNumericCode(fmt.Sprintf("%v%v", flags.StockMGSystemSetUpKey, value.StockId)) + value.KeepDecimal = GetKeepDecimal(flags.StockMGSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockMGSystemSetUpKey, value.StockId) + stockUpdateList = append(stockUpdateList, value) + } + + return stockUpdateList, totalCount, nil +} + +// PlacingStockMysOrders +// +// @Description: 马股下单 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) PlacingStockMysOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) { + // 1、通知下单订阅 + symbol := order.StockId + timeValue := QuerySystemCache(flags.ShareMysMarketType) // 市场开闭盘时间 + if !utils.CheckInPlateTime(timeValue) { + return flags.SetNull, flags.ErrStopTread + } + SubscribeMysHSetCodeList(symbol, false) // 同步写入股票列表缓存 + SubscribeMysCloseNewPrice(symbol) // 同步股票实时行情价 + + // 判定是否存在欠款订单 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe.Error(), nil + } + + order = PryNumInit(order) // 杠杆初始化 + subKey := publicData.SymbolCache(flags.Mys, symbol, flags.TradeTypePrice) + + // 马股市场系统设置 + if CheckGlobalTread(flags.MysMarket) { + return flags.SetNull, flags.ErrShareSeven + } + + // 股票交易系统设置 + var blockTime time.Time + var priceNew, userKey, adminKey string + if !CheckTypeStatus(order.Type) { + userKey = setting.ShareMysSubscribe + adminKey = setting.AdminShareMysSubscribe + } else { + // 判定:1、是否开启股票交易 2、是否在交易时间内 3、是否达到最小交易量 + check, openPrice, minNum, endTime := CheckBlockTread(flags.MysBlk, symbol) + if check { + return flags.SetNull, flags.ErrShareSeven + } + if minNum > utils.StringToInt(order.OrderNumber) { + return flags.SetNull, flags.ErrShareSix + } + priceNew = openPrice // 开仓价格 + blockTime = endTime // 平仓市价 + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + flatRatio := GetCacheForcedClosure(flags.StockMGSystemSetUpKey, symbol) // 强平阈值 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.MysMarket, userId) // 股票系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), + Status: leverStatus.Status, // 杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + order.System = system + + // 2、股票下单判定(1>下单判定设置(false无设置|true止盈止损) 2、下单判定设置(限价|市价) 3、下单判定设置(买涨|买跌)) + checkBool, stopWinPrice, stopLossPrice, err := StockMysVoteStopType(order) + if err != nil { + applogger.Error("%v PlacingStockMysOrders.StockMysVoteStopType:%v", common.ErrShareMys, err) + return flags.SetNull, err + } + limitOrMarketPrice, err := uo.StockMysVoteDealType(order) + if err != nil { + applogger.Error("%v PlacingStockMysOrders.StockMysVoteDealType:%v", common.ErrShareMys, err) + return flags.SetNull, err + } + if err = uo.VoteTradeType(order.TradeType, stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v PlacingStockMysOrders.VoteTradeType:%v", common.ErrShareMys, err) + return flags.SetNull, err + } + + // 3、订单持久化录入(并处理资产信息) + pryNum := SystemDealWithLever(order) // 杠杆值处理 + orderId, err := uo.StockMysOrderWriteDB(ctx, userId, order, limitOrMarketPrice, pryNum) + if err != nil || len(orderId) == 0 { + applogger.Error("%v PlacingStockMysOrders.StockMysOrderWriteDB:%v", common.ErrShareMys, err) + return flags.SetNull, err + } + + // 4、处理订单信息 + chg := GetShareChgMys(flags.Mys, order.StockId) // 涨跌幅标识值 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.MysMarket, time.Now()) // 开盘时间 + marketStatus, shareOrder, err := share.ShareMysCacheDeal(ctx, userId, orderId, subKey, order, chg, priceNew, closingTime, blockTime) + if err != nil || shareOrder == nil { + applogger.Error("%v PlacingStockMysOrders.ShareMysCacheDeal:%v", common.ErrShareMys, err) + return flags.SetNull, err + } + // 计算保证金 = 订单价格 * 订单数量 / 杠杆 + shareOrder.Order.MarketMoney = limitOrMarketPrice.Mul(decimal.RequireFromString(order.OrderNumber)).Div(pryNum).String() + if !flags.CheckSetting { + applogger.Debug("订单ID:%v", shareOrder.OrderId) + applogger.Debug("订单交易对:%v", shareOrder.Symbol) + applogger.Debug("订单状态:%v", shareOrder.Status) + applogger.Debug("订单用户ID:%v", shareOrder.UserId) + applogger.Debug("开盘价:%v", shareOrder.OpenPrice) + applogger.Debug("收盘价:%v", shareOrder.ClosingPrice) + applogger.Debug("下单信息:%v", shareOrder.Order) + } + + // 6、订单(挂单|持仓)缓存列表,等待队列计算 + if err = share.ShareMysHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v PlacingStockMysOrders.ShareMysHashUserOrder:%v", common.ErrShareMys, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 7、用户订阅订单信息 + orderIdKey := virtual.OrderIdListKey(userKey, userId) + if err = share.ShareMysHashUserOrder(Reds, orderIdKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockMysOrders.%v:%v", common.ErrShareMys, userKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 8、管理员订阅订单信息 + if err = share.ShareMysHashUserOrder(Reds, adminKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockMysOrders.%v:%v", common.ErrShareMys, adminKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + return orderId, nil +} + +// StockMysOrderWriteDB +// +// @Description: 马股下单操作 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) StockMysOrderWriteDB(ctx context.Context, userId int64, order structure.ShareOrder, limitOrMarketPrice, lever decimal.Decimal) (string, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockMysOrderWriteDB.Begin:%v", common.ErrShareMys, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 获取当前下单用户的资产 + var usableOld, frozenOld decimal.Decimal + stockMyr, err := uo.GetBotUserStockMysByUserIdAndStockId(session, userId, flags.ShareMysBasicUnit) + if err != nil || stockMyr == nil { + applogger.Error("%v StockMysOrderWriteDB.MYR:%v", common.ErrShareMys, err) + return flags.SetNull, flags.ErrMySqlDB + } + usableOld = decimal.RequireFromString(stockMyr.UsableNum) + frozenOld = decimal.RequireFromString(stockMyr.FrozenNum) + + // 检查用户订单资产 + if usableOld.IsZero() || usableOld.IsNegative() || frozenOld.IsNegative() { + return flags.SetNull, flags.ErrShareOne + } + + // 获取当前系统下单用户的非资产 + var usableFOld, frozenFOld decimal.Decimal + stockFMyr, err := uo.GetBotUserStockMysByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockMysOrderWriteDB.FMyr:%v", common.ErrShareMys, err) + return flags.SetNull, flags.ErrMySqlDB + } + if stockFMyr != nil { + usableFOld = decimal.RequireFromString(stockFMyr.UsableNum) + frozenFOld = decimal.RequireFromString(stockFMyr.FrozenNum) + } + if !flags.CheckSetting { + applogger.Debug("下单可用资产:%v", usableOld) + applogger.Debug("下单冻结资产:%v", frozenOld) + applogger.Debug("下单可用非资产:%v", usableFOld) + applogger.Debug("下单冻结非资产:%v", frozenFOld) + } + + // 整理当前下单信息 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 订单手续费 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 订单数量 + marketMoney := limitOrMarketPrice.Mul(orderNumber).Div(lever) // 订单金额(杠杆下单) = 订单数量 * 交易价格 / 杠杆 + totalMoney := marketMoney.Add(serviceCost) // 订单总金额 + order.MarketMoney = marketMoney.String() // 市值金额即为保证金 + + // 检查订单ID是否存在,新增下单信息 + var orderId string + if !CheckTypeStatus(order.Type) { + orderId, err = uo.VerifyBotStockMysTradeOrderId(session) + if err != nil { + applogger.Error("%v StockMysOrderWriteDB.VerifyBotStockMysTradeOrderId:%v", common.ErrShareMys, err) + return flags.SetNull, err + } + trade := orders.BotStockMysTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockMysTrade(session, trade); err != nil { + applogger.Error("%v StockMysOrderWriteDB.CreateBotStockMysTrade:%v", common.ErrShareMys, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + orderId, err = uo.VerifyBotStockBlockTradeOrderId(session) + if err != nil { + applogger.Error("%v StockMysOrderWriteDB.VerifyBotStockBlockTradeOrderId:%v", common.ErrShareMys, err) + return flags.SetNull, err + } + trade := orders.BotStockBlockTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockBlockTrade(session, trade); err != nil { + applogger.Error("%v StockMysOrderWriteDB.CreateBotStockBlockTrade:%v", common.ErrShareMys, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + // 下单判定 + residue := usableOld.Sub(totalMoney).Div(usableOld) + if usableOld.Cmp(totalMoney) <= 0 || residue.Cmp(utils.DecimalsStrInt()) <= 0 { + return flags.SetNull, flags.ErrPublicTow + } + + var usableNew, frozenNew, usableFNew, frozenFNew decimal.Decimal + usableNew = usableOld.Sub(totalMoney) // 可用资产 + frozenNew = frozenOld.Add(totalMoney) // 冻结资产 + if order.StockId != flags.ShareMysBasicUnit { + usableFNew = usableFOld.Add(orderNumber) // 可用非资产 + frozenFNew = frozenFOld // 冻结非资产 + } + + // 检查用户订单资产 + if usableNew.IsNegative() { + return flags.SetNull, flags.ErrPublicTow + } + + // 下单更新资产信息 + stockMYRModel := orders.UpdateBotUserStockMys(ctx, usableNew.String(), frozenNew.String()) + err = uo.UpdateBotUserStockMysByUserIdAndStockId(session, userId, flags.ShareMysBasicUnit, stockMYRModel) + if err != nil { + applogger.Error("%v StockMysOrderWriteDB.UpdateBotUserStockMysByUserIdAndStockId:%v", common.ErrShareMys, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 下单(新增|更新)非资产信息 + if stockFMyr == nil { + stockFMYRModel := orders.CreateBotUserStockMys(ctx, userId, order.StockId, usableFNew.String(), frozenFNew.String()) + err = uo.CreateBotUserStockMysFMYR(session, stockFMYRModel) + if err != nil { + applogger.Error("%v StockMysOrderWriteDB.CreateBotUserStockFUSD:%v", common.ErrShareMys, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + stockFMYRModel := orders.UpdateBotUserStockMys(ctx, usableFNew.String(), frozenFNew.String()) + err = uo.UpdateBotUserStockMysByUserIdAndStockId(session, userId, order.StockId, stockFMYRModel) + if err != nil { + applogger.Error("%v StockMysOrderWriteDB.UpdateFUSDL:%v", common.ErrShareMys, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockMysOrderWriteDB.Commit:%v", common.ErrShareMys, err) + return flags.SetNull, flags.ErrMySqlDB + } + + return orderId, nil +} + +// StockMysOpenOrder +// +// @Description: 马股系统开仓 +// @param ctx +// @param db +// @param userId +// @param orderId +// @param openPrice +// @param order +// @return error +func StockMysOpenOrder(ctx context.Context, db *xorm.EngineGroup, userId int64, orderId, openPrice string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockMysOpenOrder.NewSession:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockMyr, err := Uo.GetBotUserStockMysByUserIdAndStockId(session, userId, flags.ShareMysBasicUnit) + if err != nil || stockMyr == nil { + applogger.Error("%v StockMysOpenOrder.GetBotUserStockMysByUserIdAndStockId:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockMyr.UsableNum) // 用户可用资产 + frozen = decimal.RequireFromString(stockMyr.FrozenNum) // 用户冻结资产 + + // 检查用户订单开仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrPublicThree + } + + if order.StockId != flags.ShareMysBasicUnit { + stockFMyr, err := Uo.GetBotUserStockMysByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockMysOpenOrder.GetBotUserStockMysByUserIdAndStockId:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(stockFMyr.UsableNum) // 用户非可用资产 + frozenNo = decimal.RequireFromString(stockFMyr.FrozenNum) // 用户非冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + + // 转换下单信息 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 下单股数 + markerMoney := decimal.RequireFromString(order.MarketMoney) // 下单金额 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 下单手续费 + totalMoney := markerMoney.Add(serviceCost) // 下单总金额 = 下单手续费 + 下单金额 + openOrderPrice := decimal.RequireFromString(openPrice) // 开盘价格 + if !flags.CheckSetting { + applogger.Debug("下单订单数量:%v", orderNumber) + applogger.Debug("下单订单金额:%v", markerMoney) + applogger.Debug("下单订单手续费:%v", serviceCost) + applogger.Debug("下单订单总金额:%v", totalMoney) + } + + // 手续费记录 + openPriceNew := openOrderPrice.Mul(orderNumber).String() // 开仓手续费 = 开仓价格 * 股数 * 开仓手续费 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareMysMarketType, flags.OpenBrokType, orderId, openPriceNew) + if err != nil { + applogger.Error("%v StockMysOpenOrder.CalculateHandlingFeesShare:%v", common.ErrShareMys, err) + return err + } + openServiceCost := decimal.RequireFromString(cost) // 开仓手续费 + openMarkerMoney := openOrderPrice.Mul(orderNumber).Div(decimal.RequireFromString(order.PryNum)) // 开仓金额 = 开仓价格 * 股数 / 杠杆 + openTotalMoney := openMarkerMoney.Add(openServiceCost) // 开仓总金额 = 开仓金额 + 开仓手续费 + floatPrice := totalMoney.Sub(openTotalMoney) // 计算容差 = 下单总额 - 开仓总额 + if !flags.CheckSetting { + applogger.Debug("开仓订单价格:%v", openOrderPrice) + applogger.Debug("开仓手续费:%v", openServiceCost) + applogger.Debug("开仓总金额:%v", openTotalMoney) + applogger.Debug("开仓订单金额:%v", openMarkerMoney) + applogger.Debug("下单->开仓总金额容差值:%v", floatPrice) + } + + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + usableNew = usable.Add(floatPrice) // 可用资产(处理容差值) + frozenNew = frozen.Sub(totalMoney).Add(openMarkerMoney) // 冻结资产(处理容差值)---> 当前冻结金额 = 原冻结金额 - 下单总额 + if order.StockId != flags.ShareMysBasicUnit { + usableNoNew = usableNo // 非可用资产 + frozenNoNew = frozenNo // 非冻结资产 + } + + // 检查用户订单开仓资产 + if frozenNew.IsNegative() || usableNew.IsNegative() { + return flags.ErrPublicThree + } + if !flags.CheckSetting { + applogger.Debug("下单后用户可用资产:%v", usableNew) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + } + + // 处理资产信息 + userStockUsd := orders.UpdateBotUserStockMys(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockMysByUserIdAndStockId(session, userId, flags.ShareMysBasicUnit, userStockUsd); err != nil { + applogger.Error("%v StockMysOpenOrder.MYR.UpdateBotUserStockMysByUserIdAndStockId:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + + // 更新非资产信息 + if order.StockId != flags.ShareMysBasicUnit { + userStockFMyr := orders.UpdateBotUserStockMys(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = Uo.UpdateBotUserStockMysByUserIdAndStockId(session, userId, order.StockId, userStockFMyr); err != nil { + applogger.Error("%v StockMysOpenOrder.UpdateBotUserStockMysByUserIdAndStockId:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + } + + // 返佣记录|资金信息|资金详情信息 + if err = Uo.ShareMysRebateCalculation(ctx, session, int(userId), flags.ShareMysMarketType, flags.OpenBrokType, flags.OpenMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockMysOpenOrder.ShareUsRebateCalculation:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + + // 处理订单信息(成交价|仓位|开仓时间|订单总金额|手续费|持仓状态) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateOpenBotStockMysTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarkerMoney.String()) + if err = Uo.UpdateBotStockMysTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockMysOpenOrder.UpdateBotStockMysTradeByOrderId:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + var list []models.BotUserStockMysLog + qData0 := orders.CreatBotUserStockMysLog(ctx, userId, flags.CostMoney, flags.ShareMysBasicUnit, NegativeValue(openServiceCost.String()), orderId) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockMysLog(ctx, userId, flags.Freeze, flags.ShareMysBasicUnit, NegativeValue(openMarkerMoney.String()), orderId) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockMysLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockMysLogList(session, list); err != nil { + applogger.Error("%v StockMysOpenOrder.CreatBotUserStockMysLogList:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateOpenBotStockBlockTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarkerMoney.String()) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockMysOpenOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareMysBasicUnit, NegativeValue(openServiceCost.String()), orderId, order.Type) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Freeze, flags.ShareMysBasicUnit, NegativeValue(openMarkerMoney.String()), orderId, order.Type) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId, order.Type) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockMysOpenOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockMysOpenOrder.Commit:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + + return nil +} + +// StockMysClosingOrder +// +// @Description: 马股系统平仓 +// @param ctx +// @param db +// @param orderId +// @param price +// @param order +// @return error +func StockMysClosingOrder(ctx context.Context, db *xorm.EngineGroup, orderId string, price string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockMysClosingOrder.NewSession:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + + // 查询订单信息 + var userId int64 + var dealPrice, orderNumber, totalAmount, serviceCost, marketMoney decimal.Decimal + if !CheckTypeStatus(order.Type) { + tread, err := Uo.GetBotStockMysTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockMysClosingOrder.GetBotStockMysTradeByOrderIdOrStatus:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + marketMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓总金额 + } else { + tread, err := Uo.GetBotStockBlockTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockMysClosingOrder.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + marketMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓总金额 + } + + if !flags.CheckSetting { + applogger.Debug("下单开仓用户Id:%v", userId) + applogger.Debug("下单开仓开仓价格:%v", dealPrice) + applogger.Debug("下单开仓订单数量:%v", orderNumber) + applogger.Debug("下单开仓总金额:%v", totalAmount) + applogger.Debug("下单开仓手续费:%v", serviceCost) + applogger.Debug("下单开仓订单金额:%v", marketMoney) + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + userStockMyr, err := Uo.GetBotUserStockMysByUserIdAndStockId(session, userId, flags.ShareMysBasicUnit) + if err != nil { + applogger.Error("%v StockMysClosingOrder.GetBotUserStockMysByUserIdAndStockId:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(userStockMyr.UsableNum) // 用户可用资金 + frozen = decimal.RequireFromString(userStockMyr.FrozenNum) // 用户非冻结资金 + + // 检查用户订单平仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrShareTow + } + // 查询当前下单用户可用非账户和冻结金额 + if order.StockId != flags.ShareMysBasicUnit { + userStockFUsd, err := Uo.GetBotUserStockMysByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockMysClosingOrder.GetBotUserStockMysByUserIdAndStockId:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(userStockFUsd.UsableNum) // 用户非可用资金 + frozenNo = decimal.RequireFromString(userStockFUsd.FrozenNum) // 用户非冻结资金 + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + + // 手续费处理 + closePrice := decimal.RequireFromString(price) // 平仓价格 + cloePriceCost := closePrice.Mul(orderNumber).String() // 平仓手续费 = 平仓价格 * 股数 * 手续费比例 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareMysMarketType, flags.ClosingBrokType, orderId, cloePriceCost) + if err != nil { + applogger.Error("%v StockMysClosingOrder.CalculateHandlingFeesShare:%v", common.ErrShareMys, err) + return err + } + closeServiceCost := decimal.RequireFromString(cost) + if !flags.CheckSetting { + applogger.Debug("平仓价格:%v", closePrice) + applogger.Debug("平仓手续费手续费:%v", closeServiceCost) + } + + //已经实现盈亏计算公式(已平仓结算方式) + //买涨 已经实现盈亏 = (平仓成交价-开仓成交价)*股数 + //买跌 已经实现盈亏 = (开仓成交价-平仓成交价)*股数 + var usableNew, frozenNew, usableNewNo, frozenNewNo, subPrice, resultPrice decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买涨 + subPrice = closePrice.Sub(dealPrice) + resultPrice = subPrice.Mul(orderNumber) + case flags.TradeTypeSell: // 买跌 + subPrice = dealPrice.Sub(closePrice) + resultPrice = subPrice.Mul(orderNumber) + default: + + } + + // TODO: 判定亏损不能超过 = 保证金 + 平仓手续费 + if resultPrice.IsNegative() { + amountLoss := marketMoney.Sub(closeServiceCost) + if resultPrice.Abs().Cmp(amountLoss) >= 0 { + resultPrice = amountLoss.Neg() + } + } + + // 用户资产账户 + usableNew = usable.Add(resultPrice).Sub(closeServiceCost).Add(marketMoney) // 可用资产 = 原可用资产 + ((正负)盈亏) - 平仓手续费 + 开仓下单金额 + if frozen.Cmp(marketMoney) == -1 { + frozenNew = frozen.Sub(frozen) // 冻结资产 + } else { + frozenNew = frozen.Sub(marketMoney) // 冻结资产 + } + // 用户非资产账户 + if order.StockId != flags.ShareMysBasicUnit { + usableNewNo = usableNo.Sub(orderNumber) // 可用非资产 = 原可用非资产 - 下单股数 + frozenNewNo = frozenNo // 可用非冻结资产 + } + // 检查用户订单平仓资产 + if frozenNew.IsNegative() || usableNewNo.IsNegative() { + return flags.ErrShareTow + } + if !flags.CheckSetting { + applogger.Debug("可用资产:%v", usableNew) + applogger.Debug("冻结资产:%v", frozenNew) + applogger.Debug("可用非资产:%v", usableNewNo) + applogger.Debug("冻结非资产:%v", frozenNewNo) + } + + // 平仓(处理资产表(资产)) + userStockMYR := orders.UpdateBotUserStockMys(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockMysByUserIdAndStockId(session, userId, flags.ShareMysBasicUnit, userStockMYR); err != nil { + applogger.Error("%v StockMysClosingOrder.USD.UpdateBotUserStockMysByUserIdAndStockId:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + + // 平仓(处理资产表(非资产)) + if order.StockId != flags.ShareMysBasicUnit { + userStockFMYR := orders.UpdateBotUserStockMys(ctx, usableNewNo.String(), frozenNewNo.String()) + if err = Uo.UpdateBotUserStockMysByUserIdAndStockId(session, userId, order.StockId, userStockFMYR); err != nil { + applogger.Error("%v StockMysClosingOrder.UpdateBotUserStockMysByUserIdAndStockId:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + } + + // 平仓(返佣记录表|资产表|资金变动表) + if err = Uo.ShareMysRebateCalculation(ctx, session, int(userId), flags.ShareMysMarketType, flags.ClosingBrokType, flags.CloseMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockMysClosingOrder.ShareMysRebateCalculation:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + + // 平仓(处理订单信息(平仓价|保证金|平仓|订单总金额|平仓手续费|完成订单)) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateCloseBotStockMysTrade(ctx, price, cost) + if err = Uo.UpdateBotStockMysTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockMysClosingOrder.UpdateBotStockMysTradeByOrderId:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockMysLog + qData0 := orders.CreatBotUserStockMysLog(ctx, userId, flags.Thaw, flags.ShareMysBasicUnit, marketMoney.String(), orderId) // 平仓(资金变动明细表(开仓保证金)) + qData1 := orders.CreatBotUserStockMysLog(ctx, userId, flags.CostMoney, flags.ShareMysBasicUnit, NegativeValue(closeServiceCost.String()), orderId) // 平仓(资金变动明细表(-平仓手续费)) + qData2 := orders.CreatBotUserStockMysLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏)) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockMysLog(ctx, userId, flags.TransferOut, flags.ShareMysBasicUnit, resultPrice.String(), orderId) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockMysLog(ctx, userId, flags.ChangeInto, flags.ShareMysBasicUnit, resultPrice.String(), orderId) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockMysLogList(session, list); err != nil { + applogger.Error("%v StockMysClosingOrder.CreatBotUserStockMysLogList:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateCloseBotStockBlockTrade(ctx, price, cost) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockMysClosingOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Thaw, flags.ShareMysBasicUnit, marketMoney.String(), orderId, order.Type) // 平仓(资金变动明细表(开仓保证金)) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareMysBasicUnit, NegativeValue(closeServiceCost.String()), orderId, order.Type) // 平仓(资金变动明细表(-平仓手续费)) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId, order.Type) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏)) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, flags.ShareMysBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, flags.ShareMysBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockMysClosingOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockMysClosingOrder.Commit:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + + return nil +} + +// UpdateBotStockMysCancelByOrderId +// +// @Description: 马股撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockMysCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockMysCancelByOrderId.Begin:%v", common.ErrShareMys, err) + return false, flags.ErrMySqlDB + } + + // 获取订单信息 + var userId int64 + var stockId string + var marketMoneyOld, serviceCostOld, orderNumber decimal.Decimal + if !CheckTypeStatus(typeStatus) { + stockTrade, err := uo.GetBotStockMysTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockMysCancelByOrderId.GetBotStockMysTradeByOrderId:%v", common.ErrShareMys, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } else { + stockTrade, err := uo.GetBotStockBlockTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockMysCancelByOrderId.GetBotStockBlockTradeByOrderId:%v", common.ErrShareMys, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } + + // 获取用户资产信息 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockUsd, err := uo.GetBotUserStockMysByUserIdAndStockId(session, userId, flags.ShareMysBasicUnit) + if err != nil || stockUsd == nil { + applogger.Error("%v UpdateBotStockMysCancelByOrderId.USD.GetBotUserStockByUserIdAndStockId:%v", common.ErrShareMys, err) + return false, flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockUsd.UsableNum) // 用户账户可用资产 + frozen = decimal.RequireFromString(stockUsd.FrozenNum) // 用户账户冻结资产 + + // 检查用户订单撤单资产 + if frozen.IsNegative() || usable.IsNegative() { + return false, flags.ErrShareNine + } + if stockId != flags.ShareMysBasicUnit { + stockFMyr, err := uo.GetBotUserStockMysByUserIdAndStockId(session, userId, stockId) + if err != nil { + applogger.Error("%v UpdateBotStockMysCancelByOrderId.GetBotUserStockMysByUserIdAndStockId:%v", common.ErrShareMys, err) + return false, flags.ErrPublicFour + } + usableNo = decimal.RequireFromString(stockFMyr.UsableNum) // 用户非账户可用资产 + frozenNo = decimal.RequireFromString(stockFMyr.FrozenNum) // 用户非账户冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("用户原始可用资金:%v", usable) + applogger.Debug("用户原始冻结资金:%v", frozen) + applogger.Debug("用户原始可用非资金:%v", usableNo) + applogger.Debug("用户原始冻结非资金:%v", frozenNo) + } + + // 更新订单信息 + var entrustKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + botStockTrade := orders.BotStockMysCancelByOrderId(ctx) + if err = uo.UpdateBotStockMysTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockMysCancelByOrderId.MYS.UpdateBotStockMysTradeByOrderId:%v", common.ErrShareMys, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareMysEntrust + userKey = setting.ShareMysSubscribe + adminKey = setting.AdminShareMysSubscribe + } else { + botStockTrade := orders.BotStockBlockCancelByOrderId(ctx) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockMysCancelByOrderId.MYS.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareMys, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareBlkEntrust + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // Operational Spot Asset Table + totalMoney := marketMoneyOld.Add(serviceCostOld) // 订单总金额 + // update total asset data + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + usableNew = usable.Add(totalMoney) // 用户总资产 + frozenNew = frozen.Sub(totalMoney) // 用户冻结资产 + if stockId != flags.ShareMysBasicUnit { + usableNoNew = usableNo.Sub(orderNumber) // 用户非可用资产 + frozenNoNew = frozenNo // 用户非冻结资产 + } + + // 检查用户订单撤单资产 + if frozenNew.IsNegative() || usableNoNew.IsNegative() { + return false, flags.ErrShareNine + } + if !flags.CheckSetting { + applogger.Debug("用户撤单可用总资产:%v", usableNew) + applogger.Debug("用户撤单冻结总资产:%v", frozenNew) + applogger.Debug("用户非撤单可用总资产:%v", usableNoNew) + applogger.Debug("用户非撤单冻结总资产:%v", frozenNoNew) + } + + // 更新资产信息和非资产信息 + userStockMYR := orders.UpdateBotUserStockMys(ctx, usableNew.String(), frozenNew.String()) + if err = uo.UpdateBotUserStockMysByUserIdAndStockId(session, userId, flags.ShareMysBasicUnit, userStockMYR); err != nil { + applogger.Error("%v UpdateBotStockMysCancelByOrderId.UpdateBotUserStockMysByUserIdAndStockId:%v", common.ErrShareMys, err) + return false, flags.ErrMySqlDB + } + if stockId != flags.ShareMysBasicUnit { + userStockFMYT := orders.UpdateBotUserStockMys(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = uo.UpdateBotUserStockMysByUserIdAndStockId(session, userId, stockId, userStockFMYT); err != nil { + applogger.Error("%v UpdateBotStockMysCancelByOrderId.UpdateBotUserStockMysByUserIdAndStockId:%v", common.ErrShareMys, err) + return false, flags.ErrMySqlDB + } + } + + // 删除订单缓存列表 + if err = Reds.HDel(context.Background(), entrustKey, orderId).Err(); err != nil { + applogger.Error("%v UpdateBotStockMysCancelByOrderId.HDel:%v", common.ErrShareMys, err) + return false, flags.ErrCacheDB + } + + // 更新用户订阅订单缓存列表 + userSubKey := virtual.OrderIdListKey(userKey, userId) + if err = share.UpdateShareMysHashByOrderId(Reds, orderId, userSubKey, flags.Cancel); err != nil { + applogger.Error("%v UpdateBotStockMysCancelByOrderId.%v:%v", common.ErrShareMys, userKey, err) + return false, flags.ErrCacheDB + } + + // 更新管理员订阅订单缓存列表 + if err = UpdateShareMysSubscribeHashStatusByOrderId(orderId, adminKey, flags.Cancel, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockMysCancelByOrderId.%v:%v", common.ErrShareMys, adminKey, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockMysCancelByOrderId.Commit:%v", common.ErrShareMys, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockMysStopByOrderId +// +// @Description: 马股设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockMysStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockMysStopByOrderId.NewSession:%v", common.ErrShareMys, err) + return false, flags.ErrMySqlDB + } + + // 设置止盈止损 + var userId int64 + if order.StopType == 1 { + // 下单信息 + checkBool, stopWinPrice, stopLossPrice, err := uo.UpdateVoteStopType(order) + if err != nil { + applogger.Error("%v UpdateBotStockMysStopByOrderId.UpdateVoteStopType:%v", common.ErrShareMys, err) + return false, err + } + if !flags.CheckSetting { + applogger.Debug("当前止盈止损数据:%v,%v,%v", checkBool, stopWinPrice, stopLossPrice) + } + + // 设置止盈止损判定 + var tradeType int + var limitOrMarketPrice decimal.Decimal + if !CheckTypeStatus(order.Type) { + trade, err := uo.GetBotStockMysTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockMysStopByOrderId.GetBotStockMysTradeByOrderIdOrStatus:%v", common.ErrShareMys, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareMysVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockMysStopByOrderId.UpdateShareMysVoteDealType:%v", common.ErrShareMys, err) + return false, err + } + } else { + trade, err := uo.GetBotStockBlockTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockMysStopByOrderId.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareMys, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareBlockVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockMysStopByOrderId.UpdateShareBlockVoteDealType:%v", common.ErrShareMys, err) + return false, err + } + } + if !flags.CheckSetting { + applogger.Debug("当前开仓价格:%v", limitOrMarketPrice) + } + + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(int64(tradeType), stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v UpdateBotStockMysStopByOrderId.VoteTradeType:%v", common.ErrShareMys, err) + return false, err + } + } else { + order.StopLossPrice = decimal.Zero.String() + order.StopWinPrice = decimal.Zero.String() + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[userId] + if ok { + return false, flags.ErrPublicServe + } + + // 更新订单表 + var positionKey string + if !CheckTypeStatus(order.Type) { + botStockTrade := orders.BotStockMysStopByOrderId(ctx, order) + if err = uo.UpdateBotStockMysTradeByOrderId(session, order.OrderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockMysStopByOrderId.UpdateBotStockMysTradeByOrderId:%v", common.ErrShareMys, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareMysPosition + } else { + botStockTrade := orders.BotStockBlockStopByOrderId(ctx, order) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, order.OrderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockMysStopByOrderId.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareMys, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareBlkPosition + } + + // 修改持倉缓存队列 + if err = share.UpdateShareMysStopByOrderId(Reds, order, positionKey, flags.Position); err != nil { + applogger.Error("%v UpdateBotStockMysStopByOrderId.UpdateShareMysStopByOrderId:%v", common.ErrShareMys, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockMysStopByOrderId.Commit:%v", common.ErrShareMys, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockMysClosingByOrderId +// +// @Description: 马股用户平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockMysClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.MysMarket) { + return false, flags.ErrStopTread + } + + // 1、查询持仓缓存列表数据并清理对应缓存 + var positionKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + positionKey = setting.MarketShareMysPosition + userKey = setting.ShareMysSubscribe + adminKey = setting.AdminShareMysSubscribe + } else { + positionKey = setting.MarketShareBlkPosition + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + var entrustCache *share.ShareMysTallyCache + entrust, err := Reds.HGet(context.Background(), positionKey, orderId).Result() + if err != nil { + applogger.Error("%v UpdateBotStockMysClosingByOrderId.HGet:%v", common.ErrShareMys, err) + return false, flags.ErrShareFive + } + var entrustJson share.ShareMysTallyCache + if err = json.Unmarshal([]byte(entrust), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockMysClosingByOrderId.Unmarshal:%v", common.ErrShareMys, err) + return false, flags.ErrCacheDB + } + if orderId == entrustJson.OrderId { + entrustCache = &entrustJson + } + // 2、判定是否存在平仓订单 + if entrustCache == nil { + return false, err + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[entrustJson.UserId] + if ok { + return false, flags.ErrPublicServe + } + + // 市场设置交易时间(T+0,T+1,T+2s......) + if !CheckShareSystemTime(entrustCache.ClosingTime) { + return false, flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("手动平仓:%v", entrustCache) + } + + // 3、获取当前最新价格 + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Mys, entrustCache.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareMysTheLatestPrice(subKey, entrustCache.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockMysClosingByOrderId.GetShareMysTheLatestPrice:%v", common.ErrShareMys, err) + return false, flags.ErrStopTread + } + + // 4、平仓处理 + if err = StockMysClosingOrder(ctx, Msql, orderId, closingPrice.String(), entrustCache.Order); err != nil { + applogger.Error("%v UpdateBotStockMysClosingByOrderId.StockMysClosingOrder:%v", common.ErrShareMys, err) + return false, err + } + + // 5、清理持仓订单信息 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), positionKey, orderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockMysClosingByOrderId.HDel:%v", common.ErrShareMys, err) + return false, flags.ErrCacheDB + } + + // 6、平仓更新订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(userKey, entrustCache.UserId) + if err = UpdateShareMysSubscribeHashStatusByOrderId(orderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockMysClosingByOrderId.%v:%v", common.ErrShareMys, userKey, err) + return false, flags.ErrCacheDB + } + + // 7、平仓更新管理员订阅缓存订单状态 + if err = UpdateShareMysSubscribeHashStatusByOrderId(orderId, adminKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockMysClosingByOrderId.%v:%v", common.ErrShareMys, adminKey, err) + return false, flags.ErrCacheDB + } + + return true, nil +} + +// UpdateBotStockMysAllClosingByOrderId +// +// @Description: 马股用户一键平仓 +// @receiver uo +// @param ctx +// @param userId +// @return error +func (uo *userOrderRepo) UpdateBotStockMysAllClosingByOrderId(ctx context.Context, userId int64) error { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.MysMarket) { + return flags.ErrStopTread + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe + } + + // 1、查询当前用户所有订单 + orderMap, err := uo.GetBotStockMysTradeByUserId(userId) + if err != nil { + applogger.Error("%v UpdateBotStockMysAllClosingByOrderId.GetBotStockMysTradeByUserId:%v", common.ErrShareMys, err) + return flags.ErrMySqlDB + } + + // 2、查询持仓缓存列表数据-1、清理持仓列表缓存 2、处理平仓数据 3、清理订单ID缓存列表 + entrust, err := Reds.HGetAll(context.Background(), setting.MarketShareMysPosition).Result() + if err != nil { + applogger.Error("%v UpdateBotStockMysAllClosingByOrderId.HGetAll:%v", common.ErrShareMys, err) + return flags.ErrShareFive + } + + // 3、循环检查股票交易对最新价格(有一个查询不到既不能平仓) + var entrustList []share.ShareMysTallyCache + closePriceMap := make(map[string]decimal.Decimal) + for key, value := range entrust { + var entrustJson share.ShareMysTallyCache + if err = json.Unmarshal([]byte(value), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockMysAllClosingByOrderId.Unmarshal:%v", common.ErrShareMys, err) + return flags.ErrPosition + } + _, ok := orderMap[entrustJson.OrderId] + if ok { + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Mys, entrustJson.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareMysTheLatestPrice(subKey, entrustJson.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockMysAllClosingByOrderId.GetShareMysTheLatestPrice:%v", common.ErrShareMys, err) + return flags.ErrPosition + } + if !flags.CheckSetting { + applogger.Debug("订阅Key:%v,最新价格:%v,订单ID:%v", subKey, closingPrice, entrustJson.OrderId) + } + + closePriceMap[key] = closingPrice + entrustList = append(entrustList, entrustJson) + } + } + + // 4、股票一键平仓 + for _, value := range entrustList { + closePrice, ok := closePriceMap[value.OrderId] + if ok { + // 平仓 + if err = StockMysClosingOrder(ctx, uo.data.mysqlDB, value.OrderId, closePrice.String(), value.Order); err != nil { + applogger.Error("%v UpdateBotStockMysAllClosingByOrderId.StockMysClosingOrder:%v", common.ErrShareMys, err) + return err + } + + // 清理持仓缓存列表 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), setting.MarketShareMysPosition, value.OrderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockMysAllClosingByOrderId.HDel:%v", common.ErrShareMys, err) + return flags.ErrCacheDB + } + + // 平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareMysSubscribe, value.UserId) + if err = UpdateShareMysSubscribeHashStatusByOrderId(value.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockMysAllClosingByOrderId.ShareMysSubscribe:%v", common.ErrShareMys, err) + return flags.ErrCacheDB + } + + // 平仓更新管理员订阅订单状态 + if err = UpdateShareMysSubscribeHashStatusByOrderId(value.OrderId, setting.AdminShareMysSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockMysAllClosingByOrderId.AdminShareMysSubscribe:%v", common.ErrShareMys, err) + return flags.ErrCacheDB + } + } + } + + return nil +} + +// GetBotStockMysTradeByUserId +// +// @Description: +// @receiver uo +// @param ctx +// @param userId +// @return map[string]string +// @return error +func (uo *userOrderRepo) GetBotStockMysTradeByUserId(userId int64) (map[string]string, error) { + var botStockMysTrade []models.BotStockMysTrade + if err := uo.data.mysqlDB.Table(flags.BotStockMysTrade). + Where("user_id = ?", userId). + Where("status = 1"). + Find(&botStockMysTrade); err != nil { + return nil, err + } + + botMap := make(map[string]string) + for _, value := range botStockMysTrade { + botMap[value.OrderId] = value.OrderId + } + + return botMap, nil +} + +// GetShareMysTheLatestPrice +// +// @Description: +// @receiver uo +// @param ctx +// @param subKey +// @param tradeType +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) GetShareMysTheLatestPrice(subKey string, tradeType int64) (decimal.Decimal, error) { + priceNew, err := share.ShareMysSubMarketPrice(subKey) + if err != nil { + applogger.Error("%v GetShareMysTheLatestPrice.ShareMysSubMarketPrice:%v", common.ErrShareMys, err) + return decimal.Decimal{}, err + } + + priceS := decimal.RequireFromString(priceNew) + + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tradeType { + case flags.TradeTypeBuy: // 买涨 + openPrice = priceS.Sub(difference) // 开仓价格 + case flags.TradeTypeSell: // 买跌 + openPrice = priceS.Add(difference) // 开仓价格 + default: + + } + + return openPrice, nil +} + +// GetBotStockMysTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @return *models.BotStockMysTrade +// @return error +func (uo *userOrderRepo) GetBotStockMysTradeByOrderId(session *xorm.Session, orderId string) (*models.BotStockMysTrade, error) { + var botStockMysTrade []models.BotStockMysTrade + if err := session.Table(flags.BotStockMysTrade). + Where("order_id = ?", orderId). + Find(&botStockMysTrade); err != nil { + return nil, err + } + + for _, value := range botStockMysTrade { + return &value, nil + } + + return nil, nil +} + +// GetBotUserStockMysByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @return *models.BotUserStockMys +// @return error +func (uo *userOrderRepo) GetBotUserStockMysByUserIdAndStockId(session *xorm.Session, userId int64, stockId string) (*models.BotUserStockMys, error) { + var stockMYR []models.BotUserStockMys + if err := session.Table(flags.BotUserStockMys). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&stockMYR); err != nil || len(stockMYR) <= 0 { + return nil, err + } + + for _, value := range stockMYR { + return &value, nil + } + + return nil, nil +} + +// UpdateBotStockMysTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotStockMysTradeByOrderId(session *xorm.Session, orderId string, stock models.BotStockMysTrade) error { + checkInt, err := session.Table(flags.BotStockMysTrade). + Where("order_id = ?", orderId). + Update(&stock) + if err != nil || checkInt < 0 { + return err + } + + return nil +} + +// CreateBotStockMysTrade +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param trade +// @return error +func (uo *userOrderRepo) CreateBotStockMysTrade(session *xorm.Session, trade models.BotStockMysTrade) error { + _, err := session.Table(flags.BotStockMysTrade).Insert(&trade) + if err != nil { + return err + } + + return nil +} + +// CreateBotUserStockMysFMYR +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param stock +// @return error +func (uo *userOrderRepo) CreateBotUserStockMysFMYR(session *xorm.Session, stock models.BotUserStockMys) error { + _, err := session.Table(flags.BotUserStockMys).Insert(&stock) + if err != nil { + return err + } + + return nil +} + +// UpdateBotUserStockMysByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotUserStockMysByUserIdAndStockId(session *xorm.Session, userId int64, stockId string, stock models.BotUserStockMys) error { + checkNum, err := session.Table(flags.BotUserStockMys). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&stock) + + if err != nil || checkNum < 0 { + return err + } + + return nil +} + +// StockMysVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) StockMysVoteDealType(order structure.ShareOrder) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + return limitOrMarketPrice, nil +} + +// UpdateShareMysVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) UpdateShareMysVoteDealType(order *models.BotStockMysTrade) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + if len(order.DealPrice) != 0 { + dealPrice := decimal.RequireFromString(order.DealPrice) + if !dealPrice.IsZero() { + limitOrMarketPrice = dealPrice + } + } + + return limitOrMarketPrice, nil +} + +// VerifyBotStockMysTradeOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @return string +// @return error +func (uo *userOrderRepo) VerifyBotStockMysTradeOrderId(session *xorm.Session) (string, error) { + var orderId string + for { + // 生成订单ID + orderId = orders.CreateRandCodeOrder(10) + + var orderList []models.BotStockMysTrade + err := session.Table(flags.BotStockMysTrade). + Where("order_id = ?", orderId). + Find(&orderList) + + if err != nil || len(orderList) > 0 { + applogger.Error("%v VerifyBotStockMysTradeOrderId.Find:%v", common.ErrShareMys, err) + continue + } + + break + } + + return orderId, nil +} + +// VerifyBotStockBlockTradeOrderId +// +// @Description: +// @receiver uo +// @param session +// @return string +// @return error +func (uo *userOrderRepo) VerifyBotStockBlockTradeOrderId(session *xorm.Session) (string, error) { + var orderId string + for { + // 生成订单ID + orderId = orders.CreateRandCodeOrder(10) + + var orderList []models.BotStockBlockTrade + err := session.Table(flags.BotStockBlockTrade). + Where("order_id = ?", orderId). + Find(&orderList) + + if err != nil || len(orderList) > 0 { + applogger.Error("%v VerifyBotStockMysTradeOrderId.Find:%v", common.ErrShareMys, err) + continue + } + + break + } + + return orderId, nil +} + +// GetBotStockMysTradeByOrderIdOrStatus +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param status +// @return *models.BotStockMysTrade +// @return error +func (uo *userOrderRepo) GetBotStockMysTradeByOrderIdOrStatus(session *xorm.Session, orderId string, status int) (*models.BotStockMysTrade, error) { + var botStockMysTrade []models.BotStockMysTrade + if err := session.Table(flags.BotStockMysTrade). + Where("order_id = ?", orderId). + Where("`status` = ?", status). + Find(&botStockMysTrade); err != nil { + return nil, err + } + + for _, value := range botStockMysTrade { + return &value, nil + } + + return nil, nil +} diff --git a/internal/data/order_share_sgd.go b/internal/data/order_share_sgd.go new file mode 100644 index 0000000..0accda7 --- /dev/null +++ b/internal/data/order_share_sgd.go @@ -0,0 +1,1507 @@ +package data + +import ( + "context" + "encoding/json" + "github.com/go-xorm/xorm" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" + + orders "matchmaking-system/internal/data/convert" + models "matchmaking-system/internal/pkg/model" +) + +// GetBotStockSgdTradeList +// +// @Description: 新加坡股订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param userId +// @param status +// @return []*models.BotStockSgdTrade +// @return int64 +// @return error +func (uo *userOrderRepo) GetBotStockSgdTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockSgdTrade, int64, error) { + totalCount, err := uo.data.mysqlDB.Table(flags.BotStockSgdTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Count() + if err != nil { + return nil, 0, flags.ErrMySqlDB + } + if totalCount == 0 { + return nil, 0, nil + } + var stockList []*models.BotStockSgdTrade + if err = uo.data.mysqlDB.Table(flags.BotStockSgdTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Limit(int(pageSize), int(pageCount)). + Desc(GetOrderByStatusSort(status)). + Find(&stockList); err != nil { + return nil, 0, flags.ErrMySqlDB + } + + var stockUpdateList []*models.BotStockSgdTrade + for _, value := range stockList { + value.KeepDecimal = GetKeepDecimal(flags.StockSGDSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockSGDSystemSetUpKey, value.StockId) + stockUpdateList = append(stockUpdateList, value) + } + + return stockUpdateList, totalCount, nil +} + +// PlacingStockSgdOrders +// +// @Description: 新加坡股下单 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) PlacingStockSgdOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) { + // 1、通知下单订阅 + symbol := order.StockId + timeValue := QuerySystemCache(flags.ShareSgdMarketType) // 市场开闭盘时间 + if !utils.CheckInPlateTime(timeValue) { + return flags.SetNull, flags.ErrStopTread + } + SubscribeSgdHSetCodeList(symbol, false) // 同步写入股票列表缓存 + SubscribeSgdCloseNewPrice(symbol) // 同步股票实时行情价 + + // 判定是否存在欠款订单 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe.Error(), nil + } + + order = PryNumInit(order) // 杠杆初始化 + subKey := publicData.SymbolCache(flags.Sgd, symbol, flags.TradeTypePrice) + + // 新加坡股市场系统设置 + if CheckGlobalTread(flags.SgdMarket) { + return flags.SetNull, flags.ErrStopTread + } + + // 全局设置停止交易操作 + var blockTime time.Time + var priceNew, userKey, adminKey string + if !CheckTypeStatus(order.Type) { + userKey = setting.ShareSgdSubscribe + adminKey = setting.AdminShareSgdSubscribe + } else { + // 判定:1、是否开启股票交易 2、是否在交易时间内 3、是否达到最小交易量 + check, openPrice, minNum, endTime := CheckBlockTread(flags.SgdBlk, symbol) + if check { + return flags.SetNull, flags.ErrShareSeven + } + if minNum > utils.StringToInt(order.OrderNumber) { + return flags.SetNull, flags.ErrShareSix + } + priceNew = openPrice // 开仓价格 + blockTime = endTime // 平仓时间 + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + flatRatio := GetCacheForcedClosure(flags.StockSGDSystemSetUpKey, symbol) // 设置强平阈值 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.SgdMarket, userId) // 股票市场系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), // 强平阈值 + Status: leverStatus.Status, // 股杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + order.System = system + + // 2、股票下单判定 + // 下单判定设置(false无设置|true止盈止损) + checkBool, stopWinPrice, stopLossPrice, err := StockSgdVoteStopType(order) + if err != nil { + applogger.Error("%v PlacingStockSgdOrders.StockSgdVoteStopType:%v", common.ErrShareSgd, err) + return flags.SetNull, err + } + // 下单判定设置(限价|市价) + limitOrMarketPrice, err := uo.StockSgdVoteDealType(order) + if err != nil { + applogger.Error("%v PlacingStockSgdOrders.StockSgdVoteDealType:%v", common.ErrShareSgd, err) + return flags.SetNull, err + } + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(order.TradeType, stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v PlacingStockSgdOrders.VoteTradeType:%v", common.ErrShareSgd, err) + return flags.SetNull, err + } + + // 3、订单持久化录入(并处理资产信息) + pryNum := SystemDealWithLever(order) + orderId, err := uo.StockSgdOrderWriteDB(ctx, userId, order, limitOrMarketPrice, pryNum) + if err != nil || len(orderId) == 0 { + applogger.Error("%v PlacingStockSgdOrders.StockSgdOrderWriteDB:%v", common.ErrShareSgd, err) + return flags.SetNull, err + } + + // 4、处理订单信息 + chg := GetShareChgSgd(flags.Sgd, order.StockId) // 涨跌幅标识值 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.SgdMarket, time.Now()) // 开盘时间 + marketStatus, shareOrder, err := share.ShareSgdCacheDeal(ctx, userId, orderId, subKey, order, chg, priceNew, closingTime, blockTime) + if err != nil || shareOrder == nil { + applogger.Error("%v PlacingStockSgdOrders.ShareSgdCacheDeal:%v", common.ErrShareSgd, err) + return flags.SetNull, err + } + // 计算保证金 = 订单价格 * 订单数量 / 杠杆 + shareOrder.Order.MarketMoney = limitOrMarketPrice.Mul(decimal.RequireFromString(order.OrderNumber)).Div(pryNum).String() + if !flags.CheckSetting { + applogger.Debug("订单ID:%v", shareOrder.OrderId) + applogger.Debug("订单交易对:%v", shareOrder.Symbol) + applogger.Debug("订单状态:%v", shareOrder.Status) + applogger.Debug("订单用户ID:%v", shareOrder.UserId) + applogger.Debug("开盘价:%v", shareOrder.OpenPrice) + applogger.Debug("收盘价:%v", shareOrder.ClosingPrice) + applogger.Debug("下单信息:%v", shareOrder.Order) + } + + // 6、股票订单(挂单|持仓)缓存列表,等待队列计算 + if err = share.ShareSgdHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v PlacingStockSgdOrders.ShareSgdHashUserOrder:%v", common.ErrShareSgd, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 7、用户订阅股票订单信息 + orderIdKey := virtual.OrderIdListKey(userKey, userId) + if err = share.ShareSgdHashUserOrder(Reds, orderIdKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockSgdOrders.%v:%v", common.ErrShareSgd, userKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 8、管理员订阅订单信息 + if err = share.ShareSgdHashUserOrder(Reds, adminKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockSgdOrders.%v:%v", common.ErrShareSgd, adminKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + return orderId, nil +} + +// StockSgdOrderWriteDB +// +// @Description: 新加坡股下单操作 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) StockSgdOrderWriteDB(ctx context.Context, userId int64, order structure.ShareOrder, limitOrMarketPrice, lever decimal.Decimal) (string, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockSgdOrderWriteDB.Begin:%v", common.ErrShareSgd, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 获取当前下单用户的资产 + var usableOld, frozenOld decimal.Decimal + stockSgd, err := uo.GetBotUserStockSgdByUserIdAndStockId(session, userId, flags.ShareSgdBasicUnit) + if err != nil || stockSgd == nil { + applogger.Error("%v StockSgdOrderWriteDB.GetBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareSgd, err) + return flags.SetNull, flags.ErrMySqlDB + } + usableOld = decimal.RequireFromString(stockSgd.UsableNum) + frozenOld = decimal.RequireFromString(stockSgd.FrozenNum) + + // 检查用户订单下单资产 + if usableOld.IsZero() || usableOld.IsNegative() || frozenOld.IsNegative() { + return flags.SetNull, flags.ErrShareOne + } + + // 获取当前系统下单用户的非资产 + var usableFOld, frozenFOld decimal.Decimal + stockFSGD, err := uo.GetBotUserStockSgdByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockSgdOrderWriteDB.FeiSGD:%v", common.ErrShareSgd, err) + return flags.SetNull, flags.ErrMySqlDB + } + if stockFSGD != nil { + usableFOld = decimal.RequireFromString(stockFSGD.UsableNum) + frozenFOld = decimal.RequireFromString(stockFSGD.FrozenNum) + } + if !flags.CheckSetting { + applogger.Debug("下单可用资产:%v", usableOld) + applogger.Debug("下单冻结资产:%v", frozenOld) + applogger.Debug("下单查询非资产账户:%v", stockFSGD) + applogger.Debug("下单可用非资产:%v", usableFOld) + applogger.Debug("下单冻结非资产:%v", frozenFOld) + } + + // 整理当前下单信息 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 订单手续费 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 订单数量 + marketMoney := orderNumber.Mul(limitOrMarketPrice).Div(lever) // 订单金额(杠杆下单) = 订单数量 * 交易价格 / 杠杆 + totalMoney := marketMoney.Add(serviceCost) // 订单总金额 + order.MarketMoney = marketMoney.String() // 市值金额即为保证金 + + // 检查订单ID是否存在,新增下单信息 + var orderId string + if !CheckTypeStatus(order.Type) { + orderId, err = uo.VerifyBotStockSgdTradeOrderId(session) + if err != nil { + applogger.Error("%v StockSgdOrderWriteDB.VerifyBotStockSgdTradeOrderId:%v", common.ErrShareSgd, err) + return flags.SetNull, err + } + trade := orders.BotStockSgdTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockSgdTrade(session, trade); err != nil { + applogger.Error("%v StockSgdOrderWriteDB.CreateBotStockSgdTrade:%v", common.ErrShareSgd, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + orderId, err = uo.VerifyBotStockBlockTradeOrderId(session) + if err != nil { + applogger.Error("%v StockSgdOrderWriteDB.VerifyBotStockBlockTradeOrderId:%v", common.ErrShareSgd, err) + return flags.SetNull, err + } + trade := orders.BotStockBlockTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockBlockTrade(session, trade); err != nil { + applogger.Error("%v StockSgdOrderWriteDB.CreateBotStockBlockTrade:%v", common.ErrShareSgd, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + // 下单判定 + residue := usableOld.Sub(totalMoney).Div(usableOld) + if usableOld.Cmp(totalMoney) <= 0 || residue.Cmp(utils.DecimalsStrInt()) <= 0 { + return flags.SetNull, flags.ErrPublicTow + } + + var usableNew, frozenNew, usableFNew, frozenFNew decimal.Decimal + usableNew = usableOld.Sub(totalMoney) // 可用资产 + frozenNew = frozenOld.Add(totalMoney) // 冻结资产 + if order.StockId != flags.ShareSgdBasicUnit { + usableFNew = usableFOld.Add(orderNumber) // 可用非资产 + frozenFNew = frozenFOld // 冻结非资产 + } + // 检查用户订单下单资产 + if usableNew.IsNegative() { + return flags.SetNull, flags.ErrPublicTow + } + + // 下单更新资产信息 + stockSgdModel := orders.UpdateBotUserStockSgd(ctx, usableNew.String(), frozenNew.String()) + err = uo.UpdateBotUserStockSgdByUserIdAndStockId(session, userId, flags.ShareSgdBasicUnit, stockSgdModel) + if err != nil { + applogger.Error("%v StockSgdOrderWriteDB.UpdateBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareSgd, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 下单(新增|更新)非资产信息 + if stockFSGD == nil { + stockFTHBModel := orders.CreateBotUserStockSgd(ctx, userId, order.StockId, usableFNew.String(), frozenFNew.String()) + err = uo.CreateBotUserStockSgdFTHB(session, stockFTHBModel) + if err != nil { + applogger.Error("%v StockSgdOrderWriteDB.CreateBotUserStockSgdFTHB:%v", common.ErrShareSgd, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + stockFTHBModel := orders.UpdateBotUserStockSgd(ctx, usableFNew.String(), frozenFNew.String()) + err = uo.UpdateBotUserStockSgdByUserIdAndStockId(session, userId, order.StockId, stockFTHBModel) + if err != nil { + applogger.Error("%v StockSgdOrderWriteDB.UpdateBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareSgd, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockSgdOrderWriteDB.Commit:%v", common.ErrShareSgd, err) + return flags.SetNull, flags.ErrMySqlDB + } + + return orderId, nil +} + +// StockSgdOpenOrder +// +// @Description: 新加坡股系统开仓 +// @param ctx +// @param db +// @param userId +// @param orderId +// @param openPrice +// @param order +// @return error +func StockSgdOpenOrder(ctx context.Context, db *xorm.EngineGroup, userId int64, orderId, openPrice string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockSgdOpenOrder.NewSession:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockThb, err := Uo.GetBotUserStockSgdByUserIdAndStockId(session, userId, flags.ShareSgdBasicUnit) + if err != nil || stockThb == nil { + applogger.Error("%v StockSgdOpenOrder.GetBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockThb.UsableNum) // 用户可用资产 + frozen = decimal.RequireFromString(stockThb.FrozenNum) // 用户冻结资产 + + // 检查用户订单开仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrPublicThree + } + if order.StockId != flags.ShareSgdBasicUnit { + stockFThb, err := Uo.GetBotUserStockSgdByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockSgdOpenOrder.GetBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(stockFThb.UsableNum) // 用户非可用资产 + frozenNo = decimal.RequireFromString(stockFThb.FrozenNum) // 用户非冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + + // 转换股票下单信息 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 下单股数 + markerMoney := decimal.RequireFromString(order.MarketMoney) // 下单金额 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 下单手续费 + totalMoney := markerMoney.Add(serviceCost) // 下单总金额 = (下单手续费 + 下单金额) + openOrderPrice := decimal.RequireFromString(openPrice) // 开盘价格 + if !flags.CheckSetting { + applogger.Debug("下单订单数量:%v", orderNumber) + applogger.Debug("下单订单金额:%v", markerMoney) + applogger.Debug("下单订单手续费:%v", serviceCost) + applogger.Debug("下单订单总金额:%v", totalMoney) + } + + // 手续费记录 + openPriceNew := openOrderPrice.Mul(orderNumber).String() // 开仓手续费 = 开仓价格 * 股数 * 开仓手续费 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareSgdMarketType, flags.OpenBrokType, orderId, openPriceNew) + if err != nil { + applogger.Error("%v StockSgdOpenOrder.CalculateHandlingFeesShare:%v", common.ErrShareSgd, err) + return err + } + openServiceCost := decimal.RequireFromString(cost) // 开仓手续费 + openMarkerMoney := openOrderPrice.Mul(orderNumber).Div(decimal.RequireFromString(order.PryNum)) // 开仓金额 = 开仓价格 * 股数 / 杠杆 + openTotalMoney := openMarkerMoney.Add(openServiceCost) // 开仓总金额 = 开仓金额 + 开仓手续费 + floatPrice := totalMoney.Sub(openTotalMoney) // 计算容差 = 下单总额 - 开仓总额 + if !flags.CheckSetting { + applogger.Debug("开仓订单价格:%v", openOrderPrice) + applogger.Debug("开仓手续费:%v", openServiceCost) + applogger.Debug("开仓总金额:%v", openTotalMoney) + applogger.Debug("下单开仓总金额容差值:%v", floatPrice) + } + + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + usableNew = usable.Add(floatPrice) // 可用资产(处理容差值) + frozenNew = frozen.Sub(totalMoney).Add(openMarkerMoney) // 冻结资产(处理容差值)---> 当前冻结金额 = 原冻结金额 - 下单总额 + if order.StockId != flags.ShareSgdBasicUnit { + usableNoNew = usableNo // 非可用资产 + frozenNoNew = frozenNo // 非冻结资产 + } + + // 检查用户订单开仓资产 + if frozenNew.IsNegative() || usableNew.IsNegative() { + return flags.ErrPublicThree + } + if !flags.CheckSetting { + applogger.Debug("下单后用户可用资产:%v", usableNew) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + } + + // 处理资产信息 + userStockThb := orders.UpdateBotUserStockSgd(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockSgdByUserIdAndStockId(session, userId, flags.ShareSgdBasicUnit, userStockThb); err != nil { + applogger.Error("%v StockSgdOpenOrder.UpdateBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + + // 更新非资产信息 + if order.StockId != flags.ShareSgdBasicUnit { + userStockFThb := orders.UpdateBotUserStockSgd(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = Uo.UpdateBotUserStockSgdByUserIdAndStockId(session, userId, order.StockId, userStockFThb); err != nil { + applogger.Error("%v StockSgdOpenOrder.UpdateBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + } + + // 返佣记录|资金信息|资金详情信息 + if err = Uo.ShareSgdRebateCalculation(ctx, session, int(userId), flags.ShareSgdMarketType, flags.OpenBrokType, flags.OpenMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockSgdOpenOrder.ShareSgdRebateCalculation:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + + // 处理订单信息(成交价|仓位|开仓时间|订单总金额|手续费|持仓状态) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateOpenBotStockSgdTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarkerMoney.String()) + if err = Uo.UpdateBotStockSgdTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockSgdOpenOrder.UpdateBotStockSgdTradeByOrderId:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + var list []models.BotUserStockSgdLog + qData0 := orders.CreatBotUserStockSgdLog(ctx, userId, flags.CostMoney, flags.ShareSgdBasicUnit, NegativeValue(openServiceCost.String()), orderId) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockSgdLog(ctx, userId, flags.Freeze, flags.ShareSgdBasicUnit, NegativeValue(openMarkerMoney.String()), orderId) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockSgdLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockSgdLogList(session, list); err != nil { + applogger.Error("%v StockSgdOpenOrder.CreatBotUserStockSgdLogList:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateOpenBotStockBlockTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarkerMoney.String()) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockSgdOpenOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareSgdBasicUnit, NegativeValue(openServiceCost.String()), orderId, order.Type) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Freeze, flags.ShareSgdBasicUnit, NegativeValue(openMarkerMoney.String()), orderId, order.Type) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId, order.Type) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockSgdOpenOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockSgdOpenOrder.Commit:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + + return nil +} + +// StockSgdClosingOrder +// +// @Description: 新加坡股系统平仓 +// @param ctx +// @param db +// @param orderId +// @param price +// @param order +// @return error +func StockSgdClosingOrder(ctx context.Context, db *xorm.EngineGroup, orderId string, price string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockSgdClosingOrder.NewSession:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + + // 查询订单信息 + var userId int64 + var dealPrice, orderNumber, totalAmount, serviceCost, markerMoney decimal.Decimal + if !CheckTypeStatus(order.Type) { + tread, err := Uo.GetBotStockSgdTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockSgdClosingOrder.GetBotStockSgdTradeByOrderIdOrStatus:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + markerMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓下单金额 + } else { + tread, err := Uo.GetBotStockBlockTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockSgdClosingOrder.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + markerMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓下单金额 + } + + if !flags.CheckSetting { + applogger.Debug("下单开仓用户Id:%v", userId) + applogger.Debug("下单开仓开仓价格:%v", dealPrice) + applogger.Debug("下单开仓订单数量:%v", orderNumber) + applogger.Debug("下单开仓总金额:%v", totalAmount) + applogger.Debug("下单开仓手续费:%v", serviceCost) + applogger.Debug("下单开仓开仓金额:%v", markerMoney) + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + userStockThb, err := Uo.GetBotUserStockSgdByUserIdAndStockId(session, userId, flags.ShareSgdBasicUnit) + if err != nil { + applogger.Error("%v StockSgdClosingOrder.GetBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(userStockThb.UsableNum) // 用户可用资金 + frozen = decimal.RequireFromString(userStockThb.FrozenNum) // 用户非冻结资金 + + // 检查用户订单平仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrShareTow + } + + // 查询当前下单用户可用非账户和冻结金额 + if order.StockId != flags.ShareSgdBasicUnit { + userStockFThb, err := Uo.GetBotUserStockSgdByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockSgdClosingOrder.GetBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(userStockFThb.UsableNum) // 用户非可用资金 + frozenNo = decimal.RequireFromString(userStockFThb.FrozenNum) // 用户非冻结资金 + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + + // 手续费处理 + closePrice := decimal.RequireFromString(price) // 平仓价格 + cloePriceCost := closePrice.Mul(orderNumber).String() // 平仓手续费 = 平仓价格 * 股数 * 手续费比例 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareSgdMarketType, flags.ClosingBrokType, orderId, cloePriceCost) + if err != nil { + applogger.Error("%v StockSgdClosingOrder.CalculateHandlingFeesShare:%v", common.ErrShareSgd, err) + return err + } + closeServiceCost := decimal.RequireFromString(cost) + if !flags.CheckSetting { + applogger.Debug("平仓价格:%v", closePrice) + applogger.Debug("平仓手续费手续费:%v", closeServiceCost) + } + + //已经实现盈亏计算公式(已平仓结算方式) + //买涨 已经实现盈亏 = (平仓成交价-开仓成交价)*股数 + //买跌 已经实现盈亏 = (开仓成交价-平仓成交价)*股数 + var usableNew, frozenNew, usableNewNo, frozenNewNo, subPrice, resultPrice decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买涨 + subPrice = closePrice.Sub(dealPrice) + resultPrice = subPrice.Mul(orderNumber) + case flags.TradeTypeSell: // 买跌 + subPrice = dealPrice.Sub(closePrice) + resultPrice = subPrice.Mul(orderNumber) + default: + + } + + // TODO: 判定亏损不能超过 = 保证金 + 平仓手续费 + if resultPrice.IsNegative() { + amountLoss := markerMoney.Sub(closeServiceCost) + if resultPrice.Abs().Cmp(amountLoss) >= 0 { + resultPrice = amountLoss.Neg() + } + } + + // 用户资产账户 + usableNew = usable.Add(resultPrice).Sub(closeServiceCost).Add(markerMoney) // 可用资产 = 原可用资产 + ((正负)盈亏) - 平仓手续费 + 开仓下单金额 + if frozen.Cmp(markerMoney) == -1 { + frozenNew = frozen.Sub(frozen) // 冻结资产 + } else { + frozenNew = frozen.Sub(markerMoney) // 冻结资产 + } + + // 用户非资产账户 + if order.StockId != flags.ShareSgdBasicUnit { + usableNewNo = usableNo.Sub(orderNumber) // 可用非资产 = 原可用非资产 - 下单股数 + frozenNewNo = frozenNo // 可用非冻结资产 + } + + // 检查用户订单平仓资产 + if frozenNew.IsNegative() || usableNewNo.IsNegative() { + return flags.ErrShareTow + } + if !flags.CheckSetting { + applogger.Debug("可用资产:%v", usableNew) + applogger.Debug("冻结资产:%v", frozenNew) + applogger.Debug("可用非资产:%v", usableNewNo) + applogger.Debug("冻结非资产:%v", frozenNewNo) + } + + // 平仓(处理资产表(资产)) + userStockUTHB := orders.UpdateBotUserStockSgd(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockSgdByUserIdAndStockId(session, userId, flags.ShareSgdBasicUnit, userStockUTHB); err != nil { + applogger.Error("%v StockSgdClosingOrder.UpdateBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + + // 平仓(处理资产表(非资产)) + if order.StockId != flags.ShareSgdBasicUnit { + userStockFTHB := orders.UpdateBotUserStockSgd(ctx, usableNewNo.String(), frozenNewNo.String()) + if err = Uo.UpdateBotUserStockSgdByUserIdAndStockId(session, userId, order.StockId, userStockFTHB); err != nil { + applogger.Error("%v StockSgdClosingOrder..UpdateBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + } + + // 平仓(返佣记录表|资产表|资金变动表) + if err = Uo.ShareSgdRebateCalculation(ctx, session, int(userId), flags.ShareSgdMarketType, flags.ClosingBrokType, flags.CloseMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockSgdClosingOrder.ShareSgdRebateCalculation:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + + // 平仓(处理订单信息(平仓价|保证金|平仓|订单总金额|平仓手续费|完成订单)) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateCloseBotStockSgdTrade(ctx, price, cost) + if err = Uo.UpdateBotStockSgdTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockSgdClosingOrder.UpdateBotStockSgdTradeByOrderId:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockSgdLog + qData0 := orders.CreatBotUserStockSgdLog(ctx, userId, flags.Thaw, flags.ShareSgdBasicUnit, markerMoney.String(), orderId) // 平仓(资金变动明细表(开仓保证金)) + qData1 := orders.CreatBotUserStockSgdLog(ctx, userId, flags.CostMoney, flags.ShareSgdBasicUnit, NegativeValue(closeServiceCost.String()), orderId) // 平仓(资金变动明细表(-平仓手续费)) + qData2 := orders.CreatBotUserStockSgdLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockSgdLog(ctx, userId, flags.TransferOut, flags.ShareSgdBasicUnit, resultPrice.String(), orderId) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockSgdLog(ctx, userId, flags.ChangeInto, flags.ShareSgdBasicUnit, resultPrice.String(), orderId) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockSgdLogList(session, list); err != nil { + applogger.Error("%v StockSgdClosingOrder.CreatBotUserStockSgdLogList:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateCloseBotStockBlockTrade(ctx, price, cost) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockSgdClosingOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Thaw, flags.ShareSgdBasicUnit, markerMoney.String(), orderId, order.Type) // 平仓(资金变动明细表(开仓保证金)) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareSgdBasicUnit, NegativeValue(closeServiceCost.String()), orderId, order.Type) // 平仓(资金变动明细表(-平仓手续费)) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId, order.Type) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, flags.ShareSgdBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, flags.ShareSgdBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockSgdClosingOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockSgdClosingOrder.Commit:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + + return nil +} + +// UpdateBotStockSgdCancelByOrderId +// +// @Description: 新加坡股撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockSgdCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockSgdCancelByOrderId.Begin:%v", common.ErrShareSgd, err) + return false, flags.ErrMySqlDB + } + + // 获取订单信息 + var userId int64 + var stockId string + var marketMoneyOld, serviceCostOld, orderNumber decimal.Decimal + if !CheckTypeStatus(typeStatus) { + stockTrade, err := uo.GetBotStockSgdTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockSgdCancelByOrderId.GetBotStockSgdTradeByOrderId:%v", common.ErrShareSgd, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } else { + stockTrade, err := uo.GetBotStockBlockTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockSgdCancelByOrderId.GetBotStockBlockTradeByOrderId:%v", common.ErrShareSgd, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } + + // 用户资产信息 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockThb, err := uo.GetBotUserStockSgdByUserIdAndStockId(session, userId, flags.ShareSgdBasicUnit) + if err != nil || stockThb == nil { + applogger.Error("%v UpdateBotStockSgdCancelByOrderId.GetBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareSgd, err) + return false, flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockThb.UsableNum) // 用户账户可用资产 + frozen = decimal.RequireFromString(stockThb.FrozenNum) // 用户账户冻结资产 + + // 检查用户订单撤单资产 + if usable.IsNegative() || frozen.IsNegative() { + return false, flags.ErrShareNine + } + if stockId != flags.ShareSgdBasicUnit { + stockFThb, err := uo.GetBotUserStockSgdByUserIdAndStockId(session, userId, stockId) + if err != nil { + applogger.Error("%v UpdateBotStockSgdCancelByOrderId.GetBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareSgd, err) + return false, flags.ErrPublicFour + } + usableNo = decimal.RequireFromString(stockFThb.UsableNum) // 用户非账户可用资产 + frozenNo = decimal.RequireFromString(stockFThb.FrozenNum) // 用户非账户冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("用户原始可用资金:%v", usable) + applogger.Debug("用户原始冻结资金:%v", frozen) + applogger.Debug("用户原始可用非资金:%v", usableNo) + applogger.Debug("用户原始冻结非资金:%v", frozenNo) + } + + // 更新订单信息 + var entrustKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + botStockTrade := orders.BotStockSgdCancelByOrderId(ctx) + if err = uo.UpdateBotStockSgdTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockSgdCancelByOrderId.UpdateBotStockSgdTradeByOrderId:%v", common.ErrShareSgd, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareSgdEntrust + userKey = setting.ShareSgdSubscribe + adminKey = setting.AdminShareSgdSubscribe + } else { + botStockTrade := orders.BotStockBlockCancelByOrderId(ctx) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockSgdCancelByOrderId.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareSgd, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareBlkEntrust + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // Operational Spot Asset Table + totalMoney := marketMoneyOld.Add(serviceCostOld) // 订单总金额 + + // update total asset data + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + usableNew = usable.Add(totalMoney) // 用户总资产 + frozenNew = frozen.Sub(totalMoney) // 用户冻结资产 + if stockId != flags.ShareSgdBasicUnit { + usableNoNew = usableNo.Sub(orderNumber) // 用户非可用资产 + frozenNoNew = frozenNo // 用户非冻结资产 + } + + // 检查用户订单撤单资产 + if frozenNew.IsNegative() || usableNoNew.IsNegative() { + return false, flags.ErrShareNine + } + if !flags.CheckSetting { + applogger.Debug("用户撤单可用总资产:%v", usableNew) + applogger.Debug("用户撤单冻结总资产:%v", frozenNew) + applogger.Debug("用户非撤单可用总资产:%v", usableNoNew) + applogger.Debug("用户非撤单冻结总资产:%v", frozenNoNew) + } + + // 更新资产信息和非资产信息 + userStockTHB := orders.UpdateBotUserStockSgd(ctx, usableNew.String(), frozenNew.String()) + if err = uo.UpdateBotUserStockSgdByUserIdAndStockId(session, userId, flags.ShareSgdBasicUnit, userStockTHB); err != nil { + applogger.Error("%v UpdateBotStockSgdCancelByOrderId.SGD.UpdateBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareSgd, err) + return false, flags.ErrMySqlDB + } + if stockId != flags.ShareSgdBasicUnit { + userStockFTHB := orders.UpdateBotUserStockSgd(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = uo.UpdateBotUserStockSgdByUserIdAndStockId(session, userId, stockId, userStockFTHB); err != nil { + applogger.Error("%v UpdateBotStockSgdCancelByOrderId.UpdateBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareSgd, err) + return false, flags.ErrMySqlDB + } + } + + // 删除订单缓存列表 + if err = Reds.HDel(context.Background(), entrustKey, orderId).Err(); err != nil { + applogger.Error("%v UpdateBotStockSgdCancelByOrderId.HDel:%v", common.ErrShareSgd, err) + return false, flags.ErrCacheDB + } + + // 更新用户订阅订单缓存列表 + userSubKey := virtual.OrderIdListKey(userKey, userId) + if err = share.UpdateShareSgdHashByOrderId(Reds, orderId, userSubKey, flags.Cancel); err != nil { + applogger.Error("%v UpdateBotStockSgdCancelByOrderId.%v:%v", common.ErrShareSgd, userKey, err) + return false, flags.ErrCacheDB + } + + // 更新管理员订阅订单缓存列表 + if err = UpdateShareSgdSubscribeHashStatusByOrderId(orderId, adminKey, flags.Cancel, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockSgdCancelByOrderId.%v:%v", common.ErrShareSgd, adminKey, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockSgdCancelByOrderId.Commit:%v", common.ErrShareSgd, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockSgdStopByOrderId +// +// @Description: 新加坡股设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockSgdStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockSgdStopByOrderId.NewSession:%v", common.ErrShareSgd, err) + return false, flags.ErrMySqlDB + } + + // 设置止盈止损 + var userId int64 + if order.StopType == 1 { + // 下单信息 + checkBool, stopWinPrice, stopLossPrice, err := uo.UpdateVoteStopType(order) + if err != nil { + applogger.Error("%v UpdateBotStockSgdStopByOrderId.UpdateVoteStopType:%v", common.ErrShareSgd, err) + return false, err + } + if !flags.CheckSetting { + applogger.Debug("当前止盈止损数据:%v,%v,%v", checkBool, stopWinPrice, stopLossPrice) + } + + // 止盈止损判定 + var tradeType int + var limitOrMarketPrice decimal.Decimal + if !CheckTypeStatus(order.Type) { + trade, err := uo.GetBotStockSgdTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockSgdStopByOrderId.GetBotStockSgdTradeByOrderIdOrStatus:%v", common.ErrShareSgd, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareSgdVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockSgdStopByOrderId.UpdateShareSgdVoteDealType:%v", common.ErrShareSgd, err) + return false, err + } + } else { + trade, err := uo.GetBotStockBlockTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockSgdStopByOrderId.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareSgd, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareBlockVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockSgdStopByOrderId.UpdateShareBlockVoteDealType:%v", common.ErrShareSgd, err) + return false, err + } + } + if !flags.CheckSetting { + applogger.Debug("当前开仓价格:%v", limitOrMarketPrice) + } + + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(int64(tradeType), stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v UpdateBotStockSgdStopByOrderId.VoteTradeType:%v", common.ErrShareSgd, err) + return false, err + } + } else { + order.StopLossPrice = decimal.Zero.String() + order.StopWinPrice = decimal.Zero.String() + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[userId] + if ok { + return false, flags.ErrPublicServe + } + + // 更新订单表 + var positionKey string + if !CheckTypeStatus(order.Type) { + botStockTrade := orders.BotStockSgdStopByOrderId(ctx, order) + if err = uo.UpdateBotStockSgdTradeByOrderId(session, order.OrderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockSgdStopByOrderId.UpdateBotStockSgdTradeByOrderId:%v", common.ErrShareSgd, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareSgdPosition + } else { + botStockTrade := orders.BotStockBlockStopByOrderId(ctx, order) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, order.OrderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockSgdStopByOrderId.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareSgd, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareBlkPosition + } + + // 挂单缓存队列 + if err = share.UpdateShareSgdStopByOrderId(Reds, order, positionKey, flags.Position); err != nil { + applogger.Error("%v UpdateBotStockSgdStopByOrderId.UpdateShareSgdStopByOrderId:%v", common.ErrShareSgd, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockSgdStopByOrderId.Commit:%v", common.ErrShareSgd, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockSgdClosingByOrderId +// +// @Description: 新加坡股用户平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockSgdClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.SgdMarket) { + return false, flags.ErrStopTread + } + + // 1、查询持仓缓存列表数据并清理对应缓存 + var positionKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + positionKey = setting.MarketShareSgdPosition + userKey = setting.ShareSgdSubscribe + adminKey = setting.AdminShareSgdSubscribe + } else { + positionKey = setting.MarketShareBlkPosition + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + var entrustCache *share.ShareSgdTallyCache + entrust, err := Reds.HGet(context.Background(), positionKey, orderId).Result() + if err != nil { + applogger.Error("%v UpdateBotStockSgdClosingByOrderId.HGet:%v", common.ErrShareSgd, err) + return false, flags.ErrShareFive + } + var entrustJson share.ShareSgdTallyCache + if err = json.Unmarshal([]byte(entrust), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockSgdClosingByOrderId.Unmarshal:%v", common.ErrShareSgd, err) + return false, flags.ErrCacheDB + } + if orderId == entrustJson.OrderId { + entrustCache = &entrustJson + } + + // 2、判定是否存在平仓订单 + if entrustCache == nil { + return false, flags.ErrShareFive + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[entrustJson.UserId] + if ok { + return false, flags.ErrPublicServe + } + + // 市场设置交易时间(T+0,T+1,T+2s......) + if !CheckShareSystemTime(entrustCache.ClosingTime) { + return false, flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("手动平仓:%v", entrustCache) + } + + // 3、当前最新价格 + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Sgd, entrustCache.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareSgdTheLatestPrice(subKey, entrustCache.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockSgdClosingByOrderId.GetShareSgdTheLatestPrice:%v", common.ErrShareSgd, err) + return false, flags.ErrStopTread + } + + // 4、平仓处理 + if err = StockSgdClosingOrder(ctx, Msql, orderId, closingPrice.String(), entrustCache.Order); err != nil { + applogger.Error("%v UpdateBotStockSgdClosingByOrderId.StockSgdClosingOrder:%v", common.ErrShareSgd, err) + return false, err + } + + // 5、清理持仓订单信息 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), positionKey, orderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockSgdClosingByOrderId.HDel:%v", common.ErrShareSgd, err) + return false, flags.ErrCacheDB + } + + // 6、平仓更新订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(userKey, entrustCache.UserId) + if err = UpdateShareSgdSubscribeHashStatusByOrderId(orderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockSgdClosingByOrderId.%v:%v", common.ErrShareSgd, userKey, err) + return false, flags.ErrCacheDB + } + + // 7、平仓更新管理员订阅缓存订单状态 + if err = UpdateShareSgdSubscribeHashStatusByOrderId(orderId, adminKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockSgdClosingByOrderId.%v:%v", common.ErrShareSgd, adminKey, err) + return false, flags.ErrCacheDB + } + + return true, nil +} + +// UpdateBotStockSgdAllClosingByOrderId +// +// @Description: 新加坡股用户一键平仓 +// @receiver uo +// @param ctx +// @param userId +// @return error +func (uo *userOrderRepo) UpdateBotStockSgdAllClosingByOrderId(ctx context.Context, userId int64) error { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.SgdMarket) { + return flags.ErrStopTread + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe + } + + // 1、查询当前用户所有订单 + orderMap, err := uo.GetBotStockSgdTradeByUserId(userId) + if err != nil { + applogger.Error("%v UpdateBotStockSgdAllClosingByOrderId.GetBotStockSgdTradeByUserId:%v", common.ErrShareSgd, err) + return flags.ErrMySqlDB + } + + // 2、查询持仓缓存列表数据-1、清理持仓列表缓存 2、处理平仓数据 3、清理订单ID缓存列表 + entrust, err := Reds.HGetAll(context.Background(), setting.MarketShareSgdPosition).Result() + if err != nil { + applogger.Error("%v UpdateBotStockSgdAllClosingByOrderId.HGetAll:%v", common.ErrShareSgd, err) + return flags.ErrShareFive + } + + // 3、循环检查股票交易对最新价格(有一个查询不到既不能平仓) + var entrustList []share.ShareSgdTallyCache + closePriceMap := make(map[string]decimal.Decimal) + for key, value := range entrust { + var entrustJson share.ShareSgdTallyCache + if err = json.Unmarshal([]byte(value), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockSgdAllClosingByOrderId.Unmarshal:%v", common.ErrShareSgd, err) + return flags.ErrStopTread + } + _, ok := orderMap[entrustJson.OrderId] + if ok { + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Sgd, entrustJson.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareSgdTheLatestPrice(subKey, entrustJson.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockSgdAllClosingByOrderId.GetShareThaTheLatestPrice:%v", common.ErrShareSgd, err) + return flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("订阅Key:%v,最新价格:%v,订单ID:%v", subKey, closingPrice, entrustJson.OrderId) + } + + closePriceMap[key] = closingPrice + entrustList = append(entrustList, entrustJson) + } + } + + // 4、股票一键平仓 + for _, value := range entrustList { + closePrice, ok := closePriceMap[value.OrderId] + if ok { + // 平仓 + if err = StockSgdClosingOrder(ctx, uo.data.mysqlDB, value.OrderId, closePrice.String(), value.Order); err != nil { + applogger.Error("%v UpdateBotStockSgdAllClosingByOrderId.StockSgdClosingOrder:%v", common.ErrShareSgd, err) + return err + } + + // 清理持仓缓存列表 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), setting.MarketShareSgdPosition, value.OrderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockSgdAllClosingByOrderId.HDel:%v", common.ErrShareSgd, err) + return flags.ErrCacheDB + } + + // 平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareSgdSubscribe, value.UserId) + if err = UpdateShareSgdSubscribeHashStatusByOrderId(value.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockSgdAllClosingByOrderId.ShareSgdSubscribe:%v", common.ErrShareSgd, err) + return flags.ErrCacheDB + } + + // 平仓更新管理员订阅订单状态 + if err = UpdateShareSgdSubscribeHashStatusByOrderId(value.OrderId, setting.AdminShareSgdSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockSgdAllClosingByOrderId.AdminShareSgdSubscribe:%v", common.ErrShareSgd, err) + return flags.ErrCacheDB + } + } + } + + return nil +} + +// GetBotStockSgdTradeByUserId +// +// @Description: +// @receiver uo +// @param ctx +// @param userId +// @return map[string]string +// @return error +func (uo *userOrderRepo) GetBotStockSgdTradeByUserId(userId int64) (map[string]string, error) { + var botStockSgdTrade []models.BotStockSgdTrade + if err := uo.data.mysqlDB.Table(flags.BotStockSgdTrade). + Where("user_id = ?", userId). + Where("status = 1"). + Find(&botStockSgdTrade); err != nil { + return nil, err + } + + botMap := make(map[string]string) + for _, value := range botStockSgdTrade { + botMap[value.OrderId] = value.OrderId + } + + return botMap, nil +} + +// GetShareSgdTheLatestPrice +// +// @Description: +// @receiver uo +// @param ctx +// @param subKey +// @param tradeType +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) GetShareSgdTheLatestPrice(subKey string, tradeType int64) (decimal.Decimal, error) { + priceNew, err := share.ShareSgdSubMarketPrice(subKey) + if err != nil { + applogger.Error("%v GetShareSgdTheLatestPrice.ShareSgdSubMarketPrice:%v", common.ErrShareSgd, err) + return decimal.Decimal{}, err + } + + priceS := decimal.RequireFromString(priceNew) + + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tradeType { + case flags.TradeTypeBuy: // 买涨 + openPrice = priceS.Sub(difference) // 开仓价格 + case flags.TradeTypeSell: // 买跌 + openPrice = priceS.Add(difference) // 开仓价格 + default: + + } + + return openPrice, nil +} + +// GetBotStockSgdTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @return *models.BotStockSgdTrade +// @return error +func (uo *userOrderRepo) GetBotStockSgdTradeByOrderId(session *xorm.Session, orderId string) (*models.BotStockSgdTrade, error) { + var botStockSgdTrade []models.BotStockSgdTrade + if err := session.Table(flags.BotStockSgdTrade). + Where("order_id = ?", orderId). + Find(&botStockSgdTrade); err != nil { + return nil, err + } + + for _, value := range botStockSgdTrade { + return &value, nil + } + + return nil, nil +} + +// GetBotUserStockSgdByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @return *models.BotUserStockSgd +// @return error +func (uo *userOrderRepo) GetBotUserStockSgdByUserIdAndStockId(session *xorm.Session, userId int64, stockId string) (*models.BotUserStockSgd, error) { + var stockTha []models.BotUserStockSgd + if err := session.Table(flags.BotUserStockSgd). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&stockTha); err != nil || len(stockTha) <= 0 { + return nil, err + } + + for _, value := range stockTha { + return &value, nil + } + + return nil, nil +} + +// UpdateBotStockSgdTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotStockSgdTradeByOrderId(session *xorm.Session, orderId string, stock models.BotStockSgdTrade) error { + _, err := session.Table(flags.BotStockSgdTrade). + Where("order_id = ?", orderId). + Update(&stock) + + if err != nil { + return err + } + + return nil +} + +// CreateBotStockSgdTrade +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param trade +// @return error +func (uo *userOrderRepo) CreateBotStockSgdTrade(session *xorm.Session, trade models.BotStockSgdTrade) error { + _, err := session.Table(flags.BotStockSgdTrade).Insert(&trade) + if err != nil { + return err + } + + return nil +} + +// CreateBotUserStockSgdFTHB +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param stock +// @return error +func (uo *userOrderRepo) CreateBotUserStockSgdFTHB(session *xorm.Session, stock models.BotUserStockSgd) error { + _, err := session.Table(flags.BotUserStockSgd).Insert(&stock) + if err != nil { + return err + } + + return nil +} + +// UpdateBotUserStockSgdByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotUserStockSgdByUserIdAndStockId(session *xorm.Session, userId int64, stockId string, stock models.BotUserStockSgd) error { + _, err := session.Table(flags.BotUserStockSgd). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&stock) + if err != nil { + return err + } + + return nil +} + +// StockSgdVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) StockSgdVoteDealType(order structure.ShareOrder) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + return limitOrMarketPrice, nil +} + +// UpdateShareSgdVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) UpdateShareSgdVoteDealType(order *models.BotStockSgdTrade) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + if len(order.DealPrice) != 0 { + dealPrice := decimal.RequireFromString(order.DealPrice) + if !dealPrice.IsZero() { + limitOrMarketPrice = dealPrice + } + } + + return limitOrMarketPrice, nil +} + +// VerifyBotStockSgdTradeOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @return string +// @return error +func (uo *userOrderRepo) VerifyBotStockSgdTradeOrderId(session *xorm.Session) (string, error) { + var orderId string + for { + // 生成订单ID + orderId = orders.CreateRandCodeOrder(10) + + var orderList []models.BotStockSgdTrade + err := session.Table(flags.BotStockSgdTrade). + Where("order_id = ?", orderId). + Find(&orderList) + + if err != nil || len(orderList) > 0 { + applogger.Error("%v VerifyBotStockSgdTradeOrderId.Find:%v", common.ErrShareSgd, err) + continue + } + + break + } + + return orderId, nil +} + +// GetBotStockSgdTradeByOrderIdOrStatus +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param status +// @return *models.BotStockSgdTrade +// @return error +func (uo *userOrderRepo) GetBotStockSgdTradeByOrderIdOrStatus(session *xorm.Session, orderId string, status int) (*models.BotStockSgdTrade, error) { + var botStockSgdTrade []models.BotStockSgdTrade + if err := session.Table(flags.BotStockSgdTrade). + Where("order_id = ?", orderId). + Where("`status` = ?", status). + Find(&botStockSgdTrade); err != nil { + return nil, err + } + + for _, value := range botStockSgdTrade { + return &value, nil + } + + return nil, nil +} diff --git a/internal/data/order_share_tha.go b/internal/data/order_share_tha.go new file mode 100644 index 0000000..b557c11 --- /dev/null +++ b/internal/data/order_share_tha.go @@ -0,0 +1,1511 @@ +package data + +import ( + "context" + "encoding/json" + "github.com/go-xorm/xorm" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" + + orders "matchmaking-system/internal/data/convert" + models "matchmaking-system/internal/pkg/model" +) + +// GetBotStockThaTradeList +// +// @Description: 泰股订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param userId +// @param status +// @return []*models.BotStockThaTrade +// @return int64 +// @return error +func (uo *userOrderRepo) GetBotStockThaTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockThaTrade, int64, error) { + totalCount, err := uo.data.mysqlDB.Table(flags.BotStockThaTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Count() + if err != nil { + return nil, 0, flags.ErrMySqlDB + } + if totalCount == 0 { + return nil, 0, nil + } + var stockList []*models.BotStockThaTrade + if err = uo.data.mysqlDB.Table(flags.BotStockThaTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Limit(int(pageSize), int(pageCount)). + Desc(GetOrderByStatusSort(status)). + Find(&stockList); err != nil { + return nil, 0, flags.ErrMySqlDB + } + + var stockUpdateList []*models.BotStockThaTrade + for _, value := range stockList { + value.KeepDecimal = GetKeepDecimal(flags.StockTGSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockTGSystemSetUpKey, value.StockId) + stockUpdateList = append(stockUpdateList, value) + } + + return stockUpdateList, totalCount, nil +} + +// PlacingStockThaOrders +// +// @Description: 泰股下单 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) PlacingStockThaOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) { + // 1、通知下单订阅 + symbol := order.StockId + timeValue := QuerySystemCache(flags.ShareThaMarketType) // 市场开闭盘时间 + if !utils.CheckInPlateTime(timeValue) { + return flags.SetNull, flags.ErrStopTread + } + SubscribeThaHSetCodeList(symbol, false) // 同步写入股票列表缓存 + SubscribeThaCloseNewPrice(symbol) // 同步股票实时行情价 + + // 判定是否存在欠款订单 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe.Error(), nil + } + + order = PryNumInit(order) // 杠杆初始化 + subKey := publicData.SymbolCache(flags.Tha, symbol, flags.TradeTypePrice) + + // 泰股市场系统设置 + if CheckGlobalTread(flags.ThaMarket) { + return flags.SetNull, flags.ErrStopTread + } + + // 全局设置停止交易操作 + var blockTime time.Time + var priceNew, userKey, adminKey string + if !CheckTypeStatus(order.Type) { + userKey = setting.ShareThaSubscribe + adminKey = setting.AdminShareThaSubscribe + } else { + // 判定:1、是否开启股票交易 2、是否在交易时间内 3、是否达到最小交易量 + check, openPrice, minNum, endTime := CheckBlockTread(flags.ThaBlk, symbol) + if check { + return flags.SetNull, flags.ErrShareSeven + } + if minNum > utils.StringToInt(order.OrderNumber) { + return flags.SetNull, flags.ErrShareSix + } + priceNew = openPrice // 开仓价格 + blockTime = endTime // 平仓时间 + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + flatRatio := GetCacheForcedClosure(flags.StockTGSystemSetUpKey, symbol) // 设置强平阈值 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.ThaMarket, userId) // 股票市场系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), // 强平阈值 + Status: leverStatus.Status, // 杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + order.System = system + + // 2、股票下单判定 + // 下单判定设置(false无设置|true止盈止损) + checkBool, stopWinPrice, stopLossPrice, err := StockThaVoteStopType(order) + if err != nil { + applogger.Error("%v PlacingStockThaOrders.StockVoteStopType:%v", common.ErrShareTha, err) + return flags.SetNull, err + } + // 下单判定设置(限价|市价) + limitOrMarketPrice, err := uo.StockThaVoteDealType(order) + if err != nil { + applogger.Error("%v PlacingStockThaOrders.StockVoteDealType:%v", common.ErrShareTha, err) + return flags.SetNull, err + } + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(order.TradeType, stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v PlacingStockThaOrders.VoteTradeType:%v", common.ErrShareTha, err) + return flags.SetNull, err + } + + // 3、订单持久化录入(并处理资产信息) + pryNum := SystemDealWithLever(order) + orderId, err := uo.StockThaOrderWriteDB(ctx, userId, order, limitOrMarketPrice, pryNum) + if err != nil || len(orderId) == 0 { + applogger.Error("%v PlacingStockThaOrders.StockOrderWriteDB:%v", common.ErrShareTha, err) + return flags.SetNull, err + } + + // 4、处理订单信息 + chg := GetShareChgTha(flags.Tha, order.StockId) // 涨跌幅标识值 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.ThaMarket, time.Now()) // 开盘时间 + marketStatus, shareOrder, err := share.ShareThaCacheDeal(ctx, userId, orderId, subKey, order, chg, priceNew, closingTime, blockTime) + if err != nil || shareOrder == nil { + applogger.Error("%v PlacingStockThaOrders.ShareThaCacheDeal:%v", common.ErrShareTha, err) + return flags.SetNull, err + } + + // 计算保证金 = 订单价格 * 订单数量 / 杠杆 + shareOrder.Order.MarketMoney = limitOrMarketPrice.Mul(decimal.RequireFromString(order.OrderNumber)).Div(pryNum).String() + if !flags.CheckSetting { + applogger.Debug("订单ID:%v", shareOrder.OrderId) + applogger.Debug("订单交易对:%v", shareOrder.Symbol) + applogger.Debug("订单状态:%v", shareOrder.Status) + applogger.Debug("订单用户ID:%v", shareOrder.UserId) + applogger.Debug("开盘价:%v", shareOrder.OpenPrice) + applogger.Debug("收盘价:%v", shareOrder.ClosingPrice) + applogger.Debug("下单信息:%v", shareOrder.Order) + } + + // 6、订单(挂单|持仓)缓存列表,等待队列计算 + if err = share.ShareThaHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v PlacingStockThaOrders.ShareThaHashUserOrder:%v", common.ErrShareTha, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 7、用户订阅股票订单信息 + orderIdKey := virtual.OrderIdListKey(userKey, userId) + if err = share.ShareThaHashUserOrder(Reds, orderIdKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockThaOrders.%v:%v", common.ErrShareTha, userKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 8、管理员订阅订单信息 + if err = share.ShareThaHashUserOrder(Reds, adminKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockThaOrders.%v:%v", common.ErrShareTha, adminKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + return orderId, nil +} + +// StockThaOrderWriteDB +// +// @Description: 泰股下单操作 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) StockThaOrderWriteDB(ctx context.Context, userId int64, order structure.ShareOrder, limitOrMarketPrice, lever decimal.Decimal) (string, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockThaOrderWriteDB.Begin:%v", common.ErrShareTha, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 获取当前下单用户的资产 + var usableOld, frozenOld decimal.Decimal + stockThb, err := uo.GetBotUserStockThaByUserIdAndStockId(session, userId, flags.ShareThaBasicUnit) + if err != nil || stockThb == nil { + applogger.Error("%v StockThaOrderWriteDB.GetBotUserStockThaByUserIdAndStockId:%v", common.ErrShareTha, err) + return flags.SetNull, flags.ErrMySqlDB + } + usableOld = decimal.RequireFromString(stockThb.UsableNum) + frozenOld = decimal.RequireFromString(stockThb.FrozenNum) + + // 检查用户订单下单资产 + if usableOld.IsZero() || usableOld.IsNegative() || frozenOld.IsNegative() { + return flags.SetNull, flags.ErrShareOne + } + + // 获取当前系统下单用户的非资产 + var usableFOld, frozenFOld decimal.Decimal + stockFThb, err := uo.GetBotUserStockThaByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockThaOrderWriteDB.FeiTHB:%v", common.ErrShareTha, err) + return flags.SetNull, flags.ErrMySqlDB + } + if stockFThb != nil { + usableFOld = decimal.RequireFromString(stockFThb.UsableNum) + frozenFOld = decimal.RequireFromString(stockFThb.FrozenNum) + } + if !flags.CheckSetting { + applogger.Debug("下单可用资产:%v", usableOld) + applogger.Debug("下单冻结资产:%v", frozenOld) + applogger.Debug("下单可用非资产:%v", usableFOld) + applogger.Debug("下单冻结非资产:%v", frozenFOld) + } + + // 整理当前下单信息 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 订单手续费 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 订单数量 + marketMoney := orderNumber.Mul(limitOrMarketPrice).Div(lever) // 订单金额(杠杆下单) = 订单数量 * 交易价格 / 杠杆 + totalMoney := marketMoney.Add(serviceCost) // 订单总金额 + order.MarketMoney = marketMoney.String() // 市值金额即为保证金 + + // 检查订单ID是否存在,新增下单信息 + var orderId string + if !CheckTypeStatus(order.Type) { + orderId, err = uo.VerifyBotStockThaTradeOrderId(session) + if err != nil { + applogger.Error("%v StockThaOrderWriteDB.VerifyBotStockThaTradeOrderId:%v", common.ErrShareTha, err) + return flags.SetNull, err + } + trade := orders.BotStockThaTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockThaTrade(session, trade); err != nil { + applogger.Error("%v StockThaOrderWriteDB.CreateBotStockThaTrade:%v", common.ErrShareTha, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + orderId, err = uo.VerifyBotStockBlockTradeOrderId(session) + if err != nil { + applogger.Error("%v StockThaOrderWriteDB.VerifyBotStockBlockTradeOrderId:%v", common.ErrShareTha, err) + return flags.SetNull, err + } + trade := orders.BotStockBlockTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockBlockTrade(session, trade); err != nil { + applogger.Error("%v StockThaOrderWriteDB.CreateBotStockBlockTrade:%v", common.ErrShareTha, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + // 下单判定 + residue := usableOld.Sub(totalMoney).Div(usableOld) + if usableOld.Cmp(totalMoney) <= 0 || residue.Cmp(utils.DecimalsStrInt()) <= 0 { + return flags.SetNull, flags.ErrPublicTow + } + + var usableNew, frozenNew, usableFNew, frozenFNew decimal.Decimal + usableNew = usableOld.Sub(totalMoney) // 可用资产 + frozenNew = frozenOld.Add(totalMoney) // 冻结资产 + if order.StockId != flags.ShareThaBasicUnit { + usableFNew = usableFOld.Add(orderNumber) // 可用非资产 + frozenFNew = frozenFOld // 冻结非资产 + } + // 检查用户订单下单资产 + if usableNew.IsNegative() { + return flags.SetNull, flags.ErrPublicTow + } + + // 下单更新资产信息 + stockTHBModel := orders.UpdateBotUserStockTha(ctx, usableNew.String(), frozenNew.String()) + err = uo.UpdateBotUserStockThaByUserIdAndStockId(session, userId, flags.ShareThaBasicUnit, stockTHBModel) + if err != nil { + applogger.Error("%v StockThaOrderWriteDB.UpdateBotUserStockThaByUserIdAndStockId:%v", common.ErrShareTha, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 下单(新增|更新)非资产信息 + if stockFThb == nil { + stockFTHBModel := orders.CreateBotUserStockTha(ctx, userId, order.StockId, usableFNew.String(), frozenFNew.String()) + err = uo.CreateBotUserStockThaFTHB(session, stockFTHBModel) + if err != nil { + applogger.Error("%v StockThaOrderWriteDB.CreateBotUserStockThaFTHB:%v", common.ErrShareTha, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + stockFTHBModel := orders.UpdateBotUserStockTha(ctx, usableFNew.String(), frozenFNew.String()) + err = uo.UpdateBotUserStockThaByUserIdAndStockId(session, userId, order.StockId, stockFTHBModel) + if err != nil { + applogger.Error("%v StockThaOrderWriteDB.UpdateBotUserStockThaByUserIdAndStockId:%v", common.ErrShareTha, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockThaOrderWriteDB.Commit:%v", common.ErrShareTha, err) + return flags.SetNull, flags.ErrMySqlDB + } + + return orderId, nil +} + +// StockThaOpenOrder +// +// @Description: 泰股系统开仓 +// @param ctx +// @param db +// @param userId +// @param orderId +// @param openPrice +// @param order +// @return error +func StockThaOpenOrder(ctx context.Context, db *xorm.EngineGroup, userId int64, orderId, openPrice string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockThaOpenOrder.NewSession:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockThb, err := Uo.GetBotUserStockThaByUserIdAndStockId(session, userId, flags.ShareThaBasicUnit) + if err != nil || stockThb == nil { + applogger.Error("%v StockThaOpenOrder.GetBotUserStockThaByUserIdAndStockId:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockThb.UsableNum) // 用户可用资产 + frozen = decimal.RequireFromString(stockThb.FrozenNum) // 用户冻结资产 + + // 检查用户订单开仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrPublicThree + } + + if order.StockId != flags.ShareThaBasicUnit { + stockFThb, err := Uo.GetBotUserStockThaByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockThaOpenOrder.GetBotUserStockThaByUserIdAndStockId:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(stockFThb.UsableNum) // 用户非可用资产 + frozenNo = decimal.RequireFromString(stockFThb.FrozenNum) // 用户非冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + + // 转换股票下单信息 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 下单股数 + markerMoney := decimal.RequireFromString(order.MarketMoney) // 下单金额 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 下单手续费 + totalMoney := markerMoney.Add(serviceCost) // 下单总金额 = (下单手续费 + 下单金额) + openOrderPrice := decimal.RequireFromString(openPrice) // 开盘价格 + if !flags.CheckSetting { + applogger.Debug("下单订单数量:%v", orderNumber) + applogger.Debug("下单订单金额:%v", markerMoney) + applogger.Debug("下单订单手续费:%v", serviceCost) + applogger.Debug("下单订单总金额:%v", totalMoney) + } + + // 手续费记录 + openPriceNew := openOrderPrice.Mul(orderNumber).String() // 开仓手续费 = 开仓价格 * 股数 * 开仓手续费 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareThaMarketType, flags.OpenBrokType, orderId, openPriceNew) + if err != nil { + applogger.Error("%v StockThaOpenOrder.CalculateHandlingFeesShare:%v", common.ErrShareTha, err) + return err + } + openServiceCost := decimal.RequireFromString(cost) // 开仓手续费 + openMarkerMoney := openOrderPrice.Mul(orderNumber).Div(decimal.RequireFromString(order.PryNum)) // 开仓金额 = 开仓价格 * 股数 / 杠杆 + openTotalMoney := openMarkerMoney.Add(openServiceCost) // 开仓总金额 = 开仓金额 + 开仓手续费 + floatPrice := totalMoney.Sub(openTotalMoney) // 计算容差 = 下单总额 - 开仓总额 + if !flags.CheckSetting { + applogger.Debug("开仓订单价格:%v", openOrderPrice) + applogger.Debug("开仓手续费:%v", openServiceCost) + applogger.Debug("开仓总金额:%v", openTotalMoney) + applogger.Debug("下单开仓总金额容差值:%v", floatPrice) + } + + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + usableNew = usable.Add(floatPrice) // 可用资产(处理容差值) + frozenNew = frozen.Sub(totalMoney).Add(openMarkerMoney) // 冻结资产(处理容差值)---> 当前冻结金额 = 原冻结金额 - 下单总额 + if order.StockId != flags.ShareThaBasicUnit { + usableNoNew = usableNo // 非可用资产 + frozenNoNew = frozenNo // 非冻结资产 + } + + // 检查用户订单开仓资产 + if frozenNew.IsNegative() || usableNew.IsNegative() { + return flags.ErrPublicThree + } + if !flags.CheckSetting { + applogger.Debug("下单后用户可用资产:%v", usableNew) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + } + + // 处理资产信息 + userStockThb := orders.UpdateBotUserStockTha(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockThaByUserIdAndStockId(session, userId, flags.ShareThaBasicUnit, userStockThb); err != nil { + applogger.Error("%v StockThaOpenOrder.USD.UpdateBotUserStockThaByUserIdAndStockId:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + + // 更新非资产信息 + if order.StockId != flags.ShareThaBasicUnit { + userStockFThb := orders.UpdateBotUserStockTha(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = Uo.UpdateBotUserStockThaByUserIdAndStockId(session, userId, order.StockId, userStockFThb); err != nil { + applogger.Error("%v StockThaOpenOrder.UpdateBotUserStockThaByUserIdAndStockId:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + } + + // 返佣记录|资金信息|资金详情信息 + if err = Uo.ShareThaRebateCalculation(ctx, session, int(userId), flags.ShareThaMarketType, flags.OpenBrokType, flags.OpenMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockThaOpenOrder.ShareUsRebateCalculation:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + + //处理订单信息(成交价|仓位|开仓时间|订单总金额|手续费|持仓状态) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateOpenBotStockThaTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarkerMoney.String()) + if err = Uo.UpdateBotStockThaTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockThaOpenOrder.UpdateBotStockThaTradeByOrderId:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockThaLog + qData0 := orders.CreatBotUserStockThaLog(ctx, userId, flags.CostMoney, flags.ShareThaBasicUnit, NegativeValue(openServiceCost.String()), orderId) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockThaLog(ctx, userId, flags.Freeze, flags.ShareThaBasicUnit, NegativeValue(openMarkerMoney.String()), orderId) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockThaLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockThaLogList(session, list); err != nil { + applogger.Error("%v StockThaOpenOrder.CreatBotUserStockThaLogList:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateOpenBotStockBlockTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarkerMoney.String()) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockThaOpenOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareThaBasicUnit, NegativeValue(openServiceCost.String()), orderId, order.Type) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Freeze, flags.ShareThaBasicUnit, NegativeValue(openMarkerMoney.String()), orderId, order.Type) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId, order.Type) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockThaOpenOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockThaOpenOrder.Commit:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + + return nil +} + +// StockThaClosingOrder +// +// @Description: 泰股系统平仓 +// @param ctx +// @param db +// @param orderId +// @param price +// @param order +// @return error +func StockThaClosingOrder(ctx context.Context, db *xorm.EngineGroup, orderId string, price string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockThaClosingOrder.NewSession:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + + // 查询订单信息 + var userId int64 + var dealPrice, orderNumber, totalAmount, serviceCost, markerMoney decimal.Decimal + if !CheckTypeStatus(order.Type) { + tread, err := Uo.GetBotStockThaTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockThaClosingOrder.GetBotStockThaTradeByOrderIdOrStatus:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + markerMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓下单金额 + } else { + tread, err := Uo.GetBotStockBlockTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockThaClosingOrder.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + markerMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓下单金额 + } + + if !flags.CheckSetting { + applogger.Debug("下单开仓用户Id:%v", userId) + applogger.Debug("下单开仓开仓价格:%v", dealPrice) + applogger.Debug("下单开仓订单数量:%v", orderNumber) + applogger.Debug("下单开仓总金额:%v", totalAmount) + applogger.Debug("下单开仓手续费:%v", serviceCost) + applogger.Debug("下单开仓开仓金额:%v", markerMoney) + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + userStockThb, err := Uo.GetBotUserStockThaByUserIdAndStockId(session, userId, flags.ShareThaBasicUnit) + if err != nil { + applogger.Error("%v StockThaClosingOrder.GetBotUserStockThaByUserIdAndStockId:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(userStockThb.UsableNum) // 用户可用资金 + frozen = decimal.RequireFromString(userStockThb.FrozenNum) // 用户非冻结资金 + + // 检查用户订单平仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrShareTow + } + + // 查询当前下单用户可用非账户和冻结金额 + if order.StockId != flags.ShareThaBasicUnit { + userStockFThb, err := Uo.GetBotUserStockThaByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockThaClosingOrder.GetBotUserStockThaByUserIdAndStockId:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(userStockFThb.UsableNum) // 用户非可用资金 + frozenNo = decimal.RequireFromString(userStockFThb.FrozenNum) // 用户非冻结资金 + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + + // 手续费处理 + closePrice := decimal.RequireFromString(price) // 平仓价格 + cloePriceCost := closePrice.Mul(orderNumber).String() // 平仓手续费 = 平仓价格 * 股数 * 手续费比例 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareThaMarketType, flags.ClosingBrokType, orderId, cloePriceCost) + if err != nil { + applogger.Error("%v StockThaClosingOrder.CalculateHandlingFeesShare:%v", common.ErrShareTha, err) + return err + } + closeServiceCost := decimal.RequireFromString(cost) + if !flags.CheckSetting { + applogger.Debug("平仓价格:%v", closePrice) + applogger.Debug("平仓手续费手续费:%v", closeServiceCost) + } + + //已经实现盈亏计算公式(已平仓结算方式) + //买涨 已经实现盈亏 = (平仓成交价-开仓成交价)*股数 + //买跌 已经实现盈亏 = (开仓成交价-平仓成交价)*股数 + var usableNew, frozenNew, usableNewNo, frozenNewNo, subPrice, resultPrice decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买涨 + subPrice = closePrice.Sub(dealPrice) + resultPrice = subPrice.Mul(orderNumber) + case flags.TradeTypeSell: // 买跌 + subPrice = dealPrice.Sub(closePrice) + resultPrice = subPrice.Mul(orderNumber) + default: + + } + + // TODO: 判定亏损不能超过 = 保证金 + 平仓手续费 + if resultPrice.IsNegative() { + amountLoss := markerMoney.Sub(closeServiceCost) + if resultPrice.Abs().Cmp(amountLoss) >= 0 { + resultPrice = amountLoss.Neg() + } + } + + // 用户资产账户 + usableNew = usable.Add(resultPrice).Sub(closeServiceCost).Add(markerMoney) // 可用资产 = 原可用资产 + ((正负)盈亏) - 平仓手续费 + 开仓下单金额 + if frozen.Cmp(markerMoney) == -1 { + frozenNew = frozen.Sub(frozen) // 冻结资产 + } else { + frozenNew = frozen.Sub(markerMoney) // 冻结资产 + } + + // 用户非资产账户 + if order.StockId != flags.ShareThaBasicUnit { + usableNewNo = usableNo.Sub(orderNumber) // 可用非资产 = 原可用非资产 - 下单股数 + frozenNewNo = frozenNo // 可用非冻结资产 + } + + // 检查用户订单平仓资产 + if frozenNew.IsNegative() || usableNewNo.IsNegative() { + return flags.ErrShareTow + } + if !flags.CheckSetting { + applogger.Debug("可用资产:%v", usableNew) + applogger.Debug("冻结资产:%v", frozenNew) + applogger.Debug("可用非资产:%v", usableNewNo) + applogger.Debug("冻结非资产:%v", frozenNewNo) + } + + // 平仓(处理资产表(资产)) + userStockUTHB := orders.UpdateBotUserStockTha(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockThaByUserIdAndStockId(session, userId, flags.ShareThaBasicUnit, userStockUTHB); err != nil { + applogger.Error("%v StockThaClosingOrder.THB.UpdateBotUserStockThaByUserIdAndStockId:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + + // 平仓(处理资产表(非资产)) + if order.StockId != flags.ShareThaBasicUnit { + userStockFTHB := orders.UpdateBotUserStockTha(ctx, usableNewNo.String(), frozenNewNo.String()) + if err = Uo.UpdateBotUserStockThaByUserIdAndStockId(session, userId, order.StockId, userStockFTHB); err != nil { + applogger.Error("%v StockThaClosingOrder.UpdateBotUserStockThaByUserIdAndStockId:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + } + + // 平仓(返佣记录表|资产表|资金变动表) + if err = Uo.ShareThaRebateCalculation(ctx, session, int(userId), flags.ShareThaMarketType, flags.ClosingBrokType, flags.CloseMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockThaClosingOrder.ShareUsRebateCalculation:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + + // 平仓(处理订单信息(平仓价|保证金|平仓|订单总金额|平仓手续费|完成订单)) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateCloseBotStockThaTrade(ctx, price, cost) + if err = Uo.UpdateBotStockThaTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockThaClosingOrder.UpdateBotStockThaTradeByOrderId:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockThaLog + qData0 := orders.CreatBotUserStockThaLog(ctx, userId, flags.Thaw, flags.ShareThaBasicUnit, markerMoney.String(), orderId) // 平仓(资金变动明细表(开仓保证金)) + qData1 := orders.CreatBotUserStockThaLog(ctx, userId, flags.CostMoney, flags.ShareThaBasicUnit, NegativeValue(closeServiceCost.String()), orderId) // 平仓(资金变动明细表(-平仓手续费)) + qData2 := orders.CreatBotUserStockThaLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockThaLog(ctx, userId, flags.TransferOut, flags.ShareThaBasicUnit, resultPrice.String(), orderId) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockThaLog(ctx, userId, flags.ChangeInto, flags.ShareThaBasicUnit, resultPrice.String(), orderId) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockThaLogList(session, list); err != nil { + applogger.Error("%v StockThaOpenOrder.CreatBotUserStockThaLog:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateCloseBotStockBlockTrade(ctx, price, cost) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockThaClosingOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Thaw, flags.ShareThaBasicUnit, markerMoney.String(), orderId, order.Type) // 平仓(资金变动明细表(开仓保证金)) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareThaBasicUnit, NegativeValue(closeServiceCost.String()), orderId, order.Type) // 平仓(资金变动明细表(-平仓手续费)) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId, order.Type) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, flags.ShareThaBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, flags.ShareThaBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockThaOpenOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockThaClosingOrder.Commit:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + + return nil +} + +// UpdateBotStockThaCancelByOrderId +// +// @Description: 泰股撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockThaCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockThaCancelByOrderId.Begin:%v", common.ErrShareTha, err) + return false, flags.ErrMySqlDB + } + + // 获取订单信息 + var userId int64 + var stockId string + var marketMoneyOld, serviceCostOld, orderNumber decimal.Decimal + if typeStatus <= 0 { + stockTrade, err := uo.GetBotStockThaTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockThaCancelByOrderId.GetBotStockThaTradeByOrderId:%v", common.ErrShareTha, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } else { + stockTrade, err := uo.GetBotStockBlockTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockThaCancelByOrderId.GetBotStockBlockTradeByOrderId:%v", common.ErrShareTha, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } + + // 获取用户资产信息 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockThb, err := uo.GetBotUserStockThaByUserIdAndStockId(session, userId, flags.ShareThaBasicUnit) + if err != nil || stockThb == nil { + applogger.Error("%v UpdateBotStockThaCancelByOrderId.THB.GetBotUserStockThaByUserIdAndStockId:%v", common.ErrShareTha, err) + return false, flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockThb.UsableNum) // 用户账户可用资产 + frozen = decimal.RequireFromString(stockThb.FrozenNum) // 用户账户冻结资产 + // 检查用户订单撤单资产 + if usable.IsNegative() || frozen.IsNegative() { + return false, flags.ErrShareNine + } + if stockId != flags.ShareThaBasicUnit { + stockFThb, err := uo.GetBotUserStockThaByUserIdAndStockId(session, userId, stockId) + if err != nil { + applogger.Error("%v UpdateBotStockThaCancelByOrderId.GetBotUserStockThaByUserIdAndStockId:%v", common.ErrShareTha, err) + return false, flags.ErrPublicFour + } + usableNo = decimal.RequireFromString(stockFThb.UsableNum) // 用户非账户可用资产 + frozenNo = decimal.RequireFromString(stockFThb.FrozenNum) // 用户非账户冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("用户原始可用资金:%v", usable) + applogger.Debug("用户原始冻结资金:%v", frozen) + applogger.Debug("用户原始可用非资金:%v", usableNo) + applogger.Debug("用户原始冻结非资金:%v", frozenNo) + } + + // 更新订单信息 + var entrustKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + botStockTrade := orders.BotStockThaCancelByOrderId(ctx) + if err = uo.UpdateBotStockThaTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockThaCancelByOrderId.THA.UpdateBotStockThaTradeByOrderId:%v", common.ErrShareTha, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareThaEntrust + userKey = setting.ShareThaSubscribe + adminKey = setting.AdminShareThaSubscribe + } else { + botStockTrade := orders.BotStockBlockCancelByOrderId(ctx) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockThaCancelByOrderId.THA.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareTha, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareBlkEntrust + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // Operational Spot Asset Table + totalMoney := marketMoneyOld.Add(serviceCostOld) // 订单总金额 + + // update total asset data + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + usableNew = usable.Add(totalMoney) // 用户总资产 + frozenNew = frozen.Sub(totalMoney) // 用户冻结资产 + if stockId != flags.ShareThaBasicUnit { + usableNoNew = usableNo.Sub(orderNumber) // 用户非可用资产 + frozenNoNew = frozenNo // 用户非冻结资产 + } + + // 检查用户订单撤单资产 + if frozenNew.IsNegative() || usableNoNew.IsNegative() { + return false, flags.ErrShareNine + } + if !flags.CheckSetting { + applogger.Debug("用户撤单可用总资产:%v", usableNew) + applogger.Debug("用户撤单冻结总资产:%v", frozenNew) + applogger.Debug("用户非撤单可用总资产:%v", usableNoNew) + applogger.Debug("用户非撤单冻结总资产:%v", frozenNoNew) + } + + // 更新资产信息和非资产信息 + userStockTHB := orders.UpdateBotUserStockTha(ctx, usableNew.String(), frozenNew.String()) + if err = uo.UpdateBotUserStockThaByUserIdAndStockId(session, userId, flags.ShareThaBasicUnit, userStockTHB); err != nil { + applogger.Error("%v UpdateBotStockThaCancelByOrderId.UpdateBotUserStockThaByUserIdAndStockId:%v", common.ErrShareTha, err) + return false, flags.ErrMySqlDB + } + if stockId != flags.ShareThaBasicUnit { + userStockFTHB := orders.UpdateBotUserStockTha(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = uo.UpdateBotUserStockThaByUserIdAndStockId(session, userId, stockId, userStockFTHB); err != nil { + applogger.Error("%v UpdateBotStockThaCancelByOrderId.UpdateBotUserStockThaByUserIdAndStockId:%v", common.ErrShareTha, err) + return false, flags.ErrMySqlDB + } + } + + // 删除订单缓存列表 + if err = Reds.HDel(context.Background(), entrustKey, orderId).Err(); err != nil { + applogger.Error("%v UpdateBotStockThaCancelByOrderId.HDel:%v", common.ErrShareTha, err) + return false, flags.ErrCacheDB + } + + // 更新用户订阅订单缓存列表 + userSubKey := virtual.OrderIdListKey(userKey, userId) + if err = share.UpdateShareThaHashByOrderId(Reds, orderId, userSubKey, flags.Cancel); err != nil { + applogger.Error("%v UpdateBotStockThaCancelByOrderId.%v:%v", common.ErrShareTha, userKey, err) + return false, flags.ErrCacheDB + } + + // 更新管理员订阅订单缓存列表 + if err = UpdateShareThaSubscribeHashStatusByOrderId(orderId, adminKey, flags.Cancel, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockThaCancelByOrderId.%v:%v", common.ErrShareTha, adminKey, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockThaCancelByOrderId.Commit:%v", common.ErrShareTha, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockThaStopByOrderId +// +// @Description: 泰股设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockThaStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockThaStopByOrderId.NewSession:%v", common.ErrShareTha, err) + return false, flags.ErrMySqlDB + } + + // 设置止盈止损 + var userId int64 + if order.StopType == 1 { + // 股票下单信息 + checkBool, stopWinPrice, stopLossPrice, err := uo.UpdateVoteStopType(order) + if err != nil { + applogger.Error("%v UpdateBotStockThaStopByOrderId.UpdateVoteStopType:%v", common.ErrShareTha, err) + return false, err + } + if !flags.CheckSetting { + applogger.Debug("当前止盈止损数据:%v,%v,%v", checkBool, stopWinPrice, stopLossPrice) + } + + // 股票设置止盈止损判定 + var tradeType int + var limitOrMarketPrice decimal.Decimal + if !CheckTypeStatus(order.Type) { + trade, err := uo.GetBotStockThaTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockThaStopByOrderId.GetBotStockThaTradeByOrderIdOrStatus:%v", common.ErrShareTha, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareThaVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockThaStopByOrderId.UpdateShareThaVoteDealType:%v", common.ErrShareTha, err) + return false, err + } + } else { + trade, err := uo.GetBotStockBlockTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockThaStopByOrderId.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareTha, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err = uo.UpdateShareBlockVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotStockThaStopByOrderId.UpdateShareBlockVoteDealType:%v", common.ErrShareTha, err) + return false, err + } + } + if !flags.CheckSetting { + applogger.Debug("当前开仓价格:%v", limitOrMarketPrice) + } + + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(int64(tradeType), stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v UpdateBotStockThaStopByOrderId.VoteTradeType:%v", common.ErrShareTha, err) + return false, err + } + } else { + order.StopLossPrice = decimal.Zero.String() + order.StopWinPrice = decimal.Zero.String() + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[userId] + if ok { + return false, flags.ErrPublicServe + } + + // 更新订单信息 + var positionKey string + if !CheckTypeStatus(order.Type) { + botStockTrade := orders.BotStockThaStopByOrderId(ctx, order) + if err = uo.UpdateBotStockThaTradeByOrderId(session, order.OrderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockThaStopByOrderId.UpdateBotStockThaTradeByOrderId:%v", common.ErrShareTha, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareThaPosition + } else { + botStockTrade := orders.BotStockBlockStopByOrderId(ctx, order) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, order.OrderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockThaStopByOrderId.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareTha, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareBlkPosition + } + + // 挂单缓存队列 + if err = share.UpdateShareThaStopByOrderId(Reds, order, positionKey, flags.Position); err != nil { + applogger.Error("%v UpdateBotStockThaStopByOrderId.UpdateShareThaStopByOrderId:%v", common.ErrShareTha, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockThaStopByOrderId.Commit:%v", common.ErrShareTha, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockThaClosingByOrderId +// +// @Description: 泰股用户平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockThaClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.ThaMarket) { + return false, flags.ErrStopTread + } + + // 1、查询持仓缓存列表数据并清理对应缓存 + var positionKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + positionKey = setting.MarketShareThaPosition + userKey = setting.ShareThaSubscribe + adminKey = setting.AdminShareThaSubscribe + } else { + positionKey = setting.MarketShareBlkPosition + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + var entrustCache *share.ShareThaTallyCache + entrust, err := Reds.HGet(context.Background(), positionKey, orderId).Result() + if err != nil { + applogger.Error("%v UpdateBotStockThaClosingByOrderId.HGet:%v", common.ErrShareTha, err) + return false, flags.ErrShareFive + } + var entrustJson share.ShareThaTallyCache + if err = json.Unmarshal([]byte(entrust), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockThaClosingByOrderId.Unmarshal:%v", common.ErrShareTha, err) + return false, flags.ErrCacheDB + } + if orderId == entrustJson.OrderId { + entrustCache = &entrustJson + } + + // 2、判定是否存在平仓订单 + if entrustCache == nil { + return false, flags.ErrShareFive + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[entrustJson.UserId] + if ok { + return false, flags.ErrPublicServe + } + + // 市场设置交易时间(T+0,T+1,T+2s......) + if !CheckShareSystemTime(entrustCache.ClosingTime) { + return false, flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("手动平仓:%v", entrustCache) + } + + // 3、获取当前最新价格 + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Tha, entrustCache.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareThaTheLatestPrice(subKey, entrustCache.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockThaClosingByOrderId.GetShareThaTheLatestPrice:%v", common.ErrShareTha, err) + return false, flags.ErrStopTread + } + + // 4、平仓处理 + if err = StockThaClosingOrder(ctx, Msql, orderId, closingPrice.String(), entrustCache.Order); err != nil { + applogger.Error("%v UpdateBotStockThaClosingByOrderId.StockThaClosingOrder:%v", common.ErrShareTha, err) + return false, err + } + + // 5、清理持仓订单信息 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), positionKey, orderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockThaClosingByOrderId.HDel:%v", common.ErrShareTha, err) + return false, flags.ErrCacheDB + } + + // 6、平仓更新订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(userKey, entrustCache.UserId) + if err = UpdateShareThaSubscribeHashStatusByOrderId(orderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockThaClosingByOrderId.%v:%v", common.ErrShareTha, userKey, err) + return false, flags.ErrCacheDB + } + + // 7、平仓更新管理员订阅缓存订单状态 + if err = UpdateShareThaSubscribeHashStatusByOrderId(orderId, adminKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockThaClosingByOrderId.%v:%v", common.ErrShareTha, adminKey, err) + return false, flags.ErrCacheDB + } + + return true, nil +} + +// UpdateBotStockThaAllClosingByOrderId +// +// @Description: 泰股用户一键平仓 +// @receiver uo +// @param ctx +// @param userId +// @return error +func (uo *userOrderRepo) UpdateBotStockThaAllClosingByOrderId(ctx context.Context, userId int64) error { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.ThaMarket) { + return flags.ErrStopTread + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe + } + + // 1、查询当前用户所有订单 + orderMap, err := uo.GetBotStockThaTradeByUserId(userId) + if err != nil { + applogger.Error("%v UpdateBotStockThaAllClosingByOrderId.GetBotStockThaTradeByUserId:%v", common.ErrShareTha, err) + return flags.ErrMySqlDB + } + + // 2、查询持仓缓存列表数据-1、清理持仓列表缓存 2、处理平仓数据 3、清理订单ID缓存列表 + entrust, err := Reds.HGetAll(context.Background(), setting.MarketShareThaPosition).Result() + if err != nil { + applogger.Error("%v UpdateBotStockThaAllClosingByOrderId.HGetAll:%v", common.ErrShareTha, err) + return flags.ErrShareFive + } + + // 3、循环检查股票交易对最新价格(有一个查询不到既不能平仓) + var entrustList []share.ShareThaTallyCache + closePriceMap := make(map[string]decimal.Decimal) + for key, value := range entrust { + var entrustJson share.ShareThaTallyCache + if err = json.Unmarshal([]byte(value), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockThaAllClosingByOrderId.Unmarshal:%v", common.ErrShareTha, err) + return flags.ErrStopTread + } + _, ok := orderMap[entrustJson.OrderId] + if ok { + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Tha, entrustJson.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareThaTheLatestPrice(subKey, entrustJson.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockThaAllClosingByOrderId.GetShareThaTheLatestPrice:%v", common.ErrShareTha, err) + return flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("订阅Key:%v,最新价格:%v,订单ID:%v", subKey, closingPrice, entrustJson.OrderId) + } + + closePriceMap[key] = closingPrice + entrustList = append(entrustList, entrustJson) + } + } + + // 4、股票一键平仓 + for _, value := range entrustList { + closePrice, ok := closePriceMap[value.OrderId] + if ok { + // 平仓 + if err = StockThaClosingOrder(ctx, uo.data.mysqlDB, value.OrderId, closePrice.String(), value.Order); err != nil { + applogger.Error("%v UpdateBotStockThaAllClosingByOrderId.StockThaClosingOrder:%v", common.ErrShareTha, err) + return err + } + + // 清理持仓缓存列表 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), setting.MarketShareThaPosition, value.OrderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockThaAllClosingByOrderId.HDel:%v", common.ErrShareTha, err) + return flags.ErrCacheDB + } + + // 平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareThaSubscribe, value.UserId) + if err = UpdateShareThaSubscribeHashStatusByOrderId(value.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockThaAllClosingByOrderId.ShareThaSubscribe:%v", common.ErrShareTha, err) + return flags.ErrCacheDB + } + + // 平仓更新管理员订阅订单状态 + if err = UpdateShareThaSubscribeHashStatusByOrderId(value.OrderId, setting.AdminShareThaSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockThaAllClosingByOrderId.AdminShareThaSubscribe:%v", common.ErrShareTha, err) + return flags.ErrCacheDB + } + } + } + + return nil +} + +// GetBotStockThaTradeByUserId +// +// @Description: +// @receiver uo +// @param ctx +// @param userId +// @return map[string]string +// @return error +func (uo *userOrderRepo) GetBotStockThaTradeByUserId(userId int64) (map[string]string, error) { + var botStockThaTrade []models.BotStockThaTrade + if err := uo.data.mysqlDB.Table(flags.BotStockThaTrade). + Where("user_id = ?", userId). + Where("status = 1"). + Find(&botStockThaTrade); err != nil { + return nil, err + } + + botMap := make(map[string]string) + for _, value := range botStockThaTrade { + botMap[value.OrderId] = value.OrderId + } + + return botMap, nil +} + +// GetShareThaTheLatestPrice +// +// @Description: +// @receiver uo +// @param ctx +// @param subKey +// @param tradeType +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) GetShareThaTheLatestPrice(subKey string, tradeType int64) (decimal.Decimal, error) { + priceNew, err := share.ShareThaSubMarketPrice(subKey) + if err != nil { + applogger.Error("%v GetShareThaTheLatestPrice.ShareThaSubMarketPrice:%v", common.ErrShareTha, err) + return decimal.Decimal{}, err + } + + priceS := decimal.RequireFromString(priceNew) + + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tradeType { + case flags.TradeTypeBuy: // 买涨 + openPrice = priceS.Sub(difference) // 开仓价格 + case flags.TradeTypeSell: // 买跌 + openPrice = priceS.Add(difference) // 开仓价格 + default: + + } + + return openPrice, nil +} + +// GetBotStockThaTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @return *models.BotStockThaTrade +// @return error +func (uo *userOrderRepo) GetBotStockThaTradeByOrderId(session *xorm.Session, orderId string) (*models.BotStockThaTrade, error) { + var botStockThaTrade []models.BotStockThaTrade + if err := session.Table(flags.BotStockThaTrade). + Where("order_id = ?", orderId). + Find(&botStockThaTrade); err != nil { + return nil, err + } + + for _, value := range botStockThaTrade { + return &value, nil + } + + return nil, nil +} + +// GetBotUserStockThaByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @return *models.BotUserStockTha +// @return error +func (uo *userOrderRepo) GetBotUserStockThaByUserIdAndStockId(session *xorm.Session, userId int64, stockId string) (*models.BotUserStockTha, error) { + var stockTha []models.BotUserStockTha + if err := session.Table(flags.BotUserStockTha). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&stockTha); err != nil || len(stockTha) <= 0 { + return nil, err + } + + for _, value := range stockTha { + return &value, nil + } + + return nil, nil +} + +// UpdateBotStockThaTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotStockThaTradeByOrderId(session *xorm.Session, orderId string, stock models.BotStockThaTrade) error { + _, err := session.Table(flags.BotStockThaTrade). + Where("order_id = ?", orderId). + Update(&stock) + + if err != nil { + return err + } + + return nil +} + +// CreateBotStockThaTrade +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param trade +// @return error +func (uo *userOrderRepo) CreateBotStockThaTrade(session *xorm.Session, trade models.BotStockThaTrade) error { + _, err := session.Table(flags.BotStockThaTrade).Insert(&trade) + if err != nil { + return err + } + + return nil +} + +// CreateBotUserStockThaFTHB +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param stock +// @return error +func (uo *userOrderRepo) CreateBotUserStockThaFTHB(session *xorm.Session, stock models.BotUserStockTha) error { + _, err := session.Table(flags.BotUserStockTha).Insert(&stock) + if err != nil { + return err + } + + return nil +} + +// UpdateBotUserStockThaByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotUserStockThaByUserIdAndStockId(session *xorm.Session, userId int64, stockId string, stock models.BotUserStockTha) error { + _, err := session.Table(flags.BotUserStockTha). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&stock) + if err != nil { + return err + } + + return nil +} + +// StockThaVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) StockThaVoteDealType(order structure.ShareOrder) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + return limitOrMarketPrice, nil +} + +// UpdateShareThaVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) UpdateShareThaVoteDealType(order *models.BotStockThaTrade) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + if len(order.DealPrice) != 0 { + dealPrice := decimal.RequireFromString(order.DealPrice) + if !dealPrice.IsZero() { + limitOrMarketPrice = dealPrice + } + } + + return limitOrMarketPrice, nil +} + +// VerifyBotStockThaTradeOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @return string +// @return error +func (uo *userOrderRepo) VerifyBotStockThaTradeOrderId(session *xorm.Session) (string, error) { + var orderId string + for { + // 生成订单ID + orderId = orders.CreateRandCodeOrder(10) + + var orderList []models.BotStockThaTrade + err := session.Table(flags.BotStockThaTrade). + Where("order_id = ?", orderId). + Find(&orderList) + + if err != nil || len(orderList) > 0 { + applogger.Error("%v VerifyBotStockThaTradeOrderId.Find:%v", common.ErrShareTha, err) + continue + } + + break + } + + return orderId, nil +} + +// GetBotStockThaTradeByOrderIdOrStatus +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param status +// @return *models.BotStockThaTrade +// @return error +func (uo *userOrderRepo) GetBotStockThaTradeByOrderIdOrStatus(session *xorm.Session, orderId string, status int) (*models.BotStockThaTrade, error) { + var botStockThaTrade []models.BotStockThaTrade + if err := session.Table(flags.BotStockThaTrade). + Where("order_id = ?", orderId). + Where("`status` = ?", status). + Find(&botStockThaTrade); err != nil { + return nil, err + } + + for _, value := range botStockThaTrade { + return &value, nil + } + + return nil, nil +} diff --git a/internal/data/order_share_us.go b/internal/data/order_share_us.go new file mode 100644 index 0000000..fb4d68a --- /dev/null +++ b/internal/data/order_share_us.go @@ -0,0 +1,1625 @@ +package data + +import ( + "context" + "encoding/json" + "github.com/go-xorm/xorm" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" + + orders "matchmaking-system/internal/data/convert" + models "matchmaking-system/internal/pkg/model" +) + +// GetBotStockTradeList +// +// @Description: 美股订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param userId +// @param status +// @return []*models.BotStockTrade +// @return int64 +// @return error +func (uo *userOrderRepo) GetBotStockTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotStockTrade, int64, error) { + totalCount, err := uo.data.mysqlDB.Table(flags.BotStockTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Count() + if err != nil { + return nil, 0, flags.ErrMySqlDB + } + if totalCount == 0 { + return nil, 0, nil + } + var stockList []*models.BotStockTrade + if err = uo.data.mysqlDB.Table(flags.BotStockTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Limit(int(pageSize), int(pageCount)). + Desc(GetOrderByStatusSort(status)). + Find(&stockList); err != nil { + return nil, 0, flags.ErrMySqlDB + } + + var stockUpdateList []*models.BotStockTrade + for _, value := range stockList { + value.KeepDecimal = GetKeepDecimal(flags.StockUsSystemSetUpKey, value.StockId) + value.StockName = GetStockName(flags.StockUsSystemSetUpKey, value.StockId) + stockUpdateList = append(stockUpdateList, value) + } + + return stockUpdateList, totalCount, nil +} + +// PlacingStockOrders +// +// @Description: 美股下单 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) PlacingStockOrders(ctx context.Context, userId int64, order structure.ShareOrder) (string, error) { + // 1、通知下单订阅 + symbol := order.StockId + timeValue := QuerySystemCache(flags.ShareUsMarketType) // 市场开闭盘时间 + if !utils.CheckInPlateTime(timeValue) { + return flags.SetNull, flags.ErrStopTread + } + SubscribeUsHSetCodeList(symbol, false) // 同步写入股票列表缓存 + SubscribeUsCloseNewPrice(symbol) // 同步股票实时行情价 + + // 判定是否存在欠款订单 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe.Error(), nil + } + + order = PryNumInit(order) // 杠杆初始化 + subKey := publicData.SymbolCache(flags.Us, symbol, flags.TradeTypePrice) + + // 美股市场系统设置 + if CheckGlobalTread(flags.UsMarket) { + return flags.SetNull, flags.ErrShareSeven + } + + // 全局设置停止交易操作 + var blockTime time.Time + var priceNew, userKey, adminKey string + if !CheckTypeStatus(order.Type) { + userKey = setting.ShareUsSubscribe + adminKey = setting.AdminShareUsSubscribe + } else { + // 判定:1、是否开启股票交易 2、是否在交易时间内 3、是否达到最小交易量 + check, openPrice, minNum, endTime := CheckBlockTread(flags.UsBlk, symbol) + if check { + return flags.SetNull, flags.ErrShareSeven + } + if minNum > utils.StringToInt(order.OrderNumber) { + return flags.SetNull, flags.ErrShareSix + } + priceNew = openPrice // 开仓价格 + blockTime = endTime // 平仓时间 + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + flatRatio := GetCacheForcedClosure(flags.StockUsSystemSetUpKey, symbol) // 设置强平阈值 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.UsMarket, userId) // 股票市场系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), // 强平阈值 + Status: leverStatus.Status, // 杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + order.System = system + + // 2、股票下单判定 + // 下单判定设置(false无设置|true止盈止损) + checkBool, stopWinPrice, stopLossPrice, err := StockVoteStopType(order) + if err != nil { + applogger.Error("%v PlacingStockOrders.StockVoteStopType:%v", common.ErrShareUs, err) + return flags.SetNull, err + } + // 下单判定设置(限价|市价) + limitOrMarketPrice, err := uo.StockVoteDealType(order) + if err != nil { + applogger.Error("%v PlacingStockOrders.StockVoteDealType:%v", common.ErrShareUs, err) + return flags.SetNull, err + } + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(order.TradeType, stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v PlacingStockOrders.VoteTradeType:%v", common.ErrShareUs, err) + return flags.SetNull, err + } + + // 3、订单持久化录入(并处理资产信息) + pryNum := SystemDealWithLever(order) + orderId, err := uo.StockOrderWriteDB(ctx, userId, order, limitOrMarketPrice, pryNum) + if err != nil || len(orderId) == 0 { + applogger.Error("%v PlacingStockOrders.StockOrderWriteDB:%v", common.ErrShareUs, err) + return flags.SetNull, err + } + + // 4、处理订单信息 + chg := GetShareChgUs(flags.Us, order.StockId) // 涨跌幅标识值 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.UsMarket, time.Now()) // 开盘时间 + marketStatus, shareOrder, err := share.ShareUsCacheDeal(ctx, userId, orderId, subKey, order, chg, priceNew, closingTime, blockTime) + if err != nil || shareOrder == nil { + applogger.Error("%v PlacingStockOrders.ShareUsCacheDeal:%v", common.ErrShareUs, err) + return flags.SetNull, err + } + // 计算保证金 = 订单价格 * 订单数量 / 杠杆 + shareOrder.Order.MarketMoney = limitOrMarketPrice.Mul(decimal.RequireFromString(order.OrderNumber)).Div(pryNum).String() + if !flags.CheckSetting { + applogger.Debug("订单ID:%v", shareOrder.OrderId) + applogger.Debug("订单交易对:%v", shareOrder.Symbol) + applogger.Debug("订单状态:%v", shareOrder.Status) + applogger.Debug("订单用户ID:%v", shareOrder.UserId) + applogger.Debug("开盘价:%v", shareOrder.OpenPrice) + applogger.Debug("收盘价:%v", shareOrder.ClosingPrice) + applogger.Debug("下单信息:%v", shareOrder.Order) + } + + // 6、订单(挂单|持仓)缓存列表,等待队列计算 + if err = share.ShareUsHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v PlacingStockOrders.ShareUsPushAddCache:%v", common.ErrShareUs, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 7、用户订阅股票订单信息 + orderIdKey := virtual.OrderIdListKey(userKey, userId) + if err = share.ShareUsHashUserOrder(Reds, orderIdKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockOrders.%v:%v", common.ErrShareUs, userKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 8、管理员订阅订单信息 + if err = share.ShareUsHashUserOrder(Reds, adminKey, shareOrder); err != nil { + applogger.Error("%v PlacingStockOrders.%v:%v", common.ErrShareUs, adminKey, err) + return flags.SetNull, flags.ErrCacheDB + } + + return orderId, nil +} + +// StockOrderWriteDB +// +// @Description: 美股处理下单操作 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) StockOrderWriteDB(ctx context.Context, userId int64, order structure.ShareOrder, limitOrMarketPrice, lever decimal.Decimal) (string, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockOrderWriteDB.Begin:%v", common.ErrShareUs, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 获取当前下单用户的资产 + var usableOld, frozenOld decimal.Decimal + stockUsd, err := uo.GetBotUserStockByUserIdAndStockId(session, userId, flags.ShareUsBasicUnit) + if err != nil || stockUsd == nil { + applogger.Error("%v StockOrderWriteDB.USD:%v", common.ErrShareUs, err) + return flags.SetNull, flags.ErrMySqlDB + } + usableOld = decimal.RequireFromString(stockUsd.UsableNum) + frozenOld = decimal.RequireFromString(stockUsd.FrozenNum) + if !flags.CheckSetting { + applogger.Debug("下单可用资产:%v", usableOld) + applogger.Debug("下单冻结资产:%v", frozenOld) + } + + // 检查用户订单下单资产 + if usableOld.IsNegative() || frozenOld.IsNegative() { + return flags.SetNull, flags.ErrShareOne + } + + // 获取当前系统下单用户的非资产 + var usableFOld, frozenFOld decimal.Decimal + stockFUsd, err := uo.GetBotUserStockByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockOrderWriteDB.FeiUSD:%v", common.ErrShareUs, err) + return flags.SetNull, flags.ErrMySqlDB + } + if stockFUsd != nil { + usableFOld = decimal.RequireFromString(stockFUsd.UsableNum) + frozenFOld = decimal.RequireFromString(stockFUsd.FrozenNum) + } + if !flags.CheckSetting { + applogger.Debug("下单可用非资产:%v", usableFOld) + applogger.Debug("下单冻结非资产:%v", frozenFOld) + } + + // 整理当前下单信息 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 订单手续费 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 订单数量 + marketMoney := limitOrMarketPrice.Mul(orderNumber).Div(lever) // 订单金额(杠杆下单) = 订单数量 * 交易价格 / 杠杆 + totalMoney := marketMoney.Add(serviceCost) // 订单总金额 + order.MarketMoney = marketMoney.String() // 市值金额即为保证金 + + // 检查订单ID是否存在,新增下单信息 + var orderId string + if !CheckTypeStatus(order.Type) { + orderId, err = uo.VerifyBotStockTradeOrderId(session) + if err != nil { + applogger.Error("%v StockOrderWriteDB.VerifyBotStockTradeOrderId:%v", common.ErrShareUs, err) + return flags.SetNull, err + } + trade := orders.BotStockTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockTrade(session, trade); err != nil { + applogger.Error("%v StockOrderWriteDB.CreateBotStockTrade:%v", common.ErrShareUs, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + orderId, err = uo.VerifyBotStockBlockTradeOrderId(session) + if err != nil { + applogger.Error("%v StockOrderWriteDB.VerifyBotStockBlockTradeOrderId:%v", common.ErrShareUs, err) + return flags.SetNull, err + } + trade := orders.BotStockBlockTrade(ctx, userId, orderId, order) + if err = uo.CreateBotStockBlockTrade(session, trade); err != nil { + applogger.Error("%v StockOrderWriteDB.CreateBotStockBlockTrade:%v", common.ErrShareUs, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + // 下单判定 + residue := usableOld.Sub(totalMoney).Div(usableOld) + if usableOld.Cmp(totalMoney) <= 0 || residue.Cmp(utils.DecimalsStrInt()) <= 0 { + return flags.SetNull, flags.ErrPublicTow + } + + var usableNew, frozenNew, usableFNew, frozenFNew decimal.Decimal + usableNew = usableOld.Sub(totalMoney) // 可用资产 + frozenNew = frozenOld.Add(totalMoney) // 冻结资产 + if order.StockId != flags.ShareUsBasicUnit { + usableFNew = usableFOld.Add(orderNumber) // 可用非资产 + frozenFNew = frozenFOld // 冻结非资产 + } + + // 检查用户订单下单资产 + if usableNew.IsNegative() { + return flags.SetNull, flags.ErrPublicTow + } + + // 下单更新资产信息 + stockUSDModel := orders.UpdateBotUserStock(ctx, usableNew.String(), frozenNew.String()) + err = uo.UpdateBotUserStockByUserIdAndStockId(session, userId, flags.ShareUsBasicUnit, stockUSDModel) + if err != nil { + applogger.Error("%v StockOrderWriteDB.UpdateBotUserStockByUserIdAndStockId:%v", common.ErrShareUs, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 下单(新增|更新)非资产信息 + if stockFUsd == nil { + stockFUSDModel := orders.CreateBotUserStock(ctx, userId, order.StockId, usableFNew.String(), frozenFNew.String()) + err = uo.CreateBotUserStockFUSD(session, stockFUSDModel) + if err != nil { + applogger.Error("%v StockOrderWriteDB.CreateBotUserStockFUSD:%v", common.ErrShareUs, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + stockFUSDModel := orders.UpdateBotUserStock(ctx, usableFNew.String(), frozenFNew.String()) + err = uo.UpdateBotUserStockByUserIdAndStockId(session, userId, order.StockId, stockFUSDModel) + if err != nil { + applogger.Error("%v StockOrderWriteDB.UpdateFUSDL:%v", common.ErrShareUs, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockOrderWriteDB.Commit:%v", common.ErrShareUs, err) + return flags.SetNull, flags.ErrMySqlDB + } + + return orderId, nil +} + +// StockOpenOrder +// +// @Description: 美股系统开仓 +// @param ctx +// @param db +// @param userId +// @param orderId +// @param openPrice +// @param order +// @return error +func StockOpenOrder(ctx context.Context, db *xorm.EngineGroup, userId int64, orderId, openPrice string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockOpenOrder.NewSession:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockUsd, err := Uo.GetBotUserStockByUserIdAndStockId(session, userId, flags.ShareUsBasicUnit) + if err != nil || stockUsd == nil { + applogger.Error("%v StockOpenOrder.GetBotUserStockByUserIdAndStockId:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockUsd.UsableNum) // 用户可用资产 + frozen = decimal.RequireFromString(stockUsd.FrozenNum) // 用户冻结资产 + + // 检查用户订单开仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrPublicThree + } + if order.StockId != flags.ShareUsBasicUnit { + stockFUsd, err := Uo.GetBotUserStockByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockOpenOrder.GetBotUserStockByUserIdAndStockId:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(stockFUsd.UsableNum) // 用户非可用资产 + frozenNo = decimal.RequireFromString(stockFUsd.FrozenNum) // 用户非冻结资产 + } + + // 转换股票下单信息 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 下单股数 + marketMoney := decimal.RequireFromString(order.MarketMoney) // 下单金额 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 下单手续费 + totalMoney := marketMoney.Add(serviceCost) // 下单总金额 = (下单手续费 + 下单金额) + openOrderPrice := decimal.RequireFromString(openPrice) // 开盘价格 + + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + applogger.Debug("下单订单数量:%v", orderNumber) + applogger.Debug("下单订单金额:%v", marketMoney) + applogger.Debug("下单订单手续费:%v", serviceCost) + applogger.Debug("下单订单总金额:%v", totalMoney) + } + + // 手续费记录 + openPriceNew := openOrderPrice.Mul(orderNumber).String() // 开仓手续费 = 开仓价格 * 股数 * 开仓手续费 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareUsMarketType, flags.OpenBrokType, orderId, openPriceNew) + if err != nil { + applogger.Error("%v StockOpenOrder.CalculateHandlingFeesShare:%v", common.ErrShareUs, err) + return err + } + openServiceCost := decimal.RequireFromString(cost) // 开仓手续费 + openMarketMoney := openOrderPrice.Mul(orderNumber).Div(decimal.RequireFromString(order.PryNum)) // 开仓订单金额 = 开仓价格 * 开仓数量 / 杠杆 + openTotalMoney := openMarketMoney.Add(openServiceCost) // 开仓总金额 = (开仓订单金额 + 开仓手续费) + floatPrice := totalMoney.Sub(openTotalMoney) // 计算可用金额容差 = 下单总额 - 开仓总额 + + if !flags.CheckSetting { + applogger.Debug("开仓订单价格:%v", openOrderPrice) + applogger.Debug("开仓手续费:%v", openServiceCost) + applogger.Debug("开仓总金额:%v", openTotalMoney) + applogger.Debug("下单->开仓总金额容差值:%v", floatPrice) + } + + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + usableNew = usable.Add(floatPrice) // 可用资产(处理容差值) + frozenNew = frozen.Sub(totalMoney).Add(openMarketMoney) // 冻结资产 + if order.StockId != flags.ShareUsBasicUnit { + usableNoNew = usableNo // 非可用资产 + frozenNoNew = frozenNo // 非冻结资产 + } + + // 检查用户订单开仓资产 + if frozenNew.IsNegative() || usableNew.IsNegative() { + return flags.ErrPublicThree + } + if !flags.CheckSetting { + applogger.Debug("下单后用户可用资产:%v", usableNew) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + } + + // 处理资产信息 + userStockUsd := orders.UpdateBotUserStock(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockByUserIdAndStockId(session, userId, flags.ShareUsBasicUnit, userStockUsd); err != nil { + applogger.Error("%v StockOpenOrder.USD.UpdateBotUserStockByUserIdAndStockId:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + + // 更新非资产信息 + if order.StockId != flags.ShareUsBasicUnit { + userStockFUsd := orders.UpdateBotUserStock(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = Uo.UpdateBotUserStockByUserIdAndStockId(session, userId, order.StockId, userStockFUsd); err != nil { + applogger.Error("%v StockOpenOrder.USD.UpdateBotUserStockByUserIdAndStockId:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + } + + // 返佣记录|资金信息|资金详情信息 + if err = Uo.ShareUsRebateCalculation(ctx, session, int(userId), flags.ShareUsMarketType, flags.OpenBrokType, flags.OpenMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockOpenOrder.ShareUsRebateCalculation:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + + // 处理订单信息(成交价|仓位|开仓时间|订单总金额|手续费|持仓状态) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateOpenBotStockTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarketMoney.String()) + if err = Uo.UpdateBotStockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockOpenOrder.UpdateBotStockTradeByOrderId:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockLog + qData0 := orders.CreatBotUserStockLog(ctx, userId, flags.CostMoney, flags.ShareUsBasicUnit, NegativeValue(openServiceCost.String()), orderId) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockLog(ctx, userId, flags.Freeze, flags.ShareUsBasicUnit, NegativeValue(openMarketMoney.String()), orderId) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockLogList(session, list); err != nil { + applogger.Error("%v StockOpenOrder.CreatBotUserStockLogList:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateOpenBotStockBlockTrade(ctx, openPrice, orderNumber.String(), openTotalMoney.String(), openServiceCost.String(), openMarketMoney.String()) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockOpenOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareUsBasicUnit, NegativeValue(openServiceCost.String()), orderId, order.Type) // 大宗资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Freeze, flags.ShareUsBasicUnit, NegativeValue(openMarketMoney.String()), orderId, order.Type) // 大宗资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, order.StockId, orderNumber.String(), orderId, order.Type) // 大宗资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockOpenOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v StockOpenOrder.Commit:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + + return nil +} + +// StockClosingOrder +// +// @Description: 美股系统平仓 +// @param ctx +// @param db +// @param orderId +// @param price +// @param order +// @return error +func StockClosingOrder(ctx context.Context, db *xorm.EngineGroup, orderId string, price string, order structure.ShareOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v StockClosingOrder.NewSession:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + + // 交易查询订单信息 + var userId int64 + var dealPrice, orderNumber, totalAmount, serviceCost, marketMoney decimal.Decimal + if !CheckTypeStatus(order.Type) { + tread, err := Uo.GetBotStockTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockClosingOrder.GetBotStockTradeByOrderIdOrStatus:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + marketMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓订单金额 + } else { + tread, err := Uo.GetBotStockBlockTradeByOrderIdOrStatus(session, orderId, flags.PositionStatus) + if err != nil || tread == nil { + applogger.Error("%v StockClosingOrder.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + userId = int64(tread.UserId) // 用户Id + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.OrderMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + marketMoney = decimal.RequireFromString(tread.MarketMoney) // 开仓订单金额 + } + + if !flags.CheckSetting { + applogger.Debug("下单开仓用户Id:%v", userId) + applogger.Debug("下单开仓开仓价格:%v", dealPrice) + applogger.Debug("下单开仓订单数量:%v", orderNumber) + applogger.Debug("下单开仓总金额:%v", totalAmount) + applogger.Debug("下单开仓手续费:%v", serviceCost) + applogger.Debug("下单开仓订单金额:%v", marketMoney) + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + userStockUsd, err := Uo.GetBotUserStockByUserIdAndStockId(session, userId, flags.ShareUsBasicUnit) + if err != nil { + applogger.Error("%v StockClosingOrder.GetBotUserStockByUserIdAndStockId:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + usable = decimal.RequireFromString(userStockUsd.UsableNum) // 用户可用资金 + frozen = decimal.RequireFromString(userStockUsd.FrozenNum) // 用户冻结资金 + + // 检查用户订单平仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrShareTow + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + } + + // 查询当前下单用户可用非账户和冻结金额 + if order.StockId != flags.ShareUsBasicUnit { + userStockFUsd, err := Uo.GetBotUserStockByUserIdAndStockId(session, userId, order.StockId) + if err != nil { + applogger.Error("%v StockClosingOrder.GetBotUserStockByUserIdAndStockId:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + usableNo = decimal.RequireFromString(userStockFUsd.UsableNum) // 用户非可用资金 + frozenNo = decimal.RequireFromString(userStockFUsd.FrozenNum) // 用户非冻结资金 + if !flags.CheckSetting { + applogger.Debug("下单非可用金额:%v", usableNo) + applogger.Debug("下单非冻结金额:%v", frozenNo) + } + } + + // 手续费处理 + closePrice := decimal.RequireFromString(price) // 平仓价格 + cloePriceCost := closePrice.Mul(orderNumber).String() // 平仓手续费 = 平仓价格 * 股数 * 手续费比例 + cost, err := Uo.CalculateHandlingFeesShare(ctx, session, int(userId), flags.ShareUsMarketType, flags.ClosingBrokType, orderId, cloePriceCost) + if err != nil { + applogger.Error("%v StockClosingOrder.CalculateHandlingFeesShare:%v", common.ErrShareUs, err) + return err + } + closeServiceCost := decimal.RequireFromString(cost) + if !flags.CheckSetting { + applogger.Debug("平仓价格:%v", closePrice) + applogger.Debug("平仓手续费手续费:%v", closeServiceCost) + } + + //已经实现盈亏计算公式(已平仓结算方式) + //买涨 已经实现盈亏 = (平仓成交价-开仓成交价)*股数 + //买跌 已经实现盈亏 = (开仓成交价-平仓成交价)*股数 + var usableNew, frozenNew, usableNewNo, frozenNewNo, subPrice, resultPrice decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买涨 + subPrice = closePrice.Sub(dealPrice) + resultPrice = subPrice.Mul(orderNumber) + case flags.TradeTypeSell: // 买跌 + subPrice = dealPrice.Sub(closePrice) + resultPrice = subPrice.Mul(orderNumber) + default: + + } + + // TODO: 判定亏损不能超过 = 保证金 + 平仓手续费 + if resultPrice.IsNegative() { + amountLoss := marketMoney.Sub(closeServiceCost) + if resultPrice.Abs().Cmp(amountLoss) >= 0 { + resultPrice = amountLoss.Neg() + } + } + + // 用户资产账户 + usableNew = usable.Add(resultPrice).Sub(closeServiceCost).Add(marketMoney) // 可用资产 = 原可用资产 + ((正负)盈亏) - 平仓手续费 + 保证金 + if frozen.Cmp(marketMoney) == -1 { + frozenNew = frozen.Sub(frozen) // 冻结资产 = 原冻结资产 - 保证金 + } else { + frozenNew = frozen.Sub(marketMoney) // 冻结资产 = 原冻结资产 - 保证金 + } + + // 用户非资产账户 + if order.StockId != flags.ShareUsBasicUnit { + usableNewNo = usableNo.Sub(orderNumber) // 非可用资产 = 原非可用资产 + frozenNewNo = frozenNo // 非冻结资产 = 原非冻结资产 - 订单数量 + } + + // 检查用户订单平仓资产 + if frozenNew.IsNegative() || usableNewNo.IsNegative() { + return flags.ErrShareTow + } + if !flags.CheckSetting { + applogger.Debug("可用资产:%v", usableNew) + applogger.Debug("冻结资产:%v", frozenNew) + applogger.Debug("可用非资产:%v", usableNewNo) + applogger.Debug("冻结非资产:%v", frozenNewNo) + } + + // 平仓(处理资产表(资产)) + userStockUSDT := orders.UpdateBotUserStock(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserStockByUserIdAndStockId(session, userId, flags.ShareUsBasicUnit, userStockUSDT); err != nil { + applogger.Error("%v StockClosingOrder.userStockUSDT:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + + // 平仓(处理资产表(非资产)) + if order.StockId != flags.ShareUsBasicUnit { + userStockFUSDT := orders.UpdateBotUserStock(ctx, usableNewNo.String(), frozenNewNo.String()) + if err = Uo.UpdateBotUserStockByUserIdAndStockId(session, userId, order.StockId, userStockFUSDT); err != nil { + applogger.Error("%v StockClosingOrder.userStockFUSDT:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + } + + // 平仓(返佣记录表|资产表|资金变动表) + if err = Uo.ShareUsRebateCalculation(ctx, session, int(userId), flags.ShareUsMarketType, flags.ClosingBrokType, flags.CloseMRebate, cost, orderId, order.Type); err != nil { + applogger.Error("%v StockClosingOrder.ShareUsRebateCalculation:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + + // 平仓(处理订单信息(平仓价|保证金|平仓|订单总金额|平仓手续费|完成订单)) + if !CheckTypeStatus(order.Type) { + trade := orders.UpdateCloseBotStockTrade(ctx, price, cost) + if err = Uo.UpdateBotStockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockClosingOrder.UpdateBotStockTradeByOrderId:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockLog + qData0 := orders.CreatBotUserStockLog(ctx, userId, flags.Thaw, flags.ShareUsBasicUnit, marketMoney.String(), orderId) // 平仓(资金变动明细(平仓保证金)) + qData1 := orders.CreatBotUserStockLog(ctx, userId, flags.CostMoney, flags.ShareUsBasicUnit, NegativeValue(closeServiceCost.String()), orderId) // 平仓(资金变动明细表(平仓手续费)) + qData2 := orders.CreatBotUserStockLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId) // 平仓(资金变动明细表(非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏)) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockLog(ctx, userId, flags.TransferOut, flags.ShareUsBasicUnit, resultPrice.String(), orderId) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockLog(ctx, userId, flags.ChangeInto, flags.ShareUsBasicUnit, resultPrice.String(), orderId) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockLogList(session, list); err != nil { + applogger.Error("%v StockClosingOrder.CreatBotUserStockLog:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + } else { + trade := orders.UpdateCloseBotStockBlockTrade(ctx, price, cost) + if err = Uo.UpdateBotStockBlockTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v StockClosingOrder.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + + var list []models.BotUserStockBlockLog + qData0 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.Thaw, flags.ShareUsBasicUnit, marketMoney.String(), orderId, order.Type) // 平仓(资金变动明细(平仓保证金)) + qData1 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.CostMoney, flags.ShareUsBasicUnit, NegativeValue(closeServiceCost.String()), orderId, order.Type) // 平仓(资金变动明细表(平仓手续费)) + qData2 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, order.StockId, NegativeValue(orderNumber.String()), orderId, order.Type) // 平仓(资金变动明细表(非资产)) + list = append(list, qData0, qData1, qData2) + // 平仓(资金变动明细表(正负盈亏)) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.TransferOut, flags.ShareUsBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserStockBlockLog(ctx, userId, flags.ChangeInto, flags.ShareUsBasicUnit, resultPrice.String(), orderId, order.Type) + list = append(list, qData4) + } + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserStockBlockLogList(session, list); err != nil { + applogger.Error("%v StockClosingOrder.CreatBotUserStockBlockLogList:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v ContractClosingPosition.Commit:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + + return nil +} + +// UpdateBotStockCancelByOrderId +// +// @Description: 美股撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockCancelByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockCancelByOrderId.Begin:%v", common.ErrShareUs, err) + return false, flags.ErrMySqlDB + } + + // 订单信息 + var userId int64 + var stockId string + var marketMoneyOld, serviceCostOld, orderNumber decimal.Decimal + if !CheckTypeStatus(typeStatus) { + stockTrade, err := uo.GetBotStockTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockCancelByOrderId.GetBotStockTradeByOrderId:%v", common.ErrShareUs, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } else { + stockTrade, err := uo.GetBotStockBlockTradeByOrderId(session, orderId) + if err != nil || stockTrade == nil { + applogger.Error("%v UpdateBotStockCancelByOrderId.GetBotStockBlockTradeByOrderId:%v", common.ErrShareUs, err) + return false, flags.ErrMySqlDB + } + marketMoneyOld = decimal.RequireFromString(stockTrade.MarketMoney) // 订单Id + serviceCostOld = decimal.RequireFromString(stockTrade.ServiceCost) // 手续费 + orderNumber = decimal.RequireFromString(stockTrade.OrderNumber) // 订单数量 + userId = int64(stockTrade.UserId) // 用户Id + stockId = stockTrade.StockId // 下单交易对 + } + + // 获取用户资产信息 + var usable, frozen, usableNo, frozenNo decimal.Decimal + stockUsd, err := uo.GetBotUserStockByUserIdAndStockId(session, userId, flags.ShareUsBasicUnit) + if err != nil || stockUsd == nil { + applogger.Error("%v UpdateBotStockCancelByOrderId.USD.GetBotUserStockByUserIdAndStockId:%v", common.ErrShareUs, err) + return false, flags.ErrMySqlDB + } + usable = decimal.RequireFromString(stockUsd.UsableNum) // 用户账户可用资产 + frozen = decimal.RequireFromString(stockUsd.FrozenNum) // 用户账户冻结资产 + + // 检查用户订单撤单资产 + if usable.IsNegative() || frozen.IsNegative() { + return false, flags.ErrShareNine + } + if stockId != flags.ShareUsBasicUnit { + stockFUsd, err := uo.GetBotUserStockByUserIdAndStockId(session, userId, stockId) + if err != nil { + applogger.Error("%v UpdateBotStockCancelByOrderId.GetBotUserStockByUserIdAndStockId:%v", common.ErrShareUs, err) + return false, flags.ErrPublicFour + } + usableNo = decimal.RequireFromString(stockFUsd.UsableNum) // 用户非账户可用资产 + frozenNo = decimal.RequireFromString(stockFUsd.FrozenNum) // 用户非账户冻结资产 + } + if !flags.CheckSetting { + applogger.Debug("用户原始可用资金:%v", usable) + applogger.Debug("用户原始冻结资金:%v", frozen) + applogger.Debug("用户原始可用非资金:%v", usableNo) + applogger.Debug("用户原始冻结非资金:%v", frozenNo) + } + + // 更新订单信息 + var entrustKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + botStockTrade := orders.BotStockCancelByOrderId(ctx) + if err = uo.UpdateBotStockTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockCancelByOrderId.USD.UpdateBotStockTradeByOrderId:%v", common.ErrShareUs, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareUsEntrust + userKey = setting.ShareUsSubscribe + adminKey = setting.AdminShareUsSubscribe + } else { + botStockTrade := orders.BotStockBlockCancelByOrderId(ctx) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockCancelByOrderId.USD.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareUs, err) + return false, flags.ErrMySqlDB + } + // 缓存Key + entrustKey = setting.MarketShareBlkEntrust + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // Operational Spot Asset Table + totalMoney := marketMoneyOld.Add(serviceCostOld) // 订单总金额 + // update total asset data + usableNew := usable.Add(totalMoney) // 用户总资产 + frozenNew := frozen.Sub(totalMoney) // 用户冻结资产 + usableNoNew := usableNo.Sub(orderNumber) // 用户非可用资产 + frozenNoNew := frozenNo // 用户非冻结资产 + + // 检查用户订单撤单资产 + if frozenNew.IsNegative() || usableNoNew.IsNegative() { + return false, flags.ErrShareNine + } + if !flags.CheckSetting { + applogger.Debug("用户撤单可用总资产:%v", usableNew) + applogger.Debug("用户撤单冻结总资产:%v", frozenNew) + applogger.Debug("用户非撤单可用总资产:%v", usableNoNew) + applogger.Debug("用户非撤单冻结总资产:%v", frozenNoNew) + } + + // 更新资产信息和非资产信息 + userStockUSD := orders.UpdateBotUserStock(ctx, usableNew.String(), frozenNew.String()) + if err = uo.UpdateBotUserStockByUserIdAndStockId(session, userId, flags.ShareUsBasicUnit, userStockUSD); err != nil { + applogger.Error("%v UpdateBotStockCancelByOrderId.UpdateBotUserStockByUserIdAndStockId:%v", common.ErrShareUs, err) + return false, flags.ErrMySqlDB + } + if stockId != flags.ShareUsBasicUnit { + userStockFUSD := orders.UpdateBotUserStock(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = uo.UpdateBotUserStockByUserIdAndStockId(session, userId, stockId, userStockFUSD); err != nil { + applogger.Error("%v UpdateBotStockCancelByOrderId.UpdateBotUserStockByUserIdAndStockId:%v", common.ErrShareUs, err) + return false, flags.ErrMySqlDB + } + } + + // 删除订单缓存列表 + if err = Reds.HDel(context.Background(), entrustKey, orderId).Err(); err != nil { + applogger.Error("%v UpdateBotStockCancelByOrderId.HDel:%v", common.ErrShareUs, err) + return false, flags.ErrCacheDB + } + + // 更新用户订阅订单缓存列表 + userSubKey := virtual.OrderIdListKey(userKey, userId) + if err = share.UpdateShareUsHashByOrderId(Reds, orderId, userSubKey, flags.Cancel); err != nil { + applogger.Error("%v UpdateBotStockCancelByOrderId.%v:%v", common.ErrShareUs, userKey, err) + return false, flags.ErrCacheDB + } + + // 更新管理员订阅订单缓存列表 + if err = UpdateShareUsSubscribeHashStatusByOrderId(orderId, adminKey, flags.Cancel, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockCancelByOrderId.%v:%v", common.ErrShareUs, adminKey, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockCancelByOrderId.Commit:%v", common.ErrShareUs, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockStopByOrderId +// +// @Description: 美股设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotStockStopByOrderId.NewSession:%v", common.ErrShareUs, err) + return false, flags.ErrMySqlDB + } + + // 设置止盈止损 + var userId int64 + if order.StopType == 1 { + // 股票下单信息 + checkBool, stopWinPrice, stopLossPrice, err := uo.UpdateVoteStopType(order) + if err != nil { + applogger.Error("%v UpdateBotStockStopByOrderId.UpdateVoteStopType:%v", common.ErrShareUs, err) + return false, err + } + if !flags.CheckSetting { + applogger.Debug("当前止盈止损数据:%v,%v,%v", checkBool, stopWinPrice, stopLossPrice) + } + + // 设置止盈止损判定 + var tradeType int + var limitOrMarketPrice decimal.Decimal + if !CheckTypeStatus(order.Type) { + trade, err := uo.GetBotStockTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockStopByOrderId.GetBotStockTradeByOrderIdOrStatus:%v", common.ErrShareUs, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + limitOrMarketPrice, err = uo.UpdateShareVoteDealType(trade) // 下单判定设置(限价|市价|开仓价) + if err != nil { + applogger.Error("%v UpdateBotStockStopByOrderId.UpdateShareVoteDealType:%v", common.ErrShareUs, err) + return false, err + } + } else { + trade, err := uo.GetBotStockBlockTradeByOrderIdOrStatus(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotStockStopByOrderId.GetBotStockBlockTradeByOrderIdOrStatus:%v", common.ErrShareUs, err) + return false, flags.ErrShareFour + } + tradeType = trade.TradeType + userId = int64(trade.UserId) + limitOrMarketPrice, err = uo.UpdateShareBlockVoteDealType(trade) // 下单判定设置(限价|市价|开仓价) + if err != nil { + applogger.Error("%v UpdateBotStockStopByOrderId.UpdateShareBlockVoteDealType:%v", common.ErrShareUs, err) + return false, err + } + } + if !flags.CheckSetting { + applogger.Debug("当前开仓价格:%v", limitOrMarketPrice) + } + + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(int64(tradeType), stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v UpdateBotStockStopByOrderId.VoteTradeType:%v", common.ErrShareUs, err) + return false, err + } + } else { + order.StopLossPrice = decimal.Zero.String() + order.StopWinPrice = decimal.Zero.String() + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[userId] + if ok { + return false, flags.ErrPublicServe + } + + // 更新订单表 + var positionKey string + if !CheckTypeStatus(order.Type) { + botStockTrade := orders.BotStockStopByOrderId(ctx, order) + if err = uo.UpdateBotStockTradeByOrderId(session, order.OrderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockStopByOrderId.UpdateBotStockTradeByOrderId:%v", common.ErrShareUs, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareUsPosition + } else { + botStockTrade := orders.BotStockBlockStopByOrderId(ctx, order) + if err = uo.UpdateBotStockBlockTradeByOrderId(session, order.OrderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotStockStopByOrderId.UpdateBotStockBlockTradeByOrderId:%v", common.ErrShareUs, err) + return false, flags.ErrMySqlDB + } + positionKey = setting.MarketShareBlkPosition + } + + // 修改止止损止盈持仓缓存队列数据 + if err = share.UpdateShareUsStopByOrderId(Reds, order, positionKey, flags.Position); err != nil { + applogger.Error("%v UpdateBotStockStopByOrderId.UpdateShareUsStopByOrderId:%v", common.ErrShareUs, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotStockStopByOrderId.Commit:%v", common.ErrShareUs, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotStockClosingByOrderId +// +// @Description: 美股用户平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotStockClosingByOrderId(ctx context.Context, orderId string, typeStatus int64) (bool, error) { + // 下单判定冷静期停止所有交易 + if CheckGlobalTread(flags.UsMarket) { + return false, flags.ErrStopTread + } + + // 1、大宗交易查询持仓缓存列表数据并清理对应缓存 + var positionKey, userKey, adminKey string + if !CheckTypeStatus(typeStatus) { + positionKey = setting.MarketShareUsPosition + userKey = setting.ShareUsSubscribe + adminKey = setting.AdminShareUsSubscribe + } else { + positionKey = setting.MarketShareBlkPosition + userKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + var entrustCache *share.ShareUsTallyCache + entrust, err := Reds.HGet(context.Background(), positionKey, orderId).Result() + if err != nil { + applogger.Error("%v UpdateBotStockClosingByOrderId.HGet:%v", common.ErrShareUs, err) + return false, flags.ErrShareFive + } + + var entrustJson share.ShareUsTallyCache + if err = json.Unmarshal([]byte(entrust), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockClosingByOrderId.Unmarshal:%v", common.ErrShareUs, err) + return false, flags.ErrCacheDB + } + if orderId == entrustJson.OrderId { + entrustCache = &entrustJson + } + + // 3、判定是否存在平仓订单 + if entrustCache == nil { + return false, flags.ErrShareFive + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, ok := userIdMap[entrustJson.UserId] + if ok { + return false, flags.ErrPublicServe + } + + // 市场设置交易时间(T+0,T+1,T+2s......) + if !CheckShareSystemTime(entrustCache.ClosingTime) { + return false, flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("手动平仓:%v", entrustCache) + } + + // 2、获取当前最新价格 + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Us, entrustCache.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareUSTheLatestPrice(subKey, entrustCache.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockClosingByOrderId.GetShareUSTheLatestPrice:%v", common.ErrShareUs, err) + return false, flags.ErrStopTread + } + + // 4、平仓处理 + if err = StockClosingOrder(ctx, Msql, orderId, closingPrice.String(), entrustCache.Order); err != nil { + applogger.Error("%v UpdateBotStockClosingByOrderId.StockClosingOrder:%v", common.ErrShareUs, err) + return false, err + } + + // 5、清理持仓订单信息 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), positionKey, orderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockClosingByOrderId.HDel:%v", common.ErrShareUs, err) + return false, flags.ErrCacheDB + } + + // 6、平仓更新订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(userKey, entrustCache.UserId) + if err = UpdateShareUsSubscribeHashStatusByOrderId(orderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockClosingByOrderId.%v:%v", common.ErrShareUs, userKey, err) + return false, flags.ErrCacheDB + } + + // 7、平仓更新管理员订阅缓存订单状态 + if err = UpdateShareUsSubscribeHashStatusByOrderId(orderId, adminKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockClosingByOrderId.%v:%v", common.ErrShareUs, adminKey, err) + return false, flags.ErrCacheDB + } + + return true, nil +} + +// UpdateBotStockAllClosingByOrderId +// +// @Description: 美股用户一键平仓 +// @receiver uo +// @param ctx +// @param userId +// @return error +func (uo *userOrderRepo) UpdateBotStockAllClosingByOrderId(ctx context.Context, userId int64) error { + // 下单判定-冷静期停止所有交易 + if CheckGlobalTread(flags.UsMarket) { + return flags.ErrStopTread + } + + // TODO: 获取存在IPO未支付订单的用户 + userIdMap, _ := GetBotUserArrears(ctx) + _, isOk := userIdMap[userId] + if isOk { + return flags.ErrPublicServe + } + + // 1、查询当前用户所有订单 + orderMap, err := uo.GetBotStockTradeByUserId(userId) + if err != nil { + applogger.Error("%v UpdateBotStockAllClosingByOrderId.GetBotStockTradeByUserId:%v", common.ErrShareUs, err) + return flags.ErrMySqlDB + } + + // 2、查询持仓缓存列表数据-1、清理持仓列表缓存 2、处理平仓数据 3、清理订单ID缓存列表 + entrust, err := Reds.HGetAll(context.Background(), setting.MarketShareUsPosition).Result() + if err != nil { + applogger.Error("%v UpdateBotStockAllClosingByOrderId.HGetAll:%v", common.ErrShareUs, err) + return flags.ErrShareFive + } + + // 3、循环检查股票交易对最新价格(有一个查询不到既不能平仓) + var entrustList []share.ShareUsTallyCache + closePriceMap := make(map[string]decimal.Decimal) + for key, value := range entrust { + var entrustJson share.ShareUsTallyCache + if err = json.Unmarshal([]byte(value), &entrustJson); err != nil { + applogger.Error("%v UpdateBotStockAllClosingByOrderId.Unmarshal:%v", common.ErrShareUs, err) + return flags.ErrStopTread + } + + _, ok := orderMap[entrustJson.OrderId] + if ok { + var closingPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Us, entrustJson.Symbol, flags.TradeTypePrice) + closingPrice, err = uo.GetShareUSTheLatestPrice(subKey, entrustJson.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotStockAllClosingByOrderId.GetShareUSTheLatestPrice:%v", common.ErrShareUs, err) + return flags.ErrStopTread + } + if !flags.CheckSetting { + applogger.Debug("订阅Key:%v,最新价格:%v,订单ID:%v", subKey, closingPrice, entrustJson.OrderId) + } + + closePriceMap[key] = closingPrice + entrustList = append(entrustList, entrustJson) + } + } + + // 4、股票一键平仓 + for _, value := range entrustList { + closePrice, ok := closePriceMap[value.OrderId] + if ok { + // 平仓 + if err = StockClosingOrder(ctx, uo.data.mysqlDB, value.OrderId, closePrice.String(), value.Order); err != nil { + applogger.Error("%v UpdateBotStockAllClosingByOrderId.StockClosingOrder:%v", common.ErrShareUs, err) + return err + } + + // 清理持仓缓存列表 + var removedCount int64 + removedCount, err = Reds.HDel(context.Background(), setting.MarketShareUsPosition, value.OrderId).Result() + if err != nil || removedCount == 0 { + applogger.Error("%v UpdateBotStockAllClosingByOrderId.HDel:%v", common.ErrShareUs, err) + return flags.ErrCacheDB + } + + // 平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareUsSubscribe, value.UserId) + if err = UpdateShareUsSubscribeHashStatusByOrderId(value.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockAllClosingByOrderId.ShareUsSubscribe:%v", common.ErrShareUs, err) + return flags.ErrCacheDB + } + + // 平仓更新管理员订阅订单状态 + if err = UpdateShareUsSubscribeHashStatusByOrderId(value.OrderId, setting.AdminShareUsSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotStockAllClosingByOrderId.AdminShareUsSubscribe:%v", common.ErrShareUs, err) + return flags.ErrCacheDB + } + } + } + + return nil +} + +// GetBotStockTradeByUserId +// +// @Description: +// @receiver uo +// @param ctx +// @param userId +// @return map[string]string +// @return error +func (uo *userOrderRepo) GetBotStockTradeByUserId(userId int64) (map[string]string, error) { + var botStockTrade []models.BotStockTrade + if err := uo.data.mysqlDB.Table(flags.BotStockTrade). + Where("user_id = ?", userId). + Where("status = 1"). + Find(&botStockTrade); err != nil { + return nil, err + } + + botMap := make(map[string]string) + for _, value := range botStockTrade { + botMap[value.OrderId] = value.OrderId + } + + return botMap, nil +} + +// GetShareUSTheLatestPrice +// +// @Description: +// @receiver uo +// @param ctx +// @param subKey +// @param tradeType +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) GetShareUSTheLatestPrice(subKey string, tradeType int64) (decimal.Decimal, error) { + priceNew, err := share.ShareUsSubMarketPrice(subKey) + if err != nil { + applogger.Error("%v GetShareUSTheLatestPrice.ShareUsSubMarketPrice:%v", common.ErrShareUs, err) + return decimal.Decimal{}, err + } + + priceS := decimal.RequireFromString(priceNew) + + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tradeType { + case flags.TradeTypeBuy: // 买涨 + openPrice = priceS.Sub(difference) // 开仓价格 + case flags.TradeTypeSell: // 买跌 + openPrice = priceS.Add(difference) // 开仓价格 + default: + + } + + return openPrice, nil +} + +// GetBotStockTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @return *models.BotStockTrade +// @return error +func (uo *userOrderRepo) GetBotStockTradeByOrderId(session *xorm.Session, orderId string) (*models.BotStockTrade, error) { + var botStockTrade []models.BotStockTrade + if err := session.Table(flags.BotStockTrade). + Where("order_id = ?", orderId). + Find(&botStockTrade); err != nil { + return nil, err + } + + for _, value := range botStockTrade { + return &value, nil + } + + return nil, nil +} + +// GetBotStockBlockTradeByOrderId +// +// @Description: +// @receiver uo +// @param session +// @param orderId +// @return *models.botStockBlockTrade +// @return error +func (uo *userOrderRepo) GetBotStockBlockTradeByOrderId(session *xorm.Session, orderId string) (*models.BotStockBlockTrade, error) { + var botStockBlockTrade []models.BotStockBlockTrade + if err := session.Table(flags.BotStockBlockTrade). + Where("order_id = ?", orderId). + Find(&botStockBlockTrade); err != nil { + return nil, err + } + + for _, value := range botStockBlockTrade { + return &value, nil + } + + return nil, nil +} + +// GetBotUserStockByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @return *models.BotUserStock +// @return error +func (uo *userOrderRepo) GetBotUserStockByUserIdAndStockId(session *xorm.Session, userId int64, stockId string) (*models.BotUserStock, error) { + var stockUSD []models.BotUserStock + if err := session.Table(flags.BotUserStock). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&stockUSD); err != nil || len(stockUSD) < 0 { + return nil, err + } + + for _, value := range stockUSD { + return &value, nil + } + + return nil, nil +} + +// UpdateBotStockTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotStockTradeByOrderId(session *xorm.Session, orderId string, stock models.BotStockTrade) error { + checkInt, err := session.Table(flags.BotStockTrade). + Where("order_id = ?", orderId). + Update(&stock) + if err != nil || checkInt < 0 { + return err + } + + return nil +} + +// UpdateBotStockBlockTradeByOrderId +// +// @Description: +// @receiver uo +// @param session +// @param orderId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotStockBlockTradeByOrderId(session *xorm.Session, orderId string, stock models.BotStockBlockTrade) error { + checkInt, err := session.Table(flags.BotStockBlockTrade). + Where("order_id = ?", orderId). + Update(&stock) + if err != nil || checkInt < 0 { + return err + } + + return nil +} + +// CreateBotStockTrade +// +// @Description: 美股交易订单 +// @receiver uo +// @param ctx +// @param session +// @param trade +// @return error +func (uo *userOrderRepo) CreateBotStockTrade(session *xorm.Session, trade models.BotStockTrade) error { + _, err := session.Table(flags.BotStockTrade).Insert(&trade) + if err != nil { + return err + } + + return nil +} + +// CreateBotStockBlockTrade +// +// @Description: 大宗(美股)交易订单 +// @receiver uo +// @param session +// @param trade +// @return error +func (uo *userOrderRepo) CreateBotStockBlockTrade(session *xorm.Session, trade models.BotStockBlockTrade) error { + _, err := session.Table(flags.BotStockBlockTrade).Insert(&trade) + if err != nil { + return err + } + + return nil +} + +// CreateBotUserStockFUSD +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param stock +// @return error +func (uo *userOrderRepo) CreateBotUserStockFUSD(session *xorm.Session, stock models.BotUserStock) error { + _, err := session.Table(flags.BotUserStock).Insert(&stock) + if err != nil { + return err + } + + return nil +} + +// UpdateBotUserStockByUserIdAndStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param stockId +// @param stock +// @return error +func (uo *userOrderRepo) UpdateBotUserStockByUserIdAndStockId(session *xorm.Session, userId int64, stockId string, stock models.BotUserStock) error { + checkNum, err := session.Table(flags.BotUserStock). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&stock) + if err != nil || checkNum < 0 { + return err + } + + return nil +} + +// StockVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) StockVoteDealType(order structure.ShareOrder) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + return limitOrMarketPrice, nil +} + +// UpdateShareVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) UpdateShareVoteDealType(order *models.BotStockTrade) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + if len(order.DealPrice) != 0 { + dealPrice := decimal.RequireFromString(order.DealPrice) + if !dealPrice.IsZero() { + limitOrMarketPrice = dealPrice + } + } + + return limitOrMarketPrice, nil +} + +// UpdateShareBlockVoteDealType +// +// @Description: +// @receiver uo +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) UpdateShareBlockVoteDealType(order *models.BotStockBlockTrade) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + if len(order.DealPrice) != 0 { + dealPrice := decimal.RequireFromString(order.DealPrice) + if !dealPrice.IsZero() { + limitOrMarketPrice = dealPrice + } + } + + return limitOrMarketPrice, nil +} + +// VerifyBotStockTradeOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @return string +// @return error +func (uo *userOrderRepo) VerifyBotStockTradeOrderId(session *xorm.Session) (string, error) { + var orderId string + for { + // 生成订单ID + orderId = orders.CreateRandCodeOrder(10) + + var orderList []models.BotStockTrade + err := session.Table(flags.BotStockTrade). + Where("order_id = ?", orderId). + Find(&orderList) + if err != nil || len(orderList) > 0 { + applogger.Error("%v VerifyBotStockTradeOrderId.Find:%v", common.ErrShareUs, err) + continue + } + + break + } + + return orderId, nil +} + +// GetBotStockTradeByOrderIdOrStatus +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param status +// @return *models.BotStockTrade +// @return error +func (uo *userOrderRepo) GetBotStockTradeByOrderIdOrStatus(session *xorm.Session, orderId string, status int) (*models.BotStockTrade, error) { + var botStockTrade []models.BotStockTrade + if err := session.Table(flags.BotStockTrade). + Where("order_id = ?", orderId). + Where("`status` = ?", status). + Find(&botStockTrade); err != nil { + return nil, err + } + + for _, value := range botStockTrade { + return &value, nil + } + + return nil, nil +} + +// GetBotStockBlockTradeByOrderIdOrStatus +// +// @Description: +// @receiver uo +// @param session +// @param orderId +// @param status +// @return *models.BotStockBlockTrade +// @return error +func (uo *userOrderRepo) GetBotStockBlockTradeByOrderIdOrStatus(session *xorm.Session, orderId string, status int) (*models.BotStockBlockTrade, error) { + var botStockTrade []models.BotStockBlockTrade + if err := session.Table(flags.BotStockBlockTrade). + Where("order_id = ?", orderId). + Where("`status` = ?", status). + Find(&botStockTrade); err != nil { + return nil, err + } + + for _, value := range botStockTrade { + return &value, nil + } + + return nil, nil +} diff --git a/internal/data/order_virtual_contract.go b/internal/data/order_virtual_contract.go new file mode 100644 index 0000000..41e4642 --- /dev/null +++ b/internal/data/order_virtual_contract.go @@ -0,0 +1,1495 @@ +package data + +import ( + "context" + "encoding/json" + "github.com/go-xorm/xorm" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "strconv" + "strings" + + orders "matchmaking-system/internal/data/convert" + models "matchmaking-system/internal/pkg/model" +) + +// GetBotContractTradeList +// +// @Description: 合约-秒合约订单列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param userId +// @param status +// @return []*models.BotContractTrade +// @return int64 +// @return error +func (uo *userOrderRepo) GetBotContractTradeList(ctx context.Context, pageSize, pageCount, userId, status int64) ([]*models.BotContractTrade, int64, error) { + totalCount, err := uo.data.mysqlDB.Table(flags.BotContractTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Count() + if err != nil { + return nil, 0, flags.ErrMySqlDB + } + if totalCount == 0 { + return nil, 0, nil + } + var contractList []*models.BotContractTrade + if err = uo.data.mysqlDB.Table(flags.BotContractTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Limit(int(pageSize), int(pageCount)). + Desc(GetOrderByStatusSort(status)). + Find(&contractList); err != nil { + return nil, 0, flags.ErrMySqlDB + } + + var contractUpdateList []*models.BotContractTrade + for _, value := range contractList { + value.KeepDecimal = GetKeepDecimal(flags.ContractSystemSetUpKey, value.ContractId) + contractUpdateList = append(contractUpdateList, value) + } + + return contractUpdateList, totalCount, nil +} + +// CreateBotContractTrade +// +// @Description: 合约下单 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) CreateBotContractTrade(ctx context.Context, userId int64, order structure.ContractOrder) (string, error) { + // 1、合约下单订阅 + contractId := strings.ToUpper(order.ContractId) + _, ok := contract.ContractMapSymbol.Load(contractId) + if ok { + go func() { + contract.ContractMap <- []byte(contractId) + }() + } + + // 2、获取系统设置 + system, err := GetContractSystemSetUp(contractId) + if err != nil || system == nil { + return flags.SetNull, flags.ErrContractOne + } + order.System = system + + // 3、获取交易币市价 + //priceNew, err := GetDigitalCurrencyPrice(ctx, flags.Hy, contractId) + //if len(priceNew) == 0 || err != nil { + // applogger.Error("%v CreateBotContractTrade.ContractSubMarketPrice:%v", common.ErrContract, err) + // return flags.SetNull, flags.ErrPriceUpdate + //} + + // 4、合约下单判定 + // 杠杆校验 + pryNum := decimal.RequireFromString(order.PryNum) + if pryNum.Cmp(order.System.MinPry) < 0 || pryNum.Cmp(order.System.MaxPry) > 0 { + return flags.SetNull, flags.ErrContractTow + } + // 下单判定设置(false无设置|true止盈止损) + checkBool, stopWinPrice, stopLossPrice, err := ContractVoteStopType(order) + if err != nil { + applogger.Error("%v CreateBotContractTrade.ContractVoteStopType:%v", common.ErrContract, err) + return flags.SetNull, err + } + // 下单判定设置(限价|市价) + limitOrMarketPrice, err := uo.ContractVoteDealType(order) + if err != nil { + applogger.Error("%v CreateBotContractTrade.ContractVoteDealType:%v", common.ErrContract, err) + return flags.SetNull, err + } + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(order.TradeType, stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v CreateBotContractTrade.VoteTradeType:%v", common.ErrContract, err) + return flags.SetNull, err + } + + // 5、合约下单(订单信息|资产信息) + orderId, err := uo.ContractOrdersWriteDB(ctx, userId, order) + if err != nil || len(orderId) == 0 { + applogger.Error("%v CreateBotContractTrade.ContractOrdersWriteDB:%v", common.ErrContract, err) + return flags.SetNull, err + } + + // 6、写入缓存列表(挂单缓存|持仓缓存),等待撮合计算 + marketStatus, tallyCache, err := virtual.ContractCacheDeal(ctx, userId, orderId, limitOrMarketPrice.String(), order) + if err != nil || tallyCache == nil { + applogger.Error("%v CreateBotContractTrade.ContractCacheDeal:%v", common.ErrContract, err) + return flags.SetNull, err + } + + // 7、市价下单开仓处理(订单信息|资产信息|手续费|返佣|资产详情记录) + if marketStatus == setting.MarketContractPosition { + if err = ContractOpenPosition(ctx, uo.data.mysqlDB, userId, orderId, tallyCache.OpenPrice, order); err != nil { + applogger.Error("%v CreateBotContractTrade.ContractOpenPosition:%v", common.ErrContract, err) + return flags.SetNull, err + } + } + + // 8、写入(挂单|持仓)缓存列表 + if err = virtual.ContractPushAddCache(Reds, marketStatus, tallyCache); err != nil { + applogger.Error("%v CreateBotContractTrade.ContractPushAddCache:%v", common.ErrContract, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 9、写入用户订单订阅缓存列表 + orderIdKey := virtual.OrderIdListKey(setting.ContractSubscribe, userId) + if err = virtual.ContractHashSetOrderId(Reds, orderIdKey, tallyCache); err != nil { + applogger.Error("%v CreateBotContractTrade.ContractPushAddOrder:%v", common.ErrContract, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 10、写入管理员订单订阅缓存列表 + if err = virtual.ContractHashSetOrderId(Reds, setting.AdminContractSubscribe, tallyCache); err != nil { + applogger.Error("%v CreateBotContractTrade.ContractHashSetOrderId:%v", common.ErrContract, err) + return flags.SetNull, flags.ErrCacheDB + } + + return orderId, nil +} + +// ContractOrdersWriteDB +// +// @Description: 合约下单处理 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) ContractOrdersWriteDB(ctx context.Context, userId int64, order structure.ContractOrder) (string, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v ContractOrdersWriteDB.NewSession:%v", common.ErrContract, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + usable, frozen, _, err = uo.GetBotUserContract(session, userId, flags.BasicUnit) + if err != nil { + applogger.Error("%v ContractOrdersWriteDB.GetBotUserContract:%v", common.ErrContract, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 检查用户订单下单资产 + if usable.IsZero() || usable.IsNegative() || frozen.IsNegative() { + return flags.SetNull, flags.ErrPublicOne + } + // 查询当前下单用户可用非账户和冻结金额 + var checkCount int + if order.ContractId != flags.BasicUnit { + usableNo, frozenNo, checkCount, err = uo.GetBotUserContract(session, userId, order.ContractId) + if err != nil { + applogger.Error("%v ContractOrdersWriteDB.GetBotUserContract.Fei:%v", common.ErrContract, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("非下单可用金额:%v", usableNo) + applogger.Debug("非下单冻结金额:%v", frozenNo) + } + + // 写入订单信息 + orderId, err := uo.VerifyBotContractTradeOrderId(session) + if err != nil { + applogger.Error("%v ContractOrdersWriteDB.VerifyBotContractTradeOrderId:%v", common.ErrContract, err) + return flags.SetNull, err + } + if !flags.CheckSetting { + applogger.Debug("下单Id:%v", orderId) + applogger.Debug("杠杆:%v", order.PryNum) + } + + // 写入订单表 + botStockTrade := orders.BotContractTrade(ctx, userId, orderId, order) + if err = uo.CreatBotContractTrade(session, botStockTrade); err != nil { + applogger.Error("%v ContractOrdersWriteDB.CreatBotContractTrade:%v", common.ErrContract, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 订单总金额 = 保证金 + 手续费 + earnestMoney := decimal.RequireFromString(order.EarnestMoney) // 保证金 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 手续费 + totalMoney := earnestMoney.Add(serviceCost) + + // 总金额下单判定 + residue := usable.Sub(totalMoney).Div(usable) + if usable.Cmp(totalMoney) < 0 || residue.Cmp(utils.DecimalsStrInt()) < 0 { + return flags.SetNull, flags.ErrPublicOne + } + + // (买涨|买跌)处理 + var usableNew, frozenNew, usableNewNo, frozenNewNo decimal.Decimal + usableNew = usable.Sub(totalMoney) // 可用资产 + frozenNew = frozen.Add(totalMoney) // 冻结资产 + if order.ContractId != flags.BasicUnit { + usableNewNo = usableNo // 可用非资产 + frozenNewNo = frozenNo // 冻结非资产 + } + + // 检查用户订单下单资产 + if usableNew.IsNegative() || usableNew.IsZero() { + return flags.SetNull, flags.ErrPublicTow + } + if !flags.CheckSetting { + applogger.Debug("下单后用户可用资产:%v", usableNew) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + applogger.Debug("下单后用户非可用资产:%v", usableNewNo) + applogger.Debug("下单后用户非冻结资产:%v", frozenNewNo) + } + + // 更新用户资产信息 + userContractUSDT := orders.UpdateBotUserContract(ctx, usableNew.String(), frozenNew.String()) + if err = uo.UpdateBotUserContract(session, userId, flags.BasicUnit, userContractUSDT); err != nil { + applogger.Error("%v ContractOrdersWriteDB.UpdateBotUserContract:%v", common.ErrContract, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 更新非资产信息 + if order.ContractId != flags.BasicUnit { + if checkCount == 0 { + userDigitalSymbol := orders.CreatBotUserContract(ctx, userId, usableNewNo.String(), frozenNewNo.String(), order) + err = uo.CreatBotUserContract(session, userDigitalSymbol) + if err != nil { + applogger.Error("%v ContractOrdersWriteDB.CreatBotUserContract:%v", common.ErrContract, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + userContract := orders.UpdateBotUserContract(ctx, usableNewNo.String(), frozenNewNo.String()) + if err = uo.UpdateBotUserContract(session, userId, order.ContractId, userContract); err != nil { + applogger.Error("%v ContractOrdersWriteDB.UpdateBotUserContract:%v", common.ErrContract, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v ContractOrdersWriteDB.Commit:%v", common.ErrContract, err) + return flags.SetNull, flags.ErrMySqlDB + } + + return orderId, nil +} + +// ContractOpenPosition +// +// @Description: 合约开仓处理 +// @param ctx +// @param db +// @param userId +// @param orderId +// @param openPrice +// @param order +// @return error +func ContractOpenPosition(ctx context.Context, db *xorm.EngineGroup, userId int64, orderId, openPrice string, order structure.ContractOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v ContractOpenPosition.NewSession:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + usable, frozen, _, err = Uo.GetBotUserContract(session, userId, flags.BasicUnit) + if err != nil { + applogger.Error("%v ContractOpenPosition.GetBotUserContract:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrPublicThree + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + } + + if order.ContractId != flags.BasicUnit { + usableNo, frozenNo, _, err = Uo.GetBotUserContract(session, userId, order.ContractId) + if err != nil { + applogger.Error("%v ContractOpenPosition.GetBotUserContract:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + } + + // 转换下单信息 + earnestMoney := decimal.RequireFromString(order.EarnestMoney) // 下单保证金 + orderNumber := decimal.RequireFromString(order.OrderNumber) // 下单仓位 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 下单手续费 + totalMoney := earnestMoney.Add(serviceCost) // 下单总金额 = (订单手续费 + 保证金) + openOrderPrice := decimal.RequireFromString(openPrice) // 开仓价格 + openOrderNumber := orderNumber // 开仓数量 + if !flags.CheckSetting { + applogger.Debug("下单保证金:%v", earnestMoney) + applogger.Debug("下单订单数量:%v", orderNumber) + applogger.Debug("下单订单手续费:%v", serviceCost) + applogger.Debug("下单订单总金额:%v", totalMoney) + applogger.Debug("下单开仓量:%v", openOrderNumber) + applogger.Debug("下单开仓价:%v", openOrderPrice) + } + + //openFaceValue := order.System.FaceValue // 面值 + //openOrderPrice := decimal.RequireFromString(openPrice) // 开仓价格 + //pryNum := decimal.RequireFromString(order.PryNum) // 杠杆 + //openOrderNumber := orderNumber // 开仓数量 + //openOrderNumber := earnestMoney.Mul(pryNum).Div(openOrderPrice).Div(openFaceValue) // 开仓数量 = (保证金 * 杠杆) / 开仓价格 / 面值 + + // TODO: 手续费记录 + //openPriceNew := openOrderPrice.Mul(openOrderNumber).String() // 开仓手续费 = 开仓价格 * 仓位数 * 手续费比例 + //cost, err := Uo.CalculateHandlingFees(ctx, session, int(userId), flags.ContractMarketType, flags.OpenBrokType, orderId, openPriceNew, openFaceValue.String()) + //if err != nil { + // applogger.Error("%v ContractOpenPosition.CalculateHandlingFees:%v", common.ErrContract, err) + // return err + //} + //openServiceCost := decimal.RequireFromString(cost) // 开仓手续费 + + openServiceCost := serviceCost //开仓手续费 + openTotalMoney := earnestMoney.Add(openServiceCost) // 开仓总金额 = (保证金 + 开仓手续费) + floatPrice := totalMoney.Sub(openTotalMoney) // 计算容差 = 下单总额 - 开仓总额 + if !flags.CheckSetting { + applogger.Debug("开仓订单价格:%v", openOrderPrice) + applogger.Debug("开仓仓位:%v", openOrderNumber) + applogger.Debug("开仓手续费:%v", openServiceCost) + applogger.Debug("开仓总金额:%v", openTotalMoney) + applogger.Debug("下单开仓总金额容差值:%v", floatPrice) + } + + usableNew := usable.Add(floatPrice) // 可用资产(处理容差值) + frozenNew := frozen.Sub(totalMoney).Add(earnestMoney) // 冻结资产 = 冻结资产 - 下单冻结资产 + 开仓保证金 + usableNoNew := usableNo.Add(openOrderNumber) // 非可用资产 + frozenNoNew := frozenNo // 非冻结资产 + if !flags.CheckSetting { + applogger.Debug("下单后用户可用资产:%v", usableNew) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + } + applogger.Debug("下单冻结资产:%v", frozen) + applogger.Debug("下单后的冻结总资产:%v", totalMoney) + applogger.Debug("开仓后的保证金:%v", earnestMoney) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + applogger.Debug("下单后用户可用资产:%v", usableNew) + + // 检查用户平仓资产 + if usableNoNew.IsNegative() { + return flags.ErrPublicThree + } + + // 处理资产信息 + userContractUSDT := orders.UpdateBotUserContract(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserContract(session, userId, flags.BasicUnit, userContractUSDT); err != nil { + applogger.Error("%v ContractOpenPosition.UpdateBotUserContract:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + + // 更新非资产信息 + if order.ContractId != flags.BasicUnit { + userContract := orders.UpdateBotUserContract(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = Uo.UpdateBotUserContract(session, userId, order.ContractId, userContract); err != nil { + applogger.Error("%v ContractOpenPosition.UpdateBotUserContract:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + } + + // 处理订单信息(成交价|仓位|开仓时间|订单总金额|手续费|持仓状态) + trade := orders.UpdateOpenBotContractTrade(ctx, openPrice, openOrderNumber.String(), openTotalMoney.String(), openServiceCost.String()) + if err = Uo.UpdateBotContractTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v ContractOpenPosition.UpdateBotContractTradeByOrderId:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + + // 返佣记录|资金信息|资金详情信息 + if err = Uo.ContractRebateCalculation(ctx, session, int(userId), flags.ContractMarketType, flags.OpenBrokType, flags.OpenMRebate, openServiceCost.String(), orderId); err != nil { + applogger.Error("%v ContractOpenPosition.ContractRebateCalculation:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + + // 更改交易日志记录方式 + var list []models.BotUserContractLog + qData0 := orders.CreatBotUserContractLog(ctx, userId, flags.CostMoney, flags.BasicUnit, NegativeValue(openServiceCost.String()), orderId) // 资金变动明细表(开仓手续费) + qData1 := orders.CreatBotUserContractLog(ctx, userId, flags.Freeze, flags.BasicUnit, NegativeValue(earnestMoney.String()), orderId) // 资金变动明细表(开仓保证金) + qData2 := orders.CreatBotUserContractLog(ctx, userId, flags.ChangeInto, order.ContractId, orderNumber.String(), orderId) // 资金变动明细表(非资产) + list = append(list, qData0, qData1, qData2) + + // 批量写入数据信息 + if err = Uo.CreatBotUserContractLogList(session, list); err != nil { + applogger.Error("%v ContractOpenPosition.CreatBotUserContractLogList:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v ContractOpenPosition.Commit:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + + return nil +} + +// ContractClosingPosition +// +// @Description: 合约平仓处理 +// @param ctx +// @param db +// @param orderId +// @param price +// @param order +// @return error +func ContractClosingPosition(ctx context.Context, db *xorm.EngineGroup, orderId string, price string, order structure.ContractOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v ContractClosingPosition.NewSession:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + + // 查询订单信息 + tread, err := Uo.GetBotContractTradeByOrderId(session, orderId, flags.PositionStatus) + if err != nil { + applogger.Error("%v ContractClosingPosition.GetBotContractTradeByOrderId:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + var userId int64 + var dealPrice, earnestMoney, orderNumber, totalAmount, serviceCost, pryNum decimal.Decimal + if tread != nil { + userId = int64(tread.UserId) // 用户Id + earnestMoney = decimal.RequireFromString(tread.EarnestMoney) // 开仓保证金 + orderNumber = decimal.RequireFromString(tread.OrderNumber) // 下单数量 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + totalAmount = decimal.RequireFromString(tread.TotalMoney) // 开仓总金额 + serviceCost = decimal.RequireFromString(tread.ServiceCost) // 开仓手续费 + pryNum = decimal.RequireFromString(strconv.Itoa(tread.PryNum)) // 杠杆 + } + if !flags.CheckSetting { + applogger.Debug("下单开仓用户Id:%v", userId) + applogger.Debug("下单开仓开仓价格:%v", dealPrice) + applogger.Debug("下单开仓保证金:%v", earnestMoney) + applogger.Debug("下单开仓订单数量:%v", orderNumber) + applogger.Debug("下单开仓总金额:%v", totalAmount) + applogger.Debug("下单开仓手续费:%v", serviceCost) + applogger.Debug("下单杠杆:%v", pryNum) + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen, usableNo, frozenNo decimal.Decimal + usable, frozen, _, err = Uo.GetBotUserContract(session, userId, flags.BasicUnit) + if err != nil { + applogger.Error("%v ContractClosingPosition.GetBotUserContract:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + // 检查用户订单平仓资产 + if usable.IsNegative() || frozen.IsNegative() { + return flags.ErrContractFive + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + } + + // 查询当前下单用户可用非账户和冻结金额 + if order.ContractId != flags.BasicUnit { + usableNo, frozenNo, _, err = Uo.GetBotUserContract(session, userId, order.ContractId) + if err != nil { + applogger.Error("%vContractClosingPosition.GetBotUserContract:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + } + if !flags.CheckSetting { + applogger.Debug("非下单可用金额:%v", usableNo) + applogger.Debug("非下单冻结金额:%v", frozenNo) + } + + closeFaceValue := order.System.FaceValue // 面值 + + // 手续费处理 + closePrice := decimal.RequireFromString(price) // 平仓价格 + cloePriceCost := closePrice.Mul(orderNumber).String() // 平仓手续费 = 平仓价格 * 仓位数 * 手续费比例 * 面值 + cost, err := Uo.CalculateHandlingFees(ctx, session, int(userId), flags.ContractMarketType, flags.ClosingBrokType, orderId, cloePriceCost, closeFaceValue.String()) + if err != nil { + applogger.Error("%v ContractClosingPosition.CalculateHandlingFees:%v", common.ErrContract, err) + return err + } + closeServiceCost := decimal.RequireFromString(cost) + if !flags.CheckSetting { + applogger.Debug("平仓价格:%v", closePrice) + applogger.Debug("平仓手续费手续费:%v", closeServiceCost) + } + + //已经实现盈亏计算公式(已平仓结算方式) + //买涨 已经实现盈亏 = (平仓成交价-开仓成交价)*仓位数*面值*杠杆 + //买跌 已经实现盈亏 = (开仓成交价-平仓成交价)*仓位数*面值*杠杆 + var usableNew, frozenNew, usableNewNo, frozenNewNo, subPrice, resultPrice decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买涨 + subPrice = closePrice.Sub(dealPrice) + resultPrice = subPrice.Mul(orderNumber).Mul(closeFaceValue).Mul(pryNum) + case flags.TradeTypeSell: // 买跌 + subPrice = dealPrice.Sub(closePrice) + resultPrice = subPrice.Mul(orderNumber).Mul(closeFaceValue).Mul(pryNum) + default: + + } + + // TODO: 判定亏损不能超过 = 保证金 + 平仓手续费 + if resultPrice.IsNegative() { + amountLoss := earnestMoney.Sub(closeServiceCost) + if resultPrice.Abs().Cmp(amountLoss) >= 0 { + resultPrice = amountLoss.Neg() + } + } + + // 用户资产账户 + usableNew = usable.Add(resultPrice).Add(earnestMoney).Sub(closeServiceCost) // 可用资产 = 原可用资产 + ((正负)盈亏*面值) + 保证金 - 手续费 + frozenNew = frozen.Sub(earnestMoney) // 冻结资产 + if frozenNew.IsNegative() { + frozenNew = decimal.Zero + } + // 用户非资产账户 + if order.ContractId != flags.BasicUnit { + usableNewNo = usableNo.Sub(orderNumber) // 可用非资产 = 原可用非资产 - 下单仓位数 + frozenNewNo = frozenNo // 可用非冻结资产 + } + + // 检查用户订单平仓资产 + if usableNewNo.IsNegative() { + return flags.ErrContractFive + } + if !flags.CheckSetting { + applogger.Debug("可用资产:%v", usableNew) + applogger.Debug("冻结资产:%v", frozenNew) + applogger.Debug("可用非资产:%v", usableNewNo) + applogger.Debug("冻结非资产:%v", frozenNewNo) + } + + // 平仓(处理资产表(资产)) + userContractUSDT := orders.UpdateBotUserContract(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserContract(session, userId, flags.BasicUnit, userContractUSDT); err != nil { + applogger.Error("%v ContractClosingPosition.UpdateBotUserContract:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + + // 平仓(处理资产表(非资产)) + if order.ContractId != flags.BasicUnit { + userContract := orders.UpdateBotUserContract(ctx, usableNewNo.String(), frozenNewNo.String()) + if err = Uo.UpdateBotUserContract(session, userId, order.ContractId, userContract); err != nil { + applogger.Error("%v ContractClosingPosition.UpdateBotUserContract:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + } + + // 平仓(处理订单信息(平仓价|保证金|平仓|订单总金额|平仓手续费|完成订单)) + trade := orders.UpdateCloseBotContractTrade(ctx, price, earnestMoney.String(), totalAmount.String(), cost) + if err = Uo.UpdateBotContractTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v ContractClosingPosition.UpdateBotContractTradeByOrderId:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + + // 平仓(返佣记录表|资产表|资金变动表) + if err = Uo.ContractRebateCalculation(ctx, session, int(userId), flags.ContractMarketType, flags.ClosingBrokType, flags.CloseMRebate, cost, orderId); err != nil { + applogger.Error("%v ContractClosingPosition.ContractRebateCalculation:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + + // 更改交易日志记录方式 + var list []models.BotUserContractLog + qData0 := orders.CreatBotUserContractLog(ctx, userId, flags.CostMoney, flags.BasicUnit, NegativeValue(closeServiceCost.String()), orderId) // 平仓(资金变动明细表(-平仓手续费)) + qData1 := orders.CreatBotUserContractLog(ctx, userId, flags.Thaw, flags.BasicUnit, earnestMoney.String(), orderId) // 平仓(资金变动明细表(+保证金)) + qData2 := orders.CreatBotUserContractLog(ctx, userId, flags.TransferOut, order.ContractId, NegativeValue(orderNumber.String()), orderId) // 平仓(资金变动明细表(-非资产)) + list = append(list, qData0, qData1, qData2) + + // 平仓(资金变动明细表(正负盈亏)) + if resultPrice.IsNegative() { + qData3 := orders.CreatBotUserContractLog(ctx, userId, flags.TransferOut, flags.BasicUnit, resultPrice.String(), orderId) + list = append(list, qData3) + } else { + qData4 := orders.CreatBotUserContractLog(ctx, userId, flags.ChangeInto, flags.BasicUnit, resultPrice.String(), orderId) + list = append(list, qData4) + } + + // 平仓(批量写入交易订单日志信息) + if err = Uo.CreatBotUserContractLogList(session, list); err != nil { + applogger.Error("%v ContractClosingPosition.CreatBotUserContractLogList:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v ContractClosingPosition.Commit:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + + return nil +} + +// UpdateBotContractStopByOrderId +// +// @Description: 合约设置止盈止损 +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotContractStopByOrderId(ctx context.Context, order structure.StopOrder) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotContractStopByOrderId.NewSession:%v", common.ErrContract, err) + return false, flags.ErrMySqlDB + } + + // 设置止盈止损判定 + trade, err := uo.GetBotContractTradeByOrderId(session, order.OrderId, flags.PositionStatus) + if err != nil || trade == nil { + applogger.Error("%v UpdateBotContractStopByOrderId.GetBotContractTradeByOrderId:%v", common.ErrContract, err) + return false, flags.ErrMySqlDB + } + // 下单信息 + checkBool, stopWinPrice, stopLossPrice, err := uo.UpdateVoteStopType(order) + if err != nil { + applogger.Error("%v UpdateBotContractStopByOrderId.UpdateVoteStopType:%v", common.ErrContract, err) + return false, err + } + if !flags.CheckSetting { + applogger.Debug("获取当前止盈止损数据:%v,%v,%v", checkBool, stopWinPrice, stopLossPrice) + } + + // 下单判定设置(限价|市价|开仓价) + limitOrMarketPrice, err := uo.UpdateVoteDealType(trade) + if err != nil { + applogger.Error("%v UpdateBotContractStopByOrderId.UpdateVoteDealType:%v", common.ErrContract, err) + return false, err + } + if !flags.CheckSetting { + applogger.Debug("获取当前开仓价格:%v", limitOrMarketPrice) + } + + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(int64(trade.TradeType), stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v UpdateBotContractStopByOrderId.VoteTradeType:%v", common.ErrContract, err) + return false, err + } + + // 更新订单表 + botStockTrade := orders.BotContractStopByOrderId(ctx, order) + err = uo.UpdateBotContractTradeByOrderId(session, order.OrderId, botStockTrade) + if err != nil { + applogger.Error("%v UpdateBotContractStopByOrderId.Update:%v", common.ErrContract, err) + return false, flags.ErrMySqlDB + } + + // 修改挂单缓存队列 + entrust, err := LoadLRangeList(setting.MarketContractPosition) + if err != nil { + applogger.Error("%v UpdateBotContractStopByOrderId.LoadLRangeList:%v", common.ErrContract, err) + return false, flags.ErrCacheDB + } + for key, value := range entrust { + var entrustJson virtual.ContractTallyCache + if err = json.Unmarshal([]byte(value), &entrustJson); err != nil { + applogger.Error("%v UpdateBotContractStopByOrderId.Unmarshal:%v", common.ErrContract, err) + return false, flags.ErrCacheDB + } + entrustJson.Order.StopType = order.StopType + entrustJson.Order.StopWinPrice = order.StopWinPrice + entrustJson.Order.StopLossPrice = order.StopLossPrice + if !flags.CheckSetting { + applogger.Debug("修改缓存中的止盈止损Type:%v", entrustJson.Order.StopType) + applogger.Debug("修改缓存中的止盈:%v", entrustJson.Order.StopWinPrice) + applogger.Debug("修改缓存中的止损:%v", entrustJson.Order.StopLossPrice) + } + var data []byte + data, err = json.Marshal(&entrustJson) + if err != nil { + applogger.Error("%v UpdateBotContractStopByOrderId.Marshal:%v", common.ErrContract, err) + return false, flags.ErrCacheDB + } + if order.OrderId == entrustJson.OrderId { + if err = Reds.HSet(context.Background(), setting.MarketContractPosition, key, string(data)).Err(); err != nil { + applogger.Error("%v UpdateBotContractStopByOrderId.HSet:%v", common.ErrContract, err) + return false, flags.ErrCacheDB + } + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotContractStopByOrderId.Commit:%v", common.ErrContract, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotContractCancelByOrderId +// +// @Description: 合约撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotContractCancelByOrderId(ctx context.Context, orderId string) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotContractCancelByOrderId.NewSession:%v", common.ErrContract, err) + return false, flags.ErrMySqlDB + } + + // get BotContractTrade + tread, err := uo.GetBotContractTradeByOrderId(session, orderId, flags.EntrustStatus) + if err != nil { + applogger.Error("%v UpdateBotContractCancelByOrderId.GetBotContractTradeByOrderId:%v", common.ErrContract, err) + return false, flags.ErrMySqlDB + } + var userId int64 + var earnestMoneyT, serviceCostT, symbol, orderNumber string + if tread != nil { + userId = int64(tread.UserId) + earnestMoneyT = tread.EarnestMoney + serviceCostT = tread.ServiceCost + orderNumber = tread.OrderNumber + symbol, err = uo.GetSymbol(tread.ContractId) + if err != nil { + applogger.Error("%v UpdateBotContractCancelByOrderId.GetSymbol:%v", common.ErrContract, err) + return false, flags.ErrMySqlDB + } + } + + // get BotUserStock By USD + var usable, frozen, usableNo, frozenNo decimal.Decimal + usable, frozen, _, err = uo.GetBotUserContract(session, userId, flags.BasicUnit) + if err != nil { + applogger.Error("%v UpdateBotContractCancelByOrderId.GetBotUserContract:%v", common.ErrContract, err) + return false, flags.ErrMySqlDB + } + + // 检查用户订单撤单资产 + if frozen.IsNegative() || usable.IsNegative() { + return false, flags.ErrPublicFour + } + if !flags.CheckSetting { + applogger.Debug("用户原始可用资金:%v", usable) + applogger.Debug("用户原始冻结资金:%v", frozen) + } + + if symbol != flags.BasicUnit { + usableNo, frozenNo, _, err = uo.GetBotUserContract(session, userId, tread.ContractId) + if err != nil { + applogger.Error("%v UpdateBotContractCancelByOrderId.GetBotUserContract:%v", common.ErrContract, err) + return false, flags.ErrPublicFour + } + } + if !flags.CheckSetting { + applogger.Debug("用户原始可用非资金:%v", usableNo) + applogger.Debug("用户原始冻结非资金:%v", frozenNo) + } + + // 更新订单信息 + botStockTrade := orders.BotContractCancelByOrderId(ctx) + if err = uo.UpdateBotContractTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v UpdateBotContractCancelByOrderId.UpdateBotContractTradeByOrderId:%v", common.ErrContract, err) + return false, flags.ErrPublicFour + } + + // Operational Spot Asset Table + earnestMoney := decimal.RequireFromString(earnestMoneyT) // 保证金 + serviceCost := decimal.RequireFromString(serviceCostT) // 订单手续费 + totalMoney := earnestMoney.Add(serviceCost) // 订单总金额 + if !flags.CheckSetting { + applogger.Debug("撤单用户ID:%v", userId) + applogger.Debug("下单交易对:%v", symbol) + applogger.Debug("撤单订单保证金:%v", earnestMoneyT) + applogger.Debug("撤单手续费:%v", serviceCostT) + applogger.Debug("撤单订单数量:%v", orderNumber) + applogger.Debug("撤单总金额数量:%v", totalMoney) + } + + // Update total asset data + usableNew := usable.Add(totalMoney) // 用户总资产 + frozenNew := frozen.Sub(totalMoney) // 用户冻结资产 + usableNoNew := usableNo // 用户非可用资产 + frozenNoNew := frozenNo // 用户非冻结资产 + + // 检查用户订单撤单资产 + if frozenNew.IsNegative() { + return false, flags.ErrContractSeven + } + if !flags.CheckSetting { + applogger.Debug("用户撤单可用总资产:%v", usableNew) + applogger.Debug("用户撤单冻结总资产:%v", frozenNew) + applogger.Debug("用户非撤单可用总资产:%v", usableNoNew) + applogger.Debug("用户非撤单冻结总资产:%v", frozenNoNew) + } + + userContractUSDT := orders.UpdateBotUserContract(ctx, usableNew.String(), frozenNew.String()) + if err = uo.UpdateBotUserContract(session, userId, flags.BasicUnit, userContractUSDT); err != nil { + applogger.Error("%v UpdateBotContractCancelByOrderId.UpdateBotUserContract:%v", common.ErrContract, err) + return false, flags.ErrMySqlDB + } + + if symbol != flags.BasicUnit { + userContract := orders.UpdateBotUserContract(ctx, usableNoNew.String(), frozenNoNew.String()) + if err = uo.UpdateBotUserContract(session, userId, tread.ContractId, userContract); err != nil { + applogger.Error("%v UpdateBotContractCancelByOrderId.UpdateBotUserContract:%v", common.ErrContract, err) + return false, flags.ErrMySqlDB + } + } + + // 清理挂单缓存信息 + if err = Reds.HDel(context.Background(), setting.MarketContractEntrust, orderId).Err(); err != nil { + applogger.Error("%v UpdateBotContractCancelByOrderId.HDel:%v", common.ErrContract, err) + return false, flags.ErrCacheDB + } + + // 撤单更新订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(setting.ContractSubscribe, userId) + if err = UpdateContractSubscribeHashStatusByOrderId(orderId, userSubKey, flags.Cancel, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotContractCancelByOrderId.ContractSubscribe:%v", common.ErrContract, err) + return false, flags.ErrCacheDB + } + + // 撤单更新管理员订阅缓存订单状态 + if err = UpdateContractSubscribeHashStatusByOrderId(orderId, setting.AdminContractSubscribe, flags.Cancel, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotContractCancelByOrderId.AdminContractSubscribe:%v", common.ErrContract, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotContractCancelByOrderId.Commit:%v", common.ErrContract, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// UpdateBotContractClosingByOrderId +// +// @Description: 合约平仓 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotContractClosingByOrderId(ctx context.Context, orderId string) (bool, error) { + // 1、订单信息 + entrust, err := Reds.HGet(context.Background(), setting.MarketContractPosition, orderId).Result() + if err != nil { + applogger.Error("%v UpdateBotContractClosingByOrderId.MarketContractPosition.HGet:%v", common.ErrContract, err) + return false, flags.ErrMySqlDB + } + + var entrustJson virtual.ContractTallyCache + if err = json.Unmarshal([]byte(entrust), &entrustJson); err != nil { + applogger.Error("%v UpdateBotContractClosingByOrderId.Unmarshal:%v", common.ErrContract, err) + return false, flags.ErrCacheDB + } + if !flags.CheckSetting { + applogger.Debug("手动平仓:%v", entrustJson) + } + + // 2、当前最新价格 + var openPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Hy, entrustJson.Symbol, flags.TradeTypePrice) + openPrice, err = uo.GetTheLatestPrice(ctx, subKey, entrustJson.Order.TradeType) + if err != nil { + return false, flags.ErrContractEight + } + if err = Reds.HDel(context.Background(), setting.MarketContractPosition, orderId).Err(); err != nil { + applogger.Error("%v UpdateBotContractClosingByOrderId.MarketContractPosition.HDel:%v", common.ErrContract, err) + return false, flags.ErrCacheDB + } + + // 3、平仓处理 + if err = ContractClosingPosition(ctx, uo.data.mysqlDB, orderId, openPrice.String(), entrustJson.Order); err != nil { + applogger.Error("%v UpdateBotContractClosingByOrderId.ContractClosingPosition:%v", common.ErrContract, err) + return false, flags.ErrCacheDB + } + + // 4、平仓更新订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(setting.ContractSubscribe, entrustJson.UserId) + if err = UpdateContractSubscribeHashStatusByOrderId(orderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotContractClosingByOrderId.ContractSubscribe:%v", common.ErrContract, err) + return false, flags.ErrCacheDB + } + + // 5、平仓更新管理员订阅缓存订单状态 + if err = UpdateContractSubscribeHashStatusByOrderId(orderId, setting.AdminContractSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotContractCancelByOrderId.AdminContractSubscribe:%v", common.ErrContract, err) + return false, flags.ErrCacheDB + } + + return true, nil +} + +// UpdateBotContractClosingAllByOrderId +// +// @Description: 合约一键平仓 +// @receiver uo +// @param ctx +// @param userId +// @return error +func (uo *userOrderRepo) UpdateBotContractClosingAllByOrderId(ctx context.Context, userId int64) error { + // 1、查询当前用户所有订单 + orderMap, err := uo.GetBotContractTradeByUserId(userId) + if err != nil { + applogger.Error("%v UpdateBotContractClosingAllByOrderId.GetBotContractTradeByUserId:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + + // 2、查询持仓缓存列表数据-1>清理持仓列表缓存 2>处理平仓数据 3>清理订单ID缓存列表 + for _, value := range orderMap { + var entrust string + entrust, err = Reds.HGet(context.Background(), setting.MarketContractPosition, value).Result() + if err != nil { + applogger.Error("%v UpdateBotContractClosingAllByOrderId.MarketContractPosition.LRange:%v", common.ErrContract, err) + return flags.ErrCacheDB + } + var entrustJson virtual.ContractTallyCache + if err = json.Unmarshal([]byte(entrust), &entrustJson); err != nil { + applogger.Error("%v UpdateBotContractClosingAllByOrderId.Unmarshal:%v", common.ErrContract, err) + return flags.ErrCacheDB + } + + // 当前市价 + var openPrice decimal.Decimal + subKey := publicData.SymbolCache(flags.Hy, entrustJson.Symbol, flags.TradeTypePrice) + openPrice, err = uo.GetTheLatestPrice(ctx, subKey, entrustJson.Order.TradeType) + if err != nil { + applogger.Error("%v UpdateBotContractClosingAllByOrderId.GetTheLatestPrice:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + if !flags.CheckSetting { + applogger.Debug("订阅Key:%v,最新价格:%v,订单ID:%v", subKey, openPrice, entrustJson.OrderId) + } + + // 清理持仓缓存列表 + if err = Reds.HDel(context.Background(), setting.MarketContractPosition, value).Err(); err != nil { + applogger.Error("%v UpdateBotContractClosingAllByOrderId.MarketContractPosition.HDel:%v", common.ErrContract, err) + return flags.ErrCacheDB + } + + // 平仓 + if err = ContractClosingPosition(ctx, uo.data.mysqlDB, entrustJson.OrderId, openPrice.String(), entrustJson.Order); err != nil { + applogger.Error("%v UpdateBotContractClosingAllByOrderId.ContractClosingPosition:%v", common.ErrContract, err) + return err + } + + // 平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ContractSubscribe, entrustJson.UserId) + if err = UpdateContractSubscribeHashStatusByOrderId(entrustJson.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotContractClosingAllByOrderId.ContractSubscribe:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + + // 平仓更新管理员订阅订单状态 + if err = UpdateContractSubscribeHashStatusByOrderId(entrustJson.OrderId, setting.AdminContractSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v UpdateBotContractCancelByOrderId.AdminContractSubscribe:%v", common.ErrContract, err) + return flags.ErrMySqlDB + } + } + + return nil +} + +// GetBotContractTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param status +// @return *models.BotContractTrade +// @return error +func (uo *userOrderRepo) GetBotContractTradeByOrderId(session *xorm.Session, orderId string, status int) (*models.BotContractTrade, error) { + var botContractTrade []models.BotContractTrade + if err := session.Table(flags.BotContractTrade). + Where("order_id = ?", orderId). + Where("`status` = ?", status). + Find(&botContractTrade); err != nil { + return nil, err + } + + for _, value := range botContractTrade { + return &value, nil + } + + return nil, nil +} + +// GetBotContractTradeByUserId +// +// @Description: +// @receiver uo +// @param ctx +// @param userId +// @return map[string]string +// @return error +func (uo *userOrderRepo) GetBotContractTradeByUserId(userId int64) (map[string]string, error) { + var botContractTrade []models.BotContractTrade + if err := uo.data.mysqlDB.Table(flags.BotContractTrade). + Where("user_id = ? ", userId). + Where("status = 1"). + Find(&botContractTrade); err != nil { + return nil, err + } + + botMap := make(map[string]string) + for _, value := range botContractTrade { + botMap[value.OrderId] = value.OrderId + } + + return botMap, nil +} + +// GetBotUserContract +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param symbol +// @return decimal.Decimal +// @return decimal.Decimal +// @return int +// @return error +func (uo *userOrderRepo) GetBotUserContract(session *xorm.Session, userId int64, symbol string) (decimal.Decimal, decimal.Decimal, int, error) { + var contractUSDT []models.BotUserContract + if err := session.Table(flags.BotUserContract). + Where("user_id = ?", userId). + Where("contract_id = ?", strings.ToUpper(symbol)). + Find(&contractUSDT); err != nil { + return decimal.Zero, decimal.Zero, 0, err + } + + var usableNum, frozenNum decimal.Decimal + for _, value := range contractUSDT { + usableNum = decimal.RequireFromString(value.UsableNum) // 资产可用余额 + frozenNum = decimal.RequireFromString(value.FrozenNum) // 资产冻结数量 + } + + return usableNum, frozenNum, len(contractUSDT), nil +} + +// ContractVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) ContractVoteDealType(order structure.ContractOrder) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + return limitOrMarketPrice, nil +} + +// UpdateVoteDealType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) UpdateVoteDealType(order *models.BotContractTrade) (decimal.Decimal, error) { + var limitOrMarketPrice decimal.Decimal + + switch order.DealType { + case flags.DealTypeLimited: // 限价 + if len(order.LimitPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.LimitPrice) + } + case flags.DealTypeMarket: // 市价 + if len(order.MarketPrice) != 0 { + limitOrMarketPrice = decimal.RequireFromString(order.MarketPrice) + } + default: + return decimal.Decimal{}, flags.ErrPublicFive + } + + if len(order.DealPrice) != 0 { + dealPrice := decimal.RequireFromString(order.DealPrice) + if !dealPrice.IsZero() { + limitOrMarketPrice = dealPrice + } + } + + return limitOrMarketPrice, nil +} + +// UpdateVoteStopType +// +// @Description: +// @receiver uo +// @param ctx +// @param order +// @return bool +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) UpdateVoteStopType(order structure.StopOrder) (bool, decimal.Decimal, decimal.Decimal, error) { + var checkBool bool + var stopWinPrice, stopLossPrice decimal.Decimal + switch order.StopType { + case flags.StopTypeNone: // 暂无设置止盈止损 + checkBool = false + case flags.StopTypeSet: // 设置止盈止损 + if len(order.StopWinPrice) != 0 { + stopWinPrice = decimal.RequireFromString(order.StopWinPrice) + } + if len(order.StopLossPrice) != 0 { + stopLossPrice = decimal.RequireFromString(order.StopLossPrice) + } + // 判定设置是否都为零 + if stopWinPrice.IsZero() && stopLossPrice.IsZero() { + return checkBool, decimal.Decimal{}, decimal.Decimal{}, flags.ErrContractTen + } else { + checkBool = true + } + default: + return checkBool, stopWinPrice, stopLossPrice, flags.ErrContractEleven + } + + return checkBool, stopWinPrice, stopLossPrice, nil +} + +// VoteTradeType +// +// @Description: 股票判定止盈止损配置 +// @receiver uo +// @param ctx +// @param tradeType +// @param stopWinPrice +// @param stopLossPrice +// @param price +// @param checkBool +// @return error +func (uo *userOrderRepo) VoteTradeType(tradeType int64, stopWinPrice, stopLossPrice, price decimal.Decimal, checkBool bool) error { + if checkBool { + switch tradeType { + case flags.TradeTypeBuy: // 买涨 + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(price) <= 0 { + // 限价买涨下单,止盈价格必须大于限价 + return flags.ErrBuyStopWinPrice + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(price) >= 0 { + // 限价买涨下单,止损价格必须小于限价 + return flags.ErrBuyStopLossPrice + } + } + case flags.TradeTypeSell: // 买跌 + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(price) >= 0 { + // 限价买跌下单,止盈价格必须小于限价 + return flags.ErrSellStopWinPrice + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(price) <= 0 { + // 限价买跌下单,止损价格必须大于限价 + return flags.ErrSellStopLossPrice + } + } + default: + return flags.ErrContractTwelve + } + } + + return nil +} + +// VoteTradeTypeOption +// +// @Description: 期权判定止盈止损配置 +// @receiver uo +// @param dealType 市价|限价 +// @param tradeType 看涨(calls-CE)|看跌(puts-PE) +// @param tradingType 买入(buy)|卖出(sell) +// @param stopWinPrice 止盈价格 +// @param stopLossPrice 止损价格 +// @param limitOrMarketPrice 设置价格(市价|限价) +// @param bid 买一价 +// @param ask 卖一价 +// @param checkBool +// @return error +func (uo *userOrderRepo) VoteTradeTypeOption(dealType, tradeType, tradingType int64, stopWinPrice, stopLossPrice, limitOrMarketPrice, bid, ask decimal.Decimal, checkBool bool) error { + if checkBool { + switch dealType { + case flags.DealTypeMarket: // 市价 + switch tradeType { + case flags.OptionCalls: // call-(buy|sell) + return StopOrWinCmp(tradingType, ask, bid, stopWinPrice, stopLossPrice, limitOrMarketPrice, false) + case flags.OptionPuts: // put-(buy|sell) + return StopOrWinCmp(tradingType, ask, bid, stopWinPrice, stopLossPrice, limitOrMarketPrice, false) + default: + return flags.ErrContractTwelve + } + case flags.DealTypeLimited: // 限价 + switch tradeType { + case flags.TradeTypeBuy: // call-(buy|sell) + return StopOrWinCmp(tradingType, ask, bid, stopWinPrice, stopLossPrice, limitOrMarketPrice, true) + case flags.TradeTypeSell: // put-(buy|sell) + return StopOrWinCmp(tradingType, ask, bid, stopWinPrice, stopLossPrice, limitOrMarketPrice, true) + default: + return flags.ErrContractTwelve + } + default: + return flags.ErrContractTwelve + } + } + + return nil +} + +// StopOrWinCmp +// +// @Description: +// @param tradingType +// @param ask +// @param bid +// @param stopWinPrice +// @param stopLossPrice +// @return error +func StopOrWinCmp(tradingType int64, ask, bid, stopWinPrice, stopLossPrice, limitOrMarketPrice decimal.Decimal, check bool) error { + /** 期权下单止盈止损判定 + 一、call-buy 和 put-buy + 限价开仓价格 < 卖一价 + 止盈价 > 买一价 + 止损价 < 卖一价 + 二、call-sell 和 put-sell + 限价单开仓价格 > 买一价 + 止盈价 < 卖一价 + 止损价 > 买一价 + */ + switch tradingType { + case flags.OptionBuy: // buy + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(bid) > 0 { + return flags.ErrBuyStopWinPriceOption // 看涨下单,止盈价大于买一价 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(ask) < 0 { + return flags.ErrBuyStopLossPriceOption // 看涨下单,止损价小于卖一价 + } + } + if check { // limit order start + if limitOrMarketPrice.Cmp(ask) < 0 { + return flags.ErrBuyLimitPriceOption // 看涨下单,开仓价格小于卖一价 + } + } + case flags.OptionSell: // sell + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(ask) < 0 { + return flags.ErrSellStopWinPriceOption // 看跌下单,止盈价小于卖一价 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(bid) > 0 { + return flags.ErrSellStopLossPriceOption // 看跌下单,止损价大于买一价 + } + } + if check { // limit order start + if limitOrMarketPrice.Cmp(bid) > 0 { + return flags.ErrSellLimitPriceOption // 看跌下单,开仓价格大于买一价 + } + } + default: + return flags.ErrContractTwelve + } + + return nil +} + +// CreatBotUserContract +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param digital +// @return error +func (uo *userOrderRepo) CreatBotUserContract(session *xorm.Session, digital models.BotUserContract) error { + _, err := session.Table(flags.BotUserContract).Insert(&digital) + if err != nil { + return err + } + + return nil +} + +// CreatBotContractTrade +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param trade +// @return error +func (uo *userOrderRepo) CreatBotContractTrade(session *xorm.Session, trade models.BotContractTrade) error { + _, err := session.Table(flags.BotContractTrade).Insert(&trade) + if err != nil { + return err + } + + return nil +} + +// UpdateBotContractTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param trade +// @return error +func (uo *userOrderRepo) UpdateBotContractTradeByOrderId(session *xorm.Session, orderId string, trade models.BotContractTrade) error { + _, err := session.Table(flags.BotContractTrade). + Where("order_id = ?", orderId). + Update(&trade) + if err != nil { + return err + } + + return nil +} + +// UpdateBotUserContract +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param symbol +// @param userContract +// @return error +func (uo *userOrderRepo) UpdateBotUserContract(session *xorm.Session, userId int64, symbol string, userContract models.BotUserContract) error { + _, err := session.Table(flags.BotUserContract). + Where("user_id = ?", userId). + Where("contract_id = ?", symbol). + Update(&userContract) + if err != nil { + return err + } + + return nil +} + +// GetSymbol +// +// @Description: +// @receiver uo +// @param ctx +// @param contractId +// @return string +// @return error +func (uo *userOrderRepo) GetSymbol(contractId string) (string, error) { + var symbol string + symbolList := strings.Split(contractId, "-") + if len(symbolList) == 2 { + symbol = symbolList[0] + } else { + return "", flags.ErrContractThree + } + + return symbol, nil +} + +// VerifyBotContractTradeOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @return string +// @return error +func (uo *userOrderRepo) VerifyBotContractTradeOrderId(session *xorm.Session) (string, error) { + var orderId string + for { + orderId = orders.CreateRandCodeOrder(10) + + var orderList []models.BotContractTrade + err := session.Table(flags.BotContractTrade).Where("order_id = ?", orderId).Find(&orderList) + if err != nil || len(orderList) > 0 { + applogger.Error("%v VerifyBotContractTradeOrderId.Find:%v", common.ErrContract, err) + continue + } + + break + } + + return orderId, nil +} + +// GetTheLatestPrice +// +// @Description: +// @receiver uo +// @param ctx +// @param subKey +// @param tradeType +// @return decimal.Decimal +// @return error +func (uo *userOrderRepo) GetTheLatestPrice(ctx context.Context, subKey string, tradeType int64) (decimal.Decimal, error) { + priceNew, err := virtual.ContractSubMarketPrice(ctx, subKey) + if err != nil { + applogger.Error("%v GetTheLatestPrice.ContractSubMarketPrice:%v", common.ErrContract, err) + return decimal.Decimal{}, err + } + + priceS := decimal.RequireFromString(priceNew) + + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tradeType { + case flags.TradeTypeBuy: // 买涨 + openPrice = priceS.Sub(difference) // 开仓价格 + case flags.TradeTypeSell: // 买跌 + openPrice = priceS.Add(difference) // 开仓价格 + default: + + } + + return openPrice, nil +} diff --git a/internal/data/order_virtual_second.go b/internal/data/order_virtual_second.go new file mode 100644 index 0000000..86d1da0 --- /dev/null +++ b/internal/data/order_virtual_second.go @@ -0,0 +1,647 @@ +package data + +import ( + "context" + "github.com/go-xorm/xorm" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "strings" + "time" + + orders "matchmaking-system/internal/data/convert" + models "matchmaking-system/internal/pkg/model" +) + +// GetBotSecondTradeList +// +// @Description: 秒合约订单列表 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param userId +// @param status +// @param state +// @return []*models.BotContractSecTrade +// @return int64 +// @return error +func (uo *userOrderRepo) GetBotSecondTradeList(pageSize, pageCount, userId, status int64) ([]*models.BotContractSecTrade, int64, error) { + totalCount, err := uo.data.mysqlDB.Table(flags.BotContractSecTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Count() + if err != nil { + return nil, 0, flags.ErrMySqlDB + } + if totalCount == 0 { + return nil, 0, nil + } + var contractList []*models.BotContractSecTrade + if err := uo.data.mysqlDB.Table(flags.BotContractSecTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Limit(int(pageSize), int(pageCount)). + Desc(GetOrderByStatusSort(status)). + Find(&contractList); err != nil { + return nil, 0, flags.ErrMySqlDB + } + + var contractUpdateList []*models.BotContractSecTrade + for _, value := range contractList { + value.KeepDecimal = GetKeepDecimal(flags.ContractSystemSetUpKey, value.ContractId) + contractUpdateList = append(contractUpdateList, value) + } + + return contractUpdateList, totalCount, nil +} + +// CreateSecondBotContractTrade +// +// @Description: 秒合约下单 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) CreateSecondBotContractTrade(ctx context.Context, userId int64, order structure.ContractOrder) (string, error) { + // 1、下单订阅 + contractId := strings.ToUpper(order.ContractId) + _, ok := second.SecondMapSymbol.Load(contractId) + if ok { + go func() { + second.SecondMap <- []byte(contractId) + }() + } + + // 2、获取系统设置 + system, err := GetContractSystemSetUp(contractId) + if err != nil || system == nil { + return flags.SetNull, flags.ErrContractOne + } + secondSystem, err := GetContractSystemSecond() + if err != nil { + return flags.SetNull, flags.ErrContractOne + } + + order.System = system // 系统设置 + order.Proportion = secondSystem // 比例设置 + order.StopTime = time.Now().Add(time.Duration(order.Time) * time.Second) // 设置时间 + + // 3、获取交易币市价 + //priceNew, err := GetDigitalCurrencyPrice(ctx, flags.Sd, contractId) + //if len(priceNew) == 0 || err != nil { + // applogger.Error("%v CreateSecondBotContractTrade.GetDigitalCurrencyPrice:%v", common.ErrSecond, err) + // return flags.SetNull, flags.ErrPriceUpdate + //} + + // 4、下单判定 + // 下单判定设置(false无设置|true止盈止损) + checkBool, stopWinPrice, stopLossPrice, err := ContractVoteStopType(order) + if err != nil { + applogger.Error("%v CreateSecondBotContractTrade.ContractVoteStopType:%v", common.ErrSecond, err) + return flags.SetNull, err + } + // 下单判定设置(限价|市价) + limitOrMarketPrice, err := uo.ContractVoteDealType(order) + if err != nil { + applogger.Error("%v CreateSecondBotContractTrade.ContractVoteDealType:%v", common.ErrSecond, err) + return flags.SetNull, err + } + // 下单判定设置(买涨|买跌) + if err = uo.VoteTradeType(order.TradeType, stopWinPrice, stopLossPrice, limitOrMarketPrice, checkBool); err != nil { + applogger.Error("%v CreateSecondBotContractTrade.VoteTradeType:%v", common.ErrSecond, err) + return flags.SetNull, err + } + + // 5、下单(订单信息|资产信息) + orderId, err := uo.SecondWriteDB(ctx, userId, order) + if err != nil || len(orderId) == 0 { + applogger.Error("%v CreateSecondBotContractTrade.ContractSecondWriteDB:%v", common.ErrSecond, err) + return flags.SetNull, err + } + + // 6、写入缓存列表(挂单缓存|持仓缓存),等待撮合计算 + marketStatus, tallyCache, err := virtual.SecondCacheDeal(ctx, userId, orderId, limitOrMarketPrice.String(), order) + if err != nil || tallyCache == nil { + applogger.Error("%v CreateSecondBotContractTrade.ContractSecondCacheDeal:%v", common.ErrSecond, err) + return flags.SetNull, err + } + + // 7、市价下单开仓处理(订单信息|资产信息|手续费|返佣|资产详情记录) + if marketStatus == setting.MarketSecondPosition { + if err = SecondOpenPosition(ctx, uo.data.mysqlDB, userId, orderId, tallyCache.OpenPrice, order); err != nil { + applogger.Error("%v CreateSecondBotContractTrade.ContractSecondOpenPosition:%v", common.ErrSecond, err) + return flags.SetNull, err + } + } + + // 8、写入(挂单|持仓)缓存列表 + if err = virtual.SecondPushAddCache(Reds, marketStatus, tallyCache); err != nil { + applogger.Error("%v CreateSecondBotContractTrade.ContractSecondPushAddCache:%v", common.ErrSecond, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 9、写入用户订单订阅缓存列表 + orderIdKey := virtual.OrderIdListKey(setting.SecondSubscribe, userId) + if err = virtual.SecondHashSetOrderId(Reds, orderIdKey, tallyCache); err != nil { + applogger.Error("%v CreateSecondBotContractTrade.ContractSecondHashSetOrderId:%v", common.ErrSecond, err) + return flags.SetNull, flags.ErrCacheDB + } + + // 10、写入管理员订单订阅列表 + if err = virtual.SecondHashSetOrderId(Reds, setting.AdminSecondSubscribe, tallyCache); err != nil { + applogger.Error("%v CreateSecondBotContractTrade.ContractSecondHashSetOrderId:%v", common.ErrSecond, err) + return flags.SetNull, flags.ErrCacheDB + } + + return orderId, nil +} + +// SecondWriteDB +// +// @Description: 秒合约下单处理 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) SecondWriteDB(ctx context.Context, userId int64, order structure.ContractOrder) (string, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v ContractSecondWriteDB.NewSession:%v", common.ErrSecond, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen decimal.Decimal + usable, frozen, _, err = uo.GetBotUserContractSec(session, userId, flags.BasicUnit) + if err != nil { + applogger.Error("%v ContractSecondWriteDB.GetBotUserContractSec:%v", common.ErrSecond, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 检查用户订单下单资产 + if usable.IsZero() || usable.IsNegative() || frozen.IsNegative() { + return flags.SetNull, flags.ErrPublicOne + } + + // 写入订单信息 + orderId, err := uo.VerifyBotContractSecTradeOrderId(session) + if err != nil { + applogger.Error("%v ContractSecondWriteDB.VerifyBotContractSecTradeOrderId:%v", common.ErrSecond, err) + return flags.SetNull, err + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + applogger.Debug("下单ID:%v", orderId) + applogger.Debug("下单杠杆:%v", order.PryNum) + } + + botStockTrade := orders.BotContractSecTrade(ctx, userId, orderId, order) + if err = uo.CreatBotContractSecTrade(session, botStockTrade); err != nil { + applogger.Error("%v ContractSecondWriteDB.CreatBotContractSecTrade:%v", common.ErrSecond, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 转换下单信息 + orderAmount := decimal.RequireFromString(order.OrderAmount) // 订单价格 + earnestMoney := decimal.RequireFromString(order.EarnestMoney) // 保证金 + if !flags.CheckSetting { + applogger.Debug("下单订单价格:%v", orderAmount) + applogger.Debug("下单保证金:%v", earnestMoney) + } + + // 总金额下单判定 + residue := usable.Sub(earnestMoney).Div(usable) + if usable.Cmp(earnestMoney) < 0 || residue.Cmp(utils.DecimalsStrInt()) < 0 { + return flags.SetNull, flags.ErrPublicOne + } + + // (买涨|买跌)处理 + usableNew := usable.Sub(earnestMoney) // 可用资产 + frozenNew := frozen.Add(earnestMoney) // 冻结资产 + + // 检查用户订单下单资产 + if usableNew.IsNegative() || usableNew.IsZero() { + return flags.SetNull, flags.ErrPublicTow + } + if !flags.CheckSetting { + applogger.Debug("下单后用户可用资产:%v", usableNew) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + } + + // 更新用户资产信息 + userContractUSDT := orders.UpdateBotUserContractSec(ctx, usableNew.String(), frozenNew.String()) + if err = uo.UpdateBotUserContractSec(session, userId, flags.BasicUnit, userContractUSDT); err != nil { + applogger.Error("%v ContractSecondWriteDB.UpdateBotUserContractSec:%v", common.ErrSecond, err) + return flags.SetNull, flags.ErrMySqlDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v ContractSecondWriteDB.Commit:%v", common.ErrSecond, err) + return flags.SetNull, flags.ErrMySqlDB + } + + return orderId, nil +} + +// SecondOpenPosition +// +// @Description: 秒合约开仓处理 +// @param ctx +// @param db +// @param userId +// @param orderId +// @param openPrice +// @param order +// @return error +func SecondOpenPosition(ctx context.Context, db *xorm.EngineGroup, userId int64, orderId, openPrice string, order structure.ContractOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v ContractSecondOpenPosition.NewSession:%v", common.ErrSecond, err) + return flags.ErrMySqlDB + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen decimal.Decimal + usable, frozen, _, err = Uo.GetBotUserContractSec(session, userId, flags.BasicUnit) + if err != nil || usable.IsNegative() || frozen.IsNegative() { + applogger.Error("%v ContractSecondOpenPosition.GetBotUserContractSec:%v", common.ErrSecond, err) + return flags.ErrPublicThree + } + if !flags.CheckSetting { + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + } + + // 转换下单信息 + earnestMoney := decimal.RequireFromString(order.EarnestMoney) // 保证金 + + if !flags.CheckSetting { + applogger.Debug("下单保证金:%v", earnestMoney) + } + + openOrderPrice := decimal.RequireFromString(openPrice) // 开仓价格 + usableNew := usable // 可用资产 + frozenNew := frozen.Sub(earnestMoney) // 冻结资产 + if !flags.CheckSetting { + applogger.Debug("开仓订单价格:%v", openOrderPrice) + applogger.Debug("下单开仓总金额容差值:%v", earnestMoney) + applogger.Debug("下单后用户可用资产:%v", usableNew) + applogger.Debug("下单后用户冻结资产:%v", frozenNew) + } + + // 检查用户平仓资产 + if frozenNew.IsNegative() { + return flags.ErrPublicThree + } + + // 处理资产信息 + userContractUSDT := orders.UpdateBotUserContractSec(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserContractSec(session, userId, flags.BasicUnit, userContractUSDT); err != nil { + applogger.Error("%v ContractSecondOpenPosition.UpdateBotUserContractSec:%v", common.ErrSecond, err) + return flags.ErrMySqlDB + } + + // 处理订单信息(成交价|仓位|开仓时间|订单总金额|手续费|持仓状态) + trade := orders.UpdateOpenBotContractSecTrade(ctx, openPrice, decimal.Zero.String(), earnestMoney.String(), decimal.Zero.String()) + if err = Uo.UpdateBotContractSecTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v ContractSecondOpenPosition.UpdateBotContractSecTradeByOrderId:%v", common.ErrSecond, err) + return flags.ErrMySqlDB + } + + // 更改交易日志记录方式 + var list []models.BotUserContractSecLog + qData1 := orders.CreatBotUserContractSecLog(ctx, userId, flags.TransferOut, flags.BasicUnit, NegativeValue(earnestMoney.String()), orderId) // 资金变动明细表(开仓保证金) + list = append(list, qData1) + + // 批量写入数据信息 + if err = Uo.CreatBotUserContractSecLogList(session, list); err != nil { + applogger.Error("%v ContractSecondOpenPosition.CreatBotUserContractSecLogList:%v", common.ErrSecond, err) + return flags.ErrMySqlDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v ContractSecondOpenPosition.Commit:%v", common.ErrSecond, err) + return flags.ErrMySqlDB + } + + return nil +} + +// SecondClosingPosition +// +// @Description: 秒合约平仓处理 +// @param ctx +// @param db +// @param orderId +// @param price +// @param order +// @return error +func SecondClosingPosition(ctx context.Context, db *xorm.EngineGroup, orderId, closePrice string, order structure.ContractOrder) error { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v ContractSecondClosingPosition.NewSession:%v", common.ErrSecond, err) + return flags.ErrMySqlDB + } + + // 查询订单信息 + tread, err := Uo.GetBotContractSecTradeByOrderId(session, orderId, flags.PositionStatus) + if err != nil { + applogger.Error("%v ContractSecondClosingPosition.GetBotContractSecTradeByOrderId:%v", common.ErrSecond, err) + return flags.ErrMySqlDB + } + + var userId int64 + var dealPrice, earnestMoney decimal.Decimal + var closeTime time.Time + if tread != nil { + userId = int64(tread.UserId) // 用户Id + earnestMoney = decimal.RequireFromString(tread.EarnestMoney) // 开仓保证金 + dealPrice = decimal.RequireFromString(tread.DealPrice) // 开仓价格 + closeTime = tread.OpenTime.Add(time.Duration(tread.SecondTime) * time.Second) // 平仓时间 + } + + // 查询当前下单用户可用账户金额和冻结金额 + var usable, frozen decimal.Decimal + usable, frozen, _, err = Uo.GetBotUserContractSec(session, userId, flags.BasicUnit) + if err != nil || usable.IsNegative() || frozen.IsNegative() { + applogger.Error("%v ContractSecondClosingPosition.GetBotUserContract:%v", common.ErrSecond, err) + return flags.ErrContractFive + } + if !flags.CheckSetting { + applogger.Debug("下单开仓用户Id:%v", userId) + applogger.Debug("开仓下单开仓价格:%v,平仓价格:%v", dealPrice, closePrice) + applogger.Debug("下单可用金额:%v", usable) + applogger.Debug("下单冻结金额:%v", frozen) + } + + // 判定准备 + var orderStatus int + var orderValue string + checkBool := decimal.RequireFromString(closePrice).Cmp(dealPrice) // 判定平仓和开仓价格 + proValue := order.Proportion[order.Time] // 设定值 + proPrice := decimal.RequireFromString(proValue.Value).Div(decimal.RequireFromString(flags.DecimalOne)) // 设置定转化 + if !flags.CheckSetting { + applogger.Debug("平仓数据展示:%v,%v,%v", proValue, proPrice, earnestMoney.Mul(proPrice)) + } + + // 已经实现盈亏计算公式(已平仓结算方式) + // 买涨 = 平仓价格 > 开仓价格(盈利) 平仓价格 < 开仓价格(亏损) 平仓价格 = 开仓价格(不亏不盈) + // 买跌 = 平仓价格 < 开仓价格(盈利) 平仓价格 > 开仓价格(亏损) 平仓价格 = 开仓价格(不亏不盈) + var usableNew, frozenNew, resultPrice decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买涨--->{盈利|亏损|不亏不盈} + if checkBool == 1 { + resultPrice = earnestMoney.Mul(proPrice).Add(earnestMoney) + usableNew = usable.Add(resultPrice) + orderStatus = flags.OrderSetOne + orderValue = resultPrice.String() + if !flags.CheckSetting { + applogger.Debug("买涨盈利:%v", resultPrice) + } + } + if checkBool == -1 { + resultPrice = decimal.Zero + usableNew = usable + orderStatus = flags.OrderSetTwo + orderValue = NegativeValue(earnestMoney.String()) + if !flags.CheckSetting { + applogger.Debug("买涨亏损:%v", resultPrice) + } + } + if checkBool == 0 { + resultPrice = earnestMoney + usableNew = usable.Add(earnestMoney) + orderStatus = flags.OrderSetZero + orderValue = decimal.Zero.String() + if !flags.CheckSetting { + applogger.Debug("买涨平局:%v", resultPrice) + } + } + case flags.TradeTypeSell: // 买跌--->{盈利|亏损|不亏不盈} + if checkBool == -1 { + resultPrice = earnestMoney.Mul(proPrice).Add(earnestMoney) + usableNew = usable.Add(resultPrice) + orderStatus = flags.OrderSetOne + orderValue = resultPrice.String() + if !flags.CheckSetting { + applogger.Debug("买跌盈利:%v", resultPrice) + } + } + if checkBool == 1 { + resultPrice = decimal.Zero + usableNew = usable + orderStatus = flags.OrderSetTwo + orderValue = NegativeValue(earnestMoney.String()) + if !flags.CheckSetting { + applogger.Debug("买跌亏损:%v", resultPrice) + } + } + if checkBool == 0 { + resultPrice = earnestMoney + usableNew = usable.Add(earnestMoney) + orderStatus = flags.OrderSetZero + orderValue = decimal.Zero.String() + if !flags.CheckSetting { + applogger.Debug("买跌平局:%v", resultPrice) + } + } + default: + + } + frozenNew = frozen // 冻结资产 + if !flags.CheckSetting { + applogger.Debug("可用资产:%v", usableNew) + applogger.Debug("冻结资产:%v", frozenNew) + } + + // 平仓(处理资产表(资产)) + userContractUSDT := orders.UpdateBotUserContractSec(ctx, usableNew.String(), frozenNew.String()) + if err = Uo.UpdateBotUserContractSec(session, userId, flags.BasicUnit, userContractUSDT); err != nil { + applogger.Error("%v ContractSecondClosingPosition.UpdateBotUserContractSec:%v", common.ErrSecond, err) + return flags.ErrMySqlDB + } + + // 平仓(处理订单信息(平仓价|保证金|平仓|订单总金额|平仓手续费|完成订单)) + trade := orders.UpdateCloseBotContractSecTrade(ctx, closePrice, earnestMoney.String(), earnestMoney.String(), decimal.Zero.String(), orderValue, orderStatus, closeTime) + if err = Uo.UpdateBotContractSecTradeByOrderId(session, orderId, trade); err != nil { + applogger.Error("%v ContractSecondClosingPosition.UpdateBotContractSecTradeByOrderId:%v", common.ErrSecond, err) + return flags.ErrMySqlDB + } + + // 盈利-亏损不写入日志 + if !resultPrice.IsZero() { + // 平仓(资金变动明细表(正负盈亏)) + var list []models.BotUserContractSecLog + qData4 := orders.CreatBotUserContractSecLog(ctx, userId, flags.ChangeInto, flags.BasicUnit, resultPrice.String(), orderId) + list = append(list, qData4) + if err = Uo.CreatBotUserContractSecLogList(session, list); err != nil { + applogger.Error("%v ContractSecondClosingPosition.CreatBotUserContractSecLogList:%v", common.ErrSecond, err) + return flags.ErrMySqlDB + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v ContractSecondClosingPosition.Commit:%v", common.ErrSecond, err) + return flags.ErrMySqlDB + } + + return nil +} + +// GetBotContractSecTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param status +// @return *models.BotContractSecTrade +// @return error +func (uo *userOrderRepo) GetBotContractSecTradeByOrderId(session *xorm.Session, orderId string, status int) (*models.BotContractSecTrade, error) { + var botContractTrade []models.BotContractSecTrade + if err := session.Table(flags.BotContractSecTrade). + Where("order_id = ?", orderId). + Where("`status` = ?", status). + Find(&botContractTrade); err != nil { + return nil, err + } + + for _, value := range botContractTrade { + return &value, nil + } + + return nil, nil +} + +// GetBotUserContractSec +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param symbol +// @return decimal.Decimal +// @return decimal.Decimal +// @return int +// @return error +func (uo *userOrderRepo) GetBotUserContractSec(session *xorm.Session, userId int64, symbol string) (decimal.Decimal, decimal.Decimal, int, error) { + var contractUSDT []models.BotUserContractSec + if err := session.Table(flags.BotUserContractSec). + Where("user_id = ?", userId). + Where("contract_id = ?", strings.ToUpper(symbol)). + Find(&contractUSDT); err != nil { + return decimal.Zero, decimal.Zero, 0, err + } + + var usableNum, frozenNum decimal.Decimal + for _, value := range contractUSDT { + usableNum = decimal.RequireFromString(value.UsableNum) // 资产可用余额 + frozenNum = decimal.RequireFromString(value.FrozenNum) // 资产冻结数量 + } + + return usableNum, frozenNum, len(contractUSDT), nil +} + +// VerifyBotContractSecTradeOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @return string +// @return error +func (uo *userOrderRepo) VerifyBotContractSecTradeOrderId(session *xorm.Session) (string, error) { + var orderId string + for { + orderId = orders.CreateRandCodeOrder(10) + + var orderList []models.BotContractSecTrade + err := session.Table(flags.BotContractSecTrade).Where("order_id = ?", orderId).Find(&orderList) + if err != nil || len(orderList) > 0 { + applogger.Error("%v VerifyBotContractTradeOrderId.Find:%v", common.ErrSecond, err) + continue + } + + break + } + + return orderId, nil +} + +// CreatBotContractSecTrade +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param trade +// @return error +func (uo *userOrderRepo) CreatBotContractSecTrade(session *xorm.Session, trade models.BotContractSecTrade) error { + _, err := session.Table(flags.BotContractSecTrade).Insert(&trade) + if err != nil { + return err + } + + return nil +} + +// UpdateBotUserContractSec +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param symbol +// @param userContract +// @return error +func (uo *userOrderRepo) UpdateBotUserContractSec(session *xorm.Session, userId int64, symbol string, userContract models.BotUserContractSec) error { + _, err := session.Table(flags.BotUserContractSec). + Where("user_id = ?", userId). + Where("contract_id = ?", symbol). + Update(&userContract) + if err != nil { + return err + } + + return nil +} + +// UpdateBotContractSecTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param trade +// @return error +func (uo *userOrderRepo) UpdateBotContractSecTradeByOrderId(session *xorm.Session, orderId string, trade models.BotContractSecTrade) error { + _, err := session.Table(flags.BotContractSecTrade). + Where("order_id = ?", orderId). + Update(&trade) + if err != nil { + return err + } + + return nil +} diff --git a/internal/data/order_virtual_spots.go b/internal/data/order_virtual_spots.go new file mode 100644 index 0000000..76ab6b6 --- /dev/null +++ b/internal/data/order_virtual_spots.go @@ -0,0 +1,747 @@ +package data + +import ( + "context" + "github.com/go-xorm/xorm" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "strings" + + orders "matchmaking-system/internal/data/convert" + models "matchmaking-system/internal/pkg/model" +) + +// GetBotDigitalTradeList +// +// @Description: 现货列表查询 +// @receiver uo +// @param ctx +// @param pageSize +// @param pageCount +// @param userId +// @param status +// @return []*models.BotDigitalTrade +// @return int64 +// @return error +func (uo *userOrderRepo) GetBotDigitalTradeList(pageSize, pageCount, userId, status int64) ([]*models.BotDigitalTrade, int64, error) { + totalCount, err := uo.data.mysqlDB.Table(flags.BotDigitalTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Count() + if err != nil { + return nil, 0, flags.ErrMySqlDB + } + if totalCount == 0 { + return nil, 0, nil + } + var digitalList []*models.BotDigitalTrade + if err = uo.data.mysqlDB.Table(flags.BotDigitalTrade). + Where("user_id = ?", userId). + Where("status = ?", status). + Limit(int(pageSize), int(pageCount)). + Desc(GetOrderByStatusSort(status)). + Find(&digitalList); err != nil { + return nil, 0, flags.ErrMySqlDB + } + + var digitalUpdateList []*models.BotDigitalTrade + for _, value := range digitalList { + value.KeepDecimal = GetKeepDecimal(flags.SpotsSystemSetUpKey, value.DigitalId) + digitalUpdateList = append(digitalUpdateList, value) + } + + return digitalUpdateList, totalCount, nil +} + +// CreateBotDigitalTrade +// +// @Description: 现货下单 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) CreateBotDigitalTrade(ctx context.Context, userId int64, order structure.SpotsOrder) (string, error) { + // 1、下单通知订阅 + digitalId := strings.ToLower(order.DigitalId) + _, ok := spots.SpotsMapSymbol.Load(digitalId) + if ok { + go func() { + spots.SpotsMap <- []byte(digitalId) + }() + } + order.DigitalId = strings.ToUpper(order.DigitalId) + + // 2、交易币市价 + priceNew, err := GetDigitalCurrencyPrice(ctx, flags.Xh, digitalId) + if len(priceNew) == 0 || err != nil { + applogger.Error("%v CreateBotDigitalTrade.DealSpotsMarketPrice:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrPriceUpdate + } + + // 3、限价下单记录(1>下单判定 2>订单表 3>资产表[其他交易对]) + order.DealPrice = priceNew + orderId, err := uo.SpotOrdersDealDB(ctx, userId, order) + if err != nil || len(orderId) == 0 { + applogger.Error("%v CreateBotDigitalTrade.SpotOrdersDealDB:%v", common.ErrSpots, err) + return flags.SetNull, err + } + + // 4、写入缓存队列等待计算|平仓 + switch order.DealType { + case flags.DealTypeLimited: // 限价下单(限价买入挂单|限价卖出挂单) + if err = virtual.DealSpotsLimitedPrice(uo.data.redisDB, userId, order, digitalId, orderId); err != nil { + applogger.Error("%v CreateBotDigitalTrade.DealSpotsLimitedPrice:%v", common.ErrSpots, err) + return flags.SetNull, err + } + case flags.DealTypeMarket: // 市价下单(市价买入平仓|市价卖出平仓) + openPrice := decimal.RequireFromString(priceNew) + // 市价下单平仓操作-->更新订单表|更新资产表|计算手续费|录入返佣明细|录入交易明细 + orderId, err = SpotOrdersClosingDB(ctx, uo.data.mysqlDB, userId, order, orderId, openPrice.String()) + if err != nil { + applogger.Error("%v CreateBotDigitalTrade.SpotOrdersClosingDB:%v", common.ErrSpots, err) + return flags.SetNull, err + } + default: + return flags.SetNull, flags.ErrSpotMsgOne + } + + return orderId, nil +} + +// SpotOrdersClosingDB +// +// @Description: 现货平仓 +// @param ctx +// @param db +// @param userId +// @param order +// @param orderId +// @param closingPrice +// @return string +// @return error +func SpotOrdersClosingDB(ctx context.Context, db *xorm.EngineGroup, userId int64, order structure.SpotsOrder, orderId, closingPrice string) (string, error) { + session := db.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v SpotOrdersClosingDB.NewSession:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 当前用户(买入|卖出)的(可用|冻结)资产 + usableOld, frozenOld, _, err := Uo.GetBotUserDigital(session, userId, flags.BasicUnit) + if err != nil { + applogger.Error("%v SpotOrdersClosingDB.GetBotUserDigital:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 当前用户非(买入|卖出)的(可用|冻结)资产 + var usableNoOld, frozenNoOld decimal.Decimal + if order.DigitalId != flags.BasicUnit { + usableNoOld, frozenNoOld, _, err = Uo.GetBotUserDigital(session, userId, order.DigitalId) + if err != nil { + applogger.Error("%v SpotOrdersClosingDB.GetBotUserDigital:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + if !flags.CheckSetting { + applogger.Debug("可用资产:%v", usableOld) + applogger.Debug("冻结资产:%v", frozenOld) + applogger.Debug("非可用资产:%v", usableNoOld) + applogger.Debug("非冻结资产:%v", frozenNoOld) + } + + // Operational Spot Asset Table + orderNumber := decimal.RequireFromString(order.OrderNumber) // 订单数量 + orderMoney := orderNumber.Mul(decimal.RequireFromString(order.DealPrice)) // 订单金额 = (订单数量 * 订单价格) + serviceCost := decimal.RequireFromString(order.ServiceCost) // 订单手续费 + totalMoney := orderMoney.Add(serviceCost) // 订单总金额 = (订单金额 + 手续费) + if !flags.CheckSetting { + applogger.Debug("平仓开仓价格:%v", order.DealPrice) + applogger.Debug("平仓金额:%v", orderMoney) + applogger.Debug("平仓数量:%v", order.OrderNumber) + applogger.Debug("平仓手续费:%v", serviceCost) + applogger.Debug("平仓总金额:%v", totalMoney) + } + + // (开仓|平仓)价格重新计算:订单金额|手续费|订单总金额 + closePrice := decimal.RequireFromString(closingPrice) + orderNumberNew := orderMoney.Div(closePrice) // 订单数量 = 下单金额 / 平仓价格 + + // 平仓(手续费处理) + cost, err := Uo.CalculateHandlingFees(ctx, session, int(userId), flags.SpotsMarketType, int(order.TradeType), orderId, orderMoney.String(), flags.SetOne) + if err != nil { + applogger.Error("%v SpotOrdersClosingDB.CalculateHandlingFees:%v", common.ErrSpots, err) + return flags.SetNull, err + } + openOrClosingCost := decimal.RequireFromString(cost) + totalMoneyPrice := orderNumberNew.Mul(closePrice).Add(openOrClosingCost) // (开仓|平仓)订单总金额 = (开仓|平仓)订单金额 + (开仓|平仓)订单手续费 + if !flags.CheckSetting { + applogger.Debug("平仓价格:%v", closingPrice) + applogger.Debug("平仓订单数量:%v", orderNumberNew) + applogger.Debug("平仓手续费:%v", cost) + applogger.Debug("平仓总金额:%v", totalMoneyPrice) + } + + // 判定是买入还是卖出 + var usableNew, frozenNew, usableNoNew, frozenNoNew decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买入 + usableNew = usableOld.Add(totalMoney).Sub(totalMoneyPrice) // 用户总资产 + frozenNew = frozenOld.Sub(totalMoney) // 用户冻结资产 + if order.DigitalId != flags.BasicUnit { + usableNoNew = usableNoOld.Add(orderNumberNew) // 非资产 + frozenNoNew = frozenNoOld // 非冻结资产 + } + case flags.TradeTypeSell: // 卖出 + usableNew = usableOld.Add(orderMoney).Sub(openOrClosingCost) // 用户可用资产 + frozenNew = frozenOld // 用户冻结资产 + if order.DigitalId != flags.BasicUnit { + if orderNumberNew.Cmp(orderNumber) > 0 { + orderNumberNew = orderNumber + } + usableNoNew = usableNoOld.Sub(orderNumberNew) // 非可用资产 + frozenNoNew = frozenNoOld.Sub(orderNumber) // 非冻结资产 + } + default: + + } + if !flags.CheckSetting { + applogger.Debug("可用资产:%v", usableNew) + applogger.Debug("冻结资产:%v", frozenNew) + applogger.Debug("非可用资产:%v", usableNoNew) + applogger.Debug("非冻结资产:%v", frozenNoNew) + } + + // 更新用户资产信息 + userDigitalUSDT := orders.UpdateBotUserDigital(ctx, usableNew.String(), frozenNew.String()) + checkNum, err := Uo.UpdateBotUserDigital(session, userId, flags.BasicUnit, userDigitalUSDT) + if err != nil || checkNum <= 0 { + applogger.Error("%v SpotOrdersClosingDB.UpdateBotUserDigital:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 更新订单信息 + botStockTrade := orders.UpdateBotDigitalStatusByOrderId(ctx, closingPrice, cost, orderMoney.String(), totalMoneyPrice.String(), orderNumberNew.String()) + if err = Uo.UpdateBotDigitalTradeByOrderId(session, orderId, botStockTrade); err != nil { + applogger.Error("%v SpotOrdersClosingDB.UpdateBotDigitalTradeByOrderId:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 更新当前用户非的资产信息 + if order.DigitalId != flags.BasicUnit { + userDigitalSymbol := orders.UpdateBotUserDigital(ctx, usableNoNew.String(), frozenNoNew.String()) + checkNum, err = Uo.UpdateBotUserDigital(session, userId, order.DigitalId, userDigitalSymbol) + if err != nil || checkNum <= 0 { + applogger.Error("%v SpotOrdersClosingDB.UpdateBotUserDigital:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + // 返佣记录表|资产表|资金变动表 + err = Uo.SpotsRebateCalculation(ctx, session, int(userId), flags.SpotsMarketType, flags.ClosingPosition, flags.CloseMRebate, cost, orderId) + if err != nil { + applogger.Error("%v SpotOrdersClosingDB.SpotsRebateCalculation:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 交易明细表(资产|非资产|手续费) + err = Uo.CreatBotUserDigitalLog(ctx, session, userId, order.TradeType, order.DigitalId, orderMoney.String(), orderNumberNew.String(), cost, orderId) + if err != nil { + applogger.Error("%v SpotOrdersClosingDB.CreatBotUserDigitalLog:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrSpotMsgTow + } + + err = session.Commit() + if err != nil { + applogger.Error("%v SpotOrdersClosingDB.Commit:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrMySqlDB + } + + return orderId, nil +} + +// UpdateBotDigitalCancelByOrderId +// +// @Description: 现货撤单 +// @receiver uo +// @param ctx +// @param orderId +// @return bool +// @return error +func (uo *userOrderRepo) UpdateBotDigitalCancelByOrderId(ctx context.Context, orderId string) (bool, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateBotDigitalCancelByOrderId.NewSession:%v", common.ErrSpots, err) + return false, flags.ErrMySqlDB + } + + // get BotStockTrade + var digitalTrade []models.BotDigitalTrade + if err = session.Table(flags.BotDigitalTrade). + Where("order_id = ?", orderId). + Find(&digitalTrade); err != nil || len(digitalTrade) <= 0 { + applogger.Error("%v UpdateBotDigitalCancelByOrderId.Find:%v", common.ErrSpots, err) + return false, flags.ErrMySqlDB + } + var userId, tradeType int + var orderMoneyT, serviceCostT, orderNumber, digitalId string + for _, value := range digitalTrade { + userId = value.UserId + tradeType = value.TradeType + digitalId = value.DigitalId + orderNumber = value.OrderNumber + orderMoneyT = value.OrderMoney + serviceCostT = value.ServiceCost + } + if !flags.CheckSetting { + applogger.Debug("撤单用户ID:%v", userId) + applogger.Debug("撤单类型:%v", tradeType) + applogger.Debug("撤单下单币种:%v", digitalId) + applogger.Debug("撤单下单购买数量:%v", orderNumber) + applogger.Debug("撤单下单金额:%v", orderMoneyT) + applogger.Debug("撤单下单手续费:%v", serviceCostT) + } + + // get BotUserStock By + usableNum, frozenNum, _, err := uo.GetBotUserDigital(session, int64(userId), flags.BasicUnit) + if err != nil { + applogger.Error("%v UpdateBotDigitalCancelByOrderId.GetBotUserDigital:%v", common.ErrSpots, err) + return false, flags.ErrMySqlDB + } + if !flags.CheckSetting { + applogger.Debug("撤单可用资产:%v", usableNum) + applogger.Debug("撤单冻结资产:%v", frozenNum) + } + + var usableSymbolOld, frozenSymbolOld decimal.Decimal + if digitalId != flags.BasicUnit { + usableSymbolOld, frozenSymbolOld, _, err = uo.GetBotUserDigital(session, int64(userId), digitalId) + if err != nil { + applogger.Error("%v UpdateBotDigitalCancelByOrderId.GetBotUserDigital:%v", common.ErrSpots, err) + return false, flags.ErrMySqlDB + } + } + if !flags.CheckSetting { + applogger.Debug("撤单下单非可用资产:%v", usableSymbolOld) + applogger.Debug("撤单下单非冻结资产:%v", frozenSymbolOld) + } + + // update digitalCancel + botStockTrade := orders.UpdateBotDigitalCancelByOrderId(ctx) + checkInt, err := session.Table(flags.BotDigitalTrade). + Where("order_id = ?", orderId). + Update(&botStockTrade) + if err != nil || checkInt <= 0 { + applogger.Error("%v UpdateBotDigitalCancelByOrderId.UpdateBotDigitalCancelByOrderId:%v", common.ErrSpots, err) + return false, flags.ErrMySqlDB + } + + orderMoney := decimal.RequireFromString(orderMoneyT) // 订单金额 + serviceCost := decimal.RequireFromString(serviceCostT) // 手续费 + totalMoney := orderMoney.Add(serviceCost) // 订单总金额 + if !flags.CheckSetting { + applogger.Debug("下单金额:%v", orderMoney) + applogger.Debug("下单手续费:%v", serviceCost) + applogger.Debug("下单总金额:%v", totalMoney) + } + + var usableNew, frozenNew, usableSN, frozenSN decimal.Decimal + switch tradeType { + case flags.TradeTypeBuy: // 买入 + usableNew = usableNum.Add(totalMoney) // 用户总资产 + frozenNew = frozenNum.Sub(totalMoney) // 用户冻结资产 + + usableSN = usableSymbolOld // 用户可用资产 + frozenSN = frozenSymbolOld // 用户非冻结资产 + case flags.TradeTypeSell: // 卖出 + usableNew = usableNum // 用户总资产 + frozenNew = frozenNum // 用户冻结资产 + + if digitalId != flags.BasicUnit { + usableSN = usableSymbolOld.Add(decimal.RequireFromString(orderNumber)) // 其它币种可用资产 + frozenSN = frozenSymbolOld.Sub(decimal.RequireFromString(orderNumber)) // 其它币种冻结资产 + } + default: + + } + + // 更新用户非资产 + if digitalId != flags.BasicUnit { + userDigital := orders.UpdateBotUserDigital(ctx, usableSN.String(), frozenSN.String()) + checkNum, err := uo.UpdateBotUserDigital(session, int64(userId), digitalId, userDigital) + if err != nil || checkNum <= 0 { + applogger.Error("%v UpdateBotDigitalCancelByOrderId.UpdateBotUserDigital:%v", common.ErrSpots, err) + return false, flags.ErrMySqlDB + } + } + + // 更新用户资产 + userStockUSDT := orders.UpdateBotUserDigital(ctx, usableNew.String(), frozenNew.String()) + checkNum, err := uo.UpdateBotUserDigital(session, int64(userId), flags.BasicUnit, userStockUSDT) + if err != nil || checkNum <= 0 { + applogger.Error("%v UpdateBotDigitalCancelByOrderId.UpdateBotUserDigital:%v", common.ErrSpots, err) + return false, flags.ErrMySqlDB + } + + // 清理现货缓存队列 + if err = Reds.HDel(context.Background(), setting.MarketSpotsEntrust, orderId).Err(); err != nil { + applogger.Error("%v UpdateBotDigitalCancelByOrderId.HDel:%v", common.ErrSpots, err) + return false, flags.ErrCacheDB + } + + // 修改当前用户订阅订单状态 + if err = UpdateSpotsSubscribeStatusHashByOrderId(int64(userId), orderId, setting.SpotsSubscribe, flags.Cancel); err != nil { + applogger.Error("%v UpdateBotDigitalCancelByOrderId.UpdateSpotsSubscribeStatusByOrderId:%v", common.ErrSpots, err) + return false, flags.ErrCacheDB + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateBotDigitalCancelByOrderId.Commit:%v", common.ErrSpots, err) + return false, flags.ErrMySqlDB + } + + return true, nil +} + +// CreateOneClickRedemption +// +// @Description: 现货一键兑换 +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) CreateOneClickRedemption(ctx context.Context, userId int64, order structure.SpotsOrder) (string, error) { + // 1、下单通知订阅 + digitalId := strings.ToLower(order.DigitalId) + spots.SpotsMap <- []byte(digitalId) + order.DigitalId = strings.ToUpper(order.DigitalId) + + // 交易币市价 + priceNew, err := GetDigitalCurrencyPrice(ctx, flags.Xh, digitalId) + if len(priceNew) == 0 || err != nil { + applogger.Error("%v CreateOneClickRedemption.DealSpotsMarketPrice:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrNetWorkMessage + } + + // 2、市价下单记录(1>下单判定 2>订单表 3>资产表[资产|其他交易对]) + order.DealPrice = priceNew + orderId, err := uo.SpotOrdersDealDB(ctx, userId, order) + if err != nil || len(orderId) == 0 { + applogger.Error("%v CreateOneClickRedemption.SpotOrdersDealDB:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrSpotsMsgThree + } + + // 3、市价卖出下单 + switch order.DealType { + case flags.DealTypeMarket: // 市价下单(市价卖出平仓) + var openPrice decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买入 + case flags.TradeTypeSell: // 卖出 + priceSub := decimal.RequireFromString(priceNew) + difference := priceSub.Mul(utils.Difference()) // 设置价差 + openPrice = priceSub.Sub(difference) // 开仓价格 + default: + return flags.SetNull, flags.ErrSpotsMsgFour + } + + // 市价下单平仓操作-->更新订单表|更新资产表|计算手续费|录入返佣明细|录入交易明细 + if _, err = SpotOrdersClosingDB(ctx, uo.data.mysqlDB, userId, order, orderId, openPrice.String()); err != nil { + applogger.Error("%v CreateOneClickRedemption.SpotOrdersClosingDB:%v", common.ErrSpots, err) + // 一键兑换失败,撤单操作 + _, err = uo.UpdateBotDigitalCancelByOrderId(ctx, orderId) + if err != nil { + applogger.Error("%v CreateOneClickRedemption.UpdateBotDigitalCancelByOrderId:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrMySqlDB + } + return flags.SetNull, err + } + default: + return flags.SetNull, flags.ErrSpotMsgOne + } + + return orderId, nil +} + +// GetBotDigitalTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param orderId +// @return []models.BotDigitalTrade +// @return error +func (uo *userOrderRepo) GetBotDigitalTradeByOrderId(orderId string) ([]models.BotDigitalTrade, error) { + var botDigitalTrade []models.BotDigitalTrade + if err := uo.data.mysqlDB.Table(flags.BotDigitalTrade). + Where("order_id = ?", orderId). + Find(&botDigitalTrade); err != nil { + return nil, err + } + + return botDigitalTrade, nil +} + +// GetBotUserDigital +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param symbol +// @return decimal.Decimal +// @return decimal.Decimal +// @return int +// @return error +func (uo *userOrderRepo) GetBotUserDigital(session *xorm.Session, userId int64, symbol string) (decimal.Decimal, decimal.Decimal, int, error) { + var digitalUSDT []models.BotUserDigital + if err := session.Table(flags.BotUserDigital). + Where("user_id = ?", userId). + Where("digital_id = ?", strings.ToUpper(symbol)). + Find(&digitalUSDT); err != nil { + return decimal.Zero, decimal.Zero, 0, err + } + + var usableNum, frozenNum decimal.Decimal + for _, value := range digitalUSDT { + usableNum = decimal.RequireFromString(value.UsableNum) // 资产可用余额 + frozenNum = decimal.RequireFromString(value.FrozenNum) // 资产冻结数量 + } + + return usableNum, frozenNum, len(digitalUSDT), nil +} + +// SpotOrdersDealDB 订单录入 +// +// @Description: +// @receiver uo +// @param ctx +// @param userId +// @param order +// @return string +// @return error +func (uo *userOrderRepo) SpotOrdersDealDB(ctx context.Context, userId int64, order structure.SpotsOrder) (string, error) { + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v SpotOrdersDealDB:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 查询当前用户买入或者卖出的可用总资产和冻结总资产 + usableOld, frozenOld, _, err := uo.GetBotUserDigital(session, userId, flags.BasicUnit) + if err != nil { + applogger.Error("%v SpotOrdersDealDB.GetBotUserDigital:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrMySqlDB + } + if usableOld.IsZero() || frozenOld.IsNegative() { + return flags.SetNull, flags.ErrPublicOne + } + + // 查询当前用户买入或者卖出的可用总资产和冻结总非资产 + var checkCount int + var usableSymbolOld, frozenSymbolOld decimal.Decimal + if order.DigitalId != flags.BasicUnit { + usableSymbolOld, frozenSymbolOld, checkCount, err = uo.GetBotUserDigital(session, userId, order.DigitalId) + if err != nil { + applogger.Error("%v SpotOrdersDealDB.GetBotUserDigital:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + + if !flags.CheckSetting { + applogger.Debug("可用资产:%v,冻结资产:%v", userId, frozenOld) + applogger.Debug("可用非资产:%v,冻结非资产:%v", usableSymbolOld, frozenSymbolOld) + } + + // 开仓录入订单表 + checkInt, orderId, err := uo.CreatBotDigitalTrade(ctx, session, userId, order) + if err != nil || checkInt <= 0 { + applogger.Error("%v SpotOrdersDealDB.CreatBotDigitalTrade:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrMySqlDB + } + + orderNumber := decimal.RequireFromString(order.OrderNumber) // 下单数量 + orderMoney := decimal.RequireFromString(order.DealPrice).Mul(orderNumber) // 下单金额 = 訂單金額 * 訂單數量 + serviceCost := decimal.RequireFromString(order.ServiceCost) // 下单手续费 + totalMoney := orderMoney.Add(serviceCost) // 下单总金额 + + if !flags.CheckSetting { + applogger.Debug("现货下单金额:%v", orderMoney) + applogger.Debug("现货下单数量:%v", orderNumber) + applogger.Debug("现货下单手续费:%v", serviceCost) + applogger.Debug("现货下单总金额:%v", totalMoney) + } + + // 通过交易类型处理下单: 1买入(冻结资产), 2卖出(冻结资产) + var usableNew, frozenNew, usableNewNo, frozenNewNo decimal.Decimal + switch order.TradeType { + case flags.TradeTypeBuy: // 买入 + voteUsaBledOld := usableOld.Cmp(totalMoney) + voteMix := usableOld.Sub(totalMoney).Div(usableOld).Cmp(utils.DecimalsStrInt()) + if voteUsaBledOld < 0 || voteMix <= 0 { + return flags.SetNull, flags.ErrSpotsMsgSix + } + usableNew = usableOld.Sub(totalMoney) // 可用资产 + frozenNew = frozenOld.Add(totalMoney) // 冻结资产 + + usableNewNo = usableSymbolOld // 非可用资产 + frozenNewNo = frozenSymbolOld // 非冻结资产 + case flags.TradeTypeSell: // 卖出 + if usableSymbolOld.IsZero() || usableSymbolOld.Cmp(orderNumber) < 0 { + return flags.SetNull, flags.ErrPublicOne + } + usableNew = usableOld // 可用资产 + frozenNew = frozenOld // 非可用冻结资产 + + if order.DigitalId != flags.BasicUnit { + usableNewNo = usableSymbolOld // 可用非资产 + frozenNewNo = frozenSymbolOld.Add(orderNumber) // 冻结非资产 + } + default: + return flags.SetNull, flags.ErrSpotsMsgSeven + } + + // 更新当前下单用户可用资产表 + userDigitalUSDT := orders.UpdateBotUserDigital(ctx, usableNew.String(), frozenNew.String()) + checkNum, err := uo.UpdateBotUserDigital(session, userId, flags.BasicUnit, userDigitalUSDT) + if err != nil || checkNum <= 0 { + applogger.Error("%v SpotOrdersDealDB.UpdateBotUserDigital:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrMySqlDB + } + + // 更新非账户资金 + if order.DigitalId != flags.BasicUnit { + if checkCount == 0 { + userDigitalSymbol := orders.BotUserDigital(ctx, userId, usableNewNo.String(), frozenNewNo.String(), order) + checkInt, err = uo.CreatBotUserDigital(session, userDigitalSymbol) + if err != nil || checkInt <= 0 { + applogger.Error("%v SpotOrdersDealDB.CreatBotUserDigital:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrMySqlDB + } + } else { + userDigital := orders.UpdateBotUserDigital(ctx, usableNewNo.String(), frozenNewNo.String()) + checkNum, err = uo.UpdateBotUserDigital(session, userId, order.DigitalId, userDigital) + if err != nil || checkNum <= 0 { + applogger.Error("%v SpotOrdersDealDB.UpdateBotUserDigital:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrMySqlDB + } + } + } + + err = session.Commit() + if err != nil { + applogger.Error("%v SpotOrdersDealDB:%v", common.ErrSpots, err) + return flags.SetNull, flags.ErrMySqlDB + } + + return orderId, nil +} + +// CreatBotDigitalTrade +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param order +// @return int64 +// @return string +// @return error +func (uo *userOrderRepo) CreatBotDigitalTrade(ctx context.Context, session *xorm.Session, userId int64, order structure.SpotsOrder) (int64, string, error) { + var orderId string + for { + orderId = orders.CreateRandCodeOrder(10) + orderList, err := uo.GetBotDigitalTradeByOrderId(orderId) + if err != nil || len(orderList) > 0 { + applogger.Error("%v CreatBotDigitalTrade.GetBotDigitalTradeByOrderId:%v", err) + continue + } + break + } + + botStockTrade := orders.BotDigitalTrade(ctx, userId, orderId, order) + checkInt, err := session.Table(flags.BotDigitalTrade).Insert(&botStockTrade) + if err != nil || checkInt < 0 { + return 0, flags.SetNull, err + } + + return checkInt, botStockTrade.OrderId, err +} + +// UpdateBotDigitalTradeByOrderId +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param orderId +// @param trade +// @return error +func (uo *userOrderRepo) UpdateBotDigitalTradeByOrderId(session *xorm.Session, orderId string, trade models.BotDigitalTrade) error { + _, err := session.Table(flags.BotDigitalTrade). + Where("order_id = ?", orderId). + Update(&trade) + if err != nil { + return err + } + + return nil +} + +// UpdateBotUserDigital +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param symbol +// @param userDigitalUSDT +// @return int64 +// @return error +func (uo *userOrderRepo) UpdateBotUserDigital(session *xorm.Session, userId int64, symbol string, userDigitalUSDT models.BotUserDigital) (int64, error) { + checkNum, err := session.Table(flags.BotUserDigital). + Where("user_id = ?", userId). + Where("digital_id = ?", symbol). + Update(&userDigitalUSDT) + if err != nil { + return 0, nil + } + + return checkNum, nil +} + +// CreatBotUserDigital +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param digital +// @return int64 +// @return error +func (uo *userOrderRepo) CreatBotUserDigital(session *xorm.Session, digital models.BotUserDigital) (int64, error) { + checkInt, err := session.Table(flags.BotUserDigital).Insert(&digital) + if err != nil { + return 0, err + } + + return checkInt, nil +} diff --git a/internal/data/order_way_ipo.go b/internal/data/order_way_ipo.go new file mode 100644 index 0000000..e737b04 --- /dev/null +++ b/internal/data/order_way_ipo.go @@ -0,0 +1,100 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/go-xorm/xorm" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + models "matchmaking-system/internal/pkg/model" + "matchmaking-system/internal/pkg/setting" +) + +// UpdateBotStockBlockTrade +// +// @Description: 更新大宗交易订单(美股|泰股|马股|印尼股|印度股|新加坡股|港股|英股|法股|德股) +// @param session +// @param code +// @param codeOld +// @return error +func (uo *userOrderRepo) UpdateBotStockBlockTrade(session *xorm.Session, code, codeOld string) error { + var userStockBlkTrade []models.BotStockBlockTrade + if err := session.Table(flags.BotStockBlockTrade).Where("stock_id =?", codeOld).Find(&userStockBlkTrade); err != nil { + return err + } + for _, value := range userStockBlkTrade { + value.StockId = code + // 1、更新订单信息 + inCheck, err := session.Table(flags.BotStockBlockTrade).Where("trade_id =?", value.TradeId).Update(&value) + if err != nil || inCheck <= 0 { + continue + } + // 2、处理缓存订单 + orderMap, err := Reds.HGet(context.Background(), setting.AdminShareBlkSubscribe, value.OrderId).Result() + if err != nil { + continue + } + var entrustJson share.ShareBlkTallyCache + if err = json.Unmarshal([]byte(orderMap), &entrustJson); err != nil { + continue + } + var entrust *share.ShareBlkTallyCache + entrust = &entrustJson + if entrust == nil { + continue + } + entrust.Symbol = code + entrust.Order.StockId = code + // 3、处理挂单|持仓|用户订阅|管理员订阅缓存数据 + switch value.Status { + case 0: // 挂单 + if err = share.ShareBklHashUserOrder(Reds, setting.MarketShareBlkEntrust, entrust); err != nil { + continue + } + case 1: // 持仓 + if err = share.ShareBklHashUserOrder(Reds, setting.MarketShareBlkPosition, entrust); err != nil { + continue + } + default: + continue + } + // 更新用户订阅缓存 + cacheKey := fmt.Sprintf("%v-%v", setting.ShareBlkSubscribe, entrust.UserId) + if err = share.ShareBklHashUserOrder(Reds, cacheKey, entrust); err != nil { + continue + } + // 更新管理员订阅缓存 + if err = share.ShareBklHashUserOrder(Reds, setting.AdminShareBlkSubscribe, entrust); err != nil { + continue + } + } + + return nil +} + +// UpdateBotUserStockBlockLog +// +// @Description: 更新大宗交易日志表(美股|泰股|马股|印尼股|印度股|新加坡股|港股|英股|法股|德股) +// @param session +// @param code +// @param codeOld +// @return error +func (uo *userOrderRepo) UpdateBotUserStockBlockLog(session *xorm.Session, code, codeOld string) error { + var userStockBlkLog []models.BotUserStockBlockLog + if err := session.Table(flags.BotUserStockBlockLog).Where("stock_id =?", codeOld).Find(&userStockBlkLog); err != nil { + return err + } + for _, value := range userStockBlkLog { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockBlockLog).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateBotUserStockBlockLog BotUserStockBlockLog err:%v", common.ErrSharePre, err) + continue + } + } + + return nil +} diff --git a/internal/data/order_way_ipo_brl.go b/internal/data/order_way_ipo_brl.go new file mode 100644 index 0000000..89a7348 --- /dev/null +++ b/internal/data/order_way_ipo_brl.go @@ -0,0 +1,376 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + orders "matchmaking-system/internal/data/convert" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + models "matchmaking-system/internal/pkg/model" + "matchmaking-system/internal/pkg/setting" + "strings" + "time" +) + +// GetBotUserBrlPreStockOrder +// +// @Description: 巴西股新股申购列表查詢 +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserBrlPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserBrlPreStockOrder(ctx context.Context, id string) ([]models.BotUserBrlPreStockOrder, error) { + var botSgd []models.BotUserBrlPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserBrlPreStockOrder). + Where("pre_stock_id = ?", id). + Where("status = 3"). + Find(&botSgd); err != nil { + applogger.Error("%v GetBotUserBrlPreStockOrder Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botSgd, nil +} + +// GetBotUserBrlPreStockOrderByOrderNo +// +// @Description: 巴西股新股申购列表查詢orderNo +// @receiver uo +// @param ctx +// @param code +// @return []models.BotUserBrlPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserBrlPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserBrlPreStockOrder, error) { + var botGbx []models.BotUserBrlPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserBrlPreStockOrder). + In("order_no", code). + Where("trade_status = 0"). + Where("status = 3"). + Find(&botGbx); err != nil { + applogger.Error("%v GetBotUserBrlPreStockOrderByOrderNo Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botGbx, nil +} + +// GetBotUserBrlGiveStockOrders +// +// @Description: 巴西股赠股 +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserBrlGiveStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserBrlGiveStockOrders(ctx context.Context, id string) ([]models.BotUserBrlGiveStockOrder, error) { + var botSgd []models.BotUserBrlGiveStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserBrlGiveStockOrder). + Where("order_no = ?", id). + Find(&botSgd); err != nil { + applogger.Error("%v GetBotUserBrlGiveStockOrders Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botSgd, nil +} + +// GetBotStockBrlList +// +// @Description: 巴西股票代码列表 +// @receiver uo +// @param ctx +// @return []models.BotStockBrlList +// @return error +func (uo *userOrderRepo) GetBotStockBrlList(ctx context.Context) ([]models.BotStockBrlList, error) { + var data []models.BotStockBrlList + if err := uo.data.mysqlDB.Table(flags.BotStockBrlList).Find(&data); err != nil { + applogger.Error("%v GetBotStockBrlList Find:%v", common.ErrSharePre, err) + return nil, err + } + // 清理股票缓存列表 + for _, value := range data { + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + Reds.HDel(context.Background(), setting.MarketShareBrl, codeOld) + Reds.HDel(context.Background(), setting.MarketShareBlkBrl, codeOld) + } + } + + return data, nil +} + +// CreateBotUserBrlPreStockOrder +// +// @Description: 巴西股新股申购:开仓--持仓 +// @receiver uo +// @param ctx +// @param code +// @param order +// @return error +func (uo *userOrderRepo) CreateBotUserBrlPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error { + // 同步写入股票列表缓存 + SubscribeBrlHSetCodeList(code, false) + // 处理新股申购数据订单 + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v CreateBotUserBrlPreStockOrder.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 强平阈值 + flatRatio := GetCacheForcedClosure(flags.StockBRLSystemSetUpKey, code) + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), + } + // 获取开盘时间 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.BrlMarket, time.Now()) + // 初始化订单缓存map + orderMap := make(map[string]share.ShareBrlTallyCache) + for _, value := range order { + value.System = system + // 生成订单ID + var orderId string + orderId, err = uo.VerifyBotStockBrlTradeOrderId(session) + if err != nil { + applogger.Error("%v CreateBotUserBrlPreStockOrder.VerifyBotStockBrlTradeOrderId:%v", common.ErrSharePre, err) + continue + } + // 查询账户是否存在,再存更新不存在新增 + var check bool + check, err = uo.CheckStockBrlAmount(ctx, int64(value.UserId), value.StockId, value.OrderNumber, decimal.Zero.String()) + if err != nil || !check { + applogger.Error("%v CreateBotUserBrlPreStockOrder.CheckStockBrlAmount:%v", common.ErrSharePre, err) + continue + } + // 写入订单数据表 + trade := orders.BotStockBrlTradePre(ctx, int64(value.UserId), orderId, value) + if err = uo.CreateBotStockBrlTrade(session, trade); err != nil { + applogger.Error("%v CreateBotUserBrlPreStockOrder.CreateBotStockBrlTrade:%v", common.ErrSharePre, err) + continue + } + // 写入持仓缓存 + resultMsg := share.ShareBrlTallyCache{ + UserId: int64(value.UserId), // 用户Id + OrderId: orderId, // 订单ID + Symbol: value.StockId, // 下单交易对 + OpenPrice: value.LimitPrice, // 开仓价格 + Status: flags.Position, // 订单状态 + Order: value, // 下单信息 + ClosingTime: closingTime, // 平仓时间 + } + orderMap[orderId] = resultMsg + } + + if err = session.Commit(); err != nil { + applogger.Error("%v CreateBotUserBrlPreStockOrder.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 写入持仓缓存、用户订单订阅缓存、管理员订单订阅缓存 + for _, resultMsg := range orderMap { + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v CreateBotUserBrlPreStockOrder.Marshal:%v", common.ErrSharePre, err) + continue + } + // 写入持仓缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareBrlPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + // 写入用户订单订阅缓存 + orderIdKey := virtual.OrderIdListKey(setting.ShareBrlSubscribe, resultMsg.UserId) + if err = share.ShareBrlHashUserOrder(Reds, orderIdKey, &resultMsg); err != nil { + applogger.Error("%v CreateBotUserBrlPreStockOrder.ShareBrlHashUserOrder:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // 写入管理员订单订阅缓存 + if err = share.ShareBrlHashUserOrder(Reds, setting.AdminShareBrlSubscribe, &resultMsg); err != nil { + applogger.Error("%v CreateBotUserBrlPreStockOrder.ShareBrlHashUserOrder:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // TODO: 获取IPO未支付订单缓存,并更新缓存中的持仓订单ID + keyCache := fmt.Sprintf("%v%v", flags.StockIpoList, resultMsg.Order.OrderNo) + checkInt, err := Reds.Exists(ctx, keyCache).Result() + if err != nil { + continue + } + if checkInt > 0 { + if err = Reds.Set(ctx, keyCache, resultMsg.OrderId, 0).Err(); err != nil { + applogger.Error("CreateBotUserBrlPreStockOrder.Set err:%v", err) + } + } + } + + return nil +} + +// CheckStockBrlAmount +// +// @Description: 巴西股新股申购【创建|更新】用戶资产 +// @receiver uo +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return bool +// @return error +func (uo *userOrderRepo) CheckStockBrlAmount(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) (bool, error) { + var botUserStockBrl []models.BotUserStockBrl + if err := uo.data.mysqlDB.Table(flags.BotUserStockBrl). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&botUserStockBrl); err != nil { + applogger.Error("%v CheckStockBrlAmount Find:%v", common.ErrSharePre, err) + return false, err + } + var usableNumOld, frozenNumOld decimal.Decimal + for _, value := range botUserStockBrl { + usableNumOld = decimal.RequireFromString(value.UsableNum) + frozenNumOld = decimal.RequireFromString(value.FrozenNum) + } + + if len(botUserStockBrl) == 0 { + userStock := orders.CreatBotUserStockBrlPre(ctx, userId, stockId, usableNum, frozenNum) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockBrl).Insert(&userStock) + if err != nil { + applogger.Error("%v CheckStockBrlAmount Insert:%v", common.ErrSharePre, err) + return false, err + } + } else { + usableNumNew := usableNumOld.Add(decimal.RequireFromString(usableNum)) + frozenNumNew := frozenNumOld.Add(decimal.RequireFromString(frozenNum)) + userStock := orders.UpdateBotUserStockBrlPre(ctx, usableNumNew.String(), frozenNumNew.String()) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockBrl). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&userStock) + if err != nil { + applogger.Error("%v CheckStockBrlAmount Update:%v", common.ErrSharePre, err) + return false, err + } + } + + return true, nil +} + +// UpdateShareBrlTradeStockId +// +// @Description: 更新-巴西股新股申购股票stockId +// @receiver uo +// @param ctx +// @param code +// @param codeOld +// @return error +func (uo *userOrderRepo) UpdateShareBrlTradeStockId(ctx context.Context, code, codeOld string) error { + // 同步写入股票列表缓存 + SubscribeBrlHSetCodeList(code, false) + // 新增到新加坡股缓存列表 + if err := Reds.HSet(context.Background(), setting.MarketShareBrl, code, code).Err(); err != nil { + applogger.Error("%v UpdateShareBrlTradeStockId.HSet.MarketShareGbx:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateShareBrlTradeStockId.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + // 1、更新订单股票代码 + var userStockTrade []models.BotStockBrlTrade + if err = session.Table(flags.BotStockBrlTrade).Where("stock_id =?", codeOld).Find(&userStockTrade); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockTrade { + value.StockId = code + // 1、更新订单信息 + inCheck, err := session.Table(flags.BotStockBrlTrade).Where("trade_id =?", value.TradeId).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareBrlTradeStockId BotStockGbxTrade err:%v", common.ErrSharePre, err) + continue + } + // 2、处理缓存订单 + orderMap, err := Reds.HGet(context.Background(), setting.AdminShareBrlSubscribe, value.OrderId).Result() + if err != nil { + continue + } + var entrustJson share.ShareBrlTallyCache + if err = json.Unmarshal([]byte(orderMap), &entrustJson); err != nil { + continue + } + var entrust *share.ShareBrlTallyCache + entrust = &entrustJson + if entrust == nil { + continue + } + entrust.Symbol = code + entrust.Order.StockId = code + // 3、处理挂单|持仓|用户订阅|管理员订阅缓存数据 + switch value.Status { + case 0: // 挂单 + if err = share.ShareBrlHashUserOrder(Reds, setting.MarketShareBrlEntrust, entrust); err != nil { + continue + } + case 1: // 持仓 + if err = share.ShareBrlHashUserOrder(Reds, setting.MarketShareBrlPosition, entrust); err != nil { + continue + } + default: + continue + } + // 更新用户订阅缓存 + cacheKey := fmt.Sprintf("%v-%v", setting.ShareBrlSubscribe, entrust.UserId) + if err = share.ShareBrlHashUserOrder(Reds, cacheKey, entrust); err != nil { + continue + } + // 更新管理员订阅缓存 + if err = share.ShareBrlHashUserOrder(Reds, setting.AdminShareBrlSubscribe, entrust); err != nil { + continue + } + } + // 2、更新资产表股票代码 + var userStock []models.BotUserStockBrl + if err = session.Table(flags.BotUserStockBrl).Where("stock_id =?", codeOld).Find(&userStock); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStock { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockBrl).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareBrlTradeStockId BotUserStockGbx err:%v", common.ErrSharePre, err) + continue + } + } + // 3、更新资产表日志股票代码 + var userStockLog []models.BotUserStockBrlLog + if err = session.Table(flags.BotUserStockBrlLog).Where("stock_id =?", codeOld).Find(&userStockLog); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockLog { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockBrlLog).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareBrlTradeStockId BotUserStockGbxLog err:%v", common.ErrSharePre, err) + continue + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateShareBrlTradeStockId.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + return nil +} diff --git a/internal/data/order_way_ipo_eur.go b/internal/data/order_way_ipo_eur.go new file mode 100644 index 0000000..9ba6932 --- /dev/null +++ b/internal/data/order_way_ipo_eur.go @@ -0,0 +1,376 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + orders "matchmaking-system/internal/data/convert" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + models "matchmaking-system/internal/pkg/model" + "matchmaking-system/internal/pkg/setting" + "strings" + "time" +) + +// GetBotUserEurPreStockOrder +// +// @Description: 德股新股申购列表查詢 +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserEurPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserEurPreStockOrder(ctx context.Context, id string) ([]models.BotUserEurPreStockOrder, error) { + var botSgd []models.BotUserEurPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserEurPreStockOrder). + Where("pre_stock_id = ?", id). + Where("status = 3"). + Find(&botSgd); err != nil { + applogger.Error("%v GetBotUserEurPreStockOrder Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botSgd, nil +} + +// GetBotUserEurPreStockOrderByOrderNo +// +// @Description: 德股新股申购列表查詢orderNo +// @receiver uo +// @param ctx +// @param code +// @return []models.BotUserEurPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserEurPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserEurPreStockOrder, error) { + var botGbx []models.BotUserEurPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserEurPreStockOrder). + In("order_no", code). + Where("trade_status = 0"). + Where("status = 3"). + Find(&botGbx); err != nil { + applogger.Error("%v GetBotUserEurPreStockOrderByOrderNo Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botGbx, nil +} + +// GetBotUserEurGiveStockOrders +// +// @Description: 德股赠股 +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserEurGiveStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserEurGiveStockOrders(ctx context.Context, id string) ([]models.BotUserEurGiveStockOrder, error) { + var botSgd []models.BotUserEurGiveStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserEurGiveStockOrder). + Where("order_no = ?", id). + Find(&botSgd); err != nil { + applogger.Error("%v GetBotUserEurGiveStockOrders Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botSgd, nil +} + +// GetBotStockEurList +// +// @Description: 德股票代码列表 +// @receiver uo +// @param ctx +// @return []models.BotStockEurList +// @return error +func (uo *userOrderRepo) GetBotStockEurList(ctx context.Context) ([]models.BotStockEurList, error) { + var data []models.BotStockEurList + if err := uo.data.mysqlDB.Table(flags.BotStockEurList).Find(&data); err != nil { + applogger.Error("%v GetBotStockEurList Find:%v", common.ErrSharePre, err) + return nil, err + } + // 清理股票缓存列表 + for _, value := range data { + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + Reds.HDel(context.Background(), setting.MarketShareEur, codeOld) + Reds.HDel(context.Background(), setting.MarketShareBlkEur, codeOld) + } + } + + return data, nil +} + +// CreateBotUserEurPreStockOrder +// +// @Description: 德股新股申购:开仓--持仓 +// @receiver uo +// @param ctx +// @param code +// @param order +// @return error +func (uo *userOrderRepo) CreateBotUserEurPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error { + // 同步写入股票列表缓存 + SubscribeEurHSetCodeList(code, false) + // 处理新股申购数据订单 + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v CreateBotUserEurPreStockOrder.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 强平阈值 + flatRatio := GetCacheForcedClosure(flags.StockEURSystemSetUpKey, code) + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), + } + // 获取开盘时间 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.EurMarket, time.Now()) + // 初始化订单缓存map + orderMap := make(map[string]share.ShareEurTallyCache) + for _, value := range order { + value.System = system + // 生成订单ID + var orderId string + orderId, err = uo.VerifyBotStockEurTradeOrderId(session) + if err != nil { + applogger.Error("%v CreateBotUserEurPreStockOrder.VerifyBotStockEurTradeOrderId:%v", common.ErrSharePre, err) + continue + } + // 查询账户是否存在,再存更新不存在新增 + var check bool + check, err = uo.CheckStockEurAmount(ctx, int64(value.UserId), value.StockId, value.OrderNumber, decimal.Zero.String()) + if err != nil || !check { + applogger.Error("%v CreateBotUserEurPreStockOrder.CheckStockEurAmount:%v", common.ErrSharePre, err) + continue + } + // 写入订单数据表 + trade := orders.BotStockEurTradePre(ctx, int64(value.UserId), orderId, value) + if err = uo.CreateBotStockEurTrade(session, trade); err != nil { + applogger.Error("%v CreateBotUserEurPreStockOrder.CreateBotStockEurTrade:%v", common.ErrSharePre, err) + continue + } + // 写入持仓缓存 + resultMsg := share.ShareEurTallyCache{ + UserId: int64(value.UserId), // 用户Id + OrderId: orderId, // 订单ID + Symbol: value.StockId, // 下单交易对 + OpenPrice: value.LimitPrice, // 开仓价格 + Status: flags.Position, // 订单状态 + Order: value, // 下单信息 + ClosingTime: closingTime, // 平仓时间 + } + orderMap[orderId] = resultMsg + } + + if err = session.Commit(); err != nil { + applogger.Error("%v CreateBotUserEurPreStockOrder.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 写入持仓缓存、用户订单订阅缓存、管理员订单订阅缓存 + for _, resultMsg := range orderMap { + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v CreateBotUserEurPreStockOrder.Marshal:%v", common.ErrSharePre, err) + continue + } + // 写入持仓缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareEurPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + // 写入用户订单订阅缓存 + orderIdKey := virtual.OrderIdListKey(setting.ShareEurSubscribe, resultMsg.UserId) + if err = share.ShareEurHashUserOrder(Reds, orderIdKey, &resultMsg); err != nil { + applogger.Error("%v CreateBotUserEurPreStockOrder.ShareEurHashUserOrder:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // 写入管理员订单订阅缓存 + if err = share.ShareEurHashUserOrder(Reds, setting.AdminShareEurSubscribe, &resultMsg); err != nil { + applogger.Error("%v CreateBotUserEurPreStockOrder.ShareEurHashUserOrder:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // TODO: 获取IPO未支付订单缓存,并更新缓存中的持仓订单ID + keyCache := fmt.Sprintf("%v%v", flags.StockIpoList, resultMsg.Order.OrderNo) + checkInt, err := Reds.Exists(ctx, keyCache).Result() + if err != nil { + continue + } + if checkInt > 0 { + if err = Reds.Set(ctx, keyCache, resultMsg.OrderId, 0).Err(); err != nil { + applogger.Error("CreateBotUserEurPreStockOrder.Set err:%v", err) + } + } + } + + return nil +} + +// CheckStockEurAmount +// +// @Description: 德股新股申购【创建|更新】用戶资产 +// @receiver uo +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return bool +// @return error +func (uo *userOrderRepo) CheckStockEurAmount(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) (bool, error) { + var botUserStockEur []models.BotUserStockEur + if err := uo.data.mysqlDB.Table(flags.BotUserStockEur). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&botUserStockEur); err != nil { + applogger.Error("%v CheckStockEurAmount Find:%v", common.ErrSharePre, err) + return false, err + } + var usableNumOld, frozenNumOld decimal.Decimal + for _, value := range botUserStockEur { + usableNumOld = decimal.RequireFromString(value.UsableNum) + frozenNumOld = decimal.RequireFromString(value.FrozenNum) + } + + if len(botUserStockEur) == 0 { + userStock := orders.CreatBotUserStockEurPre(ctx, userId, stockId, usableNum, frozenNum) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockEur).Insert(&userStock) + if err != nil { + applogger.Error("%v CheckStockEurAmount Insert:%v", common.ErrSharePre, err) + return false, err + } + } else { + usableNumNew := usableNumOld.Add(decimal.RequireFromString(usableNum)) + frozenNumNew := frozenNumOld.Add(decimal.RequireFromString(frozenNum)) + userStock := orders.UpdateBotUserStockEurPre(ctx, usableNumNew.String(), frozenNumNew.String()) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockEur). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&userStock) + if err != nil { + applogger.Error("%v CheckStockEurAmount Update:%v", common.ErrSharePre, err) + return false, err + } + } + + return true, nil +} + +// UpdateShareEurTradeStockId +// +// @Description: 更新-德股新股申购股票stockId +// @receiver uo +// @param ctx +// @param code +// @param codeOld +// @return error +func (uo *userOrderRepo) UpdateShareEurTradeStockId(ctx context.Context, code, codeOld string) error { + // 同步写入股票列表缓存 + SubscribeEurHSetCodeList(code, false) + // 新增到新加坡股缓存列表 + if err := Reds.HSet(context.Background(), setting.MarketShareEur, code, code).Err(); err != nil { + applogger.Error("%v UpdateShareEurTradeStockId.HSet.MarketShareGbx:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateShareEurTradeStockId.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + // 1、更新订单股票代码 + var userStockTrade []models.BotStockEurTrade + if err = session.Table(flags.BotStockEurTrade).Where("stock_id =?", codeOld).Find(&userStockTrade); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockTrade { + value.StockId = code + // 1、更新订单信息 + inCheck, err := session.Table(flags.BotStockEurTrade).Where("trade_id =?", value.TradeId).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareEurTradeStockId BotStockGbxTrade err:%v", common.ErrSharePre, err) + continue + } + // 2、处理缓存订单 + orderMap, err := Reds.HGet(context.Background(), setting.AdminShareEurSubscribe, value.OrderId).Result() + if err != nil { + continue + } + var entrustJson share.ShareEurTallyCache + if err = json.Unmarshal([]byte(orderMap), &entrustJson); err != nil { + continue + } + var entrust *share.ShareEurTallyCache + entrust = &entrustJson + if entrust == nil { + continue + } + entrust.Symbol = code + entrust.Order.StockId = code + // 3、处理挂单|持仓|用户订阅|管理员订阅缓存数据 + switch value.Status { + case 0: // 挂单 + if err = share.ShareEurHashUserOrder(Reds, setting.MarketShareEurEntrust, entrust); err != nil { + continue + } + case 1: // 持仓 + if err = share.ShareEurHashUserOrder(Reds, setting.MarketShareEurPosition, entrust); err != nil { + continue + } + default: + continue + } + // 更新用户订阅缓存 + cacheKey := fmt.Sprintf("%v-%v", setting.ShareEurSubscribe, entrust.UserId) + if err = share.ShareEurHashUserOrder(Reds, cacheKey, entrust); err != nil { + continue + } + // 更新管理员订阅缓存 + if err = share.ShareEurHashUserOrder(Reds, setting.AdminShareEurSubscribe, entrust); err != nil { + continue + } + } + // 2、更新资产表股票代码 + var userStock []models.BotUserStockEur + if err = session.Table(flags.BotUserStockEur).Where("stock_id =?", codeOld).Find(&userStock); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStock { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockEur).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareEurTradeStockId BotUserStockGbx err:%v", common.ErrSharePre, err) + continue + } + } + // 3、更新资产表日志股票代码 + var userStockLog []models.BotUserStockEurLog + if err = session.Table(flags.BotUserStockEurLog).Where("stock_id =?", codeOld).Find(&userStockLog); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockLog { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockEurLog).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareEurTradeStockId BotUserStockGbxLog err:%v", common.ErrSharePre, err) + continue + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateShareEurTradeStockId.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + return nil +} diff --git a/internal/data/order_way_ipo_fur.go b/internal/data/order_way_ipo_fur.go new file mode 100644 index 0000000..84887fa --- /dev/null +++ b/internal/data/order_way_ipo_fur.go @@ -0,0 +1,376 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + orders "matchmaking-system/internal/data/convert" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + models "matchmaking-system/internal/pkg/model" + "matchmaking-system/internal/pkg/setting" + "strings" + "time" +) + +// GetBotUserFurPreStockOrder +// +// @Description: 法股新股申购列表查詢 +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserEurPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserFurPreStockOrder(ctx context.Context, id string) ([]models.BotUserFurPreStockOrder, error) { + var botSgd []models.BotUserFurPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserFurPreStockOrder). + Where("pre_stock_id = ?", id). + Where("status = 3"). + Find(&botSgd); err != nil { + applogger.Error("%v GetBotUserFurPreStockOrder Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botSgd, nil +} + +// GetBotUserFurPreStockOrderByOrderNo +// +// @Description: 法股新股申购列表查詢orderNo +// @receiver uo +// @param ctx +// @param code +// @return []models.BotUserFurPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserFurPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserFurPreStockOrder, error) { + var botGbx []models.BotUserFurPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserFurPreStockOrder). + In("order_no", code). + Where("trade_status = 0"). + Where("status = 3"). + Find(&botGbx); err != nil { + applogger.Error("%v GetBotUserFurPreStockOrderByOrderNo Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botGbx, nil +} + +// GetBotUserFurGiveStockOrders +// +// @Description: 法股赠股 +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserFurGiveStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserFurGiveStockOrders(ctx context.Context, id string) ([]models.BotUserFurGiveStockOrder, error) { + var botSgd []models.BotUserFurGiveStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserFurGiveStockOrder). + Where("order_no = ?", id). + Find(&botSgd); err != nil { + applogger.Error("%v GetBotUserFurGiveStockOrders Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botSgd, nil +} + +// GetBotStockFurList +// +// @Description: 法股票代码列表 +// @receiver uo +// @param ctx +// @return []models.BotStockFurList +// @return error +func (uo *userOrderRepo) GetBotStockFurList(ctx context.Context) ([]models.BotStockFurList, error) { + var data []models.BotStockFurList + if err := uo.data.mysqlDB.Table(flags.BotStockFurList).Find(&data); err != nil { + applogger.Error("%v GetBotStockFurList Find:%v", common.ErrSharePre, err) + return nil, err + } + // 清理股票缓存列表 + for _, value := range data { + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + Reds.HDel(context.Background(), setting.MarketShareFur, codeOld) + Reds.HDel(context.Background(), setting.MarketShareBlkFur, codeOld) + } + } + + return data, nil +} + +// CreateBotUserFurPreStockOrder +// +// @Description: 法股新股申购:开仓--持仓 +// @receiver uo +// @param ctx +// @param code +// @param order +// @return error +func (uo *userOrderRepo) CreateBotUserFurPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error { + // 同步写入股票列表缓存 + SubscribeFurHSetCodeList(code, false) + // 处理新股申购数据订单 + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v CreateBotUserFurPreStockOrder.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 强平阈值 + flatRatio := GetCacheForcedClosure(flags.StockFURSystemSetUpKey, code) + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), + } + // 获取开盘时间 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.FurMarket, time.Now()) + // 初始化订单缓存map + orderMap := make(map[string]share.ShareFurTallyCache) + for _, value := range order { + value.System = system + // 生成订单ID + var orderId string + orderId, err = uo.VerifyBotStockFurTradeOrderId(session) + if err != nil { + applogger.Error("%v CreateBotUserFurPreStockOrder.VerifyBotStockFurTradeOrderId:%v", common.ErrSharePre, err) + continue + } + // 查询账户是否存在,再存更新不存在新增 + var check bool + check, err = uo.CheckStockFurAmount(ctx, int64(value.UserId), value.StockId, value.OrderNumber, decimal.Zero.String()) + if err != nil || !check { + applogger.Error("%v CreateBotUserFurPreStockOrder.CheckStockFurAmount:%v", common.ErrSharePre, err) + continue + } + // 写入订单数据表 + trade := orders.BotStockFurTradePre(ctx, int64(value.UserId), orderId, value) + if err = uo.CreateBotStockFurTrade(session, trade); err != nil { + applogger.Error("%v CreateBotUserFurPreStockOrder.CreateBotStockFurTrade:%v", common.ErrSharePre, err) + continue + } + // 写入持仓缓存 + resultMsg := share.ShareFurTallyCache{ + UserId: int64(value.UserId), // 用户Id + OrderId: orderId, // 订单ID + Symbol: value.StockId, // 下单交易对 + OpenPrice: value.LimitPrice, // 开仓价格 + Status: flags.Position, // 订单状态 + Order: value, // 下单信息 + ClosingTime: closingTime, // 平仓时间 + } + orderMap[orderId] = resultMsg + } + + if err = session.Commit(); err != nil { + applogger.Error("%v CreateBotUserFurPreStockOrder.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 写入持仓缓存、用户订单订阅缓存、管理员订单订阅缓存 + for _, resultMsg := range orderMap { + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v CreateBotUserFurPreStockOrder.Marshal:%v", common.ErrSharePre, err) + continue + } + // 写入持仓缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareFurPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + // 写入用户订单订阅缓存 + orderIdKey := virtual.OrderIdListKey(setting.ShareFurSubscribe, resultMsg.UserId) + if err = share.ShareFurHashUserOrder(Reds, orderIdKey, &resultMsg); err != nil { + applogger.Error("%v CreateBotUserFurPreStockOrder.ShareFurHashUserOrder:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // 写入管理员订单订阅缓存 + if err = share.ShareFurHashUserOrder(Reds, setting.AdminShareFurSubscribe, &resultMsg); err != nil { + applogger.Error("%v CreateBotUserFurPreStockOrder.AdminShareFurSubscribe:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // TODO: 获取IPO未支付订单缓存,并更新缓存中的持仓订单ID + keyCache := fmt.Sprintf("%v%v", flags.StockIpoList, resultMsg.Order.OrderNo) + checkInt, err := Reds.Exists(ctx, keyCache).Result() + if err != nil { + continue + } + if checkInt > 0 { + if err = Reds.Set(ctx, keyCache, resultMsg.OrderId, 0).Err(); err != nil { + applogger.Error("CreateBotUserFurPreStockOrder.Set err:%v", err) + } + } + } + + return nil +} + +// CheckStockFurAmount +// +// @Description: 法股新股申购【创建|更新】用戶资产 +// @receiver uo +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return bool +// @return error +func (uo *userOrderRepo) CheckStockFurAmount(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) (bool, error) { + var botUserStockFur []models.BotUserStockFur + if err := uo.data.mysqlDB.Table(flags.BotUserStockFur). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&botUserStockFur); err != nil { + applogger.Error("%v CheckStockFurAmount Find:%v", common.ErrSharePre, err) + return false, err + } + var usableNumOld, frozenNumOld decimal.Decimal + for _, value := range botUserStockFur { + usableNumOld = decimal.RequireFromString(value.UsableNum) + frozenNumOld = decimal.RequireFromString(value.FrozenNum) + } + + if len(botUserStockFur) == 0 { + userStock := orders.CreatBotUserStockFurPre(ctx, userId, stockId, usableNum, frozenNum) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockFur).Insert(&userStock) + if err != nil { + applogger.Error("%v CheckStockFurAmount Insert:%v", common.ErrSharePre, err) + return false, err + } + } else { + usableNumNew := usableNumOld.Add(decimal.RequireFromString(usableNum)) + frozenNumNew := frozenNumOld.Add(decimal.RequireFromString(frozenNum)) + userStock := orders.UpdateBotUserStockFurPre(ctx, usableNumNew.String(), frozenNumNew.String()) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockFur). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&userStock) + if err != nil { + applogger.Error("%v CheckStockFurAmount Update:%v", common.ErrSharePre, err) + return false, err + } + } + + return true, nil +} + +// UpdateShareFurTradeStockId +// +// @Description: 更新-法股新股申购股票stockId +// @receiver uo +// @param ctx +// @param code +// @param codeOld +// @return error +func (uo *userOrderRepo) UpdateShareFurTradeStockId(ctx context.Context, code, codeOld string) error { + // 同步写入股票列表缓存 + SubscribeFurHSetCodeList(code, false) + // 新增到法股缓存列表 + if err := Reds.HSet(context.Background(), setting.MarketShareFur, code, code).Err(); err != nil { + applogger.Error("%v UpdateShareFurTradeStockId.HSet.MarketShareFur:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateShareFurTradeStockId.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + // 1、更新订单股票代码 + var userStockTrade []models.BotStockFurTrade + if err = session.Table(flags.BotStockFurTrade).Where("stock_id =?", codeOld).Find(&userStockTrade); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockTrade { + value.StockId = code + // 1、更新订单信息 + inCheck, err := session.Table(flags.BotStockFurTrade).Where("trade_id =?", value.TradeId).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareFurTradeStockId BotStockFurTrade err:%v", common.ErrSharePre, err) + continue + } + // 2、处理缓存订单 + orderMap, err := Reds.HGet(context.Background(), setting.AdminShareFurSubscribe, value.OrderId).Result() + if err != nil { + continue + } + var entrustJson share.ShareFurTallyCache + if err = json.Unmarshal([]byte(orderMap), &entrustJson); err != nil { + continue + } + var entrust *share.ShareFurTallyCache + entrust = &entrustJson + if entrust == nil { + continue + } + entrust.Symbol = code + entrust.Order.StockId = code + // 3、处理挂单|持仓|用户订阅|管理员订阅缓存数据 + switch value.Status { + case 0: // 挂单 + if err = share.ShareFurHashUserOrder(Reds, setting.MarketShareFurEntrust, entrust); err != nil { + continue + } + case 1: // 持仓 + if err = share.ShareFurHashUserOrder(Reds, setting.MarketShareFurPosition, entrust); err != nil { + continue + } + default: + continue + } + // 更新用户订阅缓存 + cacheKey := fmt.Sprintf("%v-%v", setting.ShareFurSubscribe, entrust.UserId) + if err = share.ShareFurHashUserOrder(Reds, cacheKey, entrust); err != nil { + continue + } + // 更新管理员订阅缓存 + if err = share.ShareFurHashUserOrder(Reds, setting.AdminShareFurSubscribe, entrust); err != nil { + continue + } + } + // 2、更新资产表股票代码 + var userStock []models.BotUserStockFur + if err = session.Table(flags.BotUserStockFur).Where("stock_id =?", codeOld).Find(&userStock); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStock { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockFur).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareFurTradeStockId BotUserStockFur err:%v", common.ErrSharePre, err) + continue + } + } + // 3、更新资产表日志股票代码 + var userStockLog []models.BotUserStockFurLog + if err = session.Table(flags.BotUserStockFurLog).Where("stock_id =?", codeOld).Find(&userStockLog); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockLog { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockFurLog).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareFurTradeStockId BotUserStockFurLog err:%v", common.ErrSharePre, err) + continue + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateShareFurTradeStockId.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + return nil +} diff --git a/internal/data/order_way_ipo_gbx.go b/internal/data/order_way_ipo_gbx.go new file mode 100644 index 0000000..e53d9fb --- /dev/null +++ b/internal/data/order_way_ipo_gbx.go @@ -0,0 +1,376 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + orders "matchmaking-system/internal/data/convert" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + models "matchmaking-system/internal/pkg/model" + "matchmaking-system/internal/pkg/setting" + "strings" + "time" +) + +// GetBotUserGbxPreStockOrder +// +// @Description: 英股新股申购列表查詢 +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserGbxPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserGbxPreStockOrder(ctx context.Context, id string) ([]models.BotUserGbxPreStockOrder, error) { + var botSgd []models.BotUserGbxPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserGbxPreStockOrder). + Where("pre_stock_id = ?", id). + Where("status = 3"). + Find(&botSgd); err != nil { + applogger.Error("%v GetBotUserGbxPreStockOrder Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botSgd, nil +} + +// GetBotUserGbxPreStockOrderByOrderNo +// +// @Description: 英股新股申购列表查詢orderNo +// @receiver uo +// @param ctx +// @param code +// @return []models.BotUserGbxPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserGbxPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserGbxPreStockOrder, error) { + var botGbx []models.BotUserGbxPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserGbxPreStockOrder). + In("order_no", code). + Where("trade_status = 0"). + Where("status = 3"). + Find(&botGbx); err != nil { + applogger.Error("%v GetBotUserGbxPreStockOrderByOrderNo Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botGbx, nil +} + +// GetBotUserGbxGiveStockOrders +// +// @Description: 英股赠股 +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserGbxGiveStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserGbxGiveStockOrders(ctx context.Context, id string) ([]models.BotUserGbxGiveStockOrder, error) { + var botSgd []models.BotUserGbxGiveStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserGbxGiveStockOrder). + Where("order_no = ?", id). + Find(&botSgd); err != nil { + applogger.Error("%v GetBotUserGbxGiveStockOrders Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botSgd, nil +} + +// GetBotStockGbxList +// +// @Description: 英股票代码列表 +// @receiver uo +// @param ctx +// @return []models.BotStockGbxList +// @return error +func (uo *userOrderRepo) GetBotStockGbxList(ctx context.Context) ([]models.BotStockGbxList, error) { + var data []models.BotStockGbxList + if err := uo.data.mysqlDB.Table(flags.BotStockGbxList).Find(&data); err != nil { + applogger.Error("%v GetBotStockGbxList Find:%v", common.ErrSharePre, err) + return nil, err + } + // 清理股票缓存列表 + for _, value := range data { + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + Reds.HDel(context.Background(), setting.MarketShareGbx, codeOld) + Reds.HDel(context.Background(), setting.MarketShareBlkGbx, codeOld) + } + } + + return data, nil +} + +// CreateBotUserGbxPreStockOrder +// +// @Description: 英股新股申购:开仓--持仓 +// @receiver uo +// @param ctx +// @param code +// @param order +// @return error +func (uo *userOrderRepo) CreateBotUserGbxPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error { + // 同步写入股票列表缓存 + SubscribeGbxHSetCodeList(code, false) + // 处理新股申购数据订单 + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v CreateBotUserGbxPreStockOrder.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 强平阈值 + flatRatio := GetCacheForcedClosure(flags.StockUkSystemSetUpKey, code) + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), + } + // 获取开盘时间 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.GbxMarket, time.Now()) + // 初始化订单缓存map + orderMap := make(map[string]share.ShareGbxTallyCache) + for _, value := range order { + value.System = system + // 生成订单ID + var orderId string + orderId, err = uo.VerifyBotStockGbxTradeOrderId(session) + if err != nil { + applogger.Error("%v CreateBotUserGbxPreStockOrder.VerifyBotStockGbxTradeOrderId:%v", common.ErrSharePre, err) + continue + } + // 查询账户是否存在,再存更新不存在新增 + var check bool + check, err = uo.CheckStockGbxAmount(ctx, int64(value.UserId), value.StockId, value.OrderNumber, decimal.Zero.String()) + if err != nil || !check { + applogger.Error("%v CreateBotUserGbxPreStockOrder.CheckStockGbxAmount:%v", common.ErrSharePre, err) + continue + } + // 写入订单数据表 + trade := orders.BotStockGbxTradePre(ctx, int64(value.UserId), orderId, value) + if err = uo.CreateBotStockGbxTrade(session, trade); err != nil { + applogger.Error("%v CreateBotUserGbxPreStockOrder.CreateBotStockGbxTrade:%v", common.ErrSharePre, err) + continue + } + // 写入持仓缓存 + resultMsg := share.ShareGbxTallyCache{ + UserId: int64(value.UserId), // 用户Id + OrderId: orderId, // 订单ID + Symbol: value.StockId, // 下单交易对 + OpenPrice: value.LimitPrice, // 开仓价格 + Status: flags.Position, // 订单状态 + Order: value, // 下单信息 + ClosingTime: closingTime, // 平仓时间 + } + orderMap[orderId] = resultMsg + } + + if err = session.Commit(); err != nil { + applogger.Error("%v CreateBotUserGbxPreStockOrder.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 写入持仓缓存、用户订单订阅缓存、管理员订单订阅缓存 + for _, resultMsg := range orderMap { + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v CreateBotUserGbxPreStockOrder.Marshal:%v", common.ErrSharePre, err) + continue + } + // 写入持仓缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareGbxPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + // 写入用户订单订阅缓存 + orderIdKey := virtual.OrderIdListKey(setting.ShareGbxSubscribe, resultMsg.UserId) + if err = share.ShareGbxHashUserOrder(Reds, orderIdKey, &resultMsg); err != nil { + applogger.Error("%v CreateBotUserGbxPreStockOrder.ShareGbxHashUserOrder:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // 写入管理员订单订阅缓存 + if err = share.ShareGbxHashUserOrder(Reds, setting.AdminShareGbxSubscribe, &resultMsg); err != nil { + applogger.Error("%v CreateBotUserGbxPreStockOrder.ShareGbxHashUserOrder:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // TODO: 获取IPO未支付订单缓存,并更新缓存中的持仓订单ID + keyCache := fmt.Sprintf("%v%v", flags.StockIpoList, resultMsg.Order.OrderNo) + checkInt, err := Reds.Exists(ctx, keyCache).Result() + if err != nil { + continue + } + if checkInt > 0 { + if err = Reds.Set(ctx, keyCache, resultMsg.OrderId, 0).Err(); err != nil { + applogger.Error("CreateBotUserGbxPreStockOrder.Set err:%v", err) + } + } + } + + return nil +} + +// CheckStockGbxAmount +// +// @Description: 英股新股申购【创建|更新】用戶资产 +// @receiver uo +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return bool +// @return error +func (uo *userOrderRepo) CheckStockGbxAmount(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) (bool, error) { + var botUserStockGbx []models.BotUserStockGbx + if err := uo.data.mysqlDB.Table(flags.BotUserStockGbx). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&botUserStockGbx); err != nil { + applogger.Error("%v CheckStockGbxAmount Find:%v", common.ErrSharePre, err) + return false, err + } + var usableNumOld, frozenNumOld decimal.Decimal + for _, value := range botUserStockGbx { + usableNumOld = decimal.RequireFromString(value.UsableNum) + frozenNumOld = decimal.RequireFromString(value.FrozenNum) + } + + if len(botUserStockGbx) == 0 { + userStock := orders.CreatBotUserStockGbxPre(ctx, userId, stockId, usableNum, frozenNum) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockGbx).Insert(&userStock) + if err != nil { + applogger.Error("%v CheckStockGbxAmount Insert:%v", common.ErrSharePre, err) + return false, err + } + } else { + usableNumNew := usableNumOld.Add(decimal.RequireFromString(usableNum)) + frozenNumNew := frozenNumOld.Add(decimal.RequireFromString(frozenNum)) + userStock := orders.UpdateBotUserStockGbxPre(ctx, usableNumNew.String(), frozenNumNew.String()) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockGbx). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&userStock) + if err != nil { + applogger.Error("%v CheckStockGbxAmount Update:%v", common.ErrSharePre, err) + return false, err + } + } + + return true, nil +} + +// UpdateShareGbxTradeStockId +// +// @Description: 更新-英股新股申购股票stockId +// @receiver uo +// @param ctx +// @param code +// @param codeOld +// @return error +func (uo *userOrderRepo) UpdateShareGbxTradeStockId(ctx context.Context, code, codeOld string) error { + // 同步写入股票列表缓存 + SubscribeGbxHSetCodeList(code, false) + // 新增到新加坡股缓存列表 + if err := Reds.HSet(context.Background(), setting.MarketShareGbx, code, code).Err(); err != nil { + applogger.Error("%v UpdateShareGbxTradeStockId.HSet.MarketShareGbx:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateShareGbxTradeStockId.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + // 1、更新订单股票代码 + var userStockTrade []models.BotStockGbxTrade + if err = session.Table(flags.BotStockGbxTrade).Where("stock_id =?", codeOld).Find(&userStockTrade); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockTrade { + value.StockId = code + // 1、更新订单信息 + inCheck, err := session.Table(flags.BotStockGbxTrade).Where("trade_id =?", value.TradeId).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareGbxTradeStockId BotStockGbxTrade err:%v", common.ErrSharePre, err) + continue + } + // 2、处理缓存订单 + orderMap, err := Reds.HGet(context.Background(), setting.AdminShareGbxSubscribe, value.OrderId).Result() + if err != nil { + continue + } + var entrustJson share.ShareGbxTallyCache + if err = json.Unmarshal([]byte(orderMap), &entrustJson); err != nil { + continue + } + var entrust *share.ShareGbxTallyCache + entrust = &entrustJson + if entrust == nil { + continue + } + entrust.Symbol = code + entrust.Order.StockId = code + // 3、处理挂单|持仓|用户订阅|管理员订阅缓存数据 + switch value.Status { + case 0: // 挂单 + if err = share.ShareGbxHashUserOrder(Reds, setting.MarketShareGbxEntrust, entrust); err != nil { + continue + } + case 1: // 持仓 + if err = share.ShareGbxHashUserOrder(Reds, setting.MarketShareGbxPosition, entrust); err != nil { + continue + } + default: + continue + } + // 更新用户订阅缓存 + cacheKey := fmt.Sprintf("%v-%v", setting.ShareGbxSubscribe, entrust.UserId) + if err = share.ShareGbxHashUserOrder(Reds, cacheKey, entrust); err != nil { + continue + } + // 更新管理员订阅缓存 + if err = share.ShareGbxHashUserOrder(Reds, setting.AdminShareGbxSubscribe, entrust); err != nil { + continue + } + } + // 2、更新资产表股票代码 + var userStock []models.BotUserStockGbx + if err = session.Table(flags.BotUserStockGbx).Where("stock_id =?", codeOld).Find(&userStock); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStock { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockGbx).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareGbxTradeStockId BotUserStockGbx err:%v", common.ErrSharePre, err) + continue + } + } + // 3、更新资产表日志股票代码 + var userStockLog []models.BotUserStockGbxLog + if err = session.Table(flags.BotUserStockGbxLog).Where("stock_id =?", codeOld).Find(&userStockLog); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockLog { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockGbxLog).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareGbxTradeStockId BotUserStockGbxLog err:%v", common.ErrSharePre, err) + continue + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateShareGbxTradeStockId.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + return nil +} diff --git a/internal/data/order_way_ipo_hkd.go b/internal/data/order_way_ipo_hkd.go new file mode 100644 index 0000000..c36b839 --- /dev/null +++ b/internal/data/order_way_ipo_hkd.go @@ -0,0 +1,378 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + orders "matchmaking-system/internal/data/convert" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + models "matchmaking-system/internal/pkg/model" + "matchmaking-system/internal/pkg/setting" + "strings" + "time" +) + +// GetBotUserHkdPreStockOrder +// +// @Description: 港股新股申购列表查詢 +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserHkdPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserHkdPreStockOrder(ctx context.Context, id string) ([]models.BotUserHkdPreStockOrder, error) { + var botSgd []models.BotUserHkdPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserHkdPreStockOrder). + Where("pre_stock_id = ?", id). + Where("status = 3"). + Find(&botSgd); err != nil { + applogger.Error("%v GetBotUserHkdPreStockOrder Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botSgd, nil +} + +// GetBotUserHkdPreStockOrderByOrderNo +// +// @Description: 港股新股申购列表查詢orderNo +// @receiver uo +// @param ctx +// @param code +// @return []models.BotUserHkdPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserHkdPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserHkdPreStockOrder, error) { + var botSgd []models.BotUserHkdPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserHkdPreStockOrder). + In("order_no", code). + Where("trade_status = 0"). + Where("status = 3"). + Find(&botSgd); err != nil { + applogger.Error("%v GetBotUserHkdPreStockOrder Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botSgd, nil +} + +// GetBotUserHkdGiveStockOrders +// +// @Description: +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserHkdGiveStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserHkdGiveStockOrders(ctx context.Context, id string) ([]models.BotUserHkdGiveStockOrder, error) { + var botSgd []models.BotUserHkdGiveStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserHkdGiveStockOrder). + Where("order_no = ?", id). + Find(&botSgd); err != nil { + applogger.Error("%v GetBotUserGivePreStockOrders Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botSgd, nil +} + +// GetBotStockHkdList +// +// @Description: 港股股票代码列表 +// @receiver uo +// @param ctx +// @return []models.BotStockHkdList +// @return error +func (uo *userOrderRepo) GetBotStockHkdList(ctx context.Context) ([]models.BotStockHkdList, error) { + var data []models.BotStockHkdList + if err := uo.data.mysqlDB.Table(flags.BotStockHkdList).Find(&data); err != nil { + applogger.Error("%v GetBotStockHkdList Find:%v", common.ErrSharePre, err) + return nil, err + } + // 清理股票缓存列表 + for _, value := range data { + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + Reds.HDel(context.Background(), setting.MarketShareHkd, codeOld) + Reds.HDel(context.Background(), setting.MarketShareBlkHkd, codeOld) + } + } + + return data, nil +} + +// CreateBotUserHkdPreStockOrder +// +// @Description: 港股新股申购:开仓--持仓 +// @receiver uo +// @param ctx +// @param code +// @param order +// @return error +func (uo *userOrderRepo) CreateBotUserHkdPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error { + // 同步写入股票列表缓存 + SubscribeHkdHSetCodeList(code, false) + // 处理新股申购数据订单 + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v CreatBotUserHkdPreStockOrder.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 强平阈值 + flatRatio := GetCacheForcedClosure(flags.StockHKDSystemSetUpKey, code) + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), + } + // 获取开盘时间 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.HkdMarket, time.Now()) + // 初始化订单缓存 + orderMap := make(map[string]share.ShareHkdTallyCache) + for _, value := range order { + value.System = system + // 生成订单ID + var orderId string + orderId, err = uo.VerifyBotStockHkdTradeOrderId(session) + if err != nil { + applogger.Error("%v CreatBotUserHkdPreStockOrder.VerifyBotStockHkdTradeOrderId:%v", common.ErrSharePre, err) + continue + } + // 查询账户是否存在,再存更新不存在新增 + var check bool + check, err = uo.CheckStockHkdAmount(ctx, int64(value.UserId), value.StockId, value.OrderNumber, decimal.Zero.String()) + if err != nil || !check { + applogger.Error("%v CreatBotUserHkdPreStockOrder.CheckStockSgdAmount:%v", common.ErrSharePre, err) + continue + } + // 写入订单数据表 + trade := orders.BotStockHkdTradePre(ctx, int64(value.UserId), orderId, value) + if err = uo.CreateBotStockHkdTrade(session, trade); err != nil { + applogger.Error("%v CreatBotUserHkdPreStockOrder.BotStockHkdTradePre:%v", common.ErrSharePre, err) + continue + } + // 写入持仓缓存 + resultMsg := share.ShareHkdTallyCache{ + UserId: int64(value.UserId), // 用户Id + OrderId: orderId, // 订单ID + Symbol: value.StockId, // 下单交易对 + OpenPrice: value.LimitPrice, // 开仓价格 + Status: flags.Position, // 订单状态 + Order: value, // 下单信息 + ClosingTime: closingTime, // 平仓时间 + } + orderMap[orderId] = resultMsg + } + + if err = session.Commit(); err != nil { + applogger.Error("%v CreatBotUserHkdPreStockOrder.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 写入持仓缓存、用户订单订阅缓存、管理员订单订阅缓存 + for _, resultMsg := range orderMap { + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v CreatBotUserHkdPreStockOrder.Marshal:%v", common.ErrSharePre, err) + continue + } + // 写入持仓缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareHkdPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + // 写入用户订单订阅缓存 + orderIdKey := virtual.OrderIdListKey(setting.ShareHkdSubscribe, resultMsg.UserId) + if err = share.ShareHkdHashUserOrder(Reds, orderIdKey, &resultMsg); err != nil { + applogger.Error("%v CreatBotUserHkdPreStockOrder.ShareHkdHashUserOrder:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // 写入管理员订单订阅缓存 + if err = share.ShareHkdHashUserOrder(Reds, setting.AdminShareHkdSubscribe, &resultMsg); err != nil { + applogger.Error("%v CreatBotUserHkdPreStockOrder.AdminShareHkdSubscribe:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // TODO: 获取IPO未支付订单缓存,并更新缓存中的持仓订单ID + keyCache := fmt.Sprintf("%v%v", flags.StockIpoList, resultMsg.Order.OrderNo) + checkInt, err := Reds.Exists(ctx, keyCache).Result() + if err != nil { + continue + } + if checkInt > 0 { + if err = Reds.Set(ctx, keyCache, resultMsg.OrderId, 0).Err(); err != nil { + applogger.Error("CreatBotUserHkdPreStockOrder.Set err:%v", err) + } + } + } + + return nil +} + +// CheckStockHkdAmount +// +// @Description: 港股新股申购【创建|更新】用戶资产 +// @receiver uo +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return bool +// @return error +func (uo *userOrderRepo) CheckStockHkdAmount(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) (bool, error) { + var botUserStockHkd []models.BotUserStockHkd + if err := uo.data.mysqlDB.Table(flags.BotUserStockHkd). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&botUserStockHkd); err != nil { + applogger.Error("%v CheckStockHkdAmount Find:%v", common.ErrSharePre, err) + return false, err + } + var usableNumOld, frozenNumOld decimal.Decimal + for _, value := range botUserStockHkd { + usableNumOld = decimal.RequireFromString(value.UsableNum) + frozenNumOld = decimal.RequireFromString(value.FrozenNum) + } + + if len(botUserStockHkd) == 0 { + // 创建账户 + userStock := orders.CreatBotUserStockHkdPre(ctx, userId, stockId, usableNum, frozenNum) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockHkd).Insert(&userStock) + if err != nil { + applogger.Error("%v CheckStockHkdAmount Insert:%v", common.ErrSharePre, err) + return false, err + } + } else { + // 更新账户 + usableNumNew := usableNumOld.Add(decimal.RequireFromString(usableNum)) + frozenNumNew := frozenNumOld.Add(decimal.RequireFromString(frozenNum)) + userStock := orders.UpdateBotUserStockHkdPre(ctx, usableNumNew.String(), frozenNumNew.String()) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockHkd). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&userStock) + if err != nil { + applogger.Error("%v CheckStockHkdAmount Update:%v", common.ErrSharePre, err) + return false, err + } + } + + return true, nil +} + +// UpdateShareHkdTradeStockId +// +// @Description: 更新-港股新股申购股票stockId +// @receiver uo +// @param ctx +// @param code +// @param codeOld +// @param stock +// @return error +func (uo *userOrderRepo) UpdateShareHkdTradeStockId(ctx context.Context, code, codeOld string) error { + // 同步写入股票列表缓存 + SubscribeHkdHSetCodeList(code, false) + // 新增到港股缓存列表 + if err := Reds.HSet(context.Background(), setting.MarketShareHkd, code, code).Err(); err != nil { + applogger.Error("%v UpdateShareHkdTradeStockId.HSet.MarketShareBlkHkd:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateShareHkdTradeStockId.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + // 1、更新订单股票代码 + var userStockTrade []models.BotStockHkdTrade + if err = session.Table(flags.BotStockHkdTrade).Where("stock_id =?", codeOld).Find(&userStockTrade); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockTrade { + value.StockId = code + // 1、更新订单信息 + inCheck, err := session.Table(flags.BotStockHkdTrade).Where("trade_id =?", value.TradeId).Update(&value) + if err != nil || inCheck <= 0 { + continue + } + // 2、处理缓存订单 + orderMap, err := Reds.HGet(context.Background(), setting.AdminShareHkdSubscribe, value.OrderId).Result() + if err != nil { + continue + } + var entrustJson share.ShareHkdTallyCache + if err = json.Unmarshal([]byte(orderMap), &entrustJson); err != nil { + continue + } + var entrust *share.ShareHkdTallyCache + entrust = &entrustJson + if entrust == nil { + continue + } + entrust.Symbol = code + entrust.Order.StockId = code + // 3、处理挂单|持仓|用户订阅|管理员订阅缓存数据 + switch value.Status { + case 0: // 挂单 + if err = share.ShareHkdHashUserOrder(Reds, setting.MarketShareHkdEntrust, entrust); err != nil { + continue + } + case 1: // 持仓 + if err = share.ShareHkdHashUserOrder(Reds, setting.MarketShareHkdPosition, entrust); err != nil { + continue + } + default: + continue + } + // 更新用户订阅缓存 + cacheKey := fmt.Sprintf("%v-%v", setting.ShareHkdSubscribe, entrust.UserId) + if err = share.ShareHkdHashUserOrder(Reds, cacheKey, entrust); err != nil { + continue + } + // 更新管理员订阅缓存 + if err = share.ShareHkdHashUserOrder(Reds, setting.AdminShareHkdSubscribe, entrust); err != nil { + continue + } + } + // 2、更新资产表股票代码 + var userStock []models.BotUserStockHkd + if err = session.Table(flags.BotUserStockHkd).Where("stock_id =?", codeOld).Find(&userStock); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStock { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockHkd).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareHkdTradeStockId BotUserStockHkd err:%v", common.ErrSharePre, err) + continue + } + } + // 3、更新资产表日志股票代码 + var userStockLog []models.BotUserStockHkdLog + if err = session.Table(flags.BotUserStockHkdLog).Where("stock_id =?", codeOld).Find(&userStockLog); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockLog { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockHkdLog).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareHkdTradeStockId BotUserStockHkdLog err:%v", common.ErrSharePre, err) + continue + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateShareHkdTradeStockId.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + return nil +} diff --git a/internal/data/order_way_ipo_idn.go b/internal/data/order_way_ipo_idn.go new file mode 100644 index 0000000..8d7d525 --- /dev/null +++ b/internal/data/order_way_ipo_idn.go @@ -0,0 +1,377 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + orders "matchmaking-system/internal/data/convert" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + models "matchmaking-system/internal/pkg/model" + "matchmaking-system/internal/pkg/setting" + "strings" + "time" +) + +// GetBotUserIdnPreStockOrder +// +// @Description: 印尼股新股申购列表查询 +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserIdnPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserIdnPreStockOrder(ctx context.Context, id string) ([]models.BotUserIdnPreStockOrder, error) { + var botIdn []models.BotUserIdnPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserIdnPreStockOrder). + Where("pre_stock_id = ?", id). + Where("status = 3"). + Find(&botIdn); err != nil { + applogger.Error("%v GetBotUserIdnPreStockOrder Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botIdn, nil +} + +// GetBotUserIdnPreStockOrderByOrderNo +// +// @Description: 印尼股新股申购列表查询orderNo +// @receiver uo +// @param ctx +// @param code +// @return []models.BotUserIdnPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserIdnPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserIdnPreStockOrder, error) { + var botIdn []models.BotUserIdnPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserIdnPreStockOrder). + In("order_no", code). + Where("trade_status = 0"). + Where("status = 3"). + Find(&botIdn); err != nil { + applogger.Error("%v GetBotUserIdnPreStockOrder Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botIdn, nil +} + +// GetBotUserIdnGiveStockOrders +// +// @Description: 印尼股赠送 +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserIdnGiveStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserIdnGiveStockOrders(ctx context.Context, id string) ([]models.BotUserIdnGiveStockOrder, error) { + var botIdn []models.BotUserIdnGiveStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserIdnGiveStockOrder).Where("order_no = ?", id).Find(&botIdn); err != nil { + applogger.Error("%v GetBotUserIdnGiveStockOrders Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botIdn, nil +} + +// GetBotStockIdnList +// +// @Description: 印尼股股票代码列表 +// @receiver uo +// @param ctx +// @return []models.BotStockIdnList +// @return error +func (uo *userOrderRepo) GetBotStockIdnList(ctx context.Context) ([]models.BotStockIdnList, error) { + var data []models.BotStockIdnList + if err := uo.data.mysqlDB.Table(flags.BotStockIdnList).Find(&data); err != nil { + applogger.Error("%v GetBotStockIdnList Find:%v", common.ErrSharePre, err) + return nil, err + } + // 清理股票缓存列表 + for _, value := range data { + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + Reds.HDel(context.Background(), setting.MarketShareIdn, codeOld) + Reds.HDel(context.Background(), setting.MarketShareBlkIdn, codeOld) + } + } + + return data, nil +} + +// CreateBotUserIdnPreStockOrder +// +// @Description: 印尼股新股申购:开仓--持仓 +// @receiver uo +// @param ctx +// @param code +// @param order +// @return error +func (uo *userOrderRepo) CreateBotUserIdnPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error { + // 同步写入股票列表缓存 + SubscribeIdnHSetCodeList(code, false) + // 处理新股申购数据订单 + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v CreatBotUserIdnPreStockOrder.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 强平阈值 + flatRatio := GetCacheForcedClosure(flags.StockYNSystemSetUpKey, code) + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), + } + // 获取开盘时间 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.IdnMarket, time.Now()) + // 初始化订单缓存map + orderMap := make(map[string]share.ShareIdnTallyCache) + for _, value := range order { + value.System = system + // 生成订单ID + var orderId string + orderId, err = uo.VerifyBotStockIdnTradeOrderId(session) + if err != nil { + applogger.Error("%v CreatBotUserIdnPreStockOrder.VerifyBotStockIdnTradeOrderId:%v", common.ErrSharePre, err) + continue + } + // 查询账户是否存在,再存更新不存在新增 + var check bool + check, err = uo.CheckStockIdnAmount(ctx, int64(value.UserId), value.StockId, value.OrderNumber, decimal.Zero.String()) + if err != nil || !check { + applogger.Error("%v CreatBotUserIdnPreStockOrder.CheckStockIdnAmount:%v", common.ErrSharePre, err) + continue + } + // 写入订单数据表 + trade := orders.BotStockIdnTradePre(ctx, int64(value.UserId), orderId, value) + if err = uo.CreateBotStockIdnTrade(session, trade); err != nil { + applogger.Error("%v CreatBotUserIdnPreStockOrder.CreateBotStockIdnTrade:%v", common.ErrSharePre, err) + continue + } + // 写入持仓缓存 + resultMsg := share.ShareIdnTallyCache{ + UserId: int64(value.UserId), // 用户Id + OrderId: orderId, // 订单ID + Symbol: value.StockId, // 下单交易对 + OpenPrice: value.LimitPrice, // 开仓价格 + Status: flags.Position, // 订单状态 + Order: value, // 下单信息 + ClosingTime: closingTime, // 平仓时间 + } + orderMap[orderId] = resultMsg + } + + if err = session.Commit(); err != nil { + applogger.Error("%v CreatBotUserIdnPreStockOrder.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 写入持仓缓存、用户订单订阅缓存、管理员订单订阅缓存 + for _, resultMsg := range orderMap { + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v CreatBotUserIdnPreStockOrder.Marshal:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // 写入持仓缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareIdnPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + applogger.Error("%v CreatBotUserIdnPreStockOrder.HSet:%v", err) + return flags.ErrCacheDB + } + // 写入用户订单订阅缓存 + orderIdKey := virtual.OrderIdListKey(setting.ShareIdnSubscribe, resultMsg.UserId) + if err = share.ShareIdnHashUserOrder(Reds, orderIdKey, &resultMsg); err != nil { + applogger.Error("%v CreatBotUserIdnPreStockOrder.ShareIdnSubscribe:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // 写入管理员订单订阅缓存 + if err = share.ShareIdnHashUserOrder(Reds, setting.AdminShareIdnSubscribe, &resultMsg); err != nil { + applogger.Error("%v CreatBotUserIdnPreStockOrder.AdminShareIdnSubscribe:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // TODO: 获取IPO未支付订单缓存,并更新缓存中的持仓订单ID + keyCache := fmt.Sprintf("%v%v", flags.StockIpoList, resultMsg.Order.OrderNo) + checkInt, err := Reds.Exists(ctx, keyCache).Result() + if err != nil { + continue + } + if checkInt > 0 { + if err = Reds.Set(ctx, keyCache, resultMsg.OrderId, 0).Err(); err != nil { + applogger.Error("CreatBotUserIdnPreStockOrder.Set err:%v", err) + } + } + } + + return nil +} + +// CheckStockIdnAmount +// +// @Description: 印尼股新股申购【创建|更新】用戶资产 +// @receiver uo +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return bool +// @return error +func (uo *userOrderRepo) CheckStockIdnAmount(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) (bool, error) { + var botUserStockIdn []models.BotUserStockIdn + if err := uo.data.mysqlDB.Table(flags.BotUserStockIdn). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&botUserStockIdn); err != nil { + applogger.Error("%v CheckStockIdnAmount Find:%v", common.ErrSharePre, err) + return false, err + } + var usableNumOld, frozenNumOld decimal.Decimal + for _, value := range botUserStockIdn { + usableNumOld = decimal.RequireFromString(value.UsableNum) + frozenNumOld = decimal.RequireFromString(value.FrozenNum) + } + + if len(botUserStockIdn) == 0 { + // 创建账户 + userStock := orders.CreatBotUserStockIdnPre(ctx, userId, stockId, usableNum, frozenNum) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockIdn).Insert(&userStock) + if err != nil { + applogger.Error("%v CheckStockIdnAmount Insert:%v", common.ErrSharePre, err) + return false, err + } + } else { + // 更新账户 + usableNumNew := usableNumOld.Add(decimal.RequireFromString(usableNum)) + frozenNumNew := frozenNumOld.Add(decimal.RequireFromString(frozenNum)) + userStock := orders.UpdateBotUserStockIdnPre(ctx, usableNumNew.String(), frozenNumNew.String()) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockIdn). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&userStock) + if err != nil { + applogger.Error("%v CheckStockIdnAmount Update:%v", common.ErrSharePre, err) + return false, err + } + } + + return true, nil +} + +// UpdateShareIdnTradeStockId +// +// @Description: 更新-印尼股新股申购股票stockId +// @receiver uo +// @param ctx +// @param code +// @param codeOld +// @param stock +// @return error +func (uo *userOrderRepo) UpdateShareIdnTradeStockId(ctx context.Context, code, codeOld string) error { + // 同步写入股票列表缓存 + SubscribeIdnHSetCodeList(code, false) + // 新增到印尼缓存列表 + if err := Reds.HSet(context.Background(), setting.MarketShareIdn, code, code).Err(); err != nil { + applogger.Error("%v UpdateShareIdnTradeStockId.HSet.MarketShareIdn:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateShareIdnTradeStockId.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + // 1、更新订单股票代码 + var userStockTrade []models.BotStockIdnTrade + if err = session.Table(flags.BotStockIdnTrade).Where("stock_id =?", codeOld).Find(&userStockTrade); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockTrade { + value.StockId = code + // 1、更新订单信息 + inCheck, err := session.Table(flags.BotStockIdnTrade).Where("trade_id =?", value.TradeId).Update(&value) + if err != nil || inCheck <= 0 { + continue + } + // 2、处理缓存订单 + orderMap, err := Reds.HGet(context.Background(), setting.AdminShareIdnSubscribe, value.OrderId).Result() + if err != nil { + continue + } + var entrustJson share.ShareIdnTallyCache + if err = json.Unmarshal([]byte(orderMap), &entrustJson); err != nil { + continue + } + var entrust *share.ShareIdnTallyCache + entrust = &entrustJson + if entrust == nil { + continue + } + entrust.Symbol = code + entrust.Order.StockId = code + // 3、处理挂单|持仓|用户订阅|管理员订阅缓存数据 + switch value.Status { + case 0: // 挂单 + if err = share.ShareIdnHashUserOrder(Reds, setting.MarketShareIdnEntrust, entrust); err != nil { + continue + } + case 1: // 持仓 + if err = share.ShareIdnHashUserOrder(Reds, setting.MarketShareIdnPosition, entrust); err != nil { + continue + } + default: + continue + } + // 更新用户订阅缓存 + cacheKey := fmt.Sprintf("%v-%v", setting.ShareIdnSubscribe, entrust.UserId) + if err = share.ShareIdnHashUserOrder(Reds, cacheKey, entrust); err != nil { + continue + } + // 更新管理员订阅缓存 + if err = share.ShareIdnHashUserOrder(Reds, setting.AdminShareIdnSubscribe, entrust); err != nil { + continue + } + } + // 2、更新资产表股票代码 + var userStock []models.BotUserStockIdn + if err = session.Table(flags.BotUserStockIdn).Where("stock_id =?", codeOld).Find(&userStock); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStock { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockIdn).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareIdnTradeStockId BotUserStockIdn err:%v", common.ErrSharePre, err) + continue + } + } + // 3、更新资产表日志股票代码 + var userStockLog []models.BotUserStockIdnLog + if err = session.Table(flags.BotUserStockIdnLog).Where("stock_id =?", codeOld).Find(&userStockLog); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockLog { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockIdnLog).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareIdnTradeStockId BotUserStockIdnLog err:%v", common.ErrSharePre, err) + continue + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateShareIdnTradeStockId.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + return nil +} diff --git a/internal/data/order_way_ipo_inr.go b/internal/data/order_way_ipo_inr.go new file mode 100644 index 0000000..0c50a0d --- /dev/null +++ b/internal/data/order_way_ipo_inr.go @@ -0,0 +1,378 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + orders "matchmaking-system/internal/data/convert" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + models "matchmaking-system/internal/pkg/model" + "matchmaking-system/internal/pkg/setting" + "strings" + "time" +) + +// GetBotUserInPreStockOrder +// +// @Description: 印度股新股申购列表查詢 +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserInPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserInPreStockOrder(ctx context.Context, id string) ([]models.BotUserInPreStockOrder, error) { + var botTha []models.BotUserInPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserInPreStockOrder). + Where("pre_stock_id = ?", id). + Where("status = 3"). + Find(&botTha); err != nil { + applogger.Error("%v GetBotUserInPreStockOrder Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botTha, nil +} + +// GetBotUserInPreStockOrderByOrderNo +// +// @Description: 印度股新股申购列表查詢orderNo +// @receiver uo +// @param ctx +// @param code +// @return []models.BotUserInPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserInPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserInPreStockOrder, error) { + var botTha []models.BotUserInPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserInPreStockOrder). + In("order_no", code). + Where("trade_status = 0"). + Where("status = 3"). + Find(&botTha); err != nil { + applogger.Error("%v GetBotUserInPreStockOrder Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botTha, nil +} + +// GetBotUserInGiveStockOrders +// +// @Description: 印度股赠股 +// @receiver uo +// @param ctx +// @param +func (uo *userOrderRepo) GetBotUserInGiveStockOrders(ctx context.Context, id string) ([]models.BotUserInGiveStockOrder, error) { + var botTha []models.BotUserInGiveStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserInGiveStockOrder). + Where("order_no = ?", id). + Find(&botTha); err != nil { + applogger.Error("%v GetBotUserInGiveStockOrders Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botTha, nil +} + +// GetBotStockInList +// +// @Description: 印度股股票代码列表 +// @receiver uo +// @param ctx +// @return []models.BotStockInList +// @return error +func (uo *userOrderRepo) GetBotStockInList(ctx context.Context) ([]models.BotStockInList, error) { + var data []models.BotStockInList + if err := uo.data.mysqlDB.Table(flags.BotStockInList).Find(&data); err != nil { + applogger.Error("%v GetBotStockInList Find:%v", common.ErrSharePre, err) + return nil, err + } + // 清理股票缓存列表 + for _, value := range data { + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + Reds.HDel(context.Background(), setting.MarketShareInr, codeOld) + Reds.HDel(context.Background(), setting.MarketShareBlkInr, codeOld) + } + } + + return data, nil +} + +// CreateBotUserInPreStockOrder +// +// @Description: 印度股新股申购:开仓--持仓 +// @receiver uo +// @param ctx +// @param code +// @param order +// @return error +func (uo *userOrderRepo) CreateBotUserInPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error { + // 同步写入股票列表缓存 + SubscribeInrHSetCodeList(code, false) + // 处理新股申购数据订单 + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v CreatBotUserInPreStockOrder.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 强平阈值 + flatRatio := GetCacheForcedClosure(flags.StockYDSystemSetUpKey, code) + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), + } + // 获取开盘时间 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.InrMarket, time.Now()) + // 初始化订单缓存map + orderMap := make(map[string]share.ShareInrTallyCache) + for _, value := range order { + value.System = system + // 生成订单ID + var orderId string + orderId, err = uo.VerifyBotStockInTradeOrderId(session) + if err != nil { + applogger.Error("%v CreatBotUserInPreStockOrder.VerifyBotStockThaTradeOrderId:%v", common.ErrSharePre, err) + continue + } + // 查询账户是否存在,再存更新不存在新增 + var check bool + check, err = uo.CheckStockInAmount(ctx, int64(value.UserId), value.StockId, value.OrderNumber, decimal.Zero.String()) + if err != nil || !check { + applogger.Error("%v CreatBotUserInPreStockOrder.CheckStockThaAmount:%v", common.ErrSharePre, err) + continue + } + // 写入订单数据表 + trade := orders.BotStockInTradePre(ctx, int64(value.UserId), orderId, value) + if err = uo.CreateBotStockInTrade(session, trade); err != nil { + applogger.Error("%v CreatBotUserInPreStockOrder.CreateBotStockThaTrade:%v", common.ErrSharePre, err) + continue + } + // 写入持仓缓存 + resultMsg := share.ShareInrTallyCache{ + UserId: int64(value.UserId), // 用户Id + OrderId: orderId, // 订单ID + Symbol: value.StockId, // 下单交易对 + OpenPrice: value.LimitPrice, // 开仓价格 + Status: flags.Position, // 订单状态 + Order: value, // 下单信息 + ClosingTime: closingTime, // 平仓时间 + } + orderMap[orderId] = resultMsg + } + + if err = session.Commit(); err != nil { + applogger.Error("%v CreatBotUserInPreStockOrder.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 写入持仓缓存、用户订单订阅缓存、管理员订单订阅缓存 + for _, resultMsg := range orderMap { + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v CreatBotUserInPreStockOrder.Marshal:%v", common.ErrSharePre, err) + continue + } + // 写入持仓缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareInrPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + // 写入用户订单订阅缓存 + orderIdKey := virtual.OrderIdListKey(setting.ShareInrSubscribe, resultMsg.UserId) + if err = share.ShareInrHashUserOrder(Reds, orderIdKey, &resultMsg); err != nil { + applogger.Error("%v CreatBotUserInPreStockOrder.ShareThaSubscribe:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // 写入管理员订单订阅缓存 + if err = share.ShareInrHashUserOrder(Reds, setting.AdminShareInrSubscribe, &resultMsg); err != nil { + applogger.Error("%v CreatBotUserInPreStockOrder.AdminShareThaSubscribe:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // TODO: 获取IPO未支付订单缓存,并更新缓存中的持仓订单ID + keyCache := fmt.Sprintf("%v%v", flags.StockIpoList, resultMsg.Order.OrderNo) + checkInt, err := Reds.Exists(ctx, keyCache).Result() + if err != nil { + applogger.Error("CreatBotUserInPreStockOrder.Exists err:%v", err) + continue + } + if checkInt > 0 { + applogger.Debug("用户ID:%v,Ipo未支付OrderNo:%v,订单号:%v", resultMsg.UserId, resultMsg.Order.OrderNo, resultMsg.OrderId) + if err = Reds.Set(ctx, keyCache, resultMsg.OrderId, 0).Err(); err != nil { + applogger.Error("CreatBotUserInPreStockOrder.Set err:%v", err) + } + } + } + + return nil +} + +// CheckStockInAmount +// +// @Description: 印度股新股申购【创建|更新】用戶资产 +// @receiver uo +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return bool +// @return error +func (uo *userOrderRepo) CheckStockInAmount(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) (bool, error) { + var botUserStockIn []models.BotUserStockIn + if err := uo.data.mysqlDB.Table(flags.BotUserStockIn). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&botUserStockIn); err != nil { + applogger.Error("%v CheckStockInAmount Find:%v", common.ErrSharePre, err) + return false, err + } + var usableNumOld, frozenNumOld decimal.Decimal + for _, value := range botUserStockIn { + usableNumOld = decimal.RequireFromString(value.UsableNum) + frozenNumOld = decimal.RequireFromString(value.FrozenNum) + } + + if len(botUserStockIn) == 0 { + // 创建账户 + userStock := orders.CreatBotUserStockInPre(ctx, userId, stockId, usableNum, frozenNum) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockIn).Insert(&userStock) + if err != nil { + applogger.Error("%v CheckStockInAmount Insert:%v", common.ErrSharePre, err) + return false, err + } + } else { + // 更新账户 + usableNumNew := usableNumOld.Add(decimal.RequireFromString(usableNum)) + frozenNumNew := frozenNumOld.Add(decimal.RequireFromString(frozenNum)) + userStock := orders.UpdateBotUserStockInPre(ctx, usableNumNew.String(), frozenNumNew.String()) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockIn). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&userStock) + if err != nil { + applogger.Error("%v CheckStockInAmount Update:%v", common.ErrSharePre, err) + return false, err + } + } + + return true, nil +} + +// UpdateShareInTradeStockId +// +// @Description: 更新-印度股新股申购股票stockId +// @receiver uo +// @param ctx +// @param code +// @param codeOld +// @param stock +// @return error +func (uo *userOrderRepo) UpdateShareInTradeStockId(ctx context.Context, code, codeOld string) error { + // 同步写入股票列表缓存 + SubscribeInrHSetCodeList(code, false) + // 新增到印度股缓存列表 + if err := Reds.HSet(context.Background(), setting.MarketShareInr, code, code).Err(); err != nil { + applogger.Error("%v UpdateShareInTradeStockId.HSet.MarketShareInr:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateShareInTradeStockId.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + // 1、更新订单股票代码 + var userStockTrade []models.BotStockInTrade + if err = session.Table(flags.BotStockInTrade).Where("stock_id =?", codeOld).Find(&userStockTrade); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockTrade { + value.StockId = code + // 1、更新订单信息 + inCheck, err := session.Table(flags.BotStockInTrade).Where("trade_id =?", value.TradeId).Update(&value) + if err != nil || inCheck <= 0 { + continue + } + // 2、处理缓存订单 + orderMap, err := Reds.HGet(context.Background(), setting.AdminShareInrSubscribe, value.OrderId).Result() + if err != nil { + continue + } + var entrustJson share.ShareInrTallyCache + if err = json.Unmarshal([]byte(orderMap), &entrustJson); err != nil { + continue + } + var entrust *share.ShareInrTallyCache + entrust = &entrustJson + if entrust == nil { + continue + } + entrust.Symbol = code + entrust.Order.StockId = code + // 3、处理挂单|持仓|用户订阅|管理员订阅缓存数据 + switch value.Status { + case 0: // 挂单 + if err = share.ShareInrHashUserOrder(Reds, setting.MarketShareInrEntrust, entrust); err != nil { + continue + } + case 1: // 持仓 + if err = share.ShareInrHashUserOrder(Reds, setting.MarketShareInrPosition, entrust); err != nil { + continue + } + default: + continue + } + // 更新用户订阅缓存 + cacheKey := fmt.Sprintf("%v-%v", setting.ShareInrSubscribe, entrust.UserId) + if err = share.ShareInrHashUserOrder(Reds, cacheKey, entrust); err != nil { + continue + } + // 更新管理员订阅缓存 + if err = share.ShareInrHashUserOrder(Reds, setting.AdminShareInrSubscribe, entrust); err != nil { + continue + } + } + // 2、更新资产表股票代码 + var userStock []models.BotUserStockIn + if err = session.Table(flags.BotUserStockIn).Where("stock_id =?", codeOld).Find(&userStock); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStock { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockIn).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareInTradeStockId BotUserStockIn err:%v", common.ErrSharePre, err) + continue + } + } + // 3、更新资产表日志股票代码 + var userStockLog []models.BotUserStockInLog + if err = session.Table(flags.BotUserStockInLog).Where("stock_id =?", codeOld).Find(&userStockLog); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockLog { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockInLog).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareInTradeStockId BotUserStockInLog err:%v", common.ErrSharePre, err) + continue + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateShareInTradeStockId.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + return nil +} diff --git a/internal/data/order_way_ipo_jpy.go b/internal/data/order_way_ipo_jpy.go new file mode 100644 index 0000000..4781a54 --- /dev/null +++ b/internal/data/order_way_ipo_jpy.go @@ -0,0 +1,376 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + orders "matchmaking-system/internal/data/convert" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + models "matchmaking-system/internal/pkg/model" + "matchmaking-system/internal/pkg/setting" + "strings" + "time" +) + +// GetBotUserJpyPreStockOrder +// +// @Description: 日股新股申购列表查詢 +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserEurPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserJpyPreStockOrder(ctx context.Context, id string) ([]models.BotUserJpPreStockOrder, error) { + var botSgd []models.BotUserJpPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserJpyPreStockOrder). + Where("pre_stock_id = ?", id). + Where("status = 3"). + Find(&botSgd); err != nil { + applogger.Error("%v GetBotUserJpyPreStockOrder Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botSgd, nil +} + +// GetBotUserJpyPreStockOrderByOrderNo +// +// @Description: 日股新股申购列表查詢orderNo +// @receiver uo +// @param ctx +// @param code +// @return []models.BotUserJpyPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserJpyPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserJpPreStockOrder, error) { + var botGbx []models.BotUserJpPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserJpyPreStockOrder). + In("order_no", code). + Where("trade_status = 0"). + Where("status = 3"). + Find(&botGbx); err != nil { + applogger.Error("%v GetBotUserJpyPreStockOrderByOrderNo Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botGbx, nil +} + +// GetBotUserJpyGiveStockOrders +// +// @Description: 日股赠股 +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserJpyGiveStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserJpyGiveStockOrders(ctx context.Context, id string) ([]models.BotUserJpGiveStockOrder, error) { + var botSgd []models.BotUserJpGiveStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserJpyGiveStockOrder). + Where("order_no = ?", id). + Find(&botSgd); err != nil { + applogger.Error("%v GetBotUserJpyGiveStockOrders Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botSgd, nil +} + +// GetBotStockJpyList +// +// @Description: 日股票代码列表 +// @receiver uo +// @param ctx +// @return []models.BotStockJpyList +// @return error +func (uo *userOrderRepo) GetBotStockJpyList(ctx context.Context) ([]models.BotStockJpList, error) { + var data []models.BotStockJpList + if err := uo.data.mysqlDB.Table(flags.BotStockJpyList).Find(&data); err != nil { + applogger.Error("%v GetBotStockJpyList Find:%v", common.ErrSharePre, err) + return nil, err + } + // 清理股票缓存列表 + for _, value := range data { + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + Reds.HDel(context.Background(), setting.MarketShareJpy, codeOld) + Reds.HDel(context.Background(), setting.MarketShareBlkJpy, codeOld) + } + } + + return data, nil +} + +// CreateBotUserJpyPreStockOrder +// +// @Description: 日股新股申购:开仓--持仓 +// @receiver uo +// @param ctx +// @param code +// @param order +// @return error +func (uo *userOrderRepo) CreateBotUserJpyPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error { + // 同步写入股票列表缓存 + SubscribeJpyHSetCodeList(code, false) + // 处理新股申购数据订单 + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v CreateBotUserJpyPreStockOrder.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 强平阈值 + flatRatio := GetCacheForcedClosure(flags.StockFURSystemSetUpKey, code) + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), + } + // 获取开盘时间 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.JpyMarket, time.Now()) + // 初始化订单缓存map + orderMap := make(map[string]share.ShareJpyTallyCache) + for _, value := range order { + value.System = system + // 生成订单ID + var orderId string + orderId, err = uo.VerifyBotStockJpyTradeOrderId(session) + if err != nil { + applogger.Error("%v CreateBotUserJpyPreStockOrder.VerifyBotStockJpyTradeOrderId:%v", common.ErrSharePre, err) + continue + } + // 查询账户是否存在,再存更新不存在新增 + var check bool + check, err = uo.CheckStockJpyAmount(ctx, int64(value.UserId), value.StockId, value.OrderNumber, decimal.Zero.String()) + if err != nil || !check { + applogger.Error("%v CreateBotUserJpyPreStockOrder.CheckStockJpyAmount:%v", common.ErrSharePre, err) + continue + } + // 写入订单数据表 + trade := orders.BotStockJpyTradePre(ctx, int64(value.UserId), orderId, value) + if err = uo.CreateBotStockJpyTrade(session, trade); err != nil { + applogger.Error("%v CreateBotUserJpyPreStockOrder.CreateBotStockJpyTrade:%v", common.ErrSharePre, err) + continue + } + // 写入持仓缓存 + resultMsg := share.ShareJpyTallyCache{ + UserId: int64(value.UserId), // 用户Id + OrderId: orderId, // 订单ID + Symbol: value.StockId, // 下单交易对 + OpenPrice: value.LimitPrice, // 开仓价格 + Status: flags.Position, // 订单状态 + Order: value, // 下单信息 + ClosingTime: closingTime, // 平仓时间 + } + orderMap[orderId] = resultMsg + } + + if err = session.Commit(); err != nil { + applogger.Error("%v CreateBotUserJpyPreStockOrder.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 写入持仓缓存、用户订单订阅缓存、管理员订单订阅缓存 + for _, resultMsg := range orderMap { + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v CreateBotUserJpyPreStockOrder.Marshal:%v", common.ErrSharePre, err) + continue + } + // 写入持仓缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareJpyPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + // 写入用户订单订阅缓存 + orderIdKey := virtual.OrderIdListKey(setting.ShareJpySubscribe, resultMsg.UserId) + if err = share.ShareJpyHashUserOrder(Reds, orderIdKey, &resultMsg); err != nil { + applogger.Error("%v CreateBotUserJpyPreStockOrder.ShareJpyHashUserOrder:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // 写入管理员订单订阅缓存 + if err = share.ShareJpyHashUserOrder(Reds, setting.AdminShareJpySubscribe, &resultMsg); err != nil { + applogger.Error("%v CreateBotUserJpyPreStockOrder.AdminShareJpySubscribe:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // TODO: 获取IPO未支付订单缓存,并更新缓存中的持仓订单ID + keyCache := fmt.Sprintf("%v%v", flags.StockIpoList, resultMsg.Order.OrderNo) + checkInt, err := Reds.Exists(ctx, keyCache).Result() + if err != nil { + continue + } + if checkInt > 0 { + if err = Reds.Set(ctx, keyCache, resultMsg.OrderId, 0).Err(); err != nil { + applogger.Error("CreateBotUserJpyPreStockOrder.Set err:%v", err) + } + } + } + + return nil +} + +// CheckStockJpyAmount +// +// @Description: 日股新股申购【创建|更新】用戶资产 +// @receiver uo +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return bool +// @return error +func (uo *userOrderRepo) CheckStockJpyAmount(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) (bool, error) { + var botUserStockJpy []models.BotUserStockJp + if err := uo.data.mysqlDB.Table(flags.BotUserStockJpy). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&botUserStockJpy); err != nil { + applogger.Error("%v CheckStockJpyAmount Find:%v", common.ErrSharePre, err) + return false, err + } + var usableNumOld, frozenNumOld decimal.Decimal + for _, value := range botUserStockJpy { + usableNumOld = decimal.RequireFromString(value.UsableNum) + frozenNumOld = decimal.RequireFromString(value.FrozenNum) + } + + if len(botUserStockJpy) == 0 { + userStock := orders.CreatBotUserStockJpyPre(ctx, userId, stockId, usableNum, frozenNum) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockJpy).Insert(&userStock) + if err != nil { + applogger.Error("%v CheckStockJpyAmount Insert:%v", common.ErrSharePre, err) + return false, err + } + } else { + usableNumNew := usableNumOld.Add(decimal.RequireFromString(usableNum)) + frozenNumNew := frozenNumOld.Add(decimal.RequireFromString(frozenNum)) + userStock := orders.UpdateBotUserStockJpyPre(ctx, usableNumNew.String(), frozenNumNew.String()) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockJpy). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&userStock) + if err != nil { + applogger.Error("%v CheckStockJpyAmount Update:%v", common.ErrSharePre, err) + return false, err + } + } + + return true, nil +} + +// UpdateShareJpyTradeStockId +// +// @Description: 更新-日股新股申购股票stockId +// @receiver uo +// @param ctx +// @param code +// @param codeOld +// @return error +func (uo *userOrderRepo) UpdateShareJpyTradeStockId(ctx context.Context, code, codeOld string) error { + // 同步写入股票列表缓存 + SubscribeJpyHSetCodeList(code, false) + // 新增到日股缓存列表 + if err := Reds.HSet(context.Background(), setting.MarketShareJpy, code, code).Err(); err != nil { + applogger.Error("%v UpdateShareJpyTradeStockId.HSet.MarketShareJpy:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateShareJpyTradeStockId.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + // 1、更新订单股票代码 + var userStockTrade []models.BotStockJpTrade + if err = session.Table(flags.BotStockJpyTrade).Where("stock_id =?", codeOld).Find(&userStockTrade); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockTrade { + value.StockId = code + // 1、更新订单信息 + inCheck, err := session.Table(flags.BotStockJpyTrade).Where("trade_id =?", value.TradeId).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareJpyTradeStockId BotStockJpyTrade err:%v", common.ErrSharePre, err) + continue + } + // 2、处理缓存订单 + orderMap, err := Reds.HGet(context.Background(), setting.AdminShareJpySubscribe, value.OrderId).Result() + if err != nil { + continue + } + var entrustJson share.ShareJpyTallyCache + if err = json.Unmarshal([]byte(orderMap), &entrustJson); err != nil { + continue + } + var entrust *share.ShareJpyTallyCache + entrust = &entrustJson + if entrust == nil { + continue + } + entrust.Symbol = code + entrust.Order.StockId = code + // 3、处理挂单|持仓|用户订阅|管理员订阅缓存数据 + switch value.Status { + case 0: // 挂单 + if err = share.ShareJpyHashUserOrder(Reds, setting.MarketShareJpyEntrust, entrust); err != nil { + continue + } + case 1: // 持仓 + if err = share.ShareJpyHashUserOrder(Reds, setting.MarketShareJpyPosition, entrust); err != nil { + continue + } + default: + continue + } + // 更新用户订阅缓存 + cacheKey := fmt.Sprintf("%v-%v", setting.ShareJpySubscribe, entrust.UserId) + if err = share.ShareJpyHashUserOrder(Reds, cacheKey, entrust); err != nil { + continue + } + // 更新管理员订阅缓存 + if err = share.ShareJpyHashUserOrder(Reds, setting.AdminShareJpySubscribe, entrust); err != nil { + continue + } + } + // 2、更新资产表股票代码 + var userStock []models.BotUserStockJp + if err = session.Table(flags.BotUserStockJpy).Where("stock_id =?", codeOld).Find(&userStock); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStock { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockJpy).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareJpyTradeStockId BotUserStockJpy err:%v", common.ErrSharePre, err) + continue + } + } + // 3、更新资产表日志股票代码 + var userStockLog []models.BotUserStockJpLog + if err = session.Table(flags.BotUserStockJpyLog).Where("stock_id =?", codeOld).Find(&userStockLog); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockLog { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockJpyLog).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareJpyTradeStockId BotUserStockJpyLog err:%v", common.ErrSharePre, err) + continue + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateShareJpyTradeStockId.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + return nil +} diff --git a/internal/data/order_way_ipo_mys.go b/internal/data/order_way_ipo_mys.go new file mode 100644 index 0000000..8bcbc93 --- /dev/null +++ b/internal/data/order_way_ipo_mys.go @@ -0,0 +1,378 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + orders "matchmaking-system/internal/data/convert" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + models "matchmaking-system/internal/pkg/model" + "matchmaking-system/internal/pkg/setting" + "strings" + "time" +) + +// GetBotUserMysPreStockOrder +// +// @Description: 马股新股申购列表查询 +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserMysPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserMysPreStockOrder(ctx context.Context, id string) ([]models.BotUserMysPreStockOrder, error) { + var botMys []models.BotUserMysPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserMysPreStockOrder). + Where("pre_stock_id = ?", id). + Where("status = 3"). + Find(&botMys); err != nil { + applogger.Error("%v GetBotUserMysPreStockOrder Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botMys, nil +} + +// GetBotUserMysPreStockOrderByOrderNo +// +// @Description: 马股新股申购列表查询orderNo +// @receiver uo +// @param ctx +// @param code +// @return []models.BotUserMysPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserMysPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserMysPreStockOrder, error) { + var botMys []models.BotUserMysPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserMysPreStockOrder). + In("order_no", code). + Where("trade_status = 0"). + Where("status = 3"). + Find(&botMys); err != nil { + applogger.Error("%v GetBotUserMysPreStockOrder Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botMys, nil +} + +// GetBotUserMysGiveStockOrders +// +// @Description: 马股赠送股票 +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserMysGiveStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserMysGiveStockOrders(ctx context.Context, id string) ([]models.BotUserMysGiveStockOrder, error) { + var botMys []models.BotUserMysGiveStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserMysGiveStockOrder). + Where("order_no = ?", id). + Find(&botMys); err != nil { + applogger.Error("%v GetBotUserMysGiveStockOrders Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botMys, nil +} + +// GetBotStockMysList +// +// @Description: 马股股票代码列表 +// @receiver uo +// @param ctx +// @return []models.BotStockMysList +// @return error +func (uo *userOrderRepo) GetBotStockMysList(ctx context.Context) ([]models.BotStockMysList, error) { + var data []models.BotStockMysList + if err := uo.data.mysqlDB.Table(flags.BotStockMysList).Find(&data); err != nil { + applogger.Error("%v GetBotStockMysList Find:%v", common.ErrSharePre, err) + return nil, err + } + // 清理股票缓存列表 + for _, value := range data { + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + Reds.HDel(context.Background(), setting.MarketShareMys, codeOld) + Reds.HDel(context.Background(), setting.MarketShareBlkMys, codeOld) + } + } + + return data, nil +} + +// CreateBotUserMysPreStockOrder +// +// @Description: 马股新股申购:开仓--持仓 +// @receiver uo +// @param ctx +// @param code +// @param order +// @return error +func (uo *userOrderRepo) CreateBotUserMysPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error { + // 同步写入股票列表缓存 + SubscribeMysHSetCodeList(code, false) + // 处理新股申购数据订单 + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v CreatBotUserMysPreStockOrder.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 强平阈值 + flatRatio := GetCacheForcedClosure(flags.StockMGSystemSetUpKey, code) + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), + } + // 获取开盘时间 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.MysMarket, time.Now()) + // 初始化订单缓存 + orderMap := make(map[string]share.ShareMysTallyCache) + for _, value := range order { + value.System = system + // 生成订单ID + var orderId string + orderId, err = uo.VerifyBotStockMysTradeOrderId(session) + if err != nil { + applogger.Error("%v CreatBotUserMysPreStockOrder.VerifyBotStockMysTradeOrderId:%v", common.ErrSharePre, err) + continue + } + // 查询账户是否存在,再存更新不存在新增 + var check bool + check, err = uo.CheckStockMysAmount(ctx, int64(value.UserId), value.StockId, value.OrderNumber, decimal.Zero.String()) + if err != nil || !check { + applogger.Error("%v CreatBotUserMysPreStockOrder.CheckStockMysAmount:%v", common.ErrSharePre, err) + continue + } + // 写入订单数据表 + trade := orders.BotStockMysTradePre(ctx, int64(value.UserId), orderId, value) + if err = uo.CreateBotStockMysTrade(session, trade); err != nil { + applogger.Error("%v CreatBotUserMysPreStockOrder.CreateBotStockMysTrade:%v", common.ErrSharePre, err) + continue + } + // 写入持仓缓存 + resultMsg := share.ShareMysTallyCache{ + UserId: int64(value.UserId), // 用户Id + OrderId: orderId, // 订单ID + Symbol: value.StockId, // 下单交易对 + OpenPrice: value.LimitPrice, // 开仓价格 + Status: flags.Position, // 订单状态 + Order: value, // 下单信息 + ClosingTime: closingTime, // 平仓时间 + } + orderMap[orderId] = resultMsg + } + + if err = session.Commit(); err != nil { + applogger.Error("%v CreatBotUserMysPreStockOrder.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 写入持仓缓存、用户订单订阅缓存、管理员订单订阅缓存 + for _, resultMsg := range orderMap { + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v CreatBotUserMysPreStockOrder.Marshal:%v", common.ErrSharePre, err) + continue + } + // 写入持仓订单缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareMysPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + // 写入用户订单订阅缓存 + orderIdKey := virtual.OrderIdListKey(setting.ShareMysSubscribe, resultMsg.UserId) + if err = share.ShareMysHashUserOrder(Reds, orderIdKey, &resultMsg); err != nil { + applogger.Error("%v CreatBotUserMysPreStockOrder.ShareMysSubscribe:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // 写入管理员订单订阅缓存 + if err = share.ShareMysHashUserOrder(Reds, setting.AdminShareMysSubscribe, &resultMsg); err != nil { + applogger.Error("%v CreatBotUserMysPreStockOrder.AdminShareMysSubscribe:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // TODO: 获取IPO未支付订单缓存,并更新缓存中的持仓订单ID + keyCache := fmt.Sprintf("%v%v", flags.StockIpoList, resultMsg.Order.OrderNo) + checkInt, err := Reds.Exists(ctx, keyCache).Result() + if err != nil { + continue + } + if checkInt > 0 { + if err = Reds.Set(ctx, keyCache, resultMsg.OrderId, 0).Err(); err != nil { + applogger.Error("CreatBotUserMysPreStockOrder.Set err:%v", err) + } + } + } + + return nil +} + +// CheckStockMysAmount +// +// @Description: 马股新股申购【创建|更新】用戶资产 +// @receiver uo +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return bool +// @return error +func (uo *userOrderRepo) CheckStockMysAmount(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) (bool, error) { + var botUserStockMys []models.BotUserStockMys + if err := uo.data.mysqlDB.Table(flags.BotUserStockMys). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&botUserStockMys); err != nil { + applogger.Error("%v CheckStockMysAmount Find:%v", common.ErrSharePre, err) + return false, err + } + var usableNumOld, frozenNumOld decimal.Decimal + for _, value := range botUserStockMys { + usableNumOld = decimal.RequireFromString(value.UsableNum) + frozenNumOld = decimal.RequireFromString(value.FrozenNum) + } + + if len(botUserStockMys) == 0 { + // 创建账户 + userStock := orders.CreatBotUserStockMysPre(ctx, userId, stockId, usableNum, frozenNum) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockMys).Insert(&userStock) + if err != nil { + applogger.Error("%v CheckStockMysAmount Insert:%v", common.ErrSharePre, err) + return false, err + } + } else { + // 更新账户 + usableNumNew := usableNumOld.Add(decimal.RequireFromString(usableNum)) + frozenNumNew := frozenNumOld.Add(decimal.RequireFromString(frozenNum)) + userStock := orders.UpdateBotUserStockMysPre(ctx, usableNumNew.String(), frozenNumNew.String()) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockMys). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&userStock) + if err != nil { + applogger.Error("%v CheckStockMysAmount Update:%v", common.ErrSharePre, err) + return false, err + } + } + + return true, nil +} + +// UpdateShareMysTradeStockId +// +// @Description: 更新-马股新股申购股票stockId +// @receiver uo +// @param ctx +// @param code +// @param codeOld +// @param stock +// @return error +func (uo *userOrderRepo) UpdateShareMysTradeStockId(ctx context.Context, code, codeOld string) error { + // 同步写入股票列表缓存 + SubscribeMysHSetCodeList(code, false) + // 新增到马股缓存列表 + if err := Reds.HSet(context.Background(), setting.MarketShareMys, code, code).Err(); err != nil { + applogger.Error("%v UpdateShareMysTradeStockId.HSet.MarketShareMys:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateShareMysTradeStockId.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + // 1、更新订单股票代码 + var userStockTrade []models.BotStockMysTrade + if err = session.Table(flags.BotStockMysTrade).Where("stock_id =?", codeOld).Find(&userStockTrade); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockTrade { + value.StockId = code + // 1、更新订单信息 + inCheck, err := session.Table(flags.BotStockMysTrade).Where("trade_id =?", value.TradeId).Update(&value) + if err != nil || inCheck <= 0 { + continue + } + // 2、处理缓存订单 + orderMap, err := Reds.HGet(context.Background(), setting.AdminShareMysSubscribe, value.OrderId).Result() + if err != nil { + continue + } + var entrustJson share.ShareMysTallyCache + if err = json.Unmarshal([]byte(orderMap), &entrustJson); err != nil { + continue + } + var entrust *share.ShareMysTallyCache + entrust = &entrustJson + if entrust == nil { + continue + } + entrust.Symbol = code + entrust.Order.StockId = code + // 3、处理挂单|持仓|用户订阅|管理员订阅缓存数据 + switch value.Status { + case 0: // 挂单 + if err = share.ShareMysHashUserOrder(Reds, setting.MarketShareMysEntrust, entrust); err != nil { + continue + } + case 1: // 持仓 + if err = share.ShareMysHashUserOrder(Reds, setting.MarketShareMysPosition, entrust); err != nil { + continue + } + default: + continue + } + // 更新用户订阅缓存 + cacheKey := fmt.Sprintf("%v-%v", setting.ShareMysSubscribe, entrust.UserId) + if err = share.ShareMysHashUserOrder(Reds, cacheKey, entrust); err != nil { + continue + } + // 更新管理员订阅缓存 + if err = share.ShareMysHashUserOrder(Reds, setting.AdminShareMysSubscribe, entrust); err != nil { + continue + } + } + // 2、更新资产表股票代码 + var userStock []models.BotUserStockMys + if err = session.Table(flags.BotUserStockMys).Where("stock_id =?", codeOld).Find(&userStock); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStock { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockMys).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareMysTradeStockId BotUserStockMys err:%v", common.ErrSharePre, err) + continue + } + } + // 3、更新资产表日志股票代码 + var userStockLog []models.BotUserStockMysLog + if err = session.Table(flags.BotUserStockMysLog).Where("stock_id =?", codeOld).Find(&userStockLog); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockLog { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockMysLog).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareMysTradeStockId BotUserStockMysLog err:%v", common.ErrSharePre, err) + continue + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateShareMysTradeStockId.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + return nil +} diff --git a/internal/data/order_way_ipo_sgd.go b/internal/data/order_way_ipo_sgd.go new file mode 100644 index 0000000..407e690 --- /dev/null +++ b/internal/data/order_way_ipo_sgd.go @@ -0,0 +1,379 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + orders "matchmaking-system/internal/data/convert" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + models "matchmaking-system/internal/pkg/model" + "matchmaking-system/internal/pkg/setting" + "strings" + "time" +) + +// GetBotUserSgdPreStockOrder +// +// @Description: 新加坡股新股申购列表查詢 +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserSgdPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserSgdPreStockOrder(ctx context.Context, id string) ([]models.BotUserSgdPreStockOrder, error) { + var botSgd []models.BotUserSgdPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserSgdPreStockOrder). + Where("pre_stock_id = ?", id). + Where("status = 3"). + Find(&botSgd); err != nil { + applogger.Error("%v GetBotUserSgdPreStockOrder Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botSgd, nil +} + +// GetBotUserSgdPreStockOrderByOrderNo +// +// @Description: 新加坡股新股申购列表查詢orderNo +// @receiver uo +// @param ctx +// @param code +// @return []models.BotUserSgdPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserSgdPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserSgdPreStockOrder, error) { + var botSgd []models.BotUserSgdPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserSgdPreStockOrder). + In("order_no", code). + Where("trade_status = 0"). + Where("status = 3"). + Find(&botSgd); err != nil { + applogger.Error("%v GetBotUserSgdPreStockOrder Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botSgd, nil +} + +// GetBotUserSgdGiveStockOrders +// +// @Description: 新加坡赠股 +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserSgdGiveStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserSgdGiveStockOrders(ctx context.Context, id string) ([]models.BotUserSgdGiveStockOrder, error) { + var botSgd []models.BotUserSgdGiveStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserSgdGiveStockOrder). + Where("order_no = ?", id). + Find(&botSgd); err != nil { + applogger.Error("%v GetBotUserSgdGiveStockOrders Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botSgd, nil +} + +// GetBotStockSgdList +// +// @Description: 新加坡股股票代码列表 +// @receiver uo +// @param ctx +// @return []models.BotStockInList +// @return error +func (uo *userOrderRepo) GetBotStockSgdList(ctx context.Context) ([]models.BotStockSgdList, error) { + var data []models.BotStockSgdList + if err := uo.data.mysqlDB.Table(flags.BotStockSgdList).Find(&data); err != nil { + applogger.Error("%v GetBotStockSgdList Find:%v", common.ErrSharePre, err) + return nil, err + } + // 清理股票缓存列表 + for _, value := range data { + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + Reds.HDel(context.Background(), setting.MarketShareSgd, codeOld) + Reds.HDel(context.Background(), setting.MarketShareBlkSgd, codeOld) + } + } + + return data, nil +} + +// CreateBotUserSgdPreStockOrder +// +// @Description: 新加坡股新股申购:开仓--持仓 +// @receiver uo +// @param ctx +// @param code +// @param order +// @return error +func (uo *userOrderRepo) CreateBotUserSgdPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error { + // 同步写入股票列表缓存 + SubscribeSgdHSetCodeList(code, false) + // 处理新股申购数据订单 + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v CreatBotUserSgdPreStockOrder.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 强平阈值 + flatRatio := GetCacheForcedClosure(flags.StockSGDSystemSetUpKey, code) + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), + } + // 获取开盘时间 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.SgdMarket, time.Now()) + // 初始化订单缓存map + orderMap := make(map[string]share.ShareSgdTallyCache) + for _, value := range order { + value.System = system + // 生成订单ID + var orderId string + orderId, err = uo.VerifyBotStockSgdTradeOrderId(session) + if err != nil { + applogger.Error("%v CreatBotUserSgdPreStockOrder.VerifyBotStockSgdTradeOrderId:%v", common.ErrSharePre, err) + continue + } + // 查询账户是否存在,再存更新不存在新增 + var check bool + check, err = uo.CheckStockSgdAmount(ctx, int64(value.UserId), value.StockId, value.OrderNumber, decimal.Zero.String()) + if err != nil || !check { + applogger.Error("%v CreatBotUserSgdPreStockOrder.CheckStockSgdAmount:%v", common.ErrSharePre, err) + continue + } + // 写入订单数据表 + trade := orders.BotStockSgdTradePre(ctx, int64(value.UserId), orderId, value) + if err = uo.CreateBotStockSgdTrade(session, trade); err != nil { + applogger.Error("%v CreatBotUserSgdPreStockOrder.CreateBotStockSgdTrade:%v", common.ErrSharePre, err) + continue + } + // 写入持仓缓存 + resultMsg := share.ShareSgdTallyCache{ + UserId: int64(value.UserId), // 用户Id + OrderId: orderId, // 订单ID + Symbol: value.StockId, // 下单交易对 + OpenPrice: value.LimitPrice, // 开仓价格 + Status: flags.Position, // 订单状态 + Order: value, // 下单信息 + ClosingTime: closingTime, // 平仓时间 + } + orderMap[orderId] = resultMsg + } + + if err = session.Commit(); err != nil { + applogger.Error("%v CreatBotUserSgdPreStockOrder.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 写入持仓缓存、用户订单订阅缓存、管理员订单订阅缓存 + for _, resultMsg := range orderMap { + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v CreatBotUserSgdPreStockOrder.Marshal:%v", common.ErrSharePre, err) + continue + } + // 写入持仓缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareSgdPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + // 写入用户订单订阅缓存 + orderIdKey := virtual.OrderIdListKey(setting.ShareSgdSubscribe, resultMsg.UserId) + if err = share.ShareSgdHashUserOrder(Reds, orderIdKey, &resultMsg); err != nil { + applogger.Error("%v CreatBotUserSgdPreStockOrder.ShareSgdHashUserOrder:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // 写入管理员订单订阅缓存 + if err = share.ShareSgdHashUserOrder(Reds, setting.AdminShareSgdSubscribe, &resultMsg); err != nil { + applogger.Error("%v CreatBotUserSgdPreStockOrder.AdminShareSgdSubscribe:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // TODO: 获取IPO未支付订单缓存,并更新缓存中的持仓订单ID + keyCache := fmt.Sprintf("%v%v", flags.StockIpoList, resultMsg.Order.OrderNo) + checkInt, err := Reds.Exists(ctx, keyCache).Result() + if err != nil { + continue + } + if checkInt > 0 { + if err = Reds.Set(ctx, keyCache, resultMsg.OrderId, 0).Err(); err != nil { + applogger.Error("CreatBotUserSgdPreStockOrder.Set err:%v", err) + } + } + } + + return nil +} + +// CheckStockSgdAmount +// +// @Description: 新加坡股新股申购【创建|更新】用戶资产 +// @receiver uo +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return bool +// @return error +func (uo *userOrderRepo) CheckStockSgdAmount(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) (bool, error) { + var botUserStockSgd []models.BotUserStockSgd + if err := uo.data.mysqlDB.Table(flags.BotUserStockSgd). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&botUserStockSgd); err != nil { + applogger.Error("%v CheckStockSgdAmount Find:%v", common.ErrSharePre, err) + return false, err + } + var usableNumOld, frozenNumOld decimal.Decimal + for _, value := range botUserStockSgd { + usableNumOld = decimal.RequireFromString(value.UsableNum) + frozenNumOld = decimal.RequireFromString(value.FrozenNum) + } + + if len(botUserStockSgd) == 0 { + // 创建账户 + userStock := orders.CreatBotUserStockSgdPre(ctx, userId, stockId, usableNum, frozenNum) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockSgd).Insert(&userStock) + if err != nil { + applogger.Error("%v CheckStockSgdAmount Insert:%v", common.ErrSharePre, err) + return false, err + } + } else { + // 更新账户 + usableNumNew := usableNumOld.Add(decimal.RequireFromString(usableNum)) + frozenNumNew := frozenNumOld.Add(decimal.RequireFromString(frozenNum)) + userStock := orders.UpdateBotUserStockSgdPre(ctx, usableNumNew.String(), frozenNumNew.String()) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockSgd). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&userStock) + if err != nil { + applogger.Error("%v CheckStockSgdAmount Update:%v", common.ErrSharePre, err) + return false, err + } + } + + return true, nil +} + +// UpdateShareSgdTradeStockId +// +// @Description: 更新-新加坡股新股申购股票stockId +// @receiver uo +// @param ctx +// @param code +// @param codeOld +// @param stock +// @return error +func (uo *userOrderRepo) UpdateShareSgdTradeStockId(ctx context.Context, code, codeOld string) error { + // 同步写入股票列表缓存 + SubscribeSgdHSetCodeList(code, false) + // 新增到新加坡股缓存列表 + if err := Reds.HSet(context.Background(), setting.MarketShareSgd, code, code).Err(); err != nil { + applogger.Error("%v UpdateShareSgdTradeStockId.HSet.MarketShareSgd:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateShareSgdTradeStockId.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + // 1、更新订单股票代码 + var userStockTrade []models.BotStockSgdTrade + if err = session.Table(flags.BotStockSgdTrade).Where("stock_id =?", codeOld).Find(&userStockTrade); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockTrade { + value.StockId = code + // 1、更新订单信息 + inCheck, err := session.Table(flags.BotStockSgdTrade).Where("trade_id =?", value.TradeId).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareSgdTradeStockId BotStockSgdTrade err:%v", common.ErrSharePre, err) + continue + } + // 2、处理缓存订单 + orderMap, err := Reds.HGet(context.Background(), setting.AdminShareSgdSubscribe, value.OrderId).Result() + if err != nil { + continue + } + var entrustJson share.ShareSgdTallyCache + if err = json.Unmarshal([]byte(orderMap), &entrustJson); err != nil { + continue + } + var entrust *share.ShareSgdTallyCache + entrust = &entrustJson + if entrust == nil { + continue + } + entrust.Symbol = code + entrust.Order.StockId = code + // 3、处理挂单|持仓|用户订阅|管理员订阅缓存数据 + switch value.Status { + case 0: // 挂单 + if err = share.ShareSgdHashUserOrder(Reds, setting.MarketShareSgdEntrust, entrust); err != nil { + continue + } + case 1: // 持仓 + if err = share.ShareSgdHashUserOrder(Reds, setting.MarketShareSgdPosition, entrust); err != nil { + continue + } + default: + continue + } + // 更新用户订阅缓存 + cacheKey := fmt.Sprintf("%v-%v", setting.ShareSgdSubscribe, entrust.UserId) + if err = share.ShareSgdHashUserOrder(Reds, cacheKey, entrust); err != nil { + continue + } + // 更新管理员订阅缓存 + if err = share.ShareSgdHashUserOrder(Reds, setting.AdminShareSgdSubscribe, entrust); err != nil { + continue + } + } + // 2、更新资产表股票代码 + var userStock []models.BotUserStockSgd + if err = session.Table(flags.BotUserStockSgd).Where("stock_id =?", codeOld).Find(&userStock); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStock { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockSgd).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareSgdTradeStockId BotUserStockSgd err:%v", common.ErrSharePre, err) + continue + } + } + // 3、更新资产表日志股票代码 + var userStockLog []models.BotUserStockSgdLog + if err = session.Table(flags.BotUserStockSgdLog).Where("stock_id =?", codeOld).Find(&userStockLog); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockLog { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockSgdLog).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareSgdTradeStockId BotUserStockSgdLog err:%v", common.ErrSharePre, err) + continue + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateShareSgdTradeStockId.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + return nil +} diff --git a/internal/data/order_way_ipo_tha.go b/internal/data/order_way_ipo_tha.go new file mode 100644 index 0000000..2be4d48 --- /dev/null +++ b/internal/data/order_way_ipo_tha.go @@ -0,0 +1,375 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + orders "matchmaking-system/internal/data/convert" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + models "matchmaking-system/internal/pkg/model" + "matchmaking-system/internal/pkg/setting" + "strings" + "time" +) + +// GetBotUserThaPreStockOrder +// +// @Description: 泰股新股申购列表查詢 +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserThaPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserThaPreStockOrder(ctx context.Context, id string) ([]models.BotUserThaPreStockOrder, error) { + var botTha []models.BotUserThaPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserThaPreStockOrder). + Where("pre_stock_id = ?", id). + Where("status = 3"). + Find(&botTha); err != nil { + applogger.Error("%v GetBotUserThaPreStockOrder Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botTha, nil +} + +// GetBotUserThaPreStockOrderByOrderNo +// +// @Description: 泰股新股申购列表查詢OrderNo +// @receiver uo +// @param ctx +// @param code +// @return []models.BotUserThaPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserThaPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserThaPreStockOrder, error) { + var botTha []models.BotUserThaPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserThaPreStockOrder). + In("order_no", code). + Where("trade_status = 0"). + Where("status = 3"). + Find(&botTha); err != nil { + applogger.Error("%v GetBotUserThaPreStockOrder Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botTha, nil +} + +// GetBotUserThaGiveStockOrders +// +// @Description: 泰股赠股票 +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserThaGiveStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserThaGiveStockOrders(ctx context.Context, id string) ([]models.BotUserThaGiveStockOrder, error) { + var botTha []models.BotUserThaGiveStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserThaGiveStockOrder). + Where("order_no = ?", id). + Find(&botTha); err != nil { + applogger.Error("%v GetBotUserThaGiveStockOrders Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botTha, nil +} + +// GetBotStockThaList +// +// @Description: 泰股股票代码列表 +// @receiver uo +// @param ctx +// @return []models.BotStockThaList +// @return error +func (uo *userOrderRepo) GetBotStockThaList(ctx context.Context) ([]models.BotStockThaList, error) { + var data []models.BotStockThaList + if err := uo.data.mysqlDB.Table(flags.BotStockThaList).Find(&data); err != nil { + applogger.Error("%v GetBotStockThaList Find:%v", common.ErrSharePre, err) + return nil, err + } + // 清理股票缓存列表 + for _, value := range data { + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + Reds.HDel(context.Background(), setting.MarketShareTha, codeOld) + Reds.HDel(context.Background(), setting.MarketShareBlkTha, codeOld) + } + } + + return data, nil +} + +// CreateBotUserThaPreStockOrder +// +// @Description: 泰股新股申购:开仓--持仓 +// @receiver uo +// @param ctx +// @param code +// @param order +// @return error +func (uo *userOrderRepo) CreateBotUserThaPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error { + // 同步写入股票列表缓存 + SubscribeThaHSetCodeList(code, false) + // 处理新股申购数据订单 + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v CreatBotUserThaPreStockOrder.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 强平阈值 + flatRatio := GetCacheForcedClosure(flags.StockTGSystemSetUpKey, code) + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), + } + // 获取开盘时间 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.ThaMarket, time.Now()) + // 初始化订单缓存 + orderMap := make(map[string]share.ShareThaTallyCache) + for _, value := range order { + value.System = system + // 生成订单ID + orderId, err := uo.VerifyBotStockThaTradeOrderId(session) + if err != nil { + applogger.Error("%v CreatBotUserThaPreStockOrder.VerifyBotStockThaTradeOrderId:%v", common.ErrSharePre, err) + continue + } + // 查询账户是否存在,再存更新不存在新增 + check, err := uo.CheckStockThaAmount(ctx, int64(value.UserId), value.StockId, value.OrderNumber, decimal.Zero.String()) + if err != nil || !check { + applogger.Error("%v CreatBotUserThaPreStockOrder.CheckStockThaAmount:%v", common.ErrSharePre, err) + continue + } + // 写入订单数据表 + trade := orders.BotStockThaTradePre(ctx, int64(value.UserId), orderId, value) + if err := uo.CreateBotStockThaTrade(session, trade); err != nil { + applogger.Error("%v CreatBotUserThaPreStockOrder.CreateBotStockThaTrade:%v", common.ErrSharePre, err) + continue + } + // 写入持仓缓存 + resultMsg := share.ShareThaTallyCache{ + UserId: int64(value.UserId), // 用户Id + OrderId: orderId, // 订单ID + Symbol: value.StockId, // 下单交易对 + OpenPrice: value.LimitPrice, // 开仓价格 + Status: flags.Position, // 订单状态 + Order: value, // 下单信息 + ClosingTime: closingTime, // 平仓时间 + } + orderMap[orderId] = resultMsg + } + + if err = session.Commit(); err != nil { + applogger.Error("%v CreatBotUserThaPreStockOrder.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 写入持仓缓存、用户订单订阅缓存、管理员订单订阅缓存 + for _, resultMsg := range orderMap { + byteStr, err := json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v CreatBotUserThaPreStockOrder.Marshal:%v", common.ErrSharePre, err) + continue + } + // 写入持仓订单缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareThaPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + // 写入用户订单订阅缓存 + orderIdKey := virtual.OrderIdListKey(setting.ShareThaSubscribe, resultMsg.UserId) + if err = share.ShareThaHashUserOrder(Reds, orderIdKey, &resultMsg); err != nil { + applogger.Error("%v CreatBotUserThaPreStockOrder.ShareThaSubscribe:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // 写入管理员订单订阅缓存 + if err = share.ShareThaHashUserOrder(Reds, setting.AdminShareThaSubscribe, &resultMsg); err != nil { + applogger.Error("%v CreatBotUserThaPreStockOrder.AdminShareThaSubscribe:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + // TODO: 获取IPO未支付订单缓存,并更新缓存中的持仓订单ID + keyCache := fmt.Sprintf("%v%v", flags.StockIpoList, resultMsg.Order.OrderNo) + checkInt, err := Reds.Exists(ctx, keyCache).Result() + if err != nil { + continue + } + if checkInt > 0 { + if err = Reds.Set(ctx, keyCache, resultMsg.OrderId, 0).Err(); err != nil { + applogger.Error("CreatBotUserThaPreStockOrder.Set err:%v", err) + } + } + } + + return nil +} + +// CheckStockThaAmount +// +// @Description: 泰股新股申购【创建|更新】用戶资产 +// @receiver uo +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return bool +// @return error +func (uo *userOrderRepo) CheckStockThaAmount(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) (bool, error) { + var botUserStockTha []models.BotUserStockTha + if err := uo.data.mysqlDB.Table(flags.BotUserStockTha). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&botUserStockTha); err != nil { + applogger.Error("%v CheckStockThaAmount Find:%v", common.ErrSharePre, err) + return false, err + } + var usableNumOld, frozenNumOld decimal.Decimal + for _, value := range botUserStockTha { + usableNumOld = decimal.RequireFromString(value.UsableNum) + frozenNumOld = decimal.RequireFromString(value.FrozenNum) + } + + if len(botUserStockTha) == 0 { + // 创建账户 + userStock := orders.CreatBotUserStockThaPre(ctx, userId, stockId, usableNum, frozenNum) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockTha).Insert(&userStock) + if err != nil { + applogger.Error("%v CheckStockThaAmount Insert:%v", common.ErrSharePre, err) + return false, err + } + } else { + // 更新账户 + usableNumNew := usableNumOld.Add(decimal.RequireFromString(usableNum)) + frozenNumNew := frozenNumOld.Add(decimal.RequireFromString(frozenNum)) + userStock := orders.UpdateBotUserStockThaPre(ctx, usableNumNew.String(), frozenNumNew.String()) + _, err := uo.data.mysqlDB.Table(flags.BotUserStockTha). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&userStock) + if err != nil { + applogger.Error("%v CheckStockThaAmount Update:%v", common.ErrSharePre, err) + return false, err + } + } + + return true, nil +} + +// UpdateShareThaTradeStockId +// +// @Description: 更新-泰股新股申购股票stockId +// @receiver uo +// @param ctx +// @param code +// @param codeOld +// @param stock +// @return error +func (uo *userOrderRepo) UpdateShareThaTradeStockId(ctx context.Context, code, codeOld string) error { + // 同步写入股票列表缓存 + SubscribeThaHSetCodeList(code, false) + // 新增到泰股缓存列表 + if err := Reds.HSet(context.Background(), setting.MarketShareTha, code, code).Err(); err != nil { + applogger.Error("%v UpdateShareThaTradeStockId.HSet.MarketShareTha:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateShareThaTradeStockId.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + // 1、更新订单股票代码 + var userStockTrade []models.BotStockThaTrade + if err = session.Table(flags.BotStockThaTrade).Where("stock_id =?", codeOld).Find(&userStockTrade); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockTrade { + value.StockId = code + // 1、更新订单信息 + inCheck, err := session.Table(flags.BotStockThaTrade).Where("trade_id =?", value.TradeId).Update(&value) + if err != nil || inCheck <= 0 { + continue + } + // 2、处理缓存订单 + orderMap, err := Reds.HGet(context.Background(), setting.AdminShareThaSubscribe, value.OrderId).Result() + if err != nil { + continue + } + var entrustJson share.ShareThaTallyCache + if err = json.Unmarshal([]byte(orderMap), &entrustJson); err != nil { + continue + } + var entrust *share.ShareThaTallyCache + entrust = &entrustJson + if entrust == nil { + continue + } + entrust.Symbol = code + entrust.Order.StockId = code + // 3、处理挂单|持仓|用户订阅|管理员订阅缓存数据 + switch value.Status { + case 0: // 挂单 + if err = share.ShareThaHashUserOrder(Reds, setting.MarketShareThaEntrust, entrust); err != nil { + continue + } + case 1: // 持仓 + if err = share.ShareThaHashUserOrder(Reds, setting.MarketShareThaPosition, entrust); err != nil { + continue + } + default: + continue + } + // 更新用户订阅缓存 + cacheKey := fmt.Sprintf("%v-%v", setting.ShareThaSubscribe, entrust.UserId) + if err = share.ShareThaHashUserOrder(Reds, cacheKey, entrust); err != nil { + continue + } + // 更新管理员订阅缓存 + if err = share.ShareThaHashUserOrder(Reds, setting.AdminShareThaSubscribe, entrust); err != nil { + continue + } + } + // 2、更新资产表股票代码 + var userStock []models.BotUserStockTha + if err = session.Table(flags.BotUserStockTha).Where("stock_id =?", codeOld).Find(&userStock); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStock { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockTha).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareThaTradeStockId BotUserStockTha err:%v", common.ErrSharePre, err) + continue + } + } + // 3、更新资产表日志股票代码 + var userStockLog []models.BotUserStockThaLog + if err = session.Table(flags.BotUserStockThaLog).Where("stock_id =?", codeOld).Find(&userStockLog); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockLog { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockThaLog).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareThaTradeStockId BotUserStockThaLog err:%v", common.ErrSharePre, err) + continue + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateShareThaTradeStockId.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + return nil +} diff --git a/internal/data/order_way_ipo_us.go b/internal/data/order_way_ipo_us.go new file mode 100644 index 0000000..b3031df --- /dev/null +++ b/internal/data/order_way_ipo_us.go @@ -0,0 +1,374 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + orders "matchmaking-system/internal/data/convert" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + models "matchmaking-system/internal/pkg/model" + "matchmaking-system/internal/pkg/setting" + "strings" + "time" +) + +// GetBotUserUsPreStockOrder +// +// @Description: 美股新股申购列表查询 +// @receiver uo +// @param ctx +// @param id +// @return []models.BotUserUsPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserUsPreStockOrder(ctx context.Context, id string) ([]models.BotUserUsPreStockOrder, error) { + var botUs []models.BotUserUsPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserUsPreStockOrder). + Where("pre_stock_id = ?", id). + Where("status = 3"). + Find(&botUs); err != nil { + applogger.Error("%v GetBotUserUsPreStockOrder Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botUs, nil +} + +// GetBotUserUsPreStockOrderByOrderNo +// +// @Description: 美股新股申购列表查询--OrderNo +// @receiver uo +// @param ctx +// @param code +// @return []models.BotUserUsPreStockOrder +// @return error +func (uo *userOrderRepo) GetBotUserUsPreStockOrderByOrderNo(ctx context.Context, code []string) ([]models.BotUserUsPreStockOrder, error) { + var botUs []models.BotUserUsPreStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserUsPreStockOrder). + In("order_no", code). + Where("trade_status = 0"). + Where("status = 3"). + Find(&botUs); err != nil { + applogger.Error("%v GetBotUserUsPreStockOrder Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botUs, nil +} + +// GetBotUserUsGiveStockOrder +// +// @Description: 美股赠送股票列表查询 +// @receiver uo +// @param ctx +// @param id +func (uo *userOrderRepo) GetBotUserUsGiveStockOrder(ctx context.Context, id string) ([]models.BotUserUsGiveStockOrder, error) { + var botUs []models.BotUserUsGiveStockOrder + if err := uo.data.mysqlDB.Table(flags.BotUserUsGiveStockOrder). + Where("order_no = ?", id). + Find(&botUs); err != nil { + applogger.Error("%v GetBotUserUsGiveStockOrder Find:%v", common.ErrSharePre, err) + return nil, err + } + + return botUs, nil +} + +// GetBotStockList +// +// @Description: 美股股票代码列表 +// @receiver uo +// @param ctx +// @return []models.BotStockList +// @return error +func (uo *userOrderRepo) GetBotStockList(ctx context.Context) ([]models.BotStockList, error) { + var data []models.BotStockList + if err := uo.data.mysqlDB.Table(flags.BotStockList).Find(&data); err != nil { + applogger.Error("%v GetBotStockList Find:%v", common.ErrSharePre, err) + return nil, err + } + // 清理股票缓存列表 + for _, value := range data { + strArray := strings.Split(value.StockCode, ":") + if len(strArray) >= 2 { + codeOld := strArray[1] + Reds.HDel(context.Background(), setting.MarketShareUs, codeOld) + Reds.HDel(context.Background(), setting.MarketShareBlkUs, codeOld) + } + } + + return data, nil +} + +// CreateBotUserUsPreStockOrder +// +// @Description: 美股新股申购:开仓--持仓 +// @receiver uo +// @param ctx +// @param code +// @param order +// @return error +func (uo *userOrderRepo) CreateBotUserUsPreStockOrder(ctx context.Context, code string, order []structure.ShareOrder) error { + // 同步写入股票列表缓存 + SubscribeUsHSetCodeList(code, false) + // 处理新股申购数据订单 + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v CreatBotUserUsPreStockOrder.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 强平阈值 + flatRatio := GetCacheForcedClosure(flags.StockUsSystemSetUpKey, code) + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), + } + // 获取开盘时间 + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.UsMarket, time.Now()) + // 初始化订单缓存 + orderMap := make(map[string]share.ShareUsTallyCache) + for _, value := range order { + value.System = system + // 生成订单ID + var orderId string + orderId, err = uo.VerifyBotStockTradeOrderId(session) + if err != nil { + applogger.Error("%v CreatBotUserUsPreStockOrder.VerifyBotStockTradeOrderId:%v", common.ErrSharePre, err) + continue + } + // 查询账户是否存在,再存更新不存在新增 + var check bool + check, err = uo.CheckStockUsAmount(ctx, int64(value.UserId), value.StockId, value.OrderNumber, decimal.Zero.String()) + if err != nil || !check { + applogger.Error("%v CreatBotUserUsPreStockOrder.CheckStockUsAmount:%v", common.ErrSharePre, err) + continue + } + // 写入订单数据表 + trade := orders.BotStockTradePre(ctx, int64(value.UserId), orderId, value) + if err = uo.CreateBotStockTrade(session, trade); err != nil { + applogger.Error("%v CreatBotUserUsPreStockOrder.CreateBotStockTrade:%v", common.ErrSharePre, err) + continue + } + // 写入持仓缓存 + resultMsg := share.ShareUsTallyCache{ + UserId: int64(value.UserId), // 用户Id + OrderId: orderId, // 订单ID + Symbol: value.StockId, // 下单交易对 + OpenPrice: value.LimitPrice, // 开仓价格 + Status: flags.Position, // 订单状态 + Order: value, // 下单信息 + ClosingTime: closingTime, // 交易下单时间 + } + orderMap[orderId] = resultMsg + } + + if err = session.Commit(); err != nil { + applogger.Error("%v CreatBotUserUsPreStockOrder.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + // 处理生成订单的持仓缓存 + for _, resultMsg := range orderMap { + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v CreatBotUserUsPreStockOrder.Marshal:%v", common.ErrSharePre, err) + continue + } + // 写入持仓订单缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareUsPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + // 写入用户订单订阅缓存 + orderIdKey := virtual.OrderIdListKey(setting.ShareUsSubscribe, resultMsg.UserId) + if err = share.ShareUsHashUserOrder(Reds, orderIdKey, &resultMsg); err != nil { + applogger.Error("%v CreatBotUserUsPreStockOrder.ShareUsSubscribe:%v", common.ErrSharePre, err) + continue + } + // 写入管理员订单订阅缓存 + if err = share.ShareUsHashUserOrder(Reds, setting.AdminShareUsSubscribe, &resultMsg); err != nil { + applogger.Error("%v CreatBotUserUsPreStockOrder.AdminShareUsSubscribe:%v", common.ErrSharePre, err) + continue + } + // TODO: 获取IPO未支付订单缓存,并更新缓存中的持仓订单ID + keyCache := fmt.Sprintf("%v%v", flags.StockIpoList, resultMsg.Order.OrderNo) + checkInt, err := Reds.Exists(ctx, keyCache).Result() + if err != nil { + continue + } + if checkInt > 0 { + if err = Reds.Set(ctx, keyCache, resultMsg.OrderId, 0).Err(); err != nil { + applogger.Error("CreatBotUserUsPreStockOrder.Set err:%v", err) + } + } + } + + return nil +} + +// CheckStockUsAmount +// +// @Description: 美股新股申购【创建|更新】用戶资产 +// @receiver uo +// @param ctx +// @param userId +// @param stockId +// @param usableNum +// @param frozenNum +// @return bool +func (uo *userOrderRepo) CheckStockUsAmount(ctx context.Context, userId int64, stockId, usableNum, frozenNum string) (bool, error) { + var botUserStock []models.BotUserStock + if err := uo.data.mysqlDB.Table(flags.BotUserStock). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&botUserStock); err != nil { + applogger.Error("%v CheckStockUsAmount Find:%v", common.ErrSharePre, err) + return false, err + } + + var usableNumOld, frozenNumOld decimal.Decimal + for _, value := range botUserStock { + usableNumOld = decimal.RequireFromString(value.UsableNum) + frozenNumOld = decimal.RequireFromString(value.FrozenNum) + } + + if len(botUserStock) == 0 { + userStock := orders.CreatBotUserStockPre(ctx, userId, stockId, usableNum, frozenNum) + _, err := uo.data.mysqlDB.Table(flags.BotUserStock).Insert(&userStock) + if err != nil { + applogger.Error("%v CheckStockUsAmount Insert:%v", common.ErrSharePre, err) + return false, err + } + } else { + usableNumNew := usableNumOld.Add(decimal.RequireFromString(usableNum)) + frozenNumNew := frozenNumOld.Add(decimal.RequireFromString(frozenNum)) + userStock := orders.UpdateBotUserStockPre(ctx, usableNumNew.String(), frozenNumNew.String()) + + _, err := uo.data.mysqlDB.Table(flags.BotUserStock). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Update(&userStock) + if err != nil { + applogger.Error("%v CheckStockUsAmount Update:%v", common.ErrSharePre, err) + return false, err + } + } + + return true, nil +} + +// UpdateShareUsTradeStockId +// +// @Description: 更新-美股新股申购股票stockId +// @receiver uo +// @param ctx +// @param code +// @param codeOld +// @param stock +// @return error +func (uo *userOrderRepo) UpdateShareUsTradeStockId(ctx context.Context, code, codeOld string) error { + // 同步写入股票列表缓存 + SubscribeUsHSetCodeList(code, false) + // 新增到美股缓存列表 + if err := Reds.HSet(context.Background(), setting.MarketShareUs, code, code).Err(); err != nil { + applogger.Error("%v UpdateShareUsTradeStockId.HSet.MarketShareUs:%v", common.ErrSharePre, err) + return flags.ErrCacheDB + } + + session := uo.data.mysqlDB.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + applogger.Error("%v UpdateShareUsTradeStockId.Begin:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + // 1、更新订单股票代码 + var userStockTrade []models.BotStockTrade + if err = session.Table(flags.BotStockTrade).Where("stock_id =?", codeOld).Find(&userStockTrade); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockTrade { + value.StockId = code + // 1、更新订单信息 + inCheck, err := session.Table(flags.BotStockTrade).Where("trade_id =?", value.TradeId).Update(&value) + if err != nil || inCheck <= 0 { + continue + } + // 2、处理缓存订单 + orderMap, err := Reds.HGet(context.Background(), setting.AdminShareUsSubscribe, value.OrderId).Result() + if err != nil { + continue + } + var entrustJson share.ShareUsTallyCache + if err = json.Unmarshal([]byte(orderMap), &entrustJson); err != nil { + continue + } + var entrust *share.ShareUsTallyCache + entrust = &entrustJson + if entrust == nil { + continue + } + entrust.Symbol = code + entrust.Order.StockId = code + // 3、处理挂单|持仓|用户订阅|管理员订阅缓存数据 + switch value.Status { + case 0: // 挂单 + if err = share.ShareUsHashUserOrder(Reds, setting.MarketShareUsEntrust, entrust); err != nil { + continue + } + case 1: // 持仓 + if err = share.ShareUsHashUserOrder(Reds, setting.MarketShareUsPosition, entrust); err != nil { + continue + } + default: + continue + } + // 更新用户订阅缓存 + if err = share.ShareUsHashUserOrder(Reds, fmt.Sprintf("%v-%v", setting.ShareUsSubscribe, entrust.UserId), entrust); err != nil { + continue + } + // 更新管理员订阅缓存 + if err = share.ShareUsHashUserOrder(Reds, setting.AdminShareUsSubscribe, entrust); err != nil { + continue + } + } + // 2、更新资产表股票代码 + var userStock []models.BotUserStock + if err = session.Table(flags.BotUserStock).Where("stock_id =?", codeOld).Find(&userStock); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStock { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStock).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareUsTradeStockId bot_user_stock err:%v", common.ErrSharePre, err) + continue + } + } + // 3、更新资产表日志股票代码 + var userStockLog []models.BotUserStockLog + if err = session.Table(flags.BotUserStockLog).Where("stock_id =?", codeOld).Find(&userStockLog); err != nil { + return flags.ErrMySqlDB + } + for _, value := range userStockLog { + value.StockId = code + inCheck, err := session.Table(flags.BotUserStockLog).Where("id =?", value.Id).Update(&value) + if err != nil || inCheck <= 0 { + applogger.Error("%v UpdateShareUsTradeStockId BotUserStockLog err:%v", common.ErrSharePre, err) + continue + } + } + + if err = session.Commit(); err != nil { + applogger.Error("%v UpdateShareUsTradeStockId.Commit:%v", common.ErrSharePre, err) + return flags.ErrMySqlDB + } + + return nil +} diff --git a/internal/data/redis/redis.go b/internal/data/redis/redis.go new file mode 100644 index 0000000..3b908df --- /dev/null +++ b/internal/data/redis/redis.go @@ -0,0 +1,112 @@ +package redis + +import ( + "context" + "matchmaking-system/internal/conf" + "matchmaking-system/internal/pkg/flags" + "time" + + red "github.com/redis/go-redis/v9" +) + +// NewRedis +// +// @Description: +// @param c +// @return *red.Client +func NewRedis(c *conf.Data) *red.Client { + client := red.NewClient(&red.Options{ + Addr: c.Redis.Addr, + DB: int(c.Redis.Db), + Password: c.Redis.Password, // no password set + }) + _, err := client.Ping(context.Background()).Result() + if err != nil { + panic(err) + } + + return client +} + +// GetCacheData +// +// @Description: Query data through key +// @param ctx +// @param redisDB +// @param key +// @return string +// @return error +func GetCacheData(ctx context.Context, redisDB *red.Client, key string) (string, error) { + rge, err := redisDB.Get(ctx, key).Result() + if err != nil { + return flags.SetNull, err + } + + return rge, nil +} + +// SetCacheData +// +// @Description: +// @param ctx +// @param redisDB +// @param key +// @param value +// @param td +// @return error +func SetCacheData(ctx context.Context, redisDB *red.Client, key string, value interface{}, td int) error { + if err := redisDB.Set(ctx, key, value, time.Duration(td)*time.Minute).Err(); err != nil { + return err + } + + return nil +} + +// GetCacheKeys +// +// @Description: Query all keys +// @param ctx +// @param redisDB +// @return []string +// @return error +func GetCacheKeys(ctx context.Context, redisDB *red.Client) ([]string, error) { + rge, err := redisDB.Keys(ctx, "*").Result() + if err != nil { + return []string{}, err + } + + return rge, nil +} + +// GetCacheCount +// +// @Description: Query the total number of Redis +// @param ctx +// @param redisDB +// @param key +// @return int64 +// @return error +func GetCacheCount(ctx context.Context, redisDB *red.Client, key string) (int64, error) { + rge, err := redisDB.DBSize(ctx).Result() + if err != nil { + return rge, err + } + + return rge, nil +} + +// SetCacheValue +// +// @Description: persistent data +// @param ctx +// @param redisDB +// @param key +// @param value +// @return error +func SetCacheValue(ctx context.Context, redisDB *red.Client, key, value string) error { + if err := redisDB.Set(ctx, key, value, 0).Err(); err != nil { + return err + } + + return nil +} diff --git a/internal/data/redis/redis_test.go b/internal/data/redis/redis_test.go new file mode 100644 index 0000000..77a19c5 --- /dev/null +++ b/internal/data/redis/redis_test.go @@ -0,0 +1,524 @@ +package redis + +import ( + "context" + "fmt" + "github.com/redis/go-redis/v9" + red "github.com/redis/go-redis/v9" + "matchmaking-system/internal/conf" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + models "matchmaking-system/internal/pkg/model" + "reflect" + "strconv" + "testing" + "time" +) + +type SetPrice struct { + PreStatus string + PreStartTime string + PreLimit string + PrePrices string + AfterStatus string + AfterStartTime string + AfterLimit string + AfterPrices string +} + +func TestRedisHash(t *testing.T) { + client := redis.NewClient(&redis.Options{ + Addr: "r-gs523wj7gcnshp3d1fpd.redis.singapore.rds.aliyuncs.com:6379", // Redis 服务器地址和端口号 + DB: 0, // Redis 数据库编号,默认为 0 + Password: "MRrfvtyujnb&hg56", // Redis 数据库密码 + }) + pong, err := client.Ping(context.Background()).Result() + if err != nil { + fmt.Println(pong, err) + return + } + + symbol, err := client.HGetAll(context.Background(), fmt.Sprintf("%v%v", flags.StockMarketList, 14)).Result() + if err != nil { + applogger.Error("GetCacheKeepDecimal.HGetAll:%v", err) + return + } + + // TODO: 开闭盘价试调 + var amOpenTime, pmOpenTime, amCloseTime, pmCloseTime time.Time + for filed, value := range symbol { + switch filed { + case "am_open_time": + amOpenTime, _ = time.Parse(flags.LayoutOne, value) + case "am_close_time": + amCloseTime, _ = time.Parse(flags.LayoutOne, value) + case "pm_open_time": + pmOpenTime, _ = time.Parse(flags.LayoutOne, value) + case "pm_close_time": + pmCloseTime, _ = time.Parse(flags.LayoutOne, value) + default: + } + } + + dateTime, _ := time.Parse(flags.LayoutOne, time.Now().Format(flags.LayoutOne)) + fmt.Println("当前时间:", dateTime) + fmt.Println("上午开盘时间:", amOpenTime) + fmt.Println("上午闭盘时间:", amCloseTime) + fmt.Println("下午开盘时间:", pmOpenTime) + fmt.Println("下午闭盘时间:", pmCloseTime) + + // 判定上午盘 + checkAmTime := dateTime.Equal(amOpenTime) || dateTime.Equal(amCloseTime) + if amOpenTime.Before(amCloseTime) { + fmt.Println("上午同天盘判定。。。。。") + // 同一天 + if dateTime.After(amOpenTime) && dateTime.Before(amCloseTime) || checkAmTime { + fmt.Println("上午正常的开盘时间。。。。。") + } + } else { + fmt.Println("上午跨天盘判定。。。。。") + // 跨天 + if dateTime.After(amOpenTime) || dateTime.Before(amCloseTime) || checkAmTime { + fmt.Println("上午正常的开盘时间。。。。。") + } + } + // 判定下午盘 + checkPmTime := dateTime.Equal(pmOpenTime) || dateTime.Equal(pmCloseTime) + if pmOpenTime.Before(pmCloseTime) { + fmt.Println("下午同天盘判定。。。。。") + // 同一天 + if dateTime.After(pmOpenTime) && dateTime.Before(pmCloseTime) || checkPmTime { + fmt.Println("下午正常的开盘时间。。。。。") + } + } else { + fmt.Println("下午跨天盘判定。。。。。") + // 跨天 + if dateTime.After(pmOpenTime) || dateTime.Before(pmCloseTime) || checkPmTime { + fmt.Println("下午正常的开盘时间。。。。。") + } + } + + // TODO: 杠杆试调 + //pryNum, err := client.Get(context.Background(), fmt.Sprintf("%v%v", flags.StockTradePryNumSet, 3)).Result() + //if err != nil { + // pryNum, err = client.Get(context.Background(), fmt.Sprintf("%v%v", flags.StockTradePryNumSet, 0)).Result() + // if err != nil { + // pryNum = flags.SetOne + // } + //} + //pryNumValue := decimal.RequireFromString(pryNum) + //fmt.Println("杠杆数据:", pryNumValue) + return + + keySymbol := fmt.Sprintf("STOCK_PRICES:3:AAPL") + symbolMap, err := client.HGetAll(context.Background(), keySymbol).Result() + if err != nil { + fmt.Println("数据信息:", err) + return + } + setModel := &SetPrice{} + + for key, value := range symbolMap { + applogger.Warn("数据展示:%v---%v", key, value) + switch key { + case "pre_status": // 盘前标识 + setModel.PreStatus = value + case "pre_start_time": + setModel.PreStartTime = value + case "pre_limit": + setModel.PreLimit = value + case "pre_prices": + setModel.PrePrices = value + case "after_status": // 盘后标识 + setModel.AfterStatus = value + case "after_start_time": + setModel.AfterStartTime = value + case "after_limit": + setModel.AfterLimit = value + case "after_prices": + setModel.AfterPrices = value + } + } + + // 设置哈希字段值 + err = client.HSet(context.Background(), "myhash", "field1", "value1").Err() + if err != nil { + fmt.Println(err) + } + err = client.HSet(context.Background(), "myhash", "field2", "value2").Err() + if err != nil { + fmt.Println(err) + } + + // 获取哈希字段值 + value, err := client.HGet(context.Background(), "myhash", "field1").Result() + if err != nil { + fmt.Println(err) + } + fmt.Println(value) + + // 获取所有哈希字段和值 + hashList, err := client.HGetAll(context.Background(), "myhash").Result() + if err != nil { + fmt.Println(err) + } + for field, value := range hashList { + fmt.Printf("Field: %s, Value: %s\n", field, value) + } + + // 删除哈希字段 + err = client.HDel(context.Background(), "myhash", "field1").Err() + if err != nil { + fmt.Println(err) + } +} + +func TestRedisFeeSetting(t *testing.T) { + client := redis.NewClient(&redis.Options{ + Addr: "18.142.112.77:6378", // Redis 服务器地址和端口号 + DB: 0, // Redis 数据库编号,默认为 0 + Password: "rfvtyujnbhg56", // Redis 数据库密码 + }) + // 获取股票手续费设置 + allStock, err := client.HGetAll(context.Background(), "TRADE:FEE:STOCK").Result() + if err != nil { + fmt.Println("股票手续费:", err) + return + } + for key, value := range allStock { + fmt.Println(key, ":", value) + } + + // 获取现货手续费设置 + allSpots, err := client.HGetAll(context.Background(), "TRADE:FEE:DIGITAL").Result() + if err != nil { + fmt.Println("现货手续费:", err) + return + } + for key, value := range allSpots { + fmt.Println(key, ":", value) + } + + // 获取合约手续费设置 + allContract, err := client.HGetAll(context.Background(), "TRADE:FEE:CONTRACT").Result() + if err != nil { + fmt.Println("合约手续费:", err) + return + } + for key, value := range allContract { + fmt.Println(key, ":", value) + } +} + +func TestRedisUserLever(t *testing.T) { + client := redis.NewClient(&redis.Options{ + Addr: "18.142.112.77:6378", // Redis 服务器地址和端口号 + DB: 0, // Redis 数据库编号,默认为 0 + Password: "rfvtyujnbhg56", // Redis 数据库密码 + }) + + //keyData := fmt.Sprintf("USER:LEVEL:%v", 9) + //allStock, err := client.HGetAll(context.Background(), keyData).Result() + //if err != nil { + // fmt.Println("获取用户返佣层级错误:", err) + // return + //} + //for key, value := range allStock { + // valueId, err := strconv.Atoi(value) + // if err != nil { + // return + // } + // fmt.Println(key, ":", valueId) + //} + + keyData := fmt.Sprintf("%v%v", flags.UserLevel, 100) + allStock, err := client.HGetAll(context.Background(), keyData).Result() + if err != nil { + fmt.Println("获取用户返佣层级错误:", err) + return + } + fmt.Println("数据展示:", keyData) + var level models.BotUserLevel + for key, value := range allStock { + valueId, err := strconv.Atoi(value) + if err != nil { + fmt.Println("转换错误:", err) + return + } + fmt.Println(key, ":", valueId) + //continue + switch key { + case "user_id": + level.UserId = valueId + case "parent_id": + level.ParentId = valueId + case "grandpa_id": + level.GrandpaId = valueId + case "top_id": + level.TopId = valueId + } + } + if level.UserId != 0 { + fmt.Println("查询用户返佣层级关系:", &level) + } + +} + +func TestRedisZset(t *testing.T) { + // 创建 Redis 客户端 + client := redis.NewClient(&redis.Options{ + Addr: "13.251.125.27:6378", // Redis 服务器地址和端口号 + DB: 0, // Redis 数据库编号,默认为 0 + Password: "rfvtyujnbhg56", // Redis 数据库密码 + }) + + // 向有序集合中添加成员和分数 + err := client.ZAdd(context.Background(), "myzset", + redis.Z{Score: float64(1.0), Member: "Alice"}, + redis.Z{Score: float64(2.0), Member: "Bob"}, + redis.Z{Score: float64(3.0), Member: "Charlie"}).Err() + if err != nil { + fmt.Println("无法向有序集合添加成员和分数:", err) + return + } + + // 获取有序集合的成员总数 + count, err := client.ZCard(context.Background(), "myzset").Result() + if err != nil { + fmt.Println("无法获取有序集合的成员总数:", err) + return + } + fmt.Println("有序集合的成员总数:", count) + + // 根据分数范围获取有序集合中的成员 + members, err := client.ZRangeByScore(context.Background(), "myzset", &redis.ZRangeBy{ + Min: "-inf", + Max: "+inf", + }).Result() + if err != nil { + fmt.Println("无法根据分数范围获取有序集合中的成员:", err) + return + } + fmt.Println("有序集合中的成员:", members) + + // 修改有序集合中的成员分数 + err = client.ZIncrBy(context.Background(), "myzset", float64(1.0), "Alice").Err() + if err != nil { + fmt.Println("无法修改有序集合中的成员分数:", err) + return + } + + // 删除有序集合中的一个或多个元素 + deletedCount, err := client.ZRem(context.Background(), "myzset", "Alice").Result() + if err != nil { + fmt.Println("无法删除有序集合中的元素:", err) + return + } + fmt.Println("已删除的元素数量:", deletedCount) + + // 获取成员的分数 + score, err := client.ZScore(context.Background(), "myzset", "Alice").Result() + if err != nil { + fmt.Println("无法获取有序集合中成员的分数:", err) + return + } + fmt.Println("有序集合中成员 Alice 的分数:", score) +} + +func TestRedisList(t *testing.T) { + // 创建一个 Redis 客户端 + client := redis.NewClient(&redis.Options{ + Addr: "13.251.125.27:6378", // Redis 服务器地址和端口号 + DB: 0, // Redis 数据库编号,默认为 0 + Password: "rfvtyujnbhg56", // Redis 数据库密码 + }) + + // 添加元素到列表的尾部 + err := client.RPush(context.Background(), "mylist", "a", "b", "c").Err() + if err != nil { + fmt.Println("添加元素失败:", err) + return + } + + // 获取列表的长度 + length, err := client.LLen(context.Background(), "mylist").Result() + if err != nil { + fmt.Println("获取列表长度失败:", err) + return + } + fmt.Println("列表长度:", length) + + // 获取列表中的所有元素 + elements, err := client.LRange(context.Background(), "mylist", 0, -1).Result() + if err != nil { + fmt.Println("获取列表中的元素失败:", err) + return + } + fmt.Println("列表中的元素:", elements) + + // 删除指定元素 + removedCount, err := client.LRem(context.Background(), "mylist", 1, "b").Result() + if err != nil { + fmt.Println("删除元素失败:", err) + return + } + fmt.Printf("成功删除了 %d 个元素\n", removedCount) + + // 从列表头部弹出一个元素 + element, err := client.LPop(context.Background(), "mylist").Result() + if err != nil { + fmt.Println("弹出元素失败:", err) + return + } + fmt.Println("弹出的元素:", element) +} + +func TestGetCacheCount(t *testing.T) { + type args struct { + ctx context.Context + redisDB *red.Client + key string + } + tests := []struct { + name string + args args + want int64 + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetCacheCount(tt.args.ctx, tt.args.redisDB, tt.args.key) + if (err != nil) != tt.wantErr { + t.Errorf("GetCacheCount() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("GetCacheCount() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetCacheData(t *testing.T) { + type args struct { + ctx context.Context + redisDB *red.Client + key string + } + tests := []struct { + name string + args args + want string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetCacheData(tt.args.ctx, tt.args.redisDB, tt.args.key) + if (err != nil) != tt.wantErr { + t.Errorf("GetCacheData() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("GetCacheData() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetCacheKeys(t *testing.T) { + type args struct { + ctx context.Context + redisDB *red.Client + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetCacheKeys(tt.args.ctx, tt.args.redisDB) + if (err != nil) != tt.wantErr { + t.Errorf("GetCacheKeys() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetCacheKeys() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestNewRedis(t *testing.T) { + type args struct { + c *conf.Data + } + tests := []struct { + name string + args args + want *red.Client + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewRedis(tt.args.c); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewRedis() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestSetCacheData(t *testing.T) { + type args struct { + ctx context.Context + redisDB *red.Client + key string + value interface{} + td int + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := SetCacheData(tt.args.ctx, tt.args.redisDB, tt.args.key, tt.args.value, tt.args.td); (err != nil) != tt.wantErr { + t.Errorf("SetCacheData() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestSetCacheValue(t *testing.T) { + type args struct { + ctx context.Context + redisDB *red.Client + key string + value string + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := SetCacheValue(tt.args.ctx, tt.args.redisDB, tt.args.key, tt.args.value); (err != nil) != tt.wantErr { + t.Errorf("SetCacheValue() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} diff --git a/internal/data/restore_cached_data.go b/internal/data/restore_cached_data.go new file mode 100644 index 0000000..8385cf7 --- /dev/null +++ b/internal/data/restore_cached_data.go @@ -0,0 +1,830 @@ +package data + +import ( + "fmt" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "strconv" + "time" + + models "matchmaking-system/internal/pkg/model" +) + +// RestoreCacheShareUs +// +// @Description: 恢复美股|德股|法股|英股|泰股|马股|印尼股|印度股|新加坡股|港股|期权|大宗交易|订单缓存数据 +// @param data +func RestoreCacheShareUs(data *Data) { + var stockList []*models.BotStockTrade + if err := data.mysqlDB.Table(flags.BotStockTrade). + Where("status in (0,1)"). + Asc("`status`"). + Find(&stockList); err != nil { + return + } + + for _, value := range stockList { + flatRatio := GetCacheForcedClosure(flags.StockUsSystemSetUpKey, value.StockId) // 设置强平阈值 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.UsMarket, int64(value.UserId)) // 股票市场系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), // 强平阈值 + Status: leverStatus.Status, // 杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.UsMarket, time.Now()) // 开盘时间 + shareOrder := &share.ShareUsTallyCache{ + UserId: int64(value.UserId), + OrderId: value.OrderId, + Symbol: value.StockId, + Status: strconv.Itoa(value.Status), + OpenPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + ClosingTime: closingTime, + Order: structure.ShareOrder{ + System: system, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + MarketMoney: value.MarketMoney, + OrderNumber: value.OrderNumber, + ServiceCost: value.ServiceCost, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + UserId: value.UserId, + PryNum: strconv.Itoa(value.PryNum), + }, + } + + // 订单状态 + var marketStatus string + switch value.Status { + case 0: + marketStatus = setting.MarketShareUsEntrust + case 1: + marketStatus = setting.MarketShareUsPosition + default: + } + + // 写入缓存数据(挂单|持仓) + if err := share.ShareUsHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareUs.%v:%v", common.ErrShareUs, marketStatus, err) + return + } + + // 写入用户订阅缓存 + userCacheKey := fmt.Sprintf("%v-%v", setting.ShareUsSubscribe, value.UserId) + if err := share.ShareUsHashUserOrder(Reds, userCacheKey, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareUs.%v:%v", common.ErrShareUs, userCacheKey, err) + return + } + + // 写入管理员订阅缓存 + adminCacheKey := setting.AdminShareUsSubscribe + if err := share.ShareUsHashUserOrder(Reds, adminCacheKey, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareUs.%v:%v", common.ErrShareUs, adminCacheKey, err) + return + } + } +} +func RestoreCacheShareEur(data *Data) { + var stockList []*models.BotStockEurTrade + if err := data.mysqlDB.Table(flags.BotStockEurTrade). + Where("status in (0,1)"). + Asc("`status`"). + Find(&stockList); err != nil { + return + } + + for _, value := range stockList { + flatRatio := GetCacheForcedClosure(flags.StockEURSystemSetUpKey, value.StockId) // 设置强平阈值 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.EurMarket, int64(value.UserId)) // 股票市场系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), // 强平阈值 + Status: leverStatus.Status, // 杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.EurMarket, time.Now()) // 开盘时间 + shareOrder := &share.ShareEurTallyCache{ + UserId: int64(value.UserId), + OrderId: value.OrderId, + Symbol: value.StockId, + Status: strconv.Itoa(value.Status), + OpenPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + ClosingTime: closingTime, + Order: structure.ShareOrder{ + System: system, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + MarketMoney: value.MarketMoney, + OrderNumber: value.OrderNumber, + ServiceCost: value.ServiceCost, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + UserId: value.UserId, + PryNum: strconv.Itoa(value.PryNum), + }, + } + + // 订单状态 + var marketStatus string + switch value.Status { + case 0: + marketStatus = setting.MarketShareEurEntrust + case 1: + marketStatus = setting.MarketShareEurPosition + default: + } + + // 写入缓存数据(挂单|持仓) + if err := share.ShareEurHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareEur.%v:%v", common.ErrShareEur, marketStatus, err) + return + } + + // 写入用户订阅缓存 + userCacheKey := fmt.Sprintf("%v-%v", setting.ShareEurSubscribe, value.UserId) + if err := share.ShareEurHashUserOrder(Reds, userCacheKey, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareEur.%v:%v", common.ErrShareEur, userCacheKey, err) + return + } + + // 写入管理员订阅缓存 + adminCacheKey := setting.AdminShareEurSubscribe + if err := share.ShareEurHashUserOrder(Reds, adminCacheKey, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareEur.%v:%v", common.ErrShareEur, adminCacheKey, err) + return + } + } +} +func RestoreCacheShareFur(data *Data) { + var stockList []*models.BotStockFurTrade + if err := data.mysqlDB.Table(flags.BotStockFurTrade). + Where("status in (0,1)"). + Asc("`status`"). + Find(&stockList); err != nil { + return + } + + for _, value := range stockList { + flatRatio := GetCacheForcedClosure(flags.StockFURSystemSetUpKey, value.StockId) // 设置强平阈值 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.FurMarket, int64(value.UserId)) // 股票市场系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), // 强平阈值 + Status: leverStatus.Status, // 杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.ThaMarket, time.Now()) // 开盘时间 + shareOrder := &share.ShareFurTallyCache{ + UserId: int64(value.UserId), + OrderId: value.OrderId, + Symbol: value.StockId, + Status: strconv.Itoa(value.Status), + OpenPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + ClosingTime: closingTime, + Order: structure.ShareOrder{ + System: system, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + MarketMoney: value.MarketMoney, + OrderNumber: value.OrderNumber, + ServiceCost: value.ServiceCost, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + UserId: value.UserId, + PryNum: strconv.Itoa(value.PryNum), + }, + } + + // 订单状态 + var marketStatus string + switch value.Status { + case 0: + marketStatus = setting.MarketShareFurEntrust + case 1: + marketStatus = setting.MarketShareFurPosition + default: + } + + // 写入缓存数据(挂单|持仓) + if err := share.ShareFurHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareFur.%v:%v", common.ErrShareFur, marketStatus, err) + return + } + + // 写入用户订阅缓存 + userCacheKey := fmt.Sprintf("%v-%v", setting.ShareFurSubscribe, value.UserId) + if err := share.ShareFurHashUserOrder(Reds, userCacheKey, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareFur.%v:%v", common.ErrShareFur, userCacheKey, err) + return + } + + // 写入管理员订阅缓存 + adminCacheKey := setting.AdminShareFurSubscribe + if err := share.ShareFurHashUserOrder(Reds, adminCacheKey, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareFur.%v:%v", common.ErrShareFur, adminCacheKey, err) + return + } + } +} +func RestoreCacheShareGbx(data *Data) { + var stockList []*models.BotStockGbxTrade + if err := data.mysqlDB.Table(flags.BotStockGbxTrade). + Where("status in (0,1)"). + Asc("`status`"). + Find(&stockList); err != nil { + return + } + + for _, value := range stockList { + flatRatio := GetCacheForcedClosure(flags.StockUkSystemSetUpKey, value.StockId) // 设置强平阈值 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.GbxMarket, int64(value.UserId)) // 股票市场系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), // 强平阈值 + Status: leverStatus.Status, // 杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.GbxMarket, time.Now()) // 开盘时间 + shareOrder := &share.ShareGbxTallyCache{ + UserId: int64(value.UserId), + OrderId: value.OrderId, + Symbol: value.StockId, + Status: strconv.Itoa(value.Status), + OpenPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + ClosingTime: closingTime, + Order: structure.ShareOrder{ + System: system, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + MarketMoney: value.MarketMoney, + OrderNumber: value.OrderNumber, + ServiceCost: value.ServiceCost, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + UserId: value.UserId, + PryNum: strconv.Itoa(value.PryNum), + }, + } + + // 订单状态 + var marketStatus string + switch value.Status { + case 0: + marketStatus = setting.MarketShareGbxEntrust + case 1: + marketStatus = setting.MarketShareGbxPosition + default: + } + + // 写入缓存数据(挂单|持仓) + if err := share.ShareGbxHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareGbx.%v:%v", common.ErrShareGbx, marketStatus, err) + return + } + + // 写入用户订阅缓存 + userCacheKey := fmt.Sprintf("%v-%v", setting.ShareGbxSubscribe, value.UserId) + if err := share.ShareGbxHashUserOrder(Reds, userCacheKey, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareGbx.%v:%v", common.ErrShareGbx, userCacheKey, err) + return + } + + // 写入管理员订阅缓存 + adminCacheKey := setting.AdminShareGbxSubscribe + if err := share.ShareGbxHashUserOrder(Reds, adminCacheKey, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareGbx.%v:%v", common.ErrShareGbx, adminCacheKey, err) + return + } + } +} + +// RestoreCacheShareTha +// +// @Description: +// @param data +func RestoreCacheShareTha(data *Data) { + var stockList []*models.BotStockThaTrade + if err := data.mysqlDB.Table(flags.BotStockThaTrade). + Where("status in (0,1)"). + Asc("`status`"). + Find(&stockList); err != nil { + return + } + + for _, value := range stockList { + flatRatio := GetCacheForcedClosure(flags.StockTGSystemSetUpKey, value.StockId) // 设置强平阈值 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.ThaMarket, int64(value.UserId)) // 股票市场系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), // 强平阈值 + Status: leverStatus.Status, // 杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.ThaMarket, time.Now()) // 开盘时间 + shareOrder := &share.ShareThaTallyCache{ + UserId: int64(value.UserId), + OrderId: value.OrderId, + Symbol: value.StockId, + Status: strconv.Itoa(value.Status), + OpenPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + ClosingTime: closingTime, + Order: structure.ShareOrder{ + System: system, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + MarketMoney: value.MarketMoney, + OrderNumber: value.OrderNumber, + ServiceCost: value.ServiceCost, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + UserId: value.UserId, + PryNum: strconv.Itoa(value.PryNum), + }, + } + + // 订单状态 + var marketStatus string + switch value.Status { + case 0: + marketStatus = setting.MarketShareThaEntrust + case 1: + marketStatus = setting.MarketShareThaPosition + default: + } + + // 写入缓存数据(挂单|持仓) + if err := share.ShareThaHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareTha.%v:%v", common.ErrShareTha, marketStatus, err) + return + } + + // 写入用户订阅缓存 + userCacheKey := fmt.Sprintf("%v-%v", setting.ShareThaSubscribe, value.UserId) + if err := share.ShareThaHashUserOrder(Reds, userCacheKey, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareTha.%v:%v", common.ErrShareTha, userCacheKey, err) + return + } + + // 写入管理员订阅缓存 + adminCacheKey := setting.AdminShareThaSubscribe + if err := share.ShareThaHashUserOrder(Reds, adminCacheKey, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareTha.%v:%v", common.ErrShareTha, adminCacheKey, err) + return + } + } +} + +// RestoreCacheShareMys +// +// @Description: +// @param data +func RestoreCacheShareMys(data *Data) { + var stockList []*models.BotStockMysTrade + if err := data.mysqlDB.Table(flags.BotStockMysTrade). + Where("status in (0,1)"). + Asc("`status`"). + Find(&stockList); err != nil { + return + } + + for _, value := range stockList { + flatRatio := GetCacheForcedClosure(flags.StockMGSystemSetUpKey, value.StockId) // 设置强平阈值 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.MysMarket, int64(value.UserId)) // 股票市场系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), // 强平阈值 + Status: leverStatus.Status, // 杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.MysMarket, time.Now()) // 开盘时间 + shareOrder := &share.ShareMysTallyCache{ + UserId: int64(value.UserId), + OrderId: value.OrderId, + Symbol: value.StockId, + Status: strconv.Itoa(value.Status), + OpenPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + ClosingTime: closingTime, + Order: structure.ShareOrder{ + System: system, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + MarketMoney: value.MarketMoney, + OrderNumber: value.OrderNumber, + ServiceCost: value.ServiceCost, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + UserId: value.UserId, + PryNum: strconv.Itoa(value.PryNum), + }, + } + + // 订单状态 + var marketStatus string + switch value.Status { + case 0: + marketStatus = setting.MarketShareMysEntrust + case 1: + marketStatus = setting.MarketShareMysPosition + default: + } + + // 写入缓存数据(挂单|持仓) + if err := share.ShareMysHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareMys.%v:%v", common.ErrShareMys, marketStatus, err) + return + } + + // 写入用户订阅缓存 + userCacheKey := fmt.Sprintf("%v-%v", setting.ShareMysSubscribe, value.UserId) + if err := share.ShareMysHashUserOrder(Reds, userCacheKey, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareMys.%v:%v", common.ErrShareMys, userCacheKey, err) + return + } + + // 写入管理员订阅缓存 + adminCacheKey := setting.AdminShareMysSubscribe + if err := share.ShareMysHashUserOrder(Reds, adminCacheKey, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareMys.%v:%v", common.ErrShareMys, adminCacheKey, err) + return + } + } +} + +// RestoreCacheShareIdn +// +// @Description: +// @param data +func RestoreCacheShareIdn(data *Data) { + var stockList []*models.BotStockIdnTrade + if err := data.mysqlDB.Table(flags.BotStockIdnTrade). + Where("status in (0,1)"). + Asc("`status`"). + Find(&stockList); err != nil { + return + } + + for _, value := range stockList { + flatRatio := GetCacheForcedClosure(flags.StockYNSystemSetUpKey, value.StockId) // 设置强平阈值 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.IdnMarket, int64(value.UserId)) // 股票市场系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), // 强平阈值 + Status: leverStatus.Status, // 杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.IdnMarket, time.Now()) // 开盘时间 + shareOrder := &share.ShareIdnTallyCache{ + UserId: int64(value.UserId), + OrderId: value.OrderId, + Symbol: value.StockId, + Status: strconv.Itoa(value.Status), + OpenPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + ClosingTime: closingTime, + Order: structure.ShareOrder{ + System: system, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + MarketMoney: value.MarketMoney, + OrderNumber: value.OrderNumber, + ServiceCost: value.ServiceCost, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + UserId: value.UserId, + PryNum: strconv.Itoa(value.PryNum), + }, + } + + // 订单状态 + var marketStatus string + switch value.Status { + case 0: + marketStatus = setting.MarketShareIdnEntrust + case 1: + marketStatus = setting.MarketShareIdnPosition + default: + } + + // 写入缓存数据(挂单|持仓) + if err := share.ShareIdnHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareIdn.%v:%v", common.ErrShareIdn, marketStatus, err) + return + } + + // 写入用户订阅缓存 + userCacheKey := fmt.Sprintf("%v-%v", setting.ShareIdnSubscribe, value.UserId) + if err := share.ShareIdnHashUserOrder(Reds, userCacheKey, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareIdn.%v:%v", common.ErrShareIdn, userCacheKey, err) + return + } + + // 写入管理员订阅缓存 + adminCacheKey := setting.AdminShareIdnSubscribe + if err := share.ShareIdnHashUserOrder(Reds, adminCacheKey, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareIdn.%v:%v", common.ErrShareIdn, adminCacheKey, err) + return + } + } +} + +// RestoreCacheShareInr +// +// @Description: +// @param data +func RestoreCacheShareInr(data *Data) { + var stockList []*models.BotStockInTrade + if err := data.mysqlDB.Table(flags.BotStockInTrade). + Where("status in (0,1)"). + Asc("`status`"). + Find(&stockList); err != nil { + return + } + + for _, value := range stockList { + flatRatio := GetCacheForcedClosure(flags.StockYDSystemSetUpKey, value.StockId) // 设置强平阈值 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.InrMarket, int64(value.UserId)) // 股票市场系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), // 强平阈值 + Status: leverStatus.Status, // 杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.InrMarket, time.Now()) // 开盘时间 + shareOrder := &share.ShareInrTallyCache{ + UserId: int64(value.UserId), + OrderId: value.OrderId, + Symbol: value.StockId, + Status: strconv.Itoa(value.Status), + OpenPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + ClosingTime: closingTime, + Order: structure.ShareOrder{ + System: system, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + MarketMoney: value.MarketMoney, + OrderNumber: value.OrderNumber, + ServiceCost: value.ServiceCost, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + UserId: value.UserId, + PryNum: strconv.Itoa(value.PryNum), + }, + } + + // 订单状态 + var marketStatus string + switch value.Status { + case 0: + marketStatus = setting.MarketShareInrEntrust + case 1: + marketStatus = setting.MarketShareInrPosition + default: + } + + // 写入缓存数据(挂单|持仓) + if err := share.ShareInrHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareInr.%v:%v", common.ErrShareInr, marketStatus, err) + return + } + + // 写入用户订阅缓存 + userCacheKey := fmt.Sprintf("%v-%v", setting.ShareInrSubscribe, value.UserId) + if err := share.ShareInrHashUserOrder(Reds, userCacheKey, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareInr.%v:%v", common.ErrShareInr, userCacheKey, err) + return + } + + // 写入管理员订阅缓存 + adminCacheKey := setting.AdminShareInrSubscribe + if err := share.ShareInrHashUserOrder(Reds, adminCacheKey, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareInr.%v:%v", common.ErrShareInr, adminCacheKey, err) + return + } + } +} + +// RestoreCacheShareSgd +// +// @Description: +// @param data +func RestoreCacheShareSgd(data *Data) { + var stockList []*models.BotStockSgdTrade + if err := data.mysqlDB.Table(flags.BotStockSgdTrade). + Where("status in (0,1)"). + Asc("`status`"). + Find(&stockList); err != nil { + return + } + + for _, value := range stockList { + flatRatio := GetCacheForcedClosure(flags.StockSGDSystemSetUpKey, value.StockId) // 设置强平阈值 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.SgdMarket, int64(value.UserId)) // 股票市场系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), // 强平阈值 + Status: leverStatus.Status, // 杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.SgdMarket, time.Now()) // 开盘时间 + shareOrder := &share.ShareSgdTallyCache{ + UserId: int64(value.UserId), + OrderId: value.OrderId, + Symbol: value.StockId, + Status: strconv.Itoa(value.Status), + OpenPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + ClosingTime: closingTime, + Order: structure.ShareOrder{ + System: system, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + MarketMoney: value.MarketMoney, + OrderNumber: value.OrderNumber, + ServiceCost: value.ServiceCost, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + UserId: value.UserId, + PryNum: strconv.Itoa(value.PryNum), + }, + } + + // 订单状态 + var marketStatus string + switch value.Status { + case 0: + marketStatus = setting.MarketShareSgdEntrust + case 1: + marketStatus = setting.MarketShareSgdPosition + default: + } + adminCacheKey := setting.AdminShareSgdSubscribe + userCacheKey := fmt.Sprintf("%v-%v", setting.ShareSgdSubscribe, value.UserId) + + // 写入缓存数据(挂单|持仓) + if err := share.ShareSgdHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareSgd.%v:%v", common.ErrShareSgd, marketStatus, err) + return + } + + // 写入用户订阅缓存 + if err := share.ShareSgdHashUserOrder(Reds, userCacheKey, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareSgd.%v:%v", common.ErrShareSgd, userCacheKey, err) + return + } + + // 写入管理员订阅缓存 + if err := share.ShareSgdHashUserOrder(Reds, adminCacheKey, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareSgd.%v:%v", common.ErrShareSgd, adminCacheKey, err) + return + } + } +} + +// RestoreCacheShareHkd +// +// @Description: +// @param data +func RestoreCacheShareHkd(data *Data) { + var stockList []*models.BotStockHkdTrade + if err := data.mysqlDB.Table(flags.BotStockHkdTrade). + Where("status in (0,1)"). + Asc("`status`"). + Find(&stockList); err != nil { + return + } + + for _, value := range stockList { + flatRatio := GetCacheForcedClosure(flags.StockHKDSystemSetUpKey, value.StockId) // 设置强平阈值 + leverStatus := SystemShareMarketLeverStatus(flags.StockMarketList, flags.HkdMarket, int64(value.UserId)) // 股票市场系统设置 + system := &structure.ShareSystem{ + StrongFlatRatio: flatRatio.String(), // 强平阈值 + Status: leverStatus.Status, // 杠杆状态 + StockMin: leverStatus.StockMin, // 开启杠杆的最小值 + LevelMin: leverStatus.LevelMin, // 杠杆最小值 + LevelMax: leverStatus.LevelMax, // 杠杆最大值 + UserStatus: leverStatus.UserStatus, // 用户开启状态 + } + closingTime := SystemTimeGenerate(flags.StockMarketList, flags.HkdMarket, time.Now()) // 开盘时间 + shareOrder := &share.ShareHkdTallyCache{ + UserId: int64(value.UserId), + OrderId: value.OrderId, + Symbol: value.StockId, + Status: strconv.Itoa(value.Status), + OpenPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + ClosingTime: closingTime, + Order: structure.ShareOrder{ + System: system, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + MarketMoney: value.MarketMoney, + OrderNumber: value.OrderNumber, + ServiceCost: value.ServiceCost, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + UserId: value.UserId, + PryNum: strconv.Itoa(value.PryNum), + }, + } + + // 订单状态 + var marketStatus string + switch value.Status { + case 0: + marketStatus = setting.MarketShareHkdEntrust + case 1: + marketStatus = setting.MarketShareHkdPosition + default: + } + adminCacheKey := setting.AdminShareHkdSubscribe + userCacheKey := fmt.Sprintf("%v-%v", setting.ShareHkdSubscribe, value.UserId) + + // 写入缓存数据(挂单|持仓) + if err := share.ShareHkdHashUserOrder(Reds, marketStatus, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareHkd.%v:%v", common.ErrShareHkd, marketStatus, err) + return + } + + // 写入用户订阅缓存 + if err := share.ShareHkdHashUserOrder(Reds, userCacheKey, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareHkd.%v:%v", common.ErrShareHkd, userCacheKey, err) + return + } + + // 写入管理员订阅缓存 + if err := share.ShareHkdHashUserOrder(Reds, adminCacheKey, shareOrder); err != nil { + applogger.Error("%v RestoreCacheShareHkd.%v:%v", common.ErrShareHkd, adminCacheKey, err) + return + } + } +} diff --git a/internal/data/restore_cached_order_no.go b/internal/data/restore_cached_order_no.go new file mode 100644 index 0000000..2edca4f --- /dev/null +++ b/internal/data/restore_cached_order_no.go @@ -0,0 +1,86 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + models "matchmaking-system/internal/pkg/model" + "matchmaking-system/internal/pkg/setting" +) + +// TradeIPoInrByOrderNo +// +// @Description: +// @param data +func TradeIPoInrByOrderNo(data *Data) { + //1、查询当前股票代码为:NSE:IEML.ST的订单 + //2、循环生成: map[userId]string 用户和订单列表的map函数 + //3、通过缓存key:shareInrSubscribe-userId 解析json找到对应的orderNo(处理为空的状况-即为不是IPO订单) + //4、通过orderNo更新缓存key:USER:ARREAR:ORDER:OrderNo 的value值为OrderId + + inrMap := GetBotStockInrTrade(data) + applogger.Error("数据展示:%v", inrMap) + + for key, _ := range inrMap { + keyCache := fmt.Sprintf("%v-%v", setting.ShareInrSubscribe, key) + orderCache, err := Reds.HGetAll(context.Background(), keyCache).Result() + if err != nil { + continue + } + + for _, vue := range orderCache { + var msg share.ShareInrTallyCache + if err = json.Unmarshal([]byte(vue), &msg); err != nil { + applogger.Error("TradeIPoInrByOrderNo err:%v", err) + continue + } + // 处理IPO缓存订单 + switch msg.Status { + case flags.Position: // 持仓 + if len(msg.Order.OrderNo) > 0 { // 非空 + ipoCache := fmt.Sprintf("%v%v", flags.StockIpoList, msg.Order.OrderNo) + checkInt, err := Reds.Exists(context.Background(), ipoCache).Result() + if err != nil { + applogger.Error("CreatBotUserUsPreStockOrder.Exists err:%v", err) + continue + } + if checkInt > 0 { + //applogger.Debug("有效--用户ID:%v,订单ID:%v,IPO订单号:%v", key, msg.OrderId, msg.Order.OrderNo) + if err = Reds.Set(context.Background(), ipoCache, msg.OrderId, 0).Err(); err != nil { + applogger.Error("CreatBotUserUsPreStockOrder.Set err:%v", err) + continue + } + } + } + default: + + } + } + } +} + +// GetBotStockInrTrade +// +// @Description: +// @param data +// @return map[int64][]string +func GetBotStockInrTrade(data *Data) map[int64][]string { + var inrList []models.BotStockInTrade + if err := data.mysqlDB.Table(flags.BotStockInTrade). + Where("stock_id = ?", "NSE:GODIGIT.ST"). //NSE:IEML.ST NSE:test123456 + Where("status = 1"). + Find(&inrList); err != nil { + return nil + } + + inrMap := make(map[int64][]string) + for _, inr := range inrList { + userId := int64(inr.UserId) + inrMap[userId] = append(inrMap[userId], inr.OrderId) + } + + return inrMap +} diff --git a/internal/data/restore_clear_cache_data.go b/internal/data/restore_clear_cache_data.go new file mode 100644 index 0000000..f97d2a1 --- /dev/null +++ b/internal/data/restore_clear_cache_data.go @@ -0,0 +1,664 @@ +package data + +import ( + "context" + "fmt" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + models "matchmaking-system/internal/pkg/model" + "matchmaking-system/internal/pkg/setting" + "time" +) + +// UserList +// +// @Description: 查询userId +// @param data +func UserList(data *Data) []models.BotUsers { + var userList []models.BotUsers + if err := data.mysqlDB.Table(flags.BotUsers).Where("status = 1").Find(&userList); err != nil { + applogger.Debug("查询用户信息错误:%v", err) + return []models.BotUsers{} + } + + return userList +} + +// TradeListByUserId +// +// @Description: 根据UserId查询持仓订单信息 +// @param data +// @param tableName +// @return map[string]string +func TradeListByUserId(data *Data, tableName string, userId int64) map[string]string { + orderMap := make(map[string]string) + switch tableName { + case flags.BotStockTrade: + var shareUsList []models.BotStockTrade + if err := data.mysqlDB.Table(tableName). + Where("status = 1 or status = 0"). + Where("user_id = ?", userId). + Find(&shareUsList); err != nil { + return nil + } + for _, value := range shareUsList { + orderMap[value.OrderId] = value.OrderId + } + case flags.BotStockThaTrade: + var shareThaList []models.BotStockThaTrade + if err := data.mysqlDB.Table(tableName). + Where("status = 1 or status = 0"). + Where("user_id = ?", userId). + Find(&shareThaList); err != nil { + return nil + } + for _, value := range shareThaList { + orderMap[value.OrderId] = value.OrderId + } + case flags.BotStockMysTrade: + var shareMysList []models.BotStockMysTrade + if err := data.mysqlDB.Table(tableName). + Where("status = 1 or status = 0"). + Where("user_id = ?", userId). + Find(&shareMysList); err != nil { + return nil + } + for _, value := range shareMysList { + orderMap[value.OrderId] = value.OrderId + } + case flags.BotStockIdnTrade: + var shareIdnList []models.BotStockIdnTrade + if err := data.mysqlDB.Table(tableName). + Where("status = 1 or status = 0"). + Where("user_id = ?", userId). + Find(&shareIdnList); err != nil { + return nil + } + for _, value := range shareIdnList { + orderMap[value.OrderId] = value.OrderId + } + case flags.BotStockInTrade: + var shareInrList []models.BotStockInTrade + if err := data.mysqlDB.Table(tableName). + Where("status = 1 or status = 0"). + Where("user_id = ?", userId). + Find(&shareInrList); err != nil { + return nil + } + for _, value := range shareInrList { + orderMap[value.OrderId] = value.OrderId + } + case flags.BotStockSgdTrade: + var shareSgdList []models.BotStockSgdTrade + if err := data.mysqlDB.Table(tableName). + Where("status = 1 or status = 0"). + Where("user_id = ?", userId). + Find(&shareSgdList); err != nil { + return nil + } + for _, value := range shareSgdList { + orderMap[value.OrderId] = value.OrderId + } + case flags.BotStockHkdTrade: + var shareHkdList []models.BotStockHkdTrade + if err := data.mysqlDB.Table(tableName). + Where("status = 1 or status = 0"). + Where("user_id = ?", userId). + Find(&shareHkdList); err != nil { + return nil + } + for _, value := range shareHkdList { + orderMap[value.OrderId] = value.OrderId + } + default: + + } + + return orderMap +} + +// TradeListByStatus +// +// @Description: 查询市场持仓订单Id +// @param data +// @param tableName +// @return map[string]string +func TradeListByStatus(data *Data, tableName string) map[string]string { + orderMap := make(map[string]string) + switch tableName { + case flags.BotStockTrade: + var shareUsList []models.BotStockTrade + if err := data.mysqlDB.Table(tableName). + Where("status = 1 or status = 0"). + Find(&shareUsList); err != nil { + return nil + } + for _, value := range shareUsList { + orderMap[value.OrderId] = value.OrderId + } + case flags.BotStockThaTrade: + var shareThaList []models.BotStockThaTrade + if err := data.mysqlDB.Table(tableName). + Where("status = 1 or status = 0"). + Find(&shareThaList); err != nil { + return nil + } + for _, value := range shareThaList { + orderMap[value.OrderId] = value.OrderId + } + case flags.BotStockMysTrade: + var shareMysList []models.BotStockMysTrade + if err := data.mysqlDB.Table(tableName). + Where("status = 1 or status = 0"). + Find(&shareMysList); err != nil { + return nil + } + for _, value := range shareMysList { + orderMap[value.OrderId] = value.OrderId + } + case flags.BotStockIdnTrade: + var shareIdnList []models.BotStockIdnTrade + if err := data.mysqlDB.Table(tableName). + Where("status = 1 or status = 0"). + Find(&shareIdnList); err != nil { + return nil + } + for _, value := range shareIdnList { + orderMap[value.OrderId] = value.OrderId + } + case flags.BotStockInTrade: + var shareInrList []models.BotStockInTrade + if err := data.mysqlDB.Table(tableName). + Where("status = 1 or status = 0"). + Find(&shareInrList); err != nil { + return nil + } + for _, value := range shareInrList { + orderMap[value.OrderId] = value.OrderId + } + case flags.BotStockSgdTrade: + var shareSgdList []models.BotStockSgdTrade + if err := data.mysqlDB.Table(tableName). + Where("status = 1 or status = 0"). + Find(&shareSgdList); err != nil { + return nil + } + for _, value := range shareSgdList { + orderMap[value.OrderId] = value.OrderId + } + case flags.BotStockHkdTrade: + var shareHkdList []models.BotStockHkdTrade + if err := data.mysqlDB.Table(tableName). + Where("status = 1 or status = 0"). + Find(&shareHkdList); err != nil { + return nil + } + for _, value := range shareHkdList { + orderMap[value.OrderId] = value.OrderId + } + default: + + } + + return orderMap +} + +// RestoreClearCacheShareUs +// +// @Description: 美股订单缓存清理 +// @param data +func RestoreClearCacheShareUs(data *Data) { + //查询用户 + userArray := UserList(data) + // 清理用户订阅订单缓存 + for _, value := range userArray { + // 通过用户查询用户持仓订单 + orderMap := TradeListByUserId(data, flags.BotStockTrade, value.UserId) + keyCache := fmt.Sprintf("%v-%v", setting.ShareUsSubscribe, value.UserId) + cacheMap, err := data.redisDB.HGetAll(context.Background(), keyCache).Result() + if err != nil { + applogger.Error("查询用户%v美股市场,用户订单订阅缓存错误:%v", value.UserId, err) + return + } + for key, _ := range cacheMap { + _, ok := orderMap[key] + if !ok { + _, err = data.redisDB.HDel(context.Background(), keyCache, key).Result() + if err != nil { + applogger.Error("清理用户订阅缓存错误:%v", err) + return + } + } + } + } + // 清理市场持仓订单缓存 + allOrderMap := TradeListByStatus(data, flags.BotStockTrade) + positionKey := fmt.Sprintf("%v", setting.MarketShareUsPosition) + positionMap, err := data.redisDB.HGetAll(context.Background(), positionKey).Result() + if err != nil { + applogger.Error("查询美股市场持仓订单缓存失败:%v", err) + return + } + for key, _ := range positionMap { + _, ok := allOrderMap[key] + if !ok { + _, err = data.redisDB.HDel(context.Background(), positionKey, key).Result() + if err != nil { + applogger.Error("清理用户持仓订单缓存错误:%v", err) + return + } + } + } + // 清理管理员订单订阅缓存 + adminKey := fmt.Sprintf("%v", setting.AdminShareUsSubscribe) + adminMap, err := data.redisDB.HGetAll(context.Background(), adminKey).Result() + if err != nil { + applogger.Error("查询美股市场持仓订单缓存失败:%v", err) + return + } + for key, _ := range adminMap { + _, ok := allOrderMap[key] + if !ok { + _, err = data.redisDB.HDel(context.Background(), adminKey, key).Result() + if err != nil { + applogger.Error("清理用户持仓订单缓存错误:%v", err) + return + } + } + } +} + +// RestoreClearCacheShareTha +// +// @Description: 泰股订单缓存清理 +// @param data +func RestoreClearCacheShareTha(data *Data) { + //查询用户 + userArray := UserList(data) + // 清理用户订阅订单缓存 + for _, value := range userArray { + // 通过用户查询用户持仓订单 + orderMap := TradeListByUserId(data, flags.BotStockThaTrade, value.UserId) + keyCache := fmt.Sprintf("%v-%v", setting.ShareThaSubscribe, value.UserId) + cacheMap, err := data.redisDB.HGetAll(context.Background(), keyCache).Result() + if err != nil { + applogger.Error("查询用户%v泰股市场,用户订单订阅缓存错误:%v", value.UserId, err) + return + } + for key, _ := range cacheMap { + _, ok := orderMap[key] + if !ok { + _, err = data.redisDB.HDel(context.Background(), keyCache, key).Result() + if err != nil { + applogger.Error("清理用户订阅缓存错误:%v", err) + return + } + } + } + } + // 清理市场持仓订单缓存 + allOrderMap := TradeListByStatus(data, flags.BotStockThaTrade) + positionKey := fmt.Sprintf("%v", setting.MarketShareThaPosition) + positionMap, err := data.redisDB.HGetAll(context.Background(), positionKey).Result() + if err != nil { + applogger.Error("查询泰股市场持仓订单缓存失败:%v", err) + return + } + for key, _ := range positionMap { + _, ok := allOrderMap[key] + if !ok { + _, err = data.redisDB.HDel(context.Background(), positionKey, key).Result() + if err != nil { + applogger.Error("清理用户持仓订单缓存错误:%v", err) + return + } + } + } + // 清理管理员订单订阅缓存 + adminKey := fmt.Sprintf("%v", setting.AdminShareThaSubscribe) + adminMap, err := data.redisDB.HGetAll(context.Background(), adminKey).Result() + if err != nil { + applogger.Error("查询泰股市场持仓订单缓存失败:%v", err) + return + } + for key, _ := range adminMap { + _, ok := allOrderMap[key] + if !ok { + _, err = data.redisDB.HDel(context.Background(), adminKey, key).Result() + if err != nil { + applogger.Error("清理用户持仓订单缓存错误:%v", err) + return + } + } + } +} + +// RestoreClearCacheShareMys +// +// @Description: 马股订单缓存清理 +// @param data +func RestoreClearCacheShareMys(data *Data) { + //查询用户 + userArray := UserList(data) + // 清理用户订阅订单缓存 + for _, value := range userArray { + // 通过用户查询用户持仓订单 + orderMap := TradeListByUserId(data, flags.BotStockMysTrade, value.UserId) + keyCache := fmt.Sprintf("%v-%v", setting.ShareMysSubscribe, value.UserId) + cacheMap, err := data.redisDB.HGetAll(context.Background(), keyCache).Result() + if err != nil { + applogger.Error("查询用户%v马股市场,用户订单订阅缓存错误:%v", value.UserId, err) + return + } + for key, _ := range cacheMap { + _, ok := orderMap[key] + if !ok { + _, err = data.redisDB.HDel(context.Background(), keyCache, key).Result() + if err != nil { + applogger.Error("清理用户订阅缓存错误:%v", err) + return + } + } + } + } + // 清理市场持仓订单缓存 + allOrderMap := TradeListByStatus(data, flags.BotStockMysTrade) + positionKey := fmt.Sprintf("%v", setting.MarketShareMysPosition) + positionMap, err := data.redisDB.HGetAll(context.Background(), positionKey).Result() + if err != nil { + applogger.Error("查询马股市场持仓订单缓存失败:%v", err) + return + } + for key, _ := range positionMap { + _, ok := allOrderMap[key] + if !ok { + _, err = data.redisDB.HDel(context.Background(), positionKey, key).Result() + if err != nil { + applogger.Error("清理用户持仓订单缓存错误:%v", err) + return + } + } + } + // 清理管理员订单订阅缓存 + adminKey := fmt.Sprintf("%v", setting.AdminShareMysSubscribe) + adminMap, err := data.redisDB.HGetAll(context.Background(), adminKey).Result() + if err != nil { + applogger.Error("查询马股市场持仓订单缓存失败:%v", err) + return + } + for key, _ := range adminMap { + _, ok := allOrderMap[key] + if !ok { + _, err = data.redisDB.HDel(context.Background(), adminKey, key).Result() + if err != nil { + applogger.Error("清理用户持仓订单缓存错误:%v", err) + return + } + } + } +} + +// RestoreClearCacheShareIdn +// +// @Description: 印尼股订单缓存清理 +// @param data +func RestoreClearCacheShareIdn(data *Data) { + //查询用户 + userArray := UserList(data) + // 清理用户订阅订单缓存 + for _, value := range userArray { + // 通过用户查询用户持仓订单 + orderMap := TradeListByUserId(data, flags.BotStockIdnTrade, value.UserId) + keyCache := fmt.Sprintf("%v-%v", setting.ShareIdnSubscribe, value.UserId) + cacheMap, err := data.redisDB.HGetAll(context.Background(), keyCache).Result() + if err != nil { + applogger.Error("查询用户%v印尼股市场,用户订单订阅缓存错误:%v", value.UserId, err) + return + } + for key, _ := range cacheMap { + _, ok := orderMap[key] + if !ok { + _, err = data.redisDB.HDel(context.Background(), keyCache, key).Result() + if err != nil { + applogger.Error("清理用户订阅缓存错误:%v", err) + return + } + } + } + } + // 清理市场持仓订单缓存 + allOrderMap := TradeListByStatus(data, flags.BotStockIdnTrade) + positionKey := fmt.Sprintf("%v", setting.MarketShareIdnPosition) + positionMap, err := data.redisDB.HGetAll(context.Background(), positionKey).Result() + if err != nil { + applogger.Error("查询印尼股市场持仓订单缓存失败:%v", err) + return + } + for key, _ := range positionMap { + _, ok := allOrderMap[key] + if !ok { + _, err = data.redisDB.HDel(context.Background(), positionKey, key).Result() + if err != nil { + applogger.Error("清理用户持仓订单缓存错误:%v", err) + return + } + } + } + // 清理管理员订单订阅缓存 + adminKey := fmt.Sprintf("%v", setting.AdminShareIdnSubscribe) + adminMap, err := data.redisDB.HGetAll(context.Background(), adminKey).Result() + if err != nil { + applogger.Error("查询印尼股市场持仓订单缓存失败:%v", err) + return + } + for key, _ := range adminMap { + _, ok := allOrderMap[key] + if !ok { + _, err = data.redisDB.HDel(context.Background(), adminKey, key).Result() + if err != nil { + applogger.Error("清理用户持仓订单缓存错误:%v", err) + return + } + } + } +} + +// RestoreClearCacheShareInr +// +// @Description: 印度股订单缓存清理 +// @param data +func RestoreClearCacheShareInr(data *Data) { + //查询用户 + userArray := UserList(data) + // 清理用户订阅订单缓存 + for _, value := range userArray { + // 通过用户查询用户持仓订单 + orderMap := TradeListByUserId(data, flags.BotStockInTrade, value.UserId) + keyCache := fmt.Sprintf("%v-%v", setting.ShareInrSubscribe, value.UserId) + cacheMap, err := data.redisDB.HGetAll(context.Background(), keyCache).Result() + if err != nil { + applogger.Error("查询用户%v印度股市场,用户订单订阅缓存错误:%v", value.UserId, err) + return + } + for key, _ := range cacheMap { + _, ok := orderMap[key] + if !ok { + applogger.Error("用户:%v订阅垃圾订单:%v", value.UserId, key) + _, err = data.redisDB.HDel(context.Background(), keyCache, key).Result() + if err != nil { + applogger.Error("清理用户订阅缓存错误:%v", err) + return + } + } + } + } + time.Sleep(1 * time.Minute) + // 清理市场持仓订单缓存 + allOrderMap := TradeListByStatus(data, flags.BotStockInTrade) + positionKey := fmt.Sprintf("%v", setting.MarketShareInrPosition) + positionMap, err := data.redisDB.HGetAll(context.Background(), positionKey).Result() + if err != nil { + applogger.Error("查询印度股市场持仓订单缓存失败:%v", err) + return + } + for key, _ := range positionMap { + _, ok := allOrderMap[key] + if !ok { + applogger.Error("持仓垃圾订单:%v", key) + _, err = data.redisDB.HDel(context.Background(), positionKey, key).Result() + if err != nil { + applogger.Error("清理用户持仓订单缓存错误:%v", err) + return + } + } + } + time.Sleep(1 * time.Minute) + // 清理管理员订单订阅缓存 + adminKey := fmt.Sprintf("%v", setting.AdminShareInrSubscribe) + adminMap, err := data.redisDB.HGetAll(context.Background(), adminKey).Result() + if err != nil { + applogger.Error("查询印度股市场持仓订单缓存失败:%v", err) + return + } + for key, _ := range adminMap { + _, ok := allOrderMap[key] + if !ok { + applogger.Error("管理员持仓垃圾订单:%v", key) + _, err = data.redisDB.HDel(context.Background(), adminKey, key).Result() + if err != nil { + applogger.Error("清理用户持仓订单缓存错误:%v", err) + return + } + } + } +} + +// RestoreClearCacheShareSgd +// +// @Description: 新加坡股订单缓存清理 +// @param data +func RestoreClearCacheShareSgd(data *Data) { + //查询用户 + userArray := UserList(data) + // 清理用户订阅订单缓存 + for _, value := range userArray { + // 通过用户查询用户持仓订单 + orderMap := TradeListByUserId(data, flags.BotStockSgdTrade, value.UserId) + keyCache := fmt.Sprintf("%v-%v", setting.ShareSgdSubscribe, value.UserId) + cacheMap, err := data.redisDB.HGetAll(context.Background(), keyCache).Result() + if err != nil { + applogger.Error("查询用户%v新加坡股市场,用户订单订阅缓存错误:%v", value.UserId, err) + return + } + for key, _ := range cacheMap { + _, ok := orderMap[key] + if !ok { + _, err = data.redisDB.HDel(context.Background(), keyCache, key).Result() + if err != nil { + applogger.Error("清理用户订阅缓存错误:%v", err) + return + } + } + } + } + // 清理市场持仓订单缓存 + allOrderMap := TradeListByStatus(data, flags.BotStockSgdTrade) + positionKey := fmt.Sprintf("%v", setting.MarketShareSgdPosition) + positionMap, err := data.redisDB.HGetAll(context.Background(), positionKey).Result() + if err != nil { + applogger.Error("查询新加坡股市场持仓订单缓存失败:%v", err) + return + } + for key, _ := range positionMap { + _, ok := allOrderMap[key] + if !ok { + _, err = data.redisDB.HDel(context.Background(), positionKey, key).Result() + if err != nil { + applogger.Error("清理用户持仓订单缓存错误:%v", err) + return + } + } + } + // 清理管理员订单订阅缓存 + adminKey := fmt.Sprintf("%v", setting.AdminShareSgdSubscribe) + adminMap, err := data.redisDB.HGetAll(context.Background(), adminKey).Result() + if err != nil { + applogger.Error("查询新加坡股市场持仓订单缓存失败:%v", err) + return + } + for key, _ := range adminMap { + _, ok := allOrderMap[key] + if !ok { + _, err = data.redisDB.HDel(context.Background(), adminKey, key).Result() + if err != nil { + applogger.Error("清理用户持仓订单缓存错误:%v", err) + return + } + } + } +} + +// RestoreClearCacheShareHkd +// +// @Description: 港股订单缓存清理 +// @param data +func RestoreClearCacheShareHkd(data *Data) { + //查询用户 + userArray := UserList(data) + // 清理用户订阅订单缓存 + for _, value := range userArray { + // 通过用户查询用户持仓订单 + orderMap := TradeListByUserId(data, flags.BotStockHkdTrade, value.UserId) + keyCache := fmt.Sprintf("%v-%v", setting.ShareHkdSubscribe, value.UserId) + cacheMap, err := data.redisDB.HGetAll(context.Background(), keyCache).Result() + if err != nil { + applogger.Error("查询用户%v港股市场,用户订单订阅缓存错误:%v", value.UserId, err) + return + } + for key, _ := range cacheMap { + _, ok := orderMap[key] + if !ok { + _, err = data.redisDB.HDel(context.Background(), keyCache, key).Result() + if err != nil { + applogger.Error("清理用户订阅缓存错误:%v", err) + return + } + } + } + } + // 清理市场持仓订单缓存 + allOrderMap := TradeListByStatus(data, flags.BotStockHkdTrade) + positionKey := fmt.Sprintf("%v", setting.MarketShareHkdPosition) + positionMap, err := data.redisDB.HGetAll(context.Background(), positionKey).Result() + if err != nil { + applogger.Error("查询港股市场持仓订单缓存失败:%v", err) + return + } + for key, _ := range positionMap { + _, ok := allOrderMap[key] + if !ok { + _, err = data.redisDB.HDel(context.Background(), positionKey, key).Result() + if err != nil { + applogger.Error("清理用户持仓订单缓存错误:%v", err) + return + } + } + } + // 清理管理员订单订阅缓存 + adminKey := fmt.Sprintf("%v", setting.AdminShareHkdSubscribe) + adminMap, err := data.redisDB.HGetAll(context.Background(), adminKey).Result() + if err != nil { + applogger.Error("查询港股市场持仓订单缓存失败:%v", err) + return + } + for key, _ := range adminMap { + _, ok := allOrderMap[key] + if !ok { + _, err = data.redisDB.HDel(context.Background(), adminKey, key).Result() + if err != nil { + applogger.Error("清理用户持仓订单缓存错误:%v", err) + return + } + } + } +} diff --git a/internal/data/sms/sms.go b/internal/data/sms/sms.go new file mode 100644 index 0000000..e2934a6 --- /dev/null +++ b/internal/data/sms/sms.go @@ -0,0 +1,86 @@ +package sms + +import ( + "context" + "fmt" + "github.com/go-kratos/kratos/v2/log" + "matchmaking-system/internal/pkg/flags" + "math/rand" + "time" +) + +// ALiYunCase +// @Description: +type ALiYunCase struct { + aly ALiYunRepo + + log *log.Helper +} + +// ALiYunRepo +// @Description: +type ALiYunRepo interface { + SendVerificationCode(ctx context.Context, phoneNumber string) (string, error) + CheckVerificationCode(ctx context.Context, phoneNumber, verificationCode string) error + CheckVerificationCodeNew(ctx context.Context, phoneNumber string) (string, error) +} + +// NewMsgSend +// +// @Description: +// @param ur +// @param logger +// @return *ALiYunCase +func NewMsgSend(ur ALiYunRepo, logger log.Logger) *ALiYunCase { + return &ALiYunCase{aly: ur, log: log.NewHelper(logger)} +} + +// RunSendSms +// +// @Description: +// @receiver al +// @param ctx +// @param phoneNumber +// @return string +// @return error +func (al *ALiYunCase) RunSendSms(ctx context.Context, phoneNumber string) (string, error) { + code, err := al.aly.CheckVerificationCodeNew(ctx, phoneNumber) + if err != nil { + return err.Error(), err + } + + if len(code) > 0 { + return code, err + } + + // Request verification code + codeMsg, err := al.aly.SendVerificationCode(ctx, phoneNumber) + if err != nil { + return flags.SetNull, err + } + + return codeMsg, nil +} + +// CreateRandCode +// +// @Description: 创建6位随机数 +// @param ctx +// @return string +func CreateRandCode(ctx context.Context) string { + return fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000)) +} + +// CreateRandCodeFrom +// +// @Description: 创建一个10位随机数作为发送方 +// @param ctx +// @param n +// @return string +func CreateRandCodeFrom(ctx context.Context, n int) string { + code := flags.SetNull + for i := 0; i < n; i++ { + code = fmt.Sprintf("%s%d", code, rand.Intn(10)) + } + return code +} diff --git a/internal/data/sms/sms_test.go b/internal/data/sms/sms_test.go new file mode 100644 index 0000000..f6f099f --- /dev/null +++ b/internal/data/sms/sms_test.go @@ -0,0 +1,204 @@ +package sms + +import ( + "context" + "github.com/go-kratos/kratos/v2/log" + "reflect" + "testing" +) + +func TestALiYunCase_RunSendSms(t *testing.T) { + type fields struct { + aly ALiYunRepo + log *log.Helper + } + type args struct { + ctx context.Context + phoneNumber string + } + tests := []struct { + name string + fields fields + args args + want string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + al := &ALiYunCase{ + aly: tt.fields.aly, + log: tt.fields.log, + } + got, err := al.RunSendSms(tt.args.ctx, tt.args.phoneNumber) + if (err != nil) != tt.wantErr { + t.Errorf("RunSendSms() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("RunSendSms() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreateRandCode(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreateRandCode(tt.args.ctx); got != tt.want { + t.Errorf("CreateRandCode() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreateRandCodeFrom(t *testing.T) { + type args struct { + ctx context.Context + n int + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreateRandCodeFrom(tt.args.ctx, tt.args.n); got != tt.want { + t.Errorf("CreateRandCodeFrom() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestNewMsgSend(t *testing.T) { + type args struct { + ur ALiYunRepo + logger log.Logger + } + tests := []struct { + name string + args args + want *ALiYunCase + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewMsgSend(tt.args.ur, tt.args.logger); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewMsgSend() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestALiYunCase_RunSendSms1(t *testing.T) { + type fields struct { + aly ALiYunRepo + log *log.Helper + } + type args struct { + ctx context.Context + phoneNumber string + } + tests := []struct { + name string + fields fields + args args + want string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + al := &ALiYunCase{ + aly: tt.fields.aly, + log: tt.fields.log, + } + got, err := al.RunSendSms(tt.args.ctx, tt.args.phoneNumber) + if (err != nil) != tt.wantErr { + t.Errorf("RunSendSms() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("RunSendSms() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreateRandCode1(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreateRandCode(tt.args.ctx); got != tt.want { + t.Errorf("CreateRandCode() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCreateRandCodeFrom1(t *testing.T) { + type args struct { + ctx context.Context + n int + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CreateRandCodeFrom(tt.args.ctx, tt.args.n); got != tt.want { + t.Errorf("CreateRandCodeFrom() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestNewMsgSend1(t *testing.T) { + type args struct { + ur ALiYunRepo + logger log.Logger + } + tests := []struct { + name string + args args + want *ALiYunCase + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewMsgSend(tt.args.ur, tt.args.logger); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewMsgSend() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/data/socket/README.md b/internal/data/socket/README.md new file mode 100644 index 0000000..4198883 --- /dev/null +++ b/internal/data/socket/README.md @@ -0,0 +1,23 @@ +# WSS-Service + +### +``` +功能块: + 1、可见功能 + 1>用户订单订阅 + 2>管理员订单列表订阅 + 3>浮动盈亏自动化计算 + 1、wss服务功能(详细参见文档:http://g.jd66.cc:3001/project/56/interface/api/507) + 1>现货 + 2>合约 + 3>秒合约 + 4>美股 + 5>马股 + 6>泰股 + 7>印尼股 + 8>印度股 + 9>港股 + 10>新加坡股 + 11>新股申购 +``` +### \ No newline at end of file diff --git a/internal/data/socket/block_admin.go b/internal/data/socket/block_admin.go new file mode 100644 index 0000000..fc1cf61 --- /dev/null +++ b/internal/data/socket/block_admin.go @@ -0,0 +1,1172 @@ +package socket + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/data" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/socket/forexData" + "matchmaking-system/internal/data/socket/moneyData" + "matchmaking-system/internal/data/socket/optionData" + "matchmaking-system/internal/data/socket/shareData" + "matchmaking-system/internal/data/socket/virtualData" + forexd "matchmaking-system/internal/data/tradedeal/forex" + "matchmaking-system/internal/data/tradedeal/money" + "matchmaking-system/internal/data/tradedeal/option" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/setting" + "strconv" + "time" +) + +// orderSubAdminShareBlkSubscribeByOrder +// +// @Description: 管理员-大宗交易股|持仓订单订阅|持仓浮动盈亏订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubAdminShareBlkSubscribeByOrder(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.SubscribeAdminShareBlk { + var hashList []share.ShareBlkTallyCache + for _, field := range psgMsg.Order { + fieldStr, err := data.Reds.HGet(context.Background(), setting.AdminShareBlkSubscribe, field).Result() + if err != nil { + continue + } + var msg share.ShareBlkTallyCache + if err = json.Unmarshal([]byte(fieldStr), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + hashList = append(hashList, msg) + } + + for _, value := range hashList { + orderModel := shareData.ShareBlkOrderProcessing(setting.AdminShareBlkSubscribe, 1, value) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理[撤单|平仓]缓存队列 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + if err := data.Reds.HDel(context.Background(), setting.AdminShareBlkSubscribe, orderModel.OrderId).Err(); err != nil { + applogger.Error("AdminShareBlkSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("Administrator block stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("Administrator cancels block order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubAdminShareBlkSubscribeBySum(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareBlkSumSubscribe { + priceSum, err := memory.ShareBlkFloating.Get(flags.FloatingBlk) + if err != nil { + continue + } + + result := &SymbolSumResult{ + Symbol: psgMsg.Symbol, + Price: string(priceSum), + } + + priceByte, err := json.Marshal(result) + if err != nil { + continue + } + + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + u.msg <- priceByte + } else { + applogger.Info("Administrator cancels block stock order subscription.") + return + } + } + + time.Sleep(1 * time.Second) + } +} + +// orderSubAdminUserShareSubscribeBySum +// +// @Description: 管理员用户[美股订单|马股订单|泰股订单|印尼股订单|印度股订单|新加坡股订单|港股订单|期权股订单|大宗股订单]持仓总浮动盈亏 +// @receiver u +// @param psgMsg +func (u *Client) orderSubAdminUserShareSubscribeBySum(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareUserSumSubscribe { + userSumPrice := make(map[int64]decimal.Decimal) + + // 统计用户总浮动盈亏 + for _, value := range psgMsg.Order { + uid, err := strconv.Atoi(value) + if err != nil { + continue + } + userId := int64(uid) + // 用户美股订单持仓总浮动盈亏 + usPriceSum := GetShareUsByPriceSum(userId, setting.AdminShareUsSubscribe) + // 用户马股订单持仓总浮动盈亏 + mysPriceSum := GetShareMysByPriceSum(userId, setting.AdminShareMysSubscribe) + // 用户泰股订单持仓总浮动盈亏 + thaPriceSum := GetShareThaByPriceSum(userId, setting.AdminShareThaSubscribe) + // 用户印尼股订单持仓总浮动盈亏 + idnPriceSum := GetShareIdnByPriceSum(userId, setting.AdminShareIdnSubscribe) + // 用户印度股订单持仓总浮动盈亏 + inrPriceSum := GetShareInrByPriceSum(userId, setting.AdminShareInrSubscribe) + // 用户新加坡股订单持仓总浮动盈亏 + sgdPriceSum := GetShareSgdByPriceSum(userId, setting.AdminShareSgdSubscribe) + // 用户德股订单持仓总浮动盈亏 + eurPriceSum := GetShareEurByPriceSum(userId, setting.AdminShareEurSubscribe) + // 用户巴西股订单持仓总浮动盈亏 + brlPriceSum := GetShareBrlByPriceSum(userId, setting.AdminShareBrlSubscribe) + // 用户法股订单持仓总浮动盈亏 + furPriceSum := GetShareFurByPriceSum(userId, setting.AdminShareFurSubscribe) + // 用户日股订单持仓总浮动盈亏 + jpyPriceSum := GetShareJpyByPriceSum(userId, setting.AdminShareJpySubscribe) + // 用户英股订单持仓总浮动盈亏 + gbxPriceSum := GetShareGbxByPriceSum(userId, setting.AdminShareGbxSubscribe) + // 用户港股订单持仓总浮动盈亏 + hkdPriceSum := GetShareHkdByPriceSum(userId, setting.AdminShareHkdSubscribe) + // 用户大宗股订单持仓总浮动盈亏 + blkPriceSum := GetShareBlkByPriceSum(userId, setting.AdminShareBlkSubscribe) + // 用户外汇股订单持仓总浮动盈亏 + forexPriceSum := GetForexByPriceSum(userId, setting.AdminForexSubscribe) + // 用户印度期权订单持仓总浮动盈亏 + optionInrPriceSum := GetShareOptionInrByPriceSum(userId) + + userSumPrice[userId] = usPriceSum.Add(mysPriceSum).Add(thaPriceSum). + Add(idnPriceSum).Add(inrPriceSum).Add(sgdPriceSum). + Add(hkdPriceSum).Add(blkPriceSum).Add(optionInrPriceSum). + Add(gbxPriceSum).Add(eurPriceSum).Add(furPriceSum). + Add(brlPriceSum).Add(jpyPriceSum).Add(forexPriceSum) + } + + result := &SymbolUserSumResult{ + Symbol: psgMsg.Symbol, + UserSumPrice: userSumPrice, + } + + priceByte, err := json.Marshal(result) + if err != nil { + applogger.Error("orderSubAdminUserShareSubscribeBySum json Marshal err:%v", err) + continue + } + + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + u.msg <- priceByte + } else { + applogger.Error("Administrator cancels block stock order subscription.") + return + } + } + + time.Sleep(1 * time.Second) + } +} + +// GetShareData +// +// @Description: 查询用户美股订单总浮动盈亏 +// @param userid +// @param shareKey +// @return decimal.Decimal +func GetShareUsByPriceSum(userid int64, topIc string) decimal.Decimal { + shareKey := fmt.Sprintf("%v-%v", setting.ShareUsSubscribe, userid) + hashMap, err := data.Reds.HGetAll(context.Background(), shareKey).Result() + if err != nil { + applogger.Error("GetShareData.HGetAll:%v", err) + return decimal.Zero + } + + var priceSum decimal.Decimal + for _, value := range hashMap { + var msg share.ShareUsTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + continue + } + if msg.Status == flags.Position { + orderModel := shareData.ShareUsOrderProcessing(topIc, msg) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch msg.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + orderNumber := decimal.RequireFromString(orderModel.OrderNumber) // 订单量 + price := subPrice.Mul(orderNumber) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + } + + return priceSum +} + +// GetShareThaByPriceSum +// +// @Description: 查询用户泰股订单总浮动盈亏 +// @param userid +// @param topIc +// @return decimal.Decimal +func GetShareThaByPriceSum(userid int64, topIc string) decimal.Decimal { + shareKey := fmt.Sprintf("%v-%v", setting.ShareThaSubscribe, userid) + hashMap, err := data.Reds.HGetAll(context.Background(), shareKey).Result() + if err != nil { + applogger.Error("GetShareData.HGetAll:%v", err) + return decimal.Zero + } + + var priceSum decimal.Decimal + for _, value := range hashMap { + var msg share.ShareThaTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + continue + } + if msg.Status == flags.Position { + orderModel := shareData.ShareThaOrderProcessing(topIc, msg) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch msg.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + orderNumber := decimal.RequireFromString(orderModel.OrderNumber) // 订单量 + price := subPrice.Mul(orderNumber) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + } + + return priceSum +} + +// GetShareMysByPriceSum +// +// @Description: 查询用户马股订单总浮动盈亏 +// @param userid +// @param topIc +// @return decimal.Decimal +func GetShareMysByPriceSum(userid int64, topIc string) decimal.Decimal { + shareKey := fmt.Sprintf("%v-%v", setting.ShareMysSubscribe, userid) + hashMap, err := data.Reds.HGetAll(context.Background(), shareKey).Result() + if err != nil { + applogger.Error("GetShareData.HGetAll:%v", err) + return decimal.Zero + } + + var priceSum decimal.Decimal + for _, value := range hashMap { + var msg share.ShareMysTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + continue + } + if msg.Status == flags.Position { + orderModel := shareData.ShareMysOrderProcessing(topIc, msg) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch msg.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + orderNumber := decimal.RequireFromString(orderModel.OrderNumber) // 订单量 + price := subPrice.Mul(orderNumber) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + } + + return priceSum +} + +// GetShareIdnByPriceSum +// +// @Description: 查询用户印尼股订单总浮动盈亏 +// @param userid +// @param topIc +// @return decimal.Decimal +func GetShareIdnByPriceSum(userid int64, topIc string) decimal.Decimal { + shareKey := fmt.Sprintf("%v-%v", setting.ShareIdnSubscribe, userid) + hashMap, err := data.Reds.HGetAll(context.Background(), shareKey).Result() + if err != nil { + applogger.Error("GetShareData.HGetAll:%v", err) + return decimal.Zero + } + + var priceSum decimal.Decimal + for _, value := range hashMap { + var msg share.ShareIdnTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + continue + } + if msg.Status == flags.Position { + orderModel := shareData.ShareIdnOrderProcessing(topIc, msg) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch msg.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + orderNumber := decimal.RequireFromString(orderModel.OrderNumber) // 订单量 + price := subPrice.Mul(orderNumber) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + } + + return priceSum +} + +// GetShareInrByPriceSum +// +// @Description: 查询用户印度股订单总浮动盈亏 +// @param userid +// @param topIc +// @return decimal.Decimal +func GetShareInrByPriceSum(userid int64, topIc string) decimal.Decimal { + shareKey := fmt.Sprintf("%v-%v", setting.ShareInrSubscribe, userid) + hashMap, err := data.Reds.HGetAll(context.Background(), shareKey).Result() + if err != nil { + applogger.Error("GetShareData.HGetAll:%v", err) + return decimal.Zero + } + + var priceSum decimal.Decimal + for _, value := range hashMap { + var msg share.ShareInrTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + continue + } + if msg.Status == flags.Position { + orderModel := shareData.ShareInrOrderProcessing(topIc, msg) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch msg.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + orderNumber := decimal.RequireFromString(orderModel.OrderNumber) // 订单量 + price := subPrice.Mul(orderNumber) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + } + + return priceSum +} + +// GetShareSgdByPriceSum +// +// @Description: 查询用户新加坡股订单总浮动盈亏 +// @param userid +// @param topIc +// @return decimal.Decimal +func GetShareSgdByPriceSum(userid int64, topIc string) decimal.Decimal { + shareKey := fmt.Sprintf("%v-%v", setting.ShareSgdSubscribe, userid) + hashMap, err := data.Reds.HGetAll(context.Background(), shareKey).Result() + if err != nil { + applogger.Error("GetShareData.HGetAll:%v", err) + return decimal.Zero + } + + var priceSum decimal.Decimal + for _, value := range hashMap { + var msg share.ShareSgdTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + continue + } + if msg.Status == flags.Position { + orderModel := shareData.ShareSgdOrderProcessing(topIc, msg) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch msg.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + orderNumber := decimal.RequireFromString(orderModel.OrderNumber) // 订单量 + price := subPrice.Mul(orderNumber) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + } + + return priceSum +} + +// GetShareFurByPriceSum +// +// @Description: 查询用户法股订单总浮动盈亏 +// @param userid +// @param topIc +// @return decimal.Decimal +func GetShareFurByPriceSum(userid int64, topIc string) decimal.Decimal { + shareKey := fmt.Sprintf("%v-%v", setting.ShareFurSubscribe, userid) + hashMap, err := data.Reds.HGetAll(context.Background(), shareKey).Result() + if err != nil { + applogger.Error("GetShareFurByPriceSum.HGetAll:%v", err) + return decimal.Zero + } + + var priceSum decimal.Decimal + for _, value := range hashMap { + var msg share.ShareFurTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + continue + } + if msg.Status == flags.Position { + orderModel := shareData.ShareFurOrderProcessing(topIc, msg) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch msg.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + orderNumber := decimal.RequireFromString(orderModel.OrderNumber) // 订单量 + price := subPrice.Mul(orderNumber) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + } + + return priceSum +} + +// GetShareJpyByPriceSum +// +// @Description: 查询用户日股订单总浮动盈亏 +// @param userid +// @param topIc +// @return decimal.Decimal +func GetShareJpyByPriceSum(userid int64, topIc string) decimal.Decimal { + shareKey := fmt.Sprintf("%v-%v", setting.ShareJpySubscribe, userid) + hashMap, err := data.Reds.HGetAll(context.Background(), shareKey).Result() + if err != nil { + applogger.Error("GetShareJpyByPriceSum.HGetAll:%v", err) + return decimal.Zero + } + + var priceSum decimal.Decimal + for _, value := range hashMap { + var msg share.ShareJpyTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + continue + } + if msg.Status == flags.Position { + orderModel := shareData.ShareJpyOrderProcessing(topIc, msg) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch msg.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + orderNumber := decimal.RequireFromString(orderModel.OrderNumber) // 订单量 + price := subPrice.Mul(orderNumber) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + } + + return priceSum +} + +// GetShareEurByPriceSum +// +// @Description: 查询用户德股订单总浮动盈亏 +// @param userid +// @param topIc +// @return decimal.Decimal +func GetShareEurByPriceSum(userid int64, topIc string) decimal.Decimal { + shareKey := fmt.Sprintf("%v-%v", setting.ShareEurSubscribe, userid) + hashMap, err := data.Reds.HGetAll(context.Background(), shareKey).Result() + if err != nil { + applogger.Error("GetShareEurByPriceSum.HGetAll:%v", err) + return decimal.Zero + } + + var priceSum decimal.Decimal + for _, value := range hashMap { + var msg share.ShareEurTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + continue + } + if msg.Status == flags.Position { + orderModel := shareData.ShareEurOrderProcessing(topIc, msg) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch msg.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + orderNumber := decimal.RequireFromString(orderModel.OrderNumber) // 订单量 + price := subPrice.Mul(orderNumber) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + } + + return priceSum +} + +// GetShareBrlByPriceSum +// +// @Description: 查询用户巴西股订单总浮动盈亏 +// @param userid +// @param topIc +// @return decimal.Decimal +func GetShareBrlByPriceSum(userid int64, topIc string) decimal.Decimal { + shareKey := fmt.Sprintf("%v-%v", setting.ShareBrlSubscribe, userid) + hashMap, err := data.Reds.HGetAll(context.Background(), shareKey).Result() + if err != nil { + applogger.Error("GetShareBrlByPriceSum.HGetAll:%v", err) + return decimal.Zero + } + + var priceSum decimal.Decimal + for _, value := range hashMap { + var msg share.ShareBrlTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + continue + } + if msg.Status == flags.Position { + orderModel := shareData.ShareBrlOrderProcessing(topIc, msg) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch msg.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + orderNumber := decimal.RequireFromString(orderModel.OrderNumber) // 订单量 + price := subPrice.Mul(orderNumber) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + } + + return priceSum +} + +// GetShareGbxByPriceSum +// +// @Description: 查询用户英股订单总浮动盈亏 +// @param userid +// @param topIc +// @return decimal.Decimal +func GetShareGbxByPriceSum(userid int64, topIc string) decimal.Decimal { + shareKey := fmt.Sprintf("%v-%v", setting.ShareGbxSubscribe, userid) + hashMap, err := data.Reds.HGetAll(context.Background(), shareKey).Result() + if err != nil { + applogger.Error("GetShareGbxByPriceSum.HGetAll:%v", err) + return decimal.Zero + } + + var priceSum decimal.Decimal + for _, value := range hashMap { + var msg share.ShareGbxTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + continue + } + if msg.Status == flags.Position { + orderModel := shareData.ShareGbxOrderProcessing(topIc, msg) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch msg.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + orderNumber := decimal.RequireFromString(orderModel.OrderNumber) // 订单量 + price := subPrice.Mul(orderNumber) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + } + + return priceSum +} + +// GetShareHkdByPriceSum +// +// @Description: 查询用户港股订单总浮动盈亏 +// @param userid +// @param topIc +// @return decimal.Decimal +func GetShareHkdByPriceSum(userid int64, topIc string) decimal.Decimal { + shareKey := fmt.Sprintf("%v-%v", setting.ShareHkdSubscribe, userid) + hashMap, err := data.Reds.HGetAll(context.Background(), shareKey).Result() + if err != nil { + applogger.Error("GetShareData.HGetAll:%v", err) + return decimal.Zero + } + + var priceSum decimal.Decimal + for _, value := range hashMap { + var msg share.ShareHkdTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + continue + } + if msg.Status == flags.Position { + orderModel := shareData.ShareHkdOrderProcessing(topIc, 0, msg) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch msg.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + orderNumber := decimal.RequireFromString(orderModel.OrderNumber) // 订单量 + price := subPrice.Mul(orderNumber) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + } + + return priceSum +} + +// GetShareBlkByPriceSum +// +// @Description: 查询用户大宗股订单总浮动盈亏 +// @param userid +// @param topIc +// @return decimal.Decimal +func GetShareBlkByPriceSum(userid int64, topIc string) decimal.Decimal { + shareKey := fmt.Sprintf("%v-%v", setting.ShareBlkSubscribe, userid) + hashMap, err := data.Reds.HGetAll(context.Background(), shareKey).Result() + if err != nil { + applogger.Error("GetShareData.HGetAll:%v", err) + return decimal.Zero + } + + var priceSum decimal.Decimal + for _, value := range hashMap { + var msg share.ShareBlkTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + continue + } + if msg.Status == flags.Position { + orderModel := shareData.ShareBlkOrderProcessing(topIc, 1, msg) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch msg.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + orderNumber := decimal.RequireFromString(orderModel.OrderNumber) // 订单量 + price := subPrice.Mul(orderNumber) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + } + + return priceSum +} + +// GetShareOptionInrByPriceSum +// +// @Description: 查询用户印度期权股订单总浮动盈亏 +// @param userid +// @return decimal.Decimal +func GetShareOptionInrByPriceSum(userid int64) decimal.Decimal { + shareKey := fmt.Sprintf("%v-%v", setting.OptionInrSubscribe, userid) + hashMap, err := data.Reds.HGetAll(context.Background(), shareKey).Result() + if err != nil { + applogger.Error("GetShareData.HGetAll:%v", err) + return decimal.Zero + } + + var priceSum decimal.Decimal + for _, value := range hashMap { + var msg option.OptionInrTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + continue + } + if msg.Status == flags.Position { + orderModel := optionData.OptionInrOrderProcessing(1, msg) + if orderModel != nil { + var newPrice, openPrice, orderNumber, subPrice, resultPrice decimal.Decimal + newPrice, err = decimal.NewFromString(orderModel.Price) // 股票实时价格 + if err != nil { + continue + } + openPrice, err = decimal.NewFromString(orderModel.OpenPrice) // 订单开仓价格 + if err != nil { + continue + } + orderNumber = decimal.RequireFromString(orderModel.OrderNumber) // 订单量 + subPrice = OptionResultPrice(msg.Order.TradeType, msg.Order.TradingType, openPrice, newPrice) // 计算浮动盈亏 + resultPrice = subPrice.Mul(orderNumber) // 计算订单浮动总盈亏 + priceSum = priceSum.Add(resultPrice) // 累加盈亏统计 + } + } + } + + return priceSum +} + +// OptionResultPrice +// +// @Description: 查询用户印度期权股订单浮动盈亏 +// @param tradeType +// @param tradingType +// @param openPrice +// @param newPrice +// @return decimal.Decimal +func OptionResultPrice(tradeType, tradingType int64, openPrice, newPrice decimal.Decimal) decimal.Decimal { + //浮动盈亏(P/L) + //1>buy call & buy put + // 1> bid买一价为0, P/L显示为 - + // 2> bid买一价大于0, P/L =(bid买一价 - Cost Price)*Contracts Quantity + //2>sell call & sell put + // 1> ask卖一价为0, P/L显示为 - + // 2> ask卖一价大于0, P/L =(Cost Price - ASK卖一价)*Contracts Quantity + var subPrice decimal.Decimal + switch tradeType { + case flags.OptionCalls: // Call + switch tradingType { + case flags.OptionBuy: // buy - call + subPrice = newPrice.Sub(openPrice) + case flags.OptionSell: // sell - call + subPrice = openPrice.Sub(newPrice) + } + case flags.OptionPuts: // PUT + switch tradingType { + case flags.OptionBuy: // buy - put + subPrice = newPrice.Sub(openPrice) + case flags.OptionSell: // sell - put + subPrice = openPrice.Sub(newPrice) + } + default: + subPrice = decimal.Zero + } + return subPrice +} + +// GetShareBlkByPriceSum +// +// @Description: 查询用户外汇股订单总浮动盈亏 +// @param userid +// @param topIc +// @return decimal.Decimal +func GetForexByPriceSum(userid int64, topIc string) decimal.Decimal { + shareKey := fmt.Sprintf("%v-%v", setting.ForexSubscribe, userid) + hashMap, err := data.Reds.HGetAll(context.Background(), shareKey).Result() + if err != nil { + applogger.Error("GetShareGbxByPriceSum.HGetAll:%v", err) + return decimal.Zero + } + + var priceSum decimal.Decimal + for _, value := range hashMap { + var msg forexd.ForexTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + continue + } + if msg.Status == flags.Position { + orderModel := forexData.ForexOrderProcessing(topIc, msg) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch msg.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + orderNumber := decimal.RequireFromString(msg.Order.OrderNumber) + pryNum := decimal.RequireFromString(msg.Order.PryNum) + price := subPrice.Mul(orderNumber).Mul(pryNum) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + } + + return priceSum +} + +// GetMoneyByPriceSum +// +// @Description: 查询用户综合(现货|合约|外汇)订单总浮动盈亏 +// @param userid +// @param topIc +// @return decimal.Decimal +func GetMoneyByPriceSum(userid int64, topIc string) decimal.Decimal { + shareKey := fmt.Sprintf("%v-%v", setting.MoneySubscribe, userid) + hashMap, err := data.Reds.HGetAll(context.Background(), shareKey).Result() + if err != nil { + applogger.Error("GetMoneyByPriceSum.HGetAll:%v", err) + return decimal.Zero + } + + var priceSum decimal.Decimal + for _, value := range hashMap { + var msg money.MoneyTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + continue + } + if msg.Status == flags.Position { + orderModel := moneyData.MoneyOrderProcessing(topIc, msg) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch msg.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + orderNumber := decimal.RequireFromString(msg.Order.OrderNumber) + pryNum := decimal.RequireFromString(msg.Order.PryNum) + price := subPrice.Mul(orderNumber).Mul(pryNum) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + } + + return priceSum +} + +// GetSpotsByPriceSum +// +// @Description: 查询用户现货订单总浮动盈亏 +// @param userid +// @param topIc +// @return decimal.Decimal +func GetSpotsByPriceSum(userid int64, topIc string) decimal.Decimal { + shareKey := fmt.Sprintf("%v-%v", setting.SpotsSubscribe, userid) + hashMap, err := data.Reds.HGetAll(context.Background(), shareKey).Result() + if err != nil { + applogger.Error("GetSpotsByPriceSum.HGetAll:%v", err) + return decimal.Zero + } + + var priceSum decimal.Decimal + for _, value := range hashMap { + var msg virtual.SpotsTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + continue + } + if msg.Status == flags.Position { + _, orderModel := virtualData.SpotOrderProcessing(topIc, msg) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch msg.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + orderNumber := decimal.RequireFromString(msg.Order.OrderNumber) + price := subPrice.Mul(orderNumber) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + } + + return priceSum +} + +// GetContractByPriceSum +// +// @Description: 查询用户合约订单总浮动盈亏 +// @param userid +// @param topIc +// @return decimal.Decimal +func GetContractByPriceSum(userid int64, topIc string) decimal.Decimal { + shareKey := fmt.Sprintf("%v-%v", setting.ContractSubscribe, userid) + hashMap, err := data.Reds.HGetAll(context.Background(), shareKey).Result() + if err != nil { + applogger.Error("GetContractByPriceSum.HGetAll:%v", err) + return decimal.Zero + } + + var priceSum decimal.Decimal + for _, value := range hashMap { + var msg virtual.ContractTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + continue + } + if msg.Status == flags.Position { + orderModel := virtualData.ContractOrderProcessing(topIc, msg) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch msg.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + orderNumber := decimal.RequireFromString(msg.Order.OrderNumber) + pryNum := decimal.RequireFromString(msg.Order.PryNum) + price := subPrice.Mul(orderNumber).Mul(pryNum) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + } + + return priceSum +} + +// GetSecondByPriceSum +// +// @Description: 查询用户秒合约订单总浮动盈亏 +// @param userid +// @param topIc +// @return decimal.Decimal +func GetSecondByPriceSum(userid int64, topIc string) decimal.Decimal { + shareKey := fmt.Sprintf("%v-%v", setting.SecondSubscribe, userid) + hashMap, err := data.Reds.HGetAll(context.Background(), shareKey).Result() + if err != nil { + applogger.Error("GetSecondByPriceSum.HGetAll:%v", err) + return decimal.Zero + } + + var priceSum decimal.Decimal + for _, value := range hashMap { + var msg virtual.ContractTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + continue + } + if msg.Status == flags.Position { + orderModel := virtualData.SecondOrderProcessing(topIc, msg) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch msg.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + orderNumber := decimal.RequireFromString(msg.Order.OrderNumber) + pryNum := decimal.RequireFromString(msg.Order.PryNum) + price := subPrice.Mul(orderNumber).Mul(pryNum) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + } + + return priceSum +} diff --git a/internal/data/socket/block_user.go b/internal/data/socket/block_user.go new file mode 100644 index 0000000..d3f5c65 --- /dev/null +++ b/internal/data/socket/block_user.go @@ -0,0 +1,74 @@ +package socket + +import ( + "context" + "encoding/json" + "matchmaking-system/internal/data" + "matchmaking-system/internal/data/socket/shareData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/setting" + "time" +) + +// orderSubShareHkdSubscribe +// +// @Description: 用户大宗交易股订单订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubShareBlkSubscribe(psgMsg *SymbolMessage) { + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.SubscribeShareBlk { + orderTokenKey := virtual.OrderIdListKey(setting.ShareBlkSubscribe, userId) + orderList, err := data.Reds.HGetAll(context.Background(), orderTokenKey).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + + for _, value := range orderList { + var msg share.ShareBlkTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + orderModel := shareData.ShareBlkOrderProcessing(setting.ShareBlkSubscribe, 0, msg) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理股票股订阅缓存订单中(撤单|平仓)状态的订单 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + err = data.Reds.HDel(context.Background(), orderTokenKey, msg.OrderId).Err() + if err != nil { + time.Sleep(5 * time.Second) + applogger.Error("ShareBlkSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User's block stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("User cancels block stock order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} diff --git a/internal/data/socket/forexData/forex.go b/internal/data/socket/forexData/forex.go new file mode 100644 index 0000000..f47ffae --- /dev/null +++ b/internal/data/socket/forexData/forex.go @@ -0,0 +1,42 @@ +package forexData + +import ( + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/forex" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" +) + +// ForexOrderProcessing +// +// @Description: 外汇订单订阅处理 +// @param topIc +// @param msg +// @return *public.OrderSub +func ForexOrderProcessing(topIc string, msg forex.ForexTallyCache) *publicData.OrderSub { + price, err := publicData.CheckForexImmediateSymbol(topIc, msg.Symbol, msg.Order.TradeType) + if err != nil { + applogger.Warn("%v ForexOrderProcessing.CheckSymbol.err:%v--%v", common.ErrForex, msg.Symbol, err) + } + + var faceValue string + if msg.Order.System != nil { + faceValue = msg.Order.System.FaceValue.String() + } + + orderM := &publicData.OrderSub{ + OrderId: msg.OrderId, + Price: price, + Status: msg.Status, + Symbol: topIc, + Count: 0, + OpenPrice: msg.OpenPrice, + Market: msg.Symbol, + OrderNumber: msg.Order.OrderNumber, + TradeType: msg.Order.TradeType, + FaceValue: faceValue, + UserId: msg.UserId, + } + + return orderM +} diff --git a/internal/data/socket/forex_admin.go b/internal/data/socket/forex_admin.go new file mode 100644 index 0000000..466d750 --- /dev/null +++ b/internal/data/socket/forex_admin.go @@ -0,0 +1,98 @@ +package socket + +import ( + "context" + "encoding/json" + "matchmaking-system/internal/data" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/socket/forexData" + "matchmaking-system/internal/data/tradedeal/forex" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/setting" + "time" +) + +// orderSubAdminForexSubscribeByOrder +// +// @Description: 管理员外汇|持仓订单订阅|持仓浮动盈亏订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubAdminForexSubscribeByOrder(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminForexSubscribe { + var hashList []forex.ForexTallyCache + for _, field := range psgMsg.Order { + fieldStr, err := data.Reds.HGet(context.Background(), setting.AdminForexSubscribe, field).Result() + if err != nil { + continue + } + var msg forex.ForexTallyCache + if err = json.Unmarshal([]byte(fieldStr), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + hashList = append(hashList, msg) + } + + for _, value := range hashList { + orderModel := forexData.ForexOrderProcessing(setting.AdminForexSubscribe, value) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理[撤单|平仓]缓存队列 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + if err := data.Reds.HDel(context.Background(), setting.AdminForexSubscribe, orderModel.OrderId).Err(); err != nil { + applogger.Error("AdminForexSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("Administrator Forex subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("Administrator cancels Forex order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubAdminForexSubscribeBySum(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminForexSumSubscribe { + priceSum, err := memory.ForexFloating.Get(flags.FloatingWh) + if err != nil { + continue + } + + result := &SymbolSumResult{ + Symbol: psgMsg.Symbol, + Price: string(priceSum), + } + + priceByte, err := json.Marshal(result) + if err != nil { + continue + } + + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + u.msg <- priceByte + } else { + applogger.Info("Administrator cancels Forex order subscription.") + return + } + } + + time.Sleep(2 * time.Second) + } +} diff --git a/internal/data/socket/forex_user.go b/internal/data/socket/forex_user.go new file mode 100644 index 0000000..42e0215 --- /dev/null +++ b/internal/data/socket/forex_user.go @@ -0,0 +1,185 @@ +package socket + +import ( + "context" + "encoding/json" + "github.com/shopspring/decimal" + "matchmaking-system/internal/data" + "matchmaking-system/internal/data/socket/forexData" + "matchmaking-system/internal/data/tradedeal/forex" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + models "matchmaking-system/internal/pkg/model" + "matchmaking-system/internal/pkg/setting" + "strconv" + "time" +) + +// orderSubForexSubscribe +// +// @Description: 用户外汇订单订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubForexSubscribe(psgMsg *SymbolMessage) { + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ForexSubscribe { + orderTokenKey := virtual.OrderIdListKey(setting.ForexSubscribe, userId) // 获取订阅Key + orderList, err := data.Reds.HGetAll(context.Background(), orderTokenKey).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + + for _, value := range orderList { + var msg forex.ForexTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + orderModel := forexData.ForexOrderProcessing(setting.ForexSubscribe, msg) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理合约订阅缓存订单中(撤单|平仓)状态的订单 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + err = data.Reds.HDel(context.Background(), orderTokenKey, msg.OrderId).Err() + if err != nil { + time.Sleep(5 * time.Second) + applogger.Error("ForexSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("orderSubForexSubscribe.Marshal:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户外汇(挂单|持仓)订阅 + } else { + applogger.Info("User cancels Forex order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubShareForexMarketSubscribe(psgMsg *SymbolMessage) { + var n int + var MarketForexCache decimal.Decimal // 缓存记录 + var marketProfitAndLoss decimal.Decimal // 用户市场累计盈亏 + var marketTotalFee decimal.Decimal // 用户市场总手续费 + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareForexMarketSubscribe { + var marketTotalAssets decimal.Decimal // 用户市场总资产 + var marketAvailable decimal.Decimal // 用户市场可用 + var marketFreeze decimal.Decimal // 用户市场冻结 + var marketFloatingPL decimal.Decimal // 用户市场总浮动盈亏 + + // 统计用户市场可用余额和冻结余额 + var botUserForex []models.BotUserForex + err = data.Msql.Table(flags.BotUserForex).Where("user_id = ?", userId).Where("contract_id = ?", flags.ForexUnit).Find(&botUserForex) + if err != nil { + marketAvailable = decimal.Zero + marketFreeze = decimal.Zero + } + for _, value := range botUserForex { + marketAvailable = decimal.RequireFromString(value.UsableNum) + marketFreeze = decimal.RequireFromString(value.FrozenNum) + } + // 判定是否存在订单 + if marketAvailable.IsZero() || marketFreeze.IsZero() { + if n == 0 { + tradeCount, _ := data.Msql.Table(flags.BotForexTrade).Where("user_id = ?", userId).In("status", 1, 3).Count() + if tradeCount > 0 { + n = 1 + } + } + } + if marketAvailable.Cmp(MarketForexCache) != 0 || n == 1 { + // 统计用户市场累计盈亏 + var botForexTrade []models.BotForexTrade + err = data.Msql.Table(flags.BotForexTrade).Where("user_id = ?", userId).Where("status = 3").Find(&botForexTrade) + if err != nil { + marketProfitAndLoss = decimal.Zero + } + for key, value := range botForexTrade { + sumValue := decimal.Zero + openPrice := decimal.RequireFromString(value.DealPrice) + closePrice := decimal.RequireFromString(value.ClosingPrice) + orderNum := decimal.RequireFromString(value.OrderNumber) + pryNum := decimal.RequireFromString(strconv.Itoa(value.PryNum)) + switch value.TradeType { + case 1: // 买张 + sumValue = closePrice.Sub(openPrice) + case 2: // 买跌 + sumValue = openPrice.Sub(closePrice) + default: + continue + } + profLass := sumValue.Mul(orderNum).Mul(pryNum) + applogger.Error("第一个:%v,买涨还是买跌:%v,开仓价:%v,平仓价:%v,订单量:%v,杠杆:%v,盈亏:%v", key, value.TradeType, openPrice, closePrice, orderNum, pryNum, profLass) + marketProfitAndLoss = marketProfitAndLoss.Add(profLass) + } + // 统计用户市场总手续费 + var botForexTradeFee models.BotForexTrade + totalFee, err := data.Msql.Table(flags.BotForexTrade).Where("user_id = ?", userId).In("status", 1, 3).Sums(botForexTradeFee, "service_cost", "closing_cost") + if err != nil || len(totalFee) != 2 { + marketTotalFee = decimal.Zero + } + marketTotalFee = decimal.NewFromFloat(totalFee[0]).Add(decimal.NewFromFloat(totalFee[1])) + MarketForexCache = marketAvailable + n = 2 + } + + // 用户市场总浮动盈亏 + pLPriceSum := GetForexByPriceSum(userId, setting.AdminForexSubscribe) + // 统计用户市场总资产 + marketTotalAssets = marketAvailable.Add(marketFreeze).Add(pLPriceSum) + // 统计用户市场总浮动盈亏 + marketFloatingPL = pLPriceSum + orderModel := &UserMarketStatistics{ + UserMarkerSubscribe: psgMsg.Symbol, + UserMarketTotalAssets: marketTotalAssets.String(), + UserMarketAvailable: marketAvailable.String(), + UserMarketFreeze: marketFreeze.String(), + UserMarketProfitAndLoss: marketProfitAndLoss.String(), + UserMarketTotalFee: marketTotalFee.String(), + UserMarketFloatingPL: marketFloatingPL.String(), + } + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User market Forex stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户市场统计订阅 + } else { + applogger.Info("User market cancels subscription to Forex stock orders.") + return + } + } + + time.Sleep(800 * time.Millisecond) + } +} diff --git a/internal/data/socket/moneyData/money.go b/internal/data/socket/moneyData/money.go new file mode 100644 index 0000000..fba977a --- /dev/null +++ b/internal/data/socket/moneyData/money.go @@ -0,0 +1,42 @@ +package moneyData + +import ( + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/money" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" +) + +// MoneyOrderProcessing +// +// @Description: 综合订单订阅处理 +// @param topIc +// @param msg +// @return *public.OrderSub +func MoneyOrderProcessing(topIc string, msg money.MoneyTallyCache) *publicData.OrderSub { + price, err := publicData.CheckMoneyImmediateSymbol(topIc, msg.Symbol, msg.Order.Type) + if err != nil { + applogger.Warn("%v MoneyOrderProcessing.CheckSymbol.err:%v--%v", common.ErrMoney, msg.Symbol, err) + } + + var faceValue string + if msg.Order.System != nil { + faceValue = msg.Order.System.FaceValue.String() + } + + orderM := &publicData.OrderSub{ + OrderId: msg.OrderId, + Price: price, + Status: msg.Status, + Symbol: topIc, + Count: 0, + OpenPrice: msg.OpenPrice, + Market: msg.Symbol, + OrderNumber: msg.Order.OrderNumber, + TradeType: msg.Order.TradeType, + FaceValue: faceValue, + UserId: msg.UserId, + } + + return orderM +} diff --git a/internal/data/socket/money_admin.go b/internal/data/socket/money_admin.go new file mode 100644 index 0000000..d03bd02 --- /dev/null +++ b/internal/data/socket/money_admin.go @@ -0,0 +1,98 @@ +package socket + +import ( + "context" + "encoding/json" + "matchmaking-system/internal/data" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/socket/moneyData" + "matchmaking-system/internal/data/tradedeal/money" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/setting" + "time" +) + +// orderSubAdminMoneySubscribeByOrder +// +// @Description: 管理员综合(现货|合约|外汇)|持仓订单订阅|持仓浮动盈亏订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubAdminMoneySubscribeByOrder(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminMoneySubscribe { + var hashList []money.MoneyTallyCache + for _, field := range psgMsg.Order { + fieldStr, err := data.Reds.HGet(context.Background(), setting.AdminMoneySubscribe, field).Result() + if err != nil { + continue + } + var msg money.MoneyTallyCache + if err = json.Unmarshal([]byte(fieldStr), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + hashList = append(hashList, msg) + } + + for _, value := range hashList { + orderModel := moneyData.MoneyOrderProcessing(setting.AdminMoneySubscribe, value) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理[撤单|平仓]缓存队列 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + if err := data.Reds.HDel(context.Background(), setting.AdminMoneySubscribe, orderModel.OrderId).Err(); err != nil { + applogger.Error("AdminMoneySubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("Administrator Money subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("Administrator cancels Money order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubAdminMoneySubscribeBySum(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminMoneySumSubscribe { + priceSum, err := memory.MoneyTotalFloating.Get(flags.FloatingZh) + if err != nil { + continue + } + + result := &SymbolSumResult{ + Symbol: psgMsg.Symbol, + Price: string(priceSum), + } + + priceByte, err := json.Marshal(result) + if err != nil { + continue + } + + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + u.msg <- priceByte + } else { + applogger.Info("Administrator cancels Money order subscription.") + return + } + } + + time.Sleep(2 * time.Second) + } +} diff --git a/internal/data/socket/money_user.go b/internal/data/socket/money_user.go new file mode 100644 index 0000000..05f26b6 --- /dev/null +++ b/internal/data/socket/money_user.go @@ -0,0 +1,228 @@ +package socket + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/data" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/socket/moneyData" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/money" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + models "matchmaking-system/internal/pkg/model" + "matchmaking-system/internal/pkg/setting" + "strconv" + "strings" + "time" +) + +// orderSubMoneySubscribe +// +// @Description: 用户综合(现货|合约|外汇)订单订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubMoneySubscribe(psgMsg *SymbolMessage, makeType int) { + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.MoneySubscribe { + orderTokenKey := virtual.OrderIdListKey(setting.MoneySubscribe, userId) // 获取订阅Key + orderList, err := data.Reds.HGetAll(context.Background(), orderTokenKey).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + + for _, value := range orderList { + var msg money.MoneyTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + + var checkBool bool + if makeType == 0 { + checkBool = true // 现货|合约|外汇 + } else { + switch msg.Order.Type { + case int64(makeType): // 可能-(现货|合约|外汇) + checkBool = true + default: + checkBool = false + } + } + + if checkBool { + orderModel := moneyData.MoneyOrderProcessing(setting.MoneySubscribe, msg) + if orderModel != nil { + var ok bool + if makeType == 0 { + _, ok = u.symbol.Load(psgMsg.Symbol) + } else { + _, ok = u.symbol.Load(fmt.Sprintf("%v-%v", psgMsg.Symbol, makeType)) + } + if ok { + // 清理订阅缓存订单中(撤单|平仓)状态的订单 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + err = data.Reds.HDel(context.Background(), orderTokenKey, msg.OrderId).Err() + if err != nil { + time.Sleep(5 * time.Second) + applogger.Error("MoneySubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("orderSubMoneySubscribe.Marshal:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("User cancels Money order subscription.") + return + } + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubShareMoneyMarketSubscribe(psgMsg *SymbolMessage) { + var n int + var MarketMoneyCache decimal.Decimal // 缓存记录 + var marketProfitAndLoss decimal.Decimal // 用户市场累计盈亏 + var marketTotalFee decimal.Decimal // 用户市场总手续费 + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareMoneyMarketSubscribe { + var marketTotalAssets decimal.Decimal // 用户市场总资产 + var marketSpotsTotalAssets decimal.Decimal // 用户现货市场总资产 + var marketAvailable decimal.Decimal // 用户市场可用 + var marketFreeze decimal.Decimal // 用户市场冻结 + var marketFloatingPL decimal.Decimal // 用户市场总浮动盈亏 + // 统计用户现货资产 + var botUserMoneySpots []models.BotUserMoney + err = data.Msql.Table(flags.BotUserMoney).Where("user_id = ?", userId).Where("stock_id NOT REGEXP 'USD$'").Find(&botUserMoneySpots) + if err != nil { + marketAvailable = decimal.Zero + marketFreeze = decimal.Zero + } + for _, value := range botUserMoneySpots { + stockId := strings.ToLower(value.StockId) + keyPrice := publicData.SymbolCache(flags.Xh, stockId, flags.TradeTypeAdminPrice) + priceNew, err := memory.GetMoneySpotsCache(keyPrice) + if err != nil { + continue + } + priceN := decimal.RequireFromString(string(priceNew)) + usableNum := decimal.RequireFromString(value.UsableNum) + marketSpotsTotalAssets = marketSpotsTotalAssets.Add(priceN.Mul(usableNum)) + } + + // 统计用户市场可用余额和冻结余额 + var botUserMoney []models.BotUserMoney + err = data.Msql.Table(flags.BotUserMoney).Where("user_id = ?", userId).Where("stock_id = ?", flags.MoneyUnit).Find(&botUserMoney) + if err != nil { + marketAvailable = decimal.Zero + marketFreeze = decimal.Zero + } + for _, value := range botUserMoney { + marketAvailable = decimal.RequireFromString(value.UsableNum) + marketFreeze = decimal.RequireFromString(value.FrozenNum) + } + // 判定是否存在订单 + if marketAvailable.IsZero() || marketFreeze.IsZero() { + if n == 0 { + tradeCount, _ := data.Msql.Table(flags.BotMoneyTrade).Where("user_id = ?", userId).In("status", 1, 3).Count() + if tradeCount > 0 { + n = 1 + } + } + } + if marketAvailable.Cmp(MarketMoneyCache) != 0 || n == 1 { + // 统计用户市场累计盈亏 + var botMoneyTrade []models.BotMoneyTrade + err = data.Msql.Table(flags.BotMoneyTrade).Where("user_id = ?", userId).Where("status = 3").Find(&botMoneyTrade) + if err != nil { + marketProfitAndLoss = decimal.Zero + } + for _, value := range botMoneyTrade { + sumValue := decimal.Zero + openPrice := decimal.RequireFromString(value.DealPrice) + closePrice := decimal.RequireFromString(value.ClosingPrice) + orderNum := decimal.RequireFromString(value.OrderNumber) + pryNum := decimal.RequireFromString(strconv.Itoa(value.PryNum)) + switch value.TradeType { + case 1: // 买张 + sumValue = closePrice.Sub(openPrice) + case 2: // 买跌 + sumValue = openPrice.Sub(closePrice) + default: + continue + } + profLass := sumValue.Mul(orderNum).Mul(pryNum) + //applogger.Error("第一个:%v,买涨还是买跌:%v,开仓价:%v,平仓价:%v,订单量:%v,杠杆:%v,盈亏:%v", key, value.TradeType, openPrice, closePrice, orderNum, pryNum, profLass) + marketProfitAndLoss = marketProfitAndLoss.Add(profLass) + } + // 统计用户市场总手续费 + var botMoneyTradeFee models.BotMoneyTrade + totalFee, err := data.Msql.Table(flags.BotMoneyTrade).Where("user_id = ?", userId).In("status", 1, 3).Sums(botMoneyTradeFee, "service_cost", "closing_cost") + if err != nil || len(totalFee) != 2 { + marketTotalFee = decimal.Zero + } + marketTotalFee = decimal.NewFromFloat(totalFee[0]).Add(decimal.NewFromFloat(totalFee[1])) + MarketMoneyCache = marketAvailable + n = 2 + } + + // 用户市场总浮动盈亏 + pLPriceSum := GetMoneyByPriceSum(userId, setting.AdminMoneySubscribe) + // 统计用户市场总资产 + marketTotalAssets = marketAvailable.Add(marketFreeze).Add(pLPriceSum).Add(marketSpotsTotalAssets) + // 统计用户市场总浮动盈亏 + marketFloatingPL = pLPriceSum + orderModel := &UserMarketStatistics{ + UserMarkerSubscribe: psgMsg.Symbol, + UserMarketTotalAssets: marketTotalAssets.String(), + UserMarketAvailable: marketAvailable.String(), + UserMarketFreeze: marketFreeze.String(), + UserMarketProfitAndLoss: marketProfitAndLoss.String(), + UserMarketTotalFee: marketTotalFee.String(), + UserMarketFloatingPL: marketFloatingPL.String(), + } + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User market Money stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户市场统计订阅 + } else { + applogger.Info("User market cancels subscription to Money stock orders.") + return + } + } + + time.Sleep(800 * time.Millisecond) + } +} diff --git a/internal/data/socket/optionData/option_inr.go b/internal/data/socket/optionData/option_inr.go new file mode 100644 index 0000000..db8975b --- /dev/null +++ b/internal/data/socket/optionData/option_inr.go @@ -0,0 +1,48 @@ +package optionData + +import ( + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/option" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" +) + +// OptionInrOrderProcessing +// +// @Description: 股票-印度期权股订阅处理 +// @param topIc +// @param msg +// @return *public.OrderSub +func OptionInrOrderProcessing(check int, msg option.OptionInrTallyCache) *publicData.OrderSub { + var top string + switch check { + case 0: + top = setting.SubscribeOptionInr + case 1: + top = setting.SubscribeAdminOptionInr + } + + price, err := publicData.CheckSymbolOption(msg) + if err != nil { + applogger.Warn("%v OptionInrOrderProcessing.CheckSymbol.err:%v--%v", common.ErrOptionInr, msg.Symbol, err) + } + + orderM := &publicData.OrderSub{ + OrderId: msg.OrderId, + Price: utils.DecimalsPrice(price), + Status: msg.Status, + Symbol: top, + Count: 0, + OpenPrice: msg.OpenPrice, + Market: msg.Symbol, + OrderNumber: msg.Order.OrderNumber, + TradeType: msg.Order.TradeType, + TradingType: msg.Order.TradingType, + ServiceCost: msg.Order.ServiceCost, + UserId: msg.UserId, + } + + return orderM +} diff --git a/internal/data/socket/option_admin.go b/internal/data/socket/option_admin.go new file mode 100644 index 0000000..74665e5 --- /dev/null +++ b/internal/data/socket/option_admin.go @@ -0,0 +1,98 @@ +package socket + +import ( + "context" + "encoding/json" + "matchmaking-system/internal/data" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/socket/optionData" + "matchmaking-system/internal/data/tradedeal/option" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/setting" + "time" +) + +// orderSubAdminOptionInrSubscribeByOrder +// +// @Description: 管理员期权-印度股|持仓订单订阅|持仓浮动盈亏订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubAdminOptionInrSubscribeByOrder(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.SubscribeAdminOptionInr { + var hashList []option.OptionInrTallyCache + for _, field := range psgMsg.Order { + fieldStr, err := data.Reds.HGet(context.Background(), setting.AdminOptionInrSubscribe, field).Result() + if err != nil { + continue + } + var msg option.OptionInrTallyCache + if err = json.Unmarshal([]byte(fieldStr), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + hashList = append(hashList, msg) + } + + for _, value := range hashList { + orderModel := optionData.OptionInrOrderProcessing(1, value) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理[撤单|平仓]缓存队列 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + if err := data.Reds.HDel(context.Background(), setting.AdminOptionInrSubscribe, orderModel.OrderId).Err(); err != nil { + applogger.Error("AdminOptionInrSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("Administrator India stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("Administrator cancels India order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubAdminOptionInrSubscribeBySum(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminOptionInrSumSubscribe { + priceSum, err := memory.OptionInrFloating.Get(flags.FloatingOpi) + if err != nil { + continue + } + + result := &SymbolSumResult{ + Symbol: psgMsg.Symbol, + Price: string(priceSum), + } + + priceByte, err := json.Marshal(result) + if err != nil { + continue + } + + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + u.msg <- priceByte + } else { + applogger.Info("Administrator cancels Indian stock order subscription.") + return + } + } + + time.Sleep(1 * time.Second) + } +} diff --git a/internal/data/socket/option_user.go b/internal/data/socket/option_user.go new file mode 100644 index 0000000..c808937 --- /dev/null +++ b/internal/data/socket/option_user.go @@ -0,0 +1,166 @@ +package socket + +import ( + "context" + "encoding/json" + "github.com/shopspring/decimal" + "matchmaking-system/internal/data" + "matchmaking-system/internal/data/socket/optionData" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/option" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/setting" + "time" +) + +// orderSubShareInrSubscribe +// +// @Description: 用户期权-印度股订单订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubOptionInrSubscribe(psgMsg *SymbolMessage) { + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.SubscribeOptionInr { + orderTokenKey := virtual.OrderIdListKey(setting.OptionInrSubscribe, userId) + orderList, err := data.Reds.HGetAll(context.Background(), orderTokenKey).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + + for _, value := range orderList { + var msg option.OptionInrTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + orderModel := optionData.OptionInrOrderProcessing(0, msg) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理印度股订阅缓存订单中(撤单|平仓)状态的订单 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + err = data.Reds.HDel(context.Background(), orderTokenKey, msg.OrderId).Err() + if err != nil { + time.Sleep(5 * time.Second) + applogger.Error("OptionInrSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User's Indian stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("User cancels Indian stock order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} + +// orderSubSumOptionInrSubscribe +// +// @Description: 用户期权-印度股订单总浮动盈亏订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubSumOptionInrSubscribe(psgMsg *SymbolMessage) { + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.SubscribeSumOptionInr { + orderTokenKey := virtual.OrderIdListKey(setting.OptionInrSubscribe, userId) + orderList, err := data.Reds.HGetAll(context.Background(), orderTokenKey).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + + var userSumOrderPL decimal.Decimal + for _, value := range orderList { + var msg option.OptionInrTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + if msg.Status == flags.Position { + orderModel := optionData.OptionInrOrderProcessing(0, msg) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + if len(orderModel.Price) == 0 || len(orderModel.OpenPrice) == 0 { + continue + } + price := decimal.RequireFromString(orderModel.Price) // 买一卖一价格 + openPrice := decimal.RequireFromString(orderModel.OpenPrice) // 开仓价格 + orderNum := decimal.RequireFromString(orderModel.OrderNumber) // 订单数量 + // 浮动盈亏(P/L) + // 1>buy call & buy put + // 1> bid买一价为0, P/L显示为 - + // 2> bid买一价大于0, P/L =(bid买一价 - Cost Price)*Contracts Quantity + // 2>sell call & sell put + // 1> ask卖一价为0, P/L显示为 - + // 2> ask卖一价大于0, P/L =(Cost Price - ASK卖一价)*Contracts Quantity + pl := decimal.Zero + switch msg.Order.TradeType { + case flags.OptionCalls: // call + switch msg.Order.TradingType { + case flags.OptionBuy: // call - buy + pl = price.Sub(openPrice).Mul(orderNum) + case flags.OptionSell: // call - sell + pl = openPrice.Sub(price).Mul(orderNum) + } + case flags.OptionPuts: // put + switch msg.Order.TradingType { + case flags.OptionBuy: // put - buy + pl = price.Sub(openPrice).Mul(orderNum) + case flags.OptionSell: // put - sell + pl = openPrice.Sub(price).Mul(orderNum) + } + } + userSumOrderPL = userSumOrderPL.Add(pl) + } else { + applogger.Info("User cancels Indian stock order subscription.") + return + } + } + } + } + // 用户持仓总浮动盈亏订阅 + sum := publicData.OptionSum{ + Type: "price", + Value: userSumOrderPL.String(), + } + orderStr, err := json.Marshal(sum) + if err != nil { + applogger.Error("User's Indian stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr + } + + time.Sleep(600 * time.Millisecond) + } +} diff --git a/internal/data/socket/order.go b/internal/data/socket/order.go new file mode 100644 index 0000000..923ed1e --- /dev/null +++ b/internal/data/socket/order.go @@ -0,0 +1,442 @@ +package socket + +import ( + "fmt" + "github.com/gorilla/websocket" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "net/http" + "strconv" + "strings" + "sync" + "time" + + uuid "github.com/satori/go.uuid" +) + +// Client +// @Description: wss client +type Client struct { + Id string // Client ID + conn *websocket.Conn // Define websocket link object + msg chan []byte // Define messages received and distributed + symbol sync.Map // Concurrent Security - Manage User Subscription Types + mux sync.Mutex // Mutual exclusive lock (used for single message sending) + token string // Obtain token information (subscribe to user pending and holding orders through token information: order userId) +} + +// WsHandlerOrder +// +// @Description: wss start +// @param w +// @param r +func WsHandlerOrder(w http.ResponseWriter, r *http.Request) { + // Start order WSS subscription service + conn, err := upGraderOrder.Upgrade(w, r, nil) + if err != nil { + applogger.Error("upGrader_Order Upgrade err:%v", err) + return + } + + queryParams := r.URL.Query() + token := queryParams.Get("token") + tokenUserId := fmt.Sprintf("%v%v", flags.UserToken, token) + + if !flags.CheckSetting { + applogger.Debug("WsHandlerOrder info %v", tokenUserId) + } + + // Register users after successful connection + client := &Client{ + Id: uuid.NewV4().String(), + conn: conn, + msg: make(chan []byte), + symbol: sync.Map{}, + mux: sync.Mutex{}, + token: tokenUserId, + } + + go readShare(client) + go writeShare(client) +} + +// readShare +// +// @Description: read message +// @param cl +func readShare(cl *Client) { + defer func() { + if err := cl.conn.Close(); err != nil { + return + } + }() + for { + _, msg, err := cl.conn.ReadMessage() + if err != nil { + applogger.Error("%v readShare.ReadMessage:%v", common.ErrContract, err) + // Link failure cleaning subscription book + cleanSubscriptionKey(cl) + applogger.Warn("Cleanup subscription key, successful.") + return + } + // Process business logic + psgMsg := SubMessage(string(msg)) + if psgMsg != nil { + switch psgMsg.Type { + case "ping": // Receiving ping + cl.msg <- []byte(ReturnValue("pong")) + case "subscribe": // Receive subscription + applogger.Info("Receive client Subscribe type:%v", string(msg)) + + // Handle duplicate subscriptions, handle link limits + _, ok := cl.symbol.Load(psgMsg.Symbol) + if ok { + applogger.Error("Cannot repeat subscription.") + } else { + // Write subscription topic manager + cl.symbol.Store(psgMsg.Symbol, psgMsg.Order) + + // TODO: 特殊处理p1的pc端的订单列表订阅问题 + var makeType int + if strings.Contains(psgMsg.Symbol, "-") { + splitStr := strings.Split(psgMsg.Symbol, "-") + if len(splitStr) == 2 { + psgMsg.Symbol = splitStr[0] + makeType, err = strconv.Atoi(splitStr[1]) + if err != nil { + makeType = 0 + } + } + } else { + makeType = 0 + } + + switch psgMsg.Symbol { + case setting.SpotsSubscribe: // Spots + go cl.orderSubSpotsSubscribe(psgMsg) + case setting.ContractSubscribe: // Contract + go cl.orderSubContractSubscribe(psgMsg) + case setting.SecondSubscribe: // Second + go cl.orderSubSecondSubscribe(psgMsg) + case setting.ForexSubscribe: // Forex + go cl.orderSubForexSubscribe(psgMsg) + case setting.MoneySubscribe: // Money + go cl.orderSubMoneySubscribe(psgMsg, makeType) + case setting.ShareUsSubscribe: // ShareUs + go cl.orderSubShareUsSubscribe(psgMsg) + case setting.ShareMysSubscribe: // ShareMys + go cl.orderSubShareMysSubscribe(psgMsg) + case setting.ShareThaSubscribe: // ShareTha + go cl.orderSubShareThaSubscribe(psgMsg) + case setting.ShareIdnSubscribe: // ShareIdn + go cl.orderSubShareIdnSubscribe(psgMsg) + case setting.ShareInrSubscribe: // ShareInr + go cl.orderSubShareInrSubscribe(psgMsg) + case setting.ShareSgdSubscribe: // shareGbx + go cl.orderSubShareSgdSubscribe(psgMsg) + case setting.ShareGbxSubscribe: // ShareSgd + go cl.orderSubShareGbxSubscribe(psgMsg) + case setting.ShareEurSubscribe: // ShareEur + go cl.orderSubShareEurSubscribe(psgMsg) + case setting.ShareFurSubscribe: // ShareFur + go cl.orderSubShareFurSubscribe(psgMsg) + case setting.ShareJpySubscribe: // ShareJpy + go cl.orderSubShareJpySubscribe(psgMsg) + case setting.ShareBrlSubscribe: // ShareBrl + go cl.orderSubShareBrlSubscribe(psgMsg) + case setting.SubscribeShareHkd: // ShareHkd + go cl.orderSubShareHkdSubscribe(psgMsg) + case setting.SubscribeOptionInr: // OptionInr + go cl.orderSubOptionInrSubscribe(psgMsg) + case setting.SubscribeSumOptionInr: // OptionInrSum + go cl.orderSubSumOptionInrSubscribe(psgMsg) + case setting.SubscribeShareBlk: // shareBlk + go cl.orderSubShareBlkSubscribe(psgMsg) + case setting.SpotsMarketSubscribe: // spots Market + go cl.orderSubSpotsMarketSubscribe(psgMsg) + case setting.ContractMarketSubscribe: // contract Market + go cl.orderSubContractMarketSubscribe(psgMsg) + case setting.SecondMarketSubscribe: // second Market + go cl.orderSubSecondMarketSubscribe(psgMsg) + case setting.ShareForexMarketSubscribe: // shareForex Market + cl.orderSubShareForexMarketSubscribe(psgMsg) + case setting.ShareMoneyMarketSubscribe: // shareMoney Market + cl.orderSubShareMoneyMarketSubscribe(psgMsg) + case setting.ShareUsMarketSubscribe: // shareUs Market + go cl.orderSubShareUsMarketSubscribe(psgMsg) + case setting.ShareInrMarketSubscribe: // shareInr Market + go cl.orderSubShareInrMarketSubscribe(psgMsg) + case setting.ShareMysMarketSubscribe: // shareMys Market + go cl.orderSubShareMysMarketSubscribe(psgMsg) + case setting.ShareThaMarketSubscribe: // shareTha Market + go cl.orderSubShareThaMarketSubscribe(psgMsg) + case setting.ShareSgdMarketSubscribe: // shareSgd Market + go cl.orderSubShareSgdMarketSubscribe(psgMsg) + case setting.ShareFurMarketSubscribe: // shareFur Market + go cl.orderSubShareFurMarketSubscribe(psgMsg) + case setting.ShareEurMarketSubscribe: // shareEur Market + go cl.orderSubShareEurMarketSubscribe(psgMsg) + case setting.ShareBrlMarketSubscribe: // shareBrl Market + go cl.orderSubShareBrlMarketSubscribe(psgMsg) + case setting.ShareIdnMarketSubscribe: // shareIdn Market + go cl.orderSubShareIdnMarketSubscribe(psgMsg) + case setting.ShareGbxMarketSubscribe: // shareGbx Market + go cl.orderSubShareGbxMarketSubscribe(psgMsg) + case setting.ShareHkdMarketSubscribe: // shareHkd Market + go cl.orderSubShareHkdMarketSubscribe(psgMsg) + case setting.ShareJpyMarketSubscribe: // shareJpy Market + go cl.orderSubShareJpyMarketSubscribe(psgMsg) + case setting.AdminContractSubscribe: // Admin Contract + go cl.orderSubAdminContractSubscribeByOrder(psgMsg) + case setting.AdminSecondSubscribe: // Admin Second + go cl.orderSubAdminSecondSubscribeByOrder(psgMsg) + case setting.AdminForexSubscribe: // Admin Forex + go cl.orderSubAdminForexSubscribeByOrder(psgMsg) + case setting.AdminMoneySubscribe: // Admin Money + go cl.orderSubAdminMoneySubscribeByOrder(psgMsg) + case setting.AdminShareUsSubscribe: // Admin ShareUs + go cl.orderSubAdminShareUsSubscribeByOrder(psgMsg) + case setting.AdminShareMysSubscribe: // Admin ShareMys + go cl.orderSubAdminShareMysSubscribeByOrder(psgMsg) + case setting.AdminShareThaSubscribe: // Admin ShareTha + go cl.orderSubAdminShareThaSubscribeByOrder(psgMsg) + case setting.AdminShareIdnSubscribe: // Admin ShareIdn + go cl.orderSubAdminShareIdnSubscribeByOrder(psgMsg) + case setting.AdminShareInrSubscribe: // Admin ShareInr + go cl.orderSubAdminShareInrSubscribeByOrder(psgMsg) + case setting.AdminShareSgdSubscribe: // admin ShareSgd + go cl.orderSubAdminShareSgdSubscribeByOrder(psgMsg) + case setting.AdminShareGbxSubscribe: // admin ShareGbx + go cl.orderSubAdminShareGbxSubscribeByOrder(psgMsg) + case setting.AdminShareEurSubscribe: // admin ShareEur + go cl.orderSubAdminShareEurSubscribeByOrder(psgMsg) + case setting.AdminShareFurSubscribe: // admin ShareFur + go cl.orderSubAdminShareFurSubscribeByOrder(psgMsg) + case setting.AdminShareJpySubscribe: // admin ShareJpy + go cl.orderSubAdminShareJpySubscribeByOrder(psgMsg) + case setting.AdminShareBrlSubscribe: // admin ShareBrl + go cl.orderSubAdminShareBrlSubscribeByOrder(psgMsg) + case setting.SubscribeAdminShareHkd: // admin ShareHkd + go cl.orderSubAdminShareHkdSubscribeByOrder(psgMsg) + case setting.SubscribeAdminOptionInr: // admin OptionInr + go cl.orderSubAdminOptionInrSubscribeByOrder(psgMsg) + case setting.SubscribeAdminShareBlk: // admin ShareBlk + go cl.orderSubAdminShareBlkSubscribeByOrder(psgMsg) + case setting.AdminContractSumSubscribe: // Admin Contract Sum + go cl.orderSubAdminContractSubscribeBySum(psgMsg) + case setting.AdminForexSumSubscribe: // Admin Forex Sum + go cl.orderSubAdminForexSubscribeBySum(psgMsg) + case setting.AdminMoneySumSubscribe: // Admin Money Sum + go cl.orderSubAdminMoneySubscribeBySum(psgMsg) + case setting.AdminShareUsSumSubscribe: // Admin ShareUs Sum + go cl.orderSubAdminShareUsSubscribeBySum(psgMsg) + case setting.AdminShareMysSumSubscribe: // Admin ShareMys Sum + go cl.orderSubAdminShareMysSubscribeBySum(psgMsg) + case setting.AdminShareThaSumSubscribe: // Admin ShareTha Sum + go cl.orderSubAdminShareThaSubscribeBySum(psgMsg) + case setting.AdminShareIdnSumSubscribe: // Admin ShareIdn Sum + go cl.orderSubAdminShareIdnSubscribeBySum(psgMsg) + case setting.AdminShareInrSumSubscribe: // Admin ShareInr Sum + go cl.orderSubAdminShareInrSubscribeBySum(psgMsg) + case setting.AdminShareSgdSumSubscribe: // Admin ShareSgd Sum + go cl.orderSubAdminShareSgdSubscribeBySum(psgMsg) + case setting.AdminShareGbxSumSubscribe: // Admin ShareGbx Sum + go cl.orderSubAdminShareGbxSubscribeBySum(psgMsg) + case setting.AdminShareHkdSumSubscribe: // Admin ShareHkd Sum + go cl.orderSubAdminShareHkdSubscribeBySum(psgMsg) + case setting.AdminShareEurSumSubscribe: // Admin ShareEur Sum + go cl.orderSubAdminShareEurSubscribeBySum(psgMsg) + case setting.AdminShareFurSumSubscribe: // Admin ShareFur Sum + go cl.orderSubAdminShareFurSubscribeBySum(psgMsg) + case setting.AdminShareJpySumSubscribe: // Admin ShareJpy Sum + go cl.orderSubAdminShareJpySubscribeBySum(psgMsg) + case setting.AdminShareBrlSumSubscribe: // Admin ShareBrl Sum + go cl.orderSubAdminShareBrlSubscribeBySum(psgMsg) + case setting.AdminOptionInrSumSubscribe: // Admin OptionInr Sum + go cl.orderSubAdminOptionInrSubscribeBySum(psgMsg) + case setting.AdminShareBlkSumSubscribe: // Admin ShareBlk Sum + go cl.orderSubAdminShareBlkSubscribeBySum(psgMsg) + case setting.AdminShareUserSumSubscribe: // Admin UserShare Sum + go cl.orderSubAdminUserShareSubscribeBySum(psgMsg) + default: + cl.msg <- []byte(ReturnValue("Please enter the correct subscription key.")) + } + } + // Notify user of successful subscription + cl.msg <- []byte(ReturnValue("subscribe success")) + case "unSubscribe": // Receive unsubscribe + applogger.Info("Receive client unSubscribe type:%v,%v", psgMsg.Symbol, cl.token) + + symbol, _ := cl.symbol.Load(psgMsg.Symbol) + applogger.Info("Get current subscription type:%v", symbol) + + // Delete the specified topic in the subscription topic manager + cl.symbol.Delete(psgMsg.Symbol) + + symbolD, _ := cl.symbol.Load(psgMsg.Symbol) + applogger.Info("Subscription type after current user deletion:%v", symbolD) + + cl.msg <- []byte(ReturnValue("unSubscribe success")) + default: + // TODO: Handling other situations transmitted by customers + applogger.Info("Please provide accurate instructions......") + } + } + } +} + +// writeShare +// +// @Description: write message +// @param cl +func writeShare(cl *Client) { + ticker := time.NewTicker(pingPeriod) + defer func() { + ticker.Stop() + if err := cl.conn.Close(); err != nil { + return + } + }() + + for { + select { + case message, ok := <-cl.msg: // send a message + // Set the dead time for writing, equivalent to HTTP timeout + if !ok { + // If the value is incorrect, close the connection, set the write status, and corresponding data + if err := cl.send(flags.SetNull); err != nil { + applogger.Error("%v writeShare.send:%v", common.ErrContract, err) + } + cleanSubscriptionKey(cl) + return + } + + // Write data in the form of io, with parameters of data type + w, err := cl.conn.NextWriter(websocket.TextMessage) + if err != nil { + return + } + + // Write data, this function is truly used to transmit data to the foreground + _, err = w.Write(message) + if err = w.Close(); err != nil { + // Close write stream + applogger.Error("%v writeShare.Close:%v", common.ErrContract, err) + cleanSubscriptionKey(cl) + return + } + case <-ticker.C: + // TODO: Need to ping if the client is online + } + } +} + +// cleanSubscriptionKey +// +// @Description: clean sub key +// @param cl +func cleanSubscriptionKey(cl *Client) { + // 用户订单列表订阅 + cl.symbol.Delete(setting.SpotsSubscribe) // 现货 + cl.symbol.Delete(setting.ContractSubscribe) // 合约 + cl.symbol.Delete(setting.SecondSubscribe) // 秒合约 + cl.symbol.Delete(setting.ForexSubscribe) // 外汇 + cl.symbol.Delete(setting.MoneySubscribe) // 综合(现货|合约|外汇) + cl.symbol.Delete(setting.ShareUsSubscribe) // 美股 + cl.symbol.Delete(setting.ShareIdnSubscribe) // 印尼股 + cl.symbol.Delete(setting.ShareThaSubscribe) // 泰股 + cl.symbol.Delete(setting.ShareInrSubscribe) // 印度股 + cl.symbol.Delete(setting.ShareMysSubscribe) // 马股 + cl.symbol.Delete(setting.ShareSgdSubscribe) // 新加坡股 + cl.symbol.Delete(setting.ShareGbxSubscribe) // 英股 + cl.symbol.Delete(setting.ShareEurSubscribe) // 德股 + cl.symbol.Delete(setting.ShareFurSubscribe) // 法股 + cl.symbol.Delete(setting.ShareBrlSubscribe) // 巴西股 + cl.symbol.Delete(setting.ShareJpySubscribe) // 日股 + cl.symbol.Delete(setting.SubscribeShareHkd) // 港股 + cl.symbol.Delete(setting.SubscribeOptionInr) // 印度期权股 + cl.symbol.Delete(setting.SubscribeSumOptionInr) // 印度期权总浮动盈亏 + cl.symbol.Delete(setting.SubscribeShareBlk) // 股票大宗 + + // 管理员订单列表订阅 + cl.symbol.Delete(setting.AdminContractSubscribe) // 管理员合约 + cl.symbol.Delete(setting.AdminSecondSubscribe) // 管理员秒合约 + cl.symbol.Delete(setting.AdminForexSubscribe) // 管理员外汇 + cl.symbol.Delete(setting.AdminMoneySubscribe) // 管理员综合(现货|合约|外汇) + cl.symbol.Delete(setting.AdminShareUsSubscribe) // 管理员美股 + cl.symbol.Delete(setting.AdminShareThaSubscribe) // 管理员泰股 + cl.symbol.Delete(setting.AdminShareIdnSubscribe) // 管理员印尼股 + cl.symbol.Delete(setting.AdminShareInrSubscribe) // 管理员印度股 + cl.symbol.Delete(setting.AdminShareMysSubscribe) // 管理员马股 + cl.symbol.Delete(setting.AdminShareSgdSubscribe) // 管理员新加坡股 + cl.symbol.Delete(setting.AdminShareGbxSubscribe) // 管理员英股 + cl.symbol.Delete(setting.AdminShareEurSubscribe) // 管理员德股 + cl.symbol.Delete(setting.AdminShareFurSubscribe) // 管理员法股 + cl.symbol.Delete(setting.AdminShareBrlSubscribe) // 管理员巴西股 + cl.symbol.Delete(setting.AdminShareJpySubscribe) // 管理员日股 + cl.symbol.Delete(setting.SubscribeAdminShareHkd) // 管理员港股 + cl.symbol.Delete(setting.SubscribeAdminOptionInr) // 管理员印度期权股 + cl.symbol.Delete(setting.SubscribeAdminShareBlk) // 管理员股票大宗股 + + // 管理员持仓订单浮动盈亏 + cl.symbol.Delete(setting.AdminContractSumSubscribe) // 管理员合约持仓订单浮动盈亏订阅 + cl.symbol.Delete(setting.AdminForexSumSubscribe) // 管理员外汇持仓订单浮动盈亏订阅 + cl.symbol.Delete(setting.AdminMoneySumSubscribe) // 管理员综合(现货|合约|外汇)持仓订单浮动盈亏订阅 + cl.symbol.Delete(setting.AdminShareUsSumSubscribe) // 管理员美股持仓订单浮动盈亏订阅 + cl.symbol.Delete(setting.AdminShareThaSumSubscribe) // 管理员泰股持仓订单浮动盈亏订阅 + cl.symbol.Delete(setting.AdminShareIdnSumSubscribe) // 管理员印尼股持仓订单浮动盈亏订阅 + cl.symbol.Delete(setting.AdminShareInrSumSubscribe) // 管理员印度股持仓订单浮动盈亏订阅 + cl.symbol.Delete(setting.AdminShareMysSumSubscribe) // 管理员马股持仓订单浮动盈亏订阅 + cl.symbol.Delete(setting.AdminShareSgdSumSubscribe) // 管理员新加坡股持仓订单浮动盈亏订阅 + cl.symbol.Delete(setting.AdminShareGbxSumSubscribe) // 管理员英股持仓订单浮动盈亏订阅 + cl.symbol.Delete(setting.AdminShareEurSumSubscribe) // 管理员德股持仓订单浮动盈亏订阅 + cl.symbol.Delete(setting.AdminShareFurSumSubscribe) // 管理员法股持仓订单浮动盈亏订阅 + cl.symbol.Delete(setting.AdminShareBrlSumSubscribe) // 管理员巴西股持仓订单浮动盈亏订阅 + cl.symbol.Delete(setting.AdminShareJpySumSubscribe) // 管理员日股持仓订单浮动盈亏订阅 + cl.symbol.Delete(setting.AdminShareHkdSumSubscribe) // 管理员港股持仓订单浮动盈亏订阅 + cl.symbol.Delete(setting.AdminOptionInrSumSubscribe) // 管理员印度期权股持仓订单浮动盈亏订阅 + cl.symbol.Delete(setting.AdminShareBlkSumSubscribe) // 管理员大宗股持仓订单浮动盈亏订阅 + + // 管理员用户持仓浮动盈亏 + cl.symbol.Delete(setting.AdminShareUserSumSubscribe) + + // 用户股票-外汇市场统计 + cl.symbol.Delete(setting.ShareUsMarketSubscribe) // 美股市场资产统计订阅 + cl.symbol.Delete(setting.ShareMysMarketSubscribe) // 马股市场资产统计订阅 + cl.symbol.Delete(setting.ShareThaMarketSubscribe) // 泰股市场资产统计订阅 + cl.symbol.Delete(setting.ShareSgdMarketSubscribe) // 新加坡股市场资产统计订阅 + cl.symbol.Delete(setting.ShareInrMarketSubscribe) // 印度股市场资产统计订阅 + cl.symbol.Delete(setting.ShareIdnMarketSubscribe) // 印尼股市场资产统计订阅 + cl.symbol.Delete(setting.ShareGbxMarketSubscribe) // 英股市场资产统计订阅 + cl.symbol.Delete(setting.ShareEurMarketSubscribe) // 德股市场资产统计订阅 + cl.symbol.Delete(setting.ShareFurMarketSubscribe) // 法股市场资产统计订阅 + cl.symbol.Delete(setting.ShareHkdMarketSubscribe) // 港股市场资产统计订阅 + cl.symbol.Delete(setting.ShareBrlMarketSubscribe) // 巴西股市场资产统计订阅 + cl.symbol.Delete(setting.ShareJpyMarketSubscribe) // 日股市场资产统计订阅 + cl.symbol.Delete(setting.ShareForexMarketSubscribe) // 外汇市场资产统计订阅 + cl.symbol.Delete(setting.ShareMoneyMarketSubscribe) // 综合(现货|合约|外汇)市场资产统计订阅 + cl.symbol.Delete(setting.ContractMarketSubscribe) // 合约市场资产统计订阅 + cl.symbol.Delete(setting.SpotsMarketSubscribe) // 现货市场资产统计订阅 + cl.symbol.Delete(setting.SecondMarketSubscribe) // 秒合约市场资产统计订阅 +} + +// send +// +// @Description: message send +// @receiver u +// @param data +// @return err +func (u *Client) send(data string) (err error) { + if u.conn == nil { + applogger.Error("WebSocket sent error: no connection available") + return err + } + + u.mux.Lock() + err = u.conn.WriteMessage(websocket.TextMessage, []byte(data)) + u.mux.Unlock() + + return err +} diff --git a/internal/data/socket/order_test.go b/internal/data/socket/order_test.go new file mode 100644 index 0000000..86880d6 --- /dev/null +++ b/internal/data/socket/order_test.go @@ -0,0 +1,114 @@ +package socket + +import ( + "github.com/gorilla/websocket" + "net/http" + "sync" + "testing" +) + +func TestClient_send(t *testing.T) { + type fields struct { + Id string + conn *websocket.Conn + msg chan []byte + symbol sync.Map + mux sync.Mutex + token string + } + type args struct { + data string + } + tests := []struct { + name string + fields fields + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + u := &Client{ + Id: tt.fields.Id, + conn: tt.fields.conn, + msg: tt.fields.msg, + symbol: tt.fields.symbol, + mux: tt.fields.mux, + token: tt.fields.token, + } + if err := u.send(tt.args.data); (err != nil) != tt.wantErr { + t.Errorf("send() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestWsHandlerOrder(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + WsHandlerOrder(tt.args.w, tt.args.r) + }) + } +} + +func Test_cleanSubscriptionKey(t *testing.T) { + type args struct { + cl *Client + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cleanSubscriptionKey(tt.args.cl) + }) + } +} + +func Test_readShare(t *testing.T) { + type args struct { + cl *Client + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + readShare(tt.args.cl) + }) + } +} + +func Test_writeShare(t *testing.T) { + type args struct { + cl *Client + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + writeShare(tt.args.cl) + }) + } +} diff --git a/internal/data/socket/order_ws.go b/internal/data/socket/order_ws.go new file mode 100644 index 0000000..73c92c2 --- /dev/null +++ b/internal/data/socket/order_ws.go @@ -0,0 +1,192 @@ +package socket + +import ( + "context" + "encoding/json" + "fmt" + "github.com/gorilla/websocket" + "github.com/shopspring/decimal" + "matchmaking-system/internal/data" + "matchmaking-system/internal/data/redis" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "net/http" + "strconv" + "time" +) + +const ( + // Time allowed to read the next pong message from the peer. + pongWait = 60 * time.Second + + // Send pings to peer with this period. Must be less than pongWait. + pingPeriod = (pongWait * 9) / 10 +) + +var upGraderOrder = websocket.Upgrader{ + // Define read/write buffer size + WriteBufferSize: 1024, + ReadBufferSize: 1024, + // Verification request + CheckOrigin: func(r *http.Request) bool { + // If it is not a get request, return an error + if r.Method != "GET" { + applogger.Error("Request method error") + return false + } + + var wss string + switch flags.CheckEnvironment { + case flags.CheckSport: // Spots Wss + wss = fmt.Sprintf("/%v", flags.SpotsWss) + case flags.CheckContract: // Contract Wss + wss = fmt.Sprintf("/%v", flags.ContractWss) + case flags.CheckSecond: // Second Wss + wss = fmt.Sprintf("/%v", flags.SecondWss) + case flags.CheckForex: // Forex Wss + wss = fmt.Sprintf("/%v", flags.ForexWss) + case flags.CheckMoney: // Money Wss + wss = fmt.Sprintf("/%v", flags.MoneyWss) + case flags.CheckShareUs: // Share Us Wss + wss = fmt.Sprintf("/%v", flags.ShareUsWss) + case flags.CheckShareMys: // Share Mys Wss + wss = fmt.Sprintf("/%v", flags.ShareMysWss) + case flags.CheckShareTha: // Share Tha Wss + wss = fmt.Sprintf("/%v", flags.ShareThaWss) + case flags.CheckShareIdn: // Share Idn Wss + wss = fmt.Sprintf("/%v", flags.ShareIdnWss) + case flags.CheckShareInr: // Share Inr Wss + wss = fmt.Sprintf("/%v", flags.ShareInrWss) + case flags.CheckShareSgd: // Share Sgd Wss + wss = fmt.Sprintf("/%v", flags.ShareSgdWss) + case flags.CheckShareHkd: // Share Hkd Wss + wss = fmt.Sprintf("/%v", flags.ShareHkdWss) + case flags.CheckShareGbx: // Share Gbx Wss + wss = fmt.Sprintf("/%v", flags.ShareGbxWss) + case flags.CheckShareEur: // Share Eur Wss + wss = fmt.Sprintf("/%v", flags.ShareEurWss) + case flags.CheckShareFur: // Share Fur Wss + wss = fmt.Sprintf("/%v", flags.ShareFurWss) + case flags.CheckShareBrl: // Share Brl Wss + wss = fmt.Sprintf("/%v", flags.ShareBrlWss) + case flags.CheckShareJpy: // Share Jpy Wss + wss = fmt.Sprintf("/%v", flags.ShareJpyWss) + case flags.CheckShareBlk: // share Blk Wss + wss = fmt.Sprintf("/%v", flags.ShareBlkWss) + case flags.CheckOptionInr: // Option Inr Wss + wss = fmt.Sprintf("/%v", flags.OptionInrWss) + case flags.CheckAdmin: // Admin Wss + wss = fmt.Sprintf("/%v", flags.AdminWss) + case flags.CheckAdminBlk: // Admin Blk Wss + wss = fmt.Sprintf("/%v", flags.AdminBlkWss) + } + + if r.URL.Path != wss { + applogger.Error("Request path error") + return false + } + + // Verification rules can also be customized according to other needs + return true + }, +} + +// PingMessage +// @Description: +type PingMessage struct { + Ping int64 `json:"ping"` +} + +// SymbolMessage +// @Description: +type SymbolMessage struct { + Type string `json:"type"` + Symbol string `json:"symbol"` + Order []string `json:"order"` +} + +// SymbolSumResult +// @Description: +type SymbolSumResult struct { + Symbol string `json:"Symbol"` + Price string `json:"Price"` +} + +// SymbolUserSumResult +// @Description: +type SymbolUserSumResult struct { + Symbol string `json:"Symbol"` + UserSumPrice map[int64]decimal.Decimal `json:"UserSumPrice"` +} + +// UserMarketStatistics +// @Description: +type UserMarketStatistics struct { + UserMarkerSubscribe string `json:"UserMarkerSubscribe"` // 用户市场订阅类型 + UserMarketTotalAssets string `json:"UserMarketTotalAssets"` // 用户市场总资产 + UserMarketAvailable string `json:"UserMarketAvailable"` // 用户市场总可用 + UserMarketFreeze string `json:"UserMarketFreeze"` // 用户市场冻结 + UserMarketProfitAndLoss string `json:"UserMarketProfitAndLoss"` // 用户市场累计盈亏 + UserMarketTotalFee string `json:"UserMarketTotalFee"` // 用户市场总手续费 + UserMarketFloatingPL string `json:"UserMarketFloatingPL"` // 用户市场总浮动盈亏 +} + +// ParsePingMessage +// +// @Description: ping message +// @param message +// @return *PingMessage +func ParsePingMessage(message string) *PingMessage { + result := PingMessage{} + err := json.Unmarshal([]byte(message), &result) + if err != nil { + return nil + } + + return &result +} + +// SubMessage +// +// @Description: 订阅消息解析 +// @param message +// @return *SymbolMessage +func SubMessage(message string) *SymbolMessage { + result := SymbolMessage{} + err := json.Unmarshal([]byte(message), &result) + if err != nil { + return nil + } + + return &result +} + +// ReturnValue +// +// @Description: 构建推送pong +// @param str +// @return string +func ReturnValue(str string) string { + pongMsg := fmt.Sprintf("{\"type\": \"%v\"}", str) + + return pongMsg +} + +// GetUserIdByToken +// +// @Description: 通过UserId验证Token +// @param token +// @return int64 +// @return error +func GetUserIdByToken(token string) (int64, error) { + userId, err := redis.GetCacheData(context.Background(), data.Reds, token) + if err != nil || len(userId) == 0 { + return 0, err + } + userID, err := strconv.Atoi(userId) + if err != nil || userID == 0 { + return 0, err + } + + return int64(userID), nil +} diff --git a/internal/data/socket/publicData/public.go b/internal/data/socket/publicData/public.go new file mode 100644 index 0000000..fd5a2a2 --- /dev/null +++ b/internal/data/socket/publicData/public.go @@ -0,0 +1,1068 @@ +package publicData + +import ( + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/tradedeal/option" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/setting" +) + +// OrderSub +// @Description: +type OrderSub struct { + OrderId string // 订单ID + Price string // 市价 + OpenPrice string // 开盘价 + Count int64 // 订单总数 + Status string // 订单状态 + Symbol string // 订阅Key + Market string // 交易对 + OrderNumber string // 仓位 + TradeType int64 // 交易类型(1买涨,2买跌) + FaceValue string // 合约面值 + Type int64 // 市场类型 + TradingType int64 // 交易方式: 1-BUY,2-SELLS + ServiceCost string // 开仓手续费 + UserId int64 // 用户ID +} + +// OptionSum +// @Description: +type OptionSum struct { + Type string // 类型 + Value string // 统计数据 +} + +// CheckSymbol +// +// @Description: 当前订阅订单交易对实时价格 +// @param topIc +// @param symbol +// @return string +// @return error +func CheckSymbol(topIc, symbol string) (string, error) { + var err error + var price []byte + + switch topIc { + case setting.SpotsSubscribe: // 用户现货订单订阅 + price, err = memory.SpotsCache.Get(SymbolCache(flags.Xh, symbol, flags.TradeTypePrice)) + if err != nil { + return flags.SetNull, err + } + case setting.ContractSubscribe: // 用户合约订单订阅 + price, err = memory.GetContractCache(SymbolCache(flags.Hy, symbol, flags.TradeTypePrice)) + if err != nil { + return flags.SetNull, err + } + case setting.SecondSubscribe: // 用户秒合约订单订阅 + price, err = memory.GetSecondCache(SymbolCache(flags.Sd, symbol, flags.TradeTypePrice)) + if err != nil { + return flags.SetNull, err + } + case setting.ShareUsSubscribe: // 用户美股订单订阅 + price, err = memory.GetShareUsCache(SymbolCache(flags.Us, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareUsClosePrice.Get(SymbolCache(flags.Us, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareMysSubscribe: // 用户马股订单订阅 + price, err = memory.GetShareMysCache(SymbolCache(flags.Mys, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareMysClosePrice.Get(SymbolCache(flags.Mys, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareThaSubscribe: // 用户泰股订单订阅 + price, err = memory.GetShareThaCache(SymbolCache(flags.Tha, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareThaClosePrice.Get(SymbolCache(flags.Tha, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareIdnSubscribe: // 用户印尼股订单订阅 + price, err = memory.GetShareIdnCache(SymbolCache(flags.Idn, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareIdnClosePrice.Get(SymbolCache(flags.Idn, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareInrSubscribe: // 用户印度股订单订阅 + price, err = memory.GetShareInrCache(SymbolCache(flags.Inr, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareInrClosePrice.Get(SymbolCache(flags.Inr, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareSgdSubscribe: // 用户新加坡股订单订阅 + price, err = memory.GetShareSgdCache(SymbolCache(flags.Sgd, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareSgdClosePrice.Get(SymbolCache(flags.Sgd, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareHkdSubscribe: // 用户港股订单订阅 + price, err = memory.GetShareHkdCache(SymbolCache(flags.Hkd, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareHkdClosePrice.Get(SymbolCache(flags.Hkd, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareGbxSubscribe: // 用户英股订单订阅 + price, err = memory.GetShareGbxCache(SymbolCache(flags.Gbx, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareGbxClosePrice.Get(SymbolCache(flags.Gbx, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareEurSubscribe: // 用户德股订单订阅 + price, err = memory.GetShareEurCache(SymbolCache(flags.Eur, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareEurClosePrice.Get(SymbolCache(flags.Eur, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareFurSubscribe: // 用户法股订单订阅 + price, err = memory.GetShareFurCache(SymbolCache(flags.Fur, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareFurClosePrice.Get(SymbolCache(flags.Fur, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareJpySubscribe: // 用户日股订单订阅 + price, err = memory.GetShareJpyCache(SymbolCache(flags.Jpy, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareJpyClosePrice.Get(SymbolCache(flags.Jpy, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareBrlSubscribe: // 用户巴西股订单订阅 + price, err = memory.GetShareBrlCache(SymbolCache(flags.Brl, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareBrlClosePrice.Get(SymbolCache(flags.Brl, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminContractSubscribe: // 管理员合约订单订阅 + price, err = memory.GetContractCache(SymbolCache(flags.Hy, symbol, flags.TradeTypePrice)) + if err != nil { + return flags.SetNull, err + } + case setting.AdminSecondSubscribe: // 管理员秒合约订单订阅 + price, err = memory.GetSecondCache(SymbolCache(flags.Sd, symbol, flags.TradeTypePrice)) + if err != nil { + return flags.SetNull, err + } + case setting.AdminShareUsSubscribe: // 管理员美股订单订阅 + price, err = memory.GetShareUsCache(SymbolCache(flags.Us, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareUsClosePrice.Get(SymbolCache(flags.Us, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareMysSubscribe: // 管理员马股订单订阅 + price, err = memory.GetShareMysCache(SymbolCache(flags.Mys, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareMysClosePrice.Get(SymbolCache(flags.Mys, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareThaSubscribe: // 管理员泰股订单订阅 + price, err = memory.GetShareThaCache(SymbolCache(flags.Tha, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareThaClosePrice.Get(SymbolCache(flags.Tha, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareIdnSubscribe: // 管理员印尼股订单订阅 + price, err = memory.GetShareIdnCache(SymbolCache(flags.Idn, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareIdnClosePrice.Get(SymbolCache(flags.Idn, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareInrSubscribe: // 管理员印度股订单订阅 + price, err = memory.GetShareInrCache(SymbolCache(flags.Inr, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareInrClosePrice.Get(SymbolCache(flags.Inr, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareSgdSubscribe: // 管理员新加坡股订单订阅 + price, err = memory.GetShareSgdCache(SymbolCache(flags.Sgd, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareSgdClosePrice.Get(SymbolCache(flags.Sgd, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareHkdSubscribe: // 管理员港股订单订阅 + price, err = memory.GetShareHkdCache(SymbolCache(flags.Hkd, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareHkdClosePrice.Get(SymbolCache(flags.Hkd, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareGbxSubscribe: // 管理员英股订单订阅 + price, err = memory.GetShareGbxCache(SymbolCache(flags.Gbx, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareGbxClosePrice.Get(SymbolCache(flags.Gbx, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareEurSubscribe: // 管理员德股订单订阅 + price, err = memory.GetShareEurCache(SymbolCache(flags.Eur, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareEurClosePrice.Get(SymbolCache(flags.Eur, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareFurSubscribe: // 管理员法股订单订阅 + price, err = memory.GetShareFurCache(SymbolCache(flags.Fur, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareFurClosePrice.Get(SymbolCache(flags.Fur, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareJpySubscribe: // 管理员日股订单订阅 + price, err = memory.GetShareJpyCache(SymbolCache(flags.Jpy, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareJpyClosePrice.Get(SymbolCache(flags.Jpy, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareBrlSubscribe: // 管理员巴西股订单订阅 + price, err = memory.GetShareBrlCache(SymbolCache(flags.Brl, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareBrlClosePrice.Get(SymbolCache(flags.Brl, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + } + + return string(price), nil +} +func CheckSymbolBak(topIc, symbol string) (string, error) { + var err error + var price []byte + + switch topIc { + case setting.SpotsSubscribe: // 用户现货订单订阅 + price, err = memory.SpotsCache.Get(SymbolCache(flags.Xh, symbol, flags.TradeTypePrice)) + if err != nil { + return flags.SetNull, err + } + case setting.ContractSubscribe: // 用户合约订单订阅 + price, err = memory.GetContractCache(SymbolCache(flags.Hy, symbol, flags.TradeTypePrice)) + if err != nil { + return flags.SetNull, err + } + case setting.SecondSubscribe: // 用户秒合约订单订阅 + price, err = memory.GetSecondCache(SymbolCache(flags.Sd, symbol, flags.TradeTypePrice)) + if err != nil { + return flags.SetNull, err + } + case setting.ShareUsSubscribe: // 用户美股订单订阅 + price, err = memory.GetShareUsCacheWs(SymbolCache(flags.Us, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareUsClosePrice.Get(SymbolCache(flags.Us, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareMysSubscribe: // 用户马股订单订阅 + price, err = memory.GetShareMysCacheWs(SymbolCache(flags.Mys, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareMysClosePrice.Get(SymbolCache(flags.Mys, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareThaSubscribe: // 用户泰股订单订阅 + price, err = memory.GetShareThaCacheWs(SymbolCache(flags.Tha, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareThaClosePrice.Get(SymbolCache(flags.Tha, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareIdnSubscribe: // 用户印尼股订单订阅 + price, err = memory.GetShareIdnCacheWs(SymbolCache(flags.Idn, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareIdnClosePrice.Get(SymbolCache(flags.Idn, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareInrSubscribe: // 用户印度股订单订阅 + price, err = memory.GetShareInrCacheWs(SymbolCache(flags.Inr, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareInrClosePrice.Get(SymbolCache(flags.Inr, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareSgdSubscribe: // 用户新加坡股订单订阅 + price, err = memory.GetShareSgdCacheWs(SymbolCache(flags.Sgd, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareSgdClosePrice.Get(SymbolCache(flags.Sgd, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareHkdSubscribe: // 用户港股订单订阅 + price, err = memory.GetShareHkdCacheWs(SymbolCache(flags.Hkd, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareHkdClosePrice.Get(SymbolCache(flags.Hkd, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareGbxSubscribe: // 用户英股订单订阅 + price, err = memory.GetShareGbxCacheWs(SymbolCache(flags.Gbx, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareGbxClosePrice.Get(SymbolCache(flags.Gbx, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareEurSubscribe: // 用户德股订单订阅 + price, err = memory.GetShareEurCacheWs(SymbolCache(flags.Eur, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareEurClosePrice.Get(SymbolCache(flags.Eur, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareFurSubscribe: // 用户法股订单订阅 + price, err = memory.GetShareFurCacheWs(SymbolCache(flags.Fur, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareFurClosePrice.Get(SymbolCache(flags.Fur, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareJpySubscribe: // 用户日股订单订阅 + price, err = memory.GetShareJpyCacheWs(SymbolCache(flags.Jpy, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareJpyClosePrice.Get(SymbolCache(flags.Jpy, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.ShareBrlSubscribe: // 用户巴西股订单订阅 + price, err = memory.GetShareBrlCacheWs(SymbolCache(flags.Brl, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareBrlClosePrice.Get(SymbolCache(flags.Brl, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminContractSubscribe: // 管理员合约订单订阅 + price, err = memory.GetContractCache(SymbolCache(flags.Hy, symbol, flags.TradeTypePrice)) + if err != nil { + return flags.SetNull, err + } + case setting.AdminSecondSubscribe: // 管理员秒合约订单订阅 + price, err = memory.GetSecondCache(SymbolCache(flags.Sd, symbol, flags.TradeTypePrice)) + if err != nil { + return flags.SetNull, err + } + case setting.AdminShareUsSubscribe: // 管理员美股订单订阅 + price, err = memory.GetShareUsCacheWs(SymbolCache(flags.Us, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareUsClosePrice.Get(SymbolCache(flags.Us, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareMysSubscribe: // 管理员马股订单订阅 + price, err = memory.GetShareMysCacheWs(SymbolCache(flags.Mys, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareMysClosePrice.Get(SymbolCache(flags.Mys, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareThaSubscribe: // 管理员泰股订单订阅 + price, err = memory.GetShareThaCacheWs(SymbolCache(flags.Tha, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareThaClosePrice.Get(SymbolCache(flags.Tha, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareIdnSubscribe: // 管理员印尼股订单订阅 + price, err = memory.GetShareIdnCacheWs(SymbolCache(flags.Idn, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareIdnClosePrice.Get(SymbolCache(flags.Idn, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareInrSubscribe: // 管理员印度股订单订阅 + price, err = memory.GetShareInrCacheWs(SymbolCache(flags.Inr, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareInrClosePrice.Get(SymbolCache(flags.Inr, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareSgdSubscribe: // 管理员新加坡股订单订阅 + price, err = memory.GetShareSgdCacheWs(SymbolCache(flags.Sgd, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareSgdClosePrice.Get(SymbolCache(flags.Sgd, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareHkdSubscribe: // 管理员港股订单订阅 + price, err = memory.GetShareHkdCacheWs(SymbolCache(flags.Hkd, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareHkdClosePrice.Get(SymbolCache(flags.Hkd, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareGbxSubscribe: // 管理员英股订单订阅 + price, err = memory.GetShareGbxCacheWs(SymbolCache(flags.Gbx, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareGbxClosePrice.Get(SymbolCache(flags.Gbx, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareEurSubscribe: // 管理员德股订单订阅 + price, err = memory.GetShareEurCacheWs(SymbolCache(flags.Eur, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareEurClosePrice.Get(SymbolCache(flags.Eur, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareFurSubscribe: // 管理员法股订单订阅 + price, err = memory.GetShareFurCacheWs(SymbolCache(flags.Fur, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareFurClosePrice.Get(SymbolCache(flags.Fur, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareJpySubscribe: // 管理员日股订单订阅 + price, err = memory.GetShareJpyCacheWs(SymbolCache(flags.Jpy, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareJpyClosePrice.Get(SymbolCache(flags.Jpy, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case setting.AdminShareBrlSubscribe: // 管理员巴西股订单订阅 + price, err = memory.GetShareBrlCacheWs(SymbolCache(flags.Brl, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareBrlClosePrice.Get(SymbolCache(flags.Brl, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + } + + return string(price), nil +} + +// CheckForexSymbol +// +// @Description: 外汇交易对买一卖一最新报价 +// @param topIc +// @param symbol +// @param tradeType +// @return string +// @return error +func CheckForexSymbol(topIc, symbol string, tradeType int64) (string, error) { + var err error + var priceNew []byte + switch tradeType { + case 1: + priceNew, err = memory.GetForexCache(SymbolCache(flags.Wh, symbol, flags.TradeTypeBuy)) + case 2: + priceNew, err = memory.GetForexCache(SymbolCache(flags.Wh, symbol, flags.TradeTypeSell)) + } + if err != nil { + return flags.SetNull, err + } + + return string(priceNew), nil +} + +// CheckForexImmediateSymbol +// +// @Description: 外汇交易即时报价 +// @param topIc +// @param symbol +// @param tradeType +// @return string +// @return error +func CheckForexImmediateSymbol(topIc, symbol string, tradeType int64) (string, error) { + priceNew, err := memory.GetForexImmediateCache(SymbolCache(flags.Wh, symbol, flags.TradeTypePrice)) + if err != nil { + return flags.SetNull, err + } + + return string(priceNew), nil +} + +// CheckMoneyImmediateSymbol +// +// @Description: 综合(现货|合约|外汇)交易即时报价 +// @param topIc +// @param symbol +// @param typeStatus +// @return string +// @return +func CheckMoneyImmediateSymbol(topIc, symbol string, marketType int64) (string, error) { + var err error + var priceNew []byte + var keyType int + if flags.CheckEnvironment == flags.CheckAdmin { + keyType = flags.TradeTypeAdminPrice + } else { + keyType = flags.TradeTypePrice + } + + switch marketType { + case flags.SpotsMarketType: // 现货 + priceNew, err = memory.GetMoneySpotsCache(SymbolCache(flags.Xh, symbol, keyType)) + if err != nil { + return flags.SetNull, err + } + case flags.ContractMarketType: // 合约 + priceNew, err = memory.GetMoneyContractCache(SymbolCache(flags.Hy, symbol, keyType)) + if err != nil { + return flags.SetNull, err + } + case flags.ForexMarketType: // 外汇 + priceNew, err = memory.GetMoneyForexImmediateCache(SymbolCache(flags.Wh, symbol, keyType)) + if err != nil { + return flags.SetNull, err + } + default: + } + + return string(priceNew), nil +} + +// CheckSymbolBlock +// +// @Description: 大宗交易当前订阅订单交易队实时价格 +// @param topIc +// @param symbol +// @param typeStatus +// @return string +// @return error +func CheckSymbolBlock(topIc, symbol string, typeStatus int64) (string, error) { + var err error + var price []byte + + switch topIc { + case setting.ShareBlkSubscribe: // 用户大宗交易订单订阅 + switch typeStatus { + case flags.ShareUsMarketType: // 美股 + price, err = memory.GetShareUsCache(SymbolCache(flags.Us, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareUsClosePrice.Get(SymbolCache(flags.Us, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareThaMarketType: // 泰股 + price, err = memory.GetShareThaCache(SymbolCache(flags.Tha, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareThaClosePrice.Get(SymbolCache(flags.Tha, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareMysMarketType: // 马股 + price, err = memory.GetShareMysCache(SymbolCache(flags.Mys, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareMysClosePrice.Get(SymbolCache(flags.Mys, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareIdnMarketType: // 印尼股 + price, err = memory.GetShareIdnCache(SymbolCache(flags.Idn, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareIdnClosePrice.Get(SymbolCache(flags.Idn, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareInrMarketType: // 印度股 + price, err = memory.GetShareInrCache(SymbolCache(flags.Inr, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareInrClosePrice.Get(SymbolCache(flags.Inr, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareSgdMarketType: // 新加坡股 + price, err = memory.GetShareSgdCache(SymbolCache(flags.Sgd, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareSgdClosePrice.Get(SymbolCache(flags.Sgd, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareHkdMarketType: // 港股 + price, err = memory.GetShareHkdCache(SymbolCache(flags.Hkd, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareHkdClosePrice.Get(SymbolCache(flags.Hkd, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareGbxMarketType: // 英股 + price, err = memory.GetShareGbxCache(SymbolCache(flags.Gbx, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareGbxClosePrice.Get(SymbolCache(flags.Gbx, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareEurMarketType: // 德股 + price, err = memory.GetShareEurCache(SymbolCache(flags.Eur, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareEurClosePrice.Get(SymbolCache(flags.Eur, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareFurMarketType: // 法股 + price, err = memory.GetShareFurCache(SymbolCache(flags.Fur, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareFurClosePrice.Get(SymbolCache(flags.Fur, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareJpyMarketType: // 日股 + price, err = memory.GetShareJpyCache(SymbolCache(flags.Jpy, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareJpyClosePrice.Get(SymbolCache(flags.Jpy, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareBrlMarketType: // 巴西股 + price, err = memory.GetShareBrlCache(SymbolCache(flags.Brl, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareBrlClosePrice.Get(SymbolCache(flags.Brl, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + } + case setting.AdminShareBlkSubscribe: // 管理员大宗交易股-订单订阅 + switch typeStatus { + case flags.ShareUsMarketType: // 美股 + price, err = memory.GetShareUsCache(SymbolCache(flags.Us, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareUsClosePrice.Get(SymbolCache(flags.Us, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareThaMarketType: // 泰股 + price, err = memory.GetShareThaCache(SymbolCache(flags.Tha, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareThaClosePrice.Get(SymbolCache(flags.Tha, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareMysMarketType: // 马股 + price, err = memory.GetShareMysCache(SymbolCache(flags.Mys, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareMysClosePrice.Get(SymbolCache(flags.Mys, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareIdnMarketType: // 印尼股 + price, err = memory.GetShareIdnCache(SymbolCache(flags.Idn, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareIdnClosePrice.Get(SymbolCache(flags.Idn, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareInrMarketType: // 印度股 + price, err = memory.GetShareInrCache(SymbolCache(flags.Inr, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareInrClosePrice.Get(SymbolCache(flags.Inr, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareSgdMarketType: // 新加坡股 + price, err = memory.GetShareSgdCache(SymbolCache(flags.Sgd, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareSgdClosePrice.Get(SymbolCache(flags.Sgd, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareHkdMarketType: // 港股 + price, err = memory.GetShareHkdCache(SymbolCache(flags.Hkd, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareHkdClosePrice.Get(SymbolCache(flags.Hkd, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareGbxMarketType: // 英股 + price, err = memory.GetShareGbxCache(SymbolCache(flags.Gbx, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareGbxClosePrice.Get(SymbolCache(flags.Gbx, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareEurMarketType: // 德股 + price, err = memory.GetShareEurCache(SymbolCache(flags.Eur, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareEurClosePrice.Get(SymbolCache(flags.Eur, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareFurMarketType: // 法股 + price, err = memory.GetShareFurCache(SymbolCache(flags.Fur, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareFurClosePrice.Get(SymbolCache(flags.Fur, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareJpyMarketType: // 日股 + price, err = memory.GetShareJpyCache(SymbolCache(flags.Jpy, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareJpyClosePrice.Get(SymbolCache(flags.Jpy, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareBrlMarketType: // 巴西股 + price, err = memory.GetShareBrlCache(SymbolCache(flags.Brl, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareBrlClosePrice.Get(SymbolCache(flags.Brl, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + } + } + + return string(price), nil +} +func CheckSymbolBlockBak(topIc, symbol string, typeStatus int64) (string, error) { + var err error + var price []byte + + switch topIc { + case setting.ShareBlkSubscribe: // 用户大宗交易订单订阅 + switch typeStatus { + case flags.ShareUsMarketType: // 美股 + price, err = memory.GetShareUsCacheWs(SymbolCache(flags.Us, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareUsClosePrice.Get(SymbolCache(flags.Us, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareThaMarketType: // 泰股 + price, err = memory.GetShareThaCacheWs(SymbolCache(flags.Tha, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareThaClosePrice.Get(SymbolCache(flags.Tha, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareMysMarketType: // 马股 + price, err = memory.GetShareMysCacheWs(SymbolCache(flags.Mys, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareMysClosePrice.Get(SymbolCache(flags.Mys, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareIdnMarketType: // 印尼股 + price, err = memory.GetShareIdnCacheWs(SymbolCache(flags.Idn, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareIdnClosePrice.Get(SymbolCache(flags.Idn, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareInrMarketType: // 印度股 + price, err = memory.GetShareInrCacheWs(SymbolCache(flags.Inr, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareInrClosePrice.Get(SymbolCache(flags.Inr, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareSgdMarketType: // 新加坡股 + price, err = memory.GetShareSgdCacheWs(SymbolCache(flags.Sgd, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareSgdClosePrice.Get(SymbolCache(flags.Sgd, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareHkdMarketType: // 港股 + price, err = memory.GetShareHkdCacheWs(SymbolCache(flags.Hkd, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareHkdClosePrice.Get(SymbolCache(flags.Hkd, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareGbxMarketType: // 英股 + price, err = memory.GetShareGbxCacheWs(SymbolCache(flags.Gbx, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareGbxClosePrice.Get(SymbolCache(flags.Gbx, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareEurMarketType: // 德股 + price, err = memory.GetShareEurCacheWs(SymbolCache(flags.Eur, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareEurClosePrice.Get(SymbolCache(flags.Eur, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareFurMarketType: // 法股 + price, err = memory.GetShareFurCacheWs(SymbolCache(flags.Fur, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareFurClosePrice.Get(SymbolCache(flags.Fur, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareJpyMarketType: // 日股 + price, err = memory.GetShareJpyCacheWs(SymbolCache(flags.Jpy, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareJpyClosePrice.Get(SymbolCache(flags.Jpy, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareBrlMarketType: // 巴西股 + price, err = memory.GetShareBrlCacheWs(SymbolCache(flags.Brl, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareBrlClosePrice.Get(SymbolCache(flags.Brl, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + } + case setting.AdminShareBlkSubscribe: // 管理员大宗交易股-订单订阅 + switch typeStatus { + case flags.ShareUsMarketType: // 美股 + price, err = memory.GetShareUsCacheWs(SymbolCache(flags.Us, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareUsClosePrice.Get(SymbolCache(flags.Us, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareThaMarketType: // 泰股 + price, err = memory.GetShareThaCacheWs(SymbolCache(flags.Tha, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareThaClosePrice.Get(SymbolCache(flags.Tha, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareMysMarketType: // 马股 + price, err = memory.GetShareMysCacheWs(SymbolCache(flags.Mys, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareMysClosePrice.Get(SymbolCache(flags.Mys, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareIdnMarketType: // 印尼股 + price, err = memory.GetShareIdnCacheWs(SymbolCache(flags.Idn, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareIdnClosePrice.Get(SymbolCache(flags.Idn, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareInrMarketType: // 印度股 + price, err = memory.GetShareInrCacheWs(SymbolCache(flags.Inr, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareInrClosePrice.Get(SymbolCache(flags.Inr, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareSgdMarketType: // 新加坡股 + price, err = memory.GetShareSgdCacheWs(SymbolCache(flags.Sgd, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareSgdClosePrice.Get(SymbolCache(flags.Sgd, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareHkdMarketType: // 港股 + price, err = memory.GetShareHkdCacheWs(SymbolCache(flags.Hkd, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareHkdClosePrice.Get(SymbolCache(flags.Hkd, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareGbxMarketType: // 英股 + price, err = memory.GetShareGbxCacheWs(SymbolCache(flags.Gbx, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareGbxClosePrice.Get(SymbolCache(flags.Gbx, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareEurMarketType: // 德股 + price, err = memory.GetShareEurCacheWs(SymbolCache(flags.Eur, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareEurClosePrice.Get(SymbolCache(flags.Eur, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareFurMarketType: // 法股 + price, err = memory.GetShareFurCacheWs(SymbolCache(flags.Fur, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareFurClosePrice.Get(SymbolCache(flags.Fur, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareJpyMarketType: // 日股 + price, err = memory.GetShareJpyCacheWs(SymbolCache(flags.Jpy, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareJpyClosePrice.Get(SymbolCache(flags.Jpy, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + case flags.ShareBrlMarketType: // 法股 + price, err = memory.GetShareBrlCacheWs(SymbolCache(flags.Brl, symbol, flags.TradeTypePrice)) + if err != nil || len(price) == 0 { + price, err = memory.ShareBrlClosePrice.Get(SymbolCache(flags.Brl, symbol, flags.TradeTypeClosePrice)) + if err != nil { + return flags.SetNull, err + } + } + } + } + + return string(price), nil +} + +// CheckSymbolOption +// +// @Description: 期权数据浮动盈亏计算价格 +// @param order +func CheckSymbolOption(order option.OptionInrTallyCache) (string, error) { + price := decimal.Zero + // 买一价格 + bidKey := SymbolCache(flags.Opi, order.Order.StockCode, flags.OptionBid) + priceBid, err := memory.GetOptionInrBid(bidKey) + if err != nil { + return flags.SetNull, err + } + bid, _ := decimal.NewFromString(string(priceBid)) + + // 卖一价格 + askKey := SymbolCache(flags.Opi, order.Order.StockCode, flags.OptionAsk) + priceAsk, err := memory.GetOptionInrAsk(askKey) + if err != nil { + return flags.SetNull, err + } + ask, _ := decimal.NewFromString(string(priceAsk)) + + // 浮动盈亏 + // buy-call 和 buy-put bid买一价 + // sell-call 和 sell-put aSK卖一价 + switch order.Order.TradeType { + case flags.OptionCalls: // call + switch order.Order.TradingType { + case flags.OptionBuy: // call - buy + if !bid.IsZero() { + price = bid + } + case flags.OptionSell: // call - sell + if !ask.IsZero() { + price = ask + } + } + case flags.OptionPuts: // put + switch order.Order.TradingType { + case flags.OptionBuy: // put - buy + if !bid.IsZero() { + price = bid + } + case flags.OptionSell: // put - sell + if !ask.IsZero() { + price = ask + } + } + } + + if price.IsZero() { + return flags.SetNull, nil + } + + return price.String(), nil +} + +// SymbolCache +// +// @Description: +// @param mark +// @param symbol +// @param types +// @return string +func SymbolCache(mark, symbol string, types int) string { + return fmt.Sprintf("%v-%v-%v", mark, symbol, types) +} diff --git a/internal/data/socket/publicData/public_test.go b/internal/data/socket/publicData/public_test.go new file mode 100644 index 0000000..331061f --- /dev/null +++ b/internal/data/socket/publicData/public_test.go @@ -0,0 +1,128 @@ +package publicData + +import "testing" + +func TestCheckSymbol(t *testing.T) { + type args struct { + topIc string + symbol string + } + tests := []struct { + name string + args args + want string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := CheckSymbol(tt.args.topIc, tt.args.symbol) + if (err != nil) != tt.wantErr { + t.Errorf("CheckSymbol() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("CheckSymbol() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCheckSymbol1(t *testing.T) { + type args struct { + topIc string + symbol string + } + tests := []struct { + name string + args args + want string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := CheckSymbol(tt.args.topIc, tt.args.symbol) + if (err != nil) != tt.wantErr { + t.Errorf("CheckSymbol() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("CheckSymbol() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestSymbolCache(t *testing.T) { + type args struct { + mark string + symbol string + types int + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := SymbolCache(tt.args.mark, tt.args.symbol, tt.args.types); got != tt.want { + t.Errorf("SymbolCache() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCheckSymbol2(t *testing.T) { + type args struct { + topIc string + symbol string + } + tests := []struct { + name string + args args + want string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := CheckSymbol(tt.args.topIc, tt.args.symbol) + if (err != nil) != tt.wantErr { + t.Errorf("CheckSymbol() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("CheckSymbol() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestSymbolCache1(t *testing.T) { + type args struct { + mark string + symbol string + types int + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := SymbolCache(tt.args.mark, tt.args.symbol, tt.args.types); got != tt.want { + t.Errorf("SymbolCache() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/data/socket/shareData/share_blk.go b/internal/data/socket/shareData/share_blk.go new file mode 100644 index 0000000..c08e4aa --- /dev/null +++ b/internal/data/socket/shareData/share_blk.go @@ -0,0 +1,47 @@ +package shareData + +import ( + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" +) + +// ShareBlkOrderProcessing +// +// @Description: 股票-大宗交易股订阅处理 +// @param topIc +// @param msg +// @return *public.OrderSub +func ShareBlkOrderProcessing(topIc string, check int, msg share.ShareBlkTallyCache) *publicData.OrderSub { + var top string + switch check { + case 0: + top = setting.SubscribeShareBlk + case 1: + top = setting.SubscribeAdminShareBlk + } + + price, err := publicData.CheckSymbolBlock(topIc, msg.Symbol, msg.Order.Type) + if err != nil { + applogger.Warn("%v ShareBlkOrderProcessing.CheckSymbol.err:%v--%v", common.ErrShareBlk, msg.Symbol, err) + } + + orderM := &publicData.OrderSub{ + OrderId: msg.OrderId, + Price: utils.DecimalsPrice(price), + Status: msg.Status, + Symbol: top, + Count: 0, + OpenPrice: msg.OpenPrice, + Market: msg.Symbol, + OrderNumber: msg.Order.OrderNumber, + TradeType: msg.Order.TradeType, + Type: msg.Order.Type, + UserId: msg.UserId, + } + + return orderM +} diff --git a/internal/data/socket/shareData/share_brl.go b/internal/data/socket/shareData/share_brl.go new file mode 100644 index 0000000..9fa0359 --- /dev/null +++ b/internal/data/socket/shareData/share_brl.go @@ -0,0 +1,37 @@ +package shareData + +import ( + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/utils" +) + +// ShareBrlOrderProcessing +// +// @Description: 股票-巴西股订阅处理 +// @param topIc +// @param msg +// @return *public.OrderSub +func ShareBrlOrderProcessing(topIc string, msg share.ShareBrlTallyCache) *publicData.OrderSub { + price, err := publicData.CheckSymbol(topIc, msg.Symbol) + if err != nil { + applogger.Warn("%v ShareBrlOrderProcessing.CheckSymbol.err:%v--%v", common.ErrShareBrl, msg.Symbol, err) + } + + orderM := &publicData.OrderSub{ + OrderId: msg.OrderId, + Price: utils.DecimalsPrice(price), + Status: msg.Status, + Symbol: topIc, + Count: 0, + OpenPrice: msg.OpenPrice, + Market: msg.Symbol, + OrderNumber: msg.Order.OrderNumber, + TradeType: msg.Order.TradeType, + UserId: msg.UserId, + } + + return orderM +} diff --git a/internal/data/socket/shareData/share_eur.go b/internal/data/socket/shareData/share_eur.go new file mode 100644 index 0000000..1044558 --- /dev/null +++ b/internal/data/socket/shareData/share_eur.go @@ -0,0 +1,37 @@ +package shareData + +import ( + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/utils" +) + +// ShareEurOrderProcessing +// +// @Description: 股票-德股订阅处理 +// @param topIc +// @param msg +// @return *public.OrderSub +func ShareEurOrderProcessing(topIc string, msg share.ShareEurTallyCache) *publicData.OrderSub { + price, err := publicData.CheckSymbol(topIc, msg.Symbol) + if err != nil { + applogger.Warn("%v ShareEurOrderProcessing.CheckSymbol.err:%v--%v", common.ErrShareEur, msg.Symbol, err) + } + + orderM := &publicData.OrderSub{ + OrderId: msg.OrderId, + Price: utils.DecimalsPrice(price), + Status: msg.Status, + Symbol: topIc, + Count: 0, + OpenPrice: msg.OpenPrice, + Market: msg.Symbol, + OrderNumber: msg.Order.OrderNumber, + TradeType: msg.Order.TradeType, + UserId: msg.UserId, + } + + return orderM +} diff --git a/internal/data/socket/shareData/share_fur.go b/internal/data/socket/shareData/share_fur.go new file mode 100644 index 0000000..7381a80 --- /dev/null +++ b/internal/data/socket/shareData/share_fur.go @@ -0,0 +1,37 @@ +package shareData + +import ( + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/utils" +) + +// ShareFurOrderProcessing +// +// @Description: 股票-法股订阅处理 +// @param topIc +// @param msg +// @return *public.OrderSub +func ShareFurOrderProcessing(topIc string, msg share.ShareFurTallyCache) *publicData.OrderSub { + price, err := publicData.CheckSymbol(topIc, msg.Symbol) + if err != nil { + applogger.Warn("%v ShareFurOrderProcessing.CheckSymbol.err:%v--%v", common.ErrShareFur, msg.Symbol, err) + } + + orderM := &publicData.OrderSub{ + OrderId: msg.OrderId, + Price: utils.DecimalsPrice(price), + Status: msg.Status, + Symbol: topIc, + Count: 0, + OpenPrice: msg.OpenPrice, + Market: msg.Symbol, + OrderNumber: msg.Order.OrderNumber, + TradeType: msg.Order.TradeType, + UserId: msg.UserId, + } + + return orderM +} diff --git a/internal/data/socket/shareData/share_gbx.go b/internal/data/socket/shareData/share_gbx.go new file mode 100644 index 0000000..d491a06 --- /dev/null +++ b/internal/data/socket/shareData/share_gbx.go @@ -0,0 +1,37 @@ +package shareData + +import ( + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/utils" +) + +// ShareGbxOrderProcessing +// +// @Description: 股票-英股订阅处理 +// @param topIc +// @param msg +// @return *public.OrderSub +func ShareGbxOrderProcessing(topIc string, msg share.ShareGbxTallyCache) *publicData.OrderSub { + price, err := publicData.CheckSymbol(topIc, msg.Symbol) + if err != nil { + applogger.Warn("%v ShareGbxOrderProcessing.CheckSymbol.err:%v--%v", common.ErrShareGbx, msg.Symbol, err) + } + + orderM := &publicData.OrderSub{ + OrderId: msg.OrderId, + Price: utils.DecimalsPrice(price), + Status: msg.Status, + Symbol: topIc, + Count: 0, + OpenPrice: msg.OpenPrice, + Market: msg.Symbol, + OrderNumber: msg.Order.OrderNumber, + TradeType: msg.Order.TradeType, + UserId: msg.UserId, + } + + return orderM +} diff --git a/internal/data/socket/shareData/share_hkd.go b/internal/data/socket/shareData/share_hkd.go new file mode 100644 index 0000000..cb0431a --- /dev/null +++ b/internal/data/socket/shareData/share_hkd.go @@ -0,0 +1,46 @@ +package shareData + +import ( + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" +) + +// ShareHkdOrderProcessing +// +// @Description: 股票-港股订阅处理 +// @param topIc +// @param msg +// @return *public.OrderSub +func ShareHkdOrderProcessing(topIc string, check int, msg share.ShareHkdTallyCache) *publicData.OrderSub { + var top string + switch check { + case 0: + top = setting.SubscribeShareHkd + case 1: + top = setting.SubscribeAdminShareHkd + } + + price, err := publicData.CheckSymbol(topIc, msg.Symbol) + if err != nil { + applogger.Warn("%v ShareHkdOrderProcessing.CheckSymbol.err:%v--%v", common.ErrShareHkd, msg.Symbol, err) + } + + orderM := &publicData.OrderSub{ + OrderId: msg.OrderId, + Price: utils.DecimalsPrice(price), + Status: msg.Status, + Symbol: top, + Count: 0, + OpenPrice: msg.OpenPrice, + Market: msg.Symbol, + OrderNumber: msg.Order.OrderNumber, + TradeType: msg.Order.TradeType, + UserId: msg.UserId, + } + + return orderM +} diff --git a/internal/data/socket/shareData/share_idn.go b/internal/data/socket/shareData/share_idn.go new file mode 100644 index 0000000..f77265c --- /dev/null +++ b/internal/data/socket/shareData/share_idn.go @@ -0,0 +1,37 @@ +package shareData + +import ( + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/utils" +) + +// ShareIdnOrderProcessing +// +// @Description: 股票-印尼股订阅处理 +// @param topIc +// @param msg +// @return *public.OrderSub +func ShareIdnOrderProcessing(topIc string, msg share.ShareIdnTallyCache) *publicData.OrderSub { + price, err := publicData.CheckSymbol(topIc, msg.Symbol) + if err != nil { + applogger.Warn("%v ShareIdnOrderProcessing.CheckSymbol.err:%v--%v", common.ErrShareIdn, msg.Symbol, err) + } + + orderM := &publicData.OrderSub{ + OrderId: msg.OrderId, + Price: utils.DecimalsPrice(price), + Status: msg.Status, + Symbol: topIc, + Count: 0, + OpenPrice: msg.OpenPrice, + Market: msg.Symbol, + OrderNumber: msg.Order.OrderNumber, + TradeType: msg.Order.TradeType, + UserId: msg.UserId, + } + + return orderM +} diff --git a/internal/data/socket/shareData/share_inr.go b/internal/data/socket/shareData/share_inr.go new file mode 100644 index 0000000..fd03117 --- /dev/null +++ b/internal/data/socket/shareData/share_inr.go @@ -0,0 +1,37 @@ +package shareData + +import ( + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/utils" +) + +// ShareInrOrderProcessing +// +// @Description: 股票-印度股订阅处理 +// @param topIc +// @param msg +// @return *public.OrderSub +func ShareInrOrderProcessing(topIc string, msg share.ShareInrTallyCache) *publicData.OrderSub { + price, err := publicData.CheckSymbol(topIc, msg.Symbol) + if err != nil { + applogger.Warn("%v ShareInrOrderProcessing.CheckSymbol.err:%v--%v", common.ErrShareInr, msg.Symbol, err) + } + + orderM := &publicData.OrderSub{ + OrderId: msg.OrderId, + Price: utils.DecimalsPrice(price), + Status: msg.Status, + Symbol: topIc, + Count: 0, + OpenPrice: msg.OpenPrice, + Market: msg.Symbol, + OrderNumber: msg.Order.OrderNumber, + TradeType: msg.Order.TradeType, + UserId: msg.UserId, + } + + return orderM +} diff --git a/internal/data/socket/shareData/share_jpy.go b/internal/data/socket/shareData/share_jpy.go new file mode 100644 index 0000000..5cd495a --- /dev/null +++ b/internal/data/socket/shareData/share_jpy.go @@ -0,0 +1,37 @@ +package shareData + +import ( + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/utils" +) + +// ShareJpyOrderProcessing +// +// @Description: 股票-日股订阅处理 +// @param topIc +// @param msg +// @return *public.OrderSub +func ShareJpyOrderProcessing(topIc string, msg share.ShareJpyTallyCache) *publicData.OrderSub { + price, err := publicData.CheckSymbol(topIc, msg.Symbol) + if err != nil { + applogger.Warn("%v ShareJpyOrderProcessing.CheckSymbol.err:%v--%v", common.ErrShareJpy, msg.Symbol, err) + } + + orderM := &publicData.OrderSub{ + OrderId: msg.OrderId, + Price: utils.DecimalsPrice(price), + Status: msg.Status, + Symbol: topIc, + Count: 0, + OpenPrice: msg.OpenPrice, + Market: msg.Symbol, + OrderNumber: msg.Order.OrderNumber, + TradeType: msg.Order.TradeType, + UserId: msg.UserId, + } + + return orderM +} diff --git a/internal/data/socket/shareData/share_mys.go b/internal/data/socket/shareData/share_mys.go new file mode 100644 index 0000000..1d11154 --- /dev/null +++ b/internal/data/socket/shareData/share_mys.go @@ -0,0 +1,37 @@ +package shareData + +import ( + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/utils" +) + +// ShareMysOrderProcessing +// +// @Description: 股票-马股订阅处理 +// @param topIc +// @param msg +// @return *public.OrderSub +func ShareMysOrderProcessing(topIc string, msg share.ShareMysTallyCache) *publicData.OrderSub { + price, err := publicData.CheckSymbol(topIc, msg.Symbol) + if err != nil { + applogger.Warn("%v ShareMysOrderProcessing.CheckSymbol.err:%v--%v", common.ErrShareMys, msg.Symbol, err) + } + + orderM := &publicData.OrderSub{ + OrderId: msg.OrderId, + Price: utils.DecimalsPrice(price), + Status: msg.Status, + Symbol: topIc, + Count: 0, + OpenPrice: msg.OpenPrice, + Market: msg.Symbol, + OrderNumber: msg.Order.OrderNumber, + TradeType: msg.Order.TradeType, + UserId: msg.UserId, + } + + return orderM +} diff --git a/internal/data/socket/shareData/share_sgd.go b/internal/data/socket/shareData/share_sgd.go new file mode 100644 index 0000000..d28a34e --- /dev/null +++ b/internal/data/socket/shareData/share_sgd.go @@ -0,0 +1,37 @@ +package shareData + +import ( + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/utils" +) + +// ShareSgdOrderProcessing +// +// @Description: 股票-新加坡股订阅处理 +// @param topIc +// @param msg +// @return *public.OrderSub +func ShareSgdOrderProcessing(topIc string, msg share.ShareSgdTallyCache) *publicData.OrderSub { + price, err := publicData.CheckSymbol(topIc, msg.Symbol) + if err != nil { + applogger.Warn("%v ShareSgdOrderProcessing.CheckSymbol.err:%v--%v", common.ErrShareSgd, msg.Symbol, err) + } + + orderM := &publicData.OrderSub{ + OrderId: msg.OrderId, + Price: utils.DecimalsPrice(price), + Status: msg.Status, + Symbol: topIc, + Count: 0, + OpenPrice: msg.OpenPrice, + Market: msg.Symbol, + OrderNumber: msg.Order.OrderNumber, + TradeType: msg.Order.TradeType, + UserId: msg.UserId, + } + + return orderM +} diff --git a/internal/data/socket/shareData/share_tha.go b/internal/data/socket/shareData/share_tha.go new file mode 100644 index 0000000..79c0cab --- /dev/null +++ b/internal/data/socket/shareData/share_tha.go @@ -0,0 +1,37 @@ +package shareData + +import ( + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/utils" +) + +// ShareThaOrderProcessing +// +// @Description: 股票-泰股订阅处理 +// @param topIc +// @param msg +// @return *public.OrderSub +func ShareThaOrderProcessing(topIc string, msg share.ShareThaTallyCache) *publicData.OrderSub { + price, err := publicData.CheckSymbol(topIc, msg.Symbol) + if err != nil { + applogger.Warn("%v ShareThaOrderProcessing.CheckSymbol.err:%v--%v", common.ErrShareTha, msg.Symbol, err) + } + + orderM := &publicData.OrderSub{ + OrderId: msg.OrderId, + Price: utils.DecimalsPrice(price), + Status: msg.Status, + Symbol: topIc, + Count: 0, + OpenPrice: msg.OpenPrice, + Market: msg.Symbol, + OrderNumber: msg.Order.OrderNumber, + TradeType: msg.Order.TradeType, + UserId: msg.UserId, + } + + return orderM +} diff --git a/internal/data/socket/shareData/share_us.go b/internal/data/socket/shareData/share_us.go new file mode 100644 index 0000000..f9b5585 --- /dev/null +++ b/internal/data/socket/shareData/share_us.go @@ -0,0 +1,37 @@ +package shareData + +import ( + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/utils" +) + +// ShareUsOrderProcessing +// +// @Description: 股票-美股订阅处理 +// @param topIc +// @param msg +// @return *public.OrderSub +func ShareUsOrderProcessing(topIc string, msg share.ShareUsTallyCache) *publicData.OrderSub { + price, err := publicData.CheckSymbol(topIc, msg.Symbol) + if err != nil { + applogger.Warn("%v ShareUsOrderProcessing.CheckSymbol.err:%v--%v", common.ErrShareUs, msg.Symbol, err) + } + + orderM := &publicData.OrderSub{ + OrderId: msg.OrderId, + Price: utils.DecimalsPrice(price), + Status: msg.Status, + Symbol: topIc, + Count: 0, + OpenPrice: msg.OpenPrice, + Market: msg.Symbol, + OrderNumber: msg.Order.OrderNumber, + TradeType: msg.Order.TradeType, + UserId: msg.UserId, + } + + return orderM +} diff --git a/internal/data/socket/share_admin.go b/internal/data/socket/share_admin.go new file mode 100644 index 0000000..364fe80 --- /dev/null +++ b/internal/data/socket/share_admin.go @@ -0,0 +1,1022 @@ +package socket + +import ( + "context" + "encoding/json" + "matchmaking-system/internal/data" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/socket/shareData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/setting" + "time" +) + +// orderSubAdminShareUsSubscribeByOrder +// +// @Description: 管理员美股|订单订阅|持仓订单订阅|持仓浮动盈亏订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubAdminShareUsSubscribeByOrder(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareUsSubscribe { + var hashList []share.ShareUsTallyCache + for _, field := range psgMsg.Order { + fieldStr, err := data.Reds.HGet(context.Background(), setting.AdminShareUsSubscribe, field).Result() + if err != nil { + continue + } + var msg share.ShareUsTallyCache + if err = json.Unmarshal([]byte(fieldStr), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + hashList = append(hashList, msg) + } + + for _, value := range hashList { + orderModel := shareData.ShareUsOrderProcessing(setting.AdminShareUsSubscribe, value) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理[撤单|平仓]缓存队列 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + if err := data.Reds.HDel(context.Background(), setting.AdminShareUsSubscribe, orderModel.OrderId).Err(); err != nil { + applogger.Error("AdminSecondSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("Administrator's US stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Warn("Administrator cancels subscription to US stock orders.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubAdminShareUsSubscribeBySum(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareUsSumSubscribe { + priceSum, err := memory.ShareUsFloating.Get(flags.FloatingUs) + if err != nil { + continue + } + + result := &SymbolSumResult{ + Symbol: psgMsg.Symbol, + Price: string(priceSum), + } + + priceByte, err := json.Marshal(result) + if err != nil { + continue + } + + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + u.msg <- priceByte + } else { + applogger.Info("Administrator cancels subscription to US stock orders.") + return + } + } + + time.Sleep(1 * time.Second) + } +} + +// orderSubAdminShareMysSubscribeByOrder +// +// @Description: 管理员马股|订单订阅|持仓订单订阅|持仓浮动盈亏订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubAdminShareMysSubscribeByOrder(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareMysSubscribe { + var hashList []share.ShareMysTallyCache + for _, field := range psgMsg.Order { + fieldStr, err := data.Reds.HGet(context.Background(), setting.AdminShareMysSubscribe, field).Result() + if err != nil { + continue + } + var msg share.ShareMysTallyCache + if err = json.Unmarshal([]byte(fieldStr), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + hashList = append(hashList, msg) + } + + for _, value := range hashList { + orderModel := shareData.ShareMysOrderProcessing(setting.AdminShareMysSubscribe, value) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理[撤单|平仓]缓存队列 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + if err := data.Reds.HDel(context.Background(), setting.AdminShareMysSubscribe, orderModel.OrderId).Err(); err != nil { + applogger.Error("AdminShareThaSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("Administrator's stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("Administrator cancels subscription to horse stock orders.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubAdminShareMysSubscribeBySum(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareMysSumSubscribe { + priceSum, err := memory.ShareMysFloating.Get(flags.FloatingMys) + if err != nil { + continue + } + + result := &SymbolSumResult{ + Symbol: psgMsg.Symbol, + Price: string(priceSum), + } + + priceByte, err := json.Marshal(result) + if err != nil { + continue + } + + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + u.msg <- priceByte + } else { + applogger.Info("Administrator cancels subscription to horse stock orders.") + return + } + } + + time.Sleep(1 * time.Second) + } +} + +// orderSubAdminShareThaSubscribeByOrder +// +// @Description: 管理员泰股|订单订阅|持仓订单订阅|持仓浮动盈亏订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubAdminShareThaSubscribeByOrder(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareThaSubscribe { + var hashList []share.ShareThaTallyCache + for _, field := range psgMsg.Order { + fieldStr, err := data.Reds.HGet(context.Background(), setting.AdminShareThaSubscribe, field).Result() + if err != nil { + continue + } + var msg share.ShareThaTallyCache + if err = json.Unmarshal([]byte(fieldStr), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + hashList = append(hashList, msg) + } + + for _, value := range hashList { + orderModel := shareData.ShareThaOrderProcessing(setting.AdminShareThaSubscribe, value) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理[撤单|平仓]缓存队列 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + if err := data.Reds.HDel(context.Background(), setting.AdminShareThaSubscribe, orderModel.OrderId).Err(); err != nil { + applogger.Error("AdminShareThaSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("Administrator Tai Stock Subscription Cache Order Error:%v", err) + time.Sleep(5 * time.Second) + continue + } + + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("Administrator cancels subscription to Thai stock orders.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubAdminShareThaSubscribeBySum(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareThaSumSubscribe { + priceSum, err := memory.ShareThaFloating.Get(flags.FloatingTha) + if err != nil { + continue + } + + result := &SymbolSumResult{ + Symbol: psgMsg.Symbol, + Price: string(priceSum), + } + + priceByte, err := json.Marshal(result) + if err != nil { + continue + } + + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + u.msg <- priceByte + } else { + applogger.Info("Administrator cancels subscription to Thai stock orders.") + return + } + } + + time.Sleep(1 * time.Second) + } +} + +// orderSubAdminShareIdnSubscribeByOrder +// +// @Description: 管理员印尼股|订单订阅|持仓订单订阅|持仓浮动盈亏订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubAdminShareIdnSubscribeByOrder(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareIdnSubscribe { + var hashList []share.ShareIdnTallyCache + for _, field := range psgMsg.Order { + fieldStr, err := data.Reds.HGet(context.Background(), setting.AdminShareIdnSubscribe, field).Result() + if err != nil { + continue + } + var msg share.ShareIdnTallyCache + if err = json.Unmarshal([]byte(fieldStr), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + hashList = append(hashList, msg) + } + + for _, value := range hashList { + orderModel := shareData.ShareIdnOrderProcessing(setting.AdminShareIdnSubscribe, value) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理[撤单|平仓]缓存队列 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + if err := data.Reds.HDel(context.Background(), setting.AdminShareIdnSubscribe, orderModel.OrderId).Err(); err != nil { + applogger.Error("AdminShareIdnSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("Administrator Indonesia stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("Administrator cancels Indonesian order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubAdminShareIdnSubscribeBySum(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareIdnSumSubscribe { + priceSum, err := memory.ShareIdnFloating.Get(flags.FloatingIdn) + if err != nil { + continue + } + + result := &SymbolSumResult{ + Symbol: psgMsg.Symbol, + Price: string(priceSum), + } + + priceByte, err := json.Marshal(result) + if err != nil { + continue + } + + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + u.msg <- priceByte + } else { + applogger.Info("Administrator cancels Indonesian stock order subscription.") + return + } + } + + time.Sleep(1 * time.Second) + } +} + +// orderSubAdminShareInrSubscribeByOrder +// +// @Description: 管理员-印度股|订单订阅|持仓订单订阅|持仓浮动盈亏订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubAdminShareInrSubscribeByOrder(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareInrSubscribe { + var hashList []share.ShareInrTallyCache + for _, field := range psgMsg.Order { + fieldStr, err := data.Reds.HGet(context.Background(), psgMsg.Symbol, field).Result() + if err != nil { + continue + } + var msg share.ShareInrTallyCache + if err = json.Unmarshal([]byte(fieldStr), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + hashList = append(hashList, msg) + } + + for _, value := range hashList { + orderModel := shareData.ShareInrOrderProcessing(psgMsg.Symbol, value) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理[撤单|平仓]缓存队列 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + if err := data.Reds.HDel(context.Background(), psgMsg.Symbol, orderModel.OrderId).Err(); err != nil { + applogger.Error("AdminShareInrSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("Administrator India stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("Administrator cancels India order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubAdminShareInrSubscribeBySum(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareInrSumSubscribe { + priceSum, err := memory.ShareInrFloating.Get(flags.FloatingInr) + if err != nil { + continue + } + + result := &SymbolSumResult{ + Symbol: psgMsg.Symbol, + Price: string(priceSum), + } + + priceByte, err := json.Marshal(result) + if err != nil { + continue + } + + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + u.msg <- priceByte + } else { + applogger.Info("Administrator cancels Indian stock order subscription.") + return + } + } + + time.Sleep(1 * time.Second) + } +} + +// orderSubAdminShareInrSubscribe +// +// @Description: 管理员-新加坡股|持仓订单订阅|持仓浮动盈亏订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubAdminShareSgdSubscribeByOrder(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareSgdSubscribe { + var hashList []share.ShareSgdTallyCache + for _, field := range psgMsg.Order { + fieldStr, err := data.Reds.HGet(context.Background(), setting.AdminShareSgdSubscribe, field).Result() + if err != nil { + continue + } + var msg share.ShareSgdTallyCache + if err = json.Unmarshal([]byte(fieldStr), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + hashList = append(hashList, msg) + } + + for _, value := range hashList { + orderModel := shareData.ShareSgdOrderProcessing(setting.AdminShareSgdSubscribe, value) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理[撤单|平仓]缓存队列 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + if err := data.Reds.HDel(context.Background(), setting.AdminShareSgdSubscribe, orderModel.OrderId).Err(); err != nil { + applogger.Error("AdminShareSgdSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("Administrator Singapore stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("Administrator cancels Singapore order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubAdminShareSgdSubscribeBySum(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareSgdSumSubscribe { + priceSum, err := memory.ShareSgdFloating.Get(flags.FloatingSgd) + if err != nil { + continue + } + + result := &SymbolSumResult{ + Symbol: psgMsg.Symbol, + Price: string(priceSum), + } + + priceByte, err := json.Marshal(result) + if err != nil { + continue + } + + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + u.msg <- priceByte + } else { + applogger.Info("Administrator cancels Singapore stock order subscription.") + return + } + } + + time.Sleep(1 * time.Second) + } +} + +// orderSubAdminShareGbxSubscribeByOrder +// +// @Description: 管理员-英股|持仓订单订阅|持仓浮动盈亏订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubAdminShareGbxSubscribeByOrder(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareGbxSubscribe { + var hashList []share.ShareGbxTallyCache + for _, field := range psgMsg.Order { + fieldStr, err := data.Reds.HGet(context.Background(), setting.AdminShareGbxSubscribe, field).Result() + if err != nil { + continue + } + var msg share.ShareGbxTallyCache + if err = json.Unmarshal([]byte(fieldStr), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + hashList = append(hashList, msg) + } + + for _, value := range hashList { + orderModel := shareData.ShareGbxOrderProcessing(setting.AdminShareGbxSubscribe, value) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理[撤单|平仓]缓存队列 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + if err := data.Reds.HDel(context.Background(), setting.AdminShareGbxSubscribe, orderModel.OrderId).Err(); err != nil { + applogger.Error("AdminShareGbxSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("Administrator UK stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("Administrator cancels UK order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubAdminShareGbxSubscribeBySum(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareGbxSumSubscribe { + priceSum, err := memory.ShareGbxFloating.Get(flags.FloatingGbx) + if err != nil { + continue + } + + result := &SymbolSumResult{ + Symbol: psgMsg.Symbol, + Price: string(priceSum), + } + + priceByte, err := json.Marshal(result) + if err != nil { + continue + } + + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + u.msg <- priceByte + } else { + applogger.Info("Administrator cancels UK stock order subscription.") + return + } + } + + time.Sleep(1 * time.Second) + } +} + +// orderSubAdminShareHkdSubscribeByOrder +// +// @Description: 管理员-港股|持仓订单订阅|持仓浮动盈亏订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubAdminShareHkdSubscribeByOrder(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.SubscribeAdminShareHkd { + var hashList []share.ShareHkdTallyCache + for _, field := range psgMsg.Order { + fieldStr, err := data.Reds.HGet(context.Background(), setting.AdminShareHkdSubscribe, field).Result() + if err != nil { + continue + } + var msg share.ShareHkdTallyCache + if err = json.Unmarshal([]byte(fieldStr), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + hashList = append(hashList, msg) + } + + for _, value := range hashList { + orderModel := shareData.ShareHkdOrderProcessing(setting.AdminShareHkdSubscribe, 1, value) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理[撤单|平仓]缓存队列 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + if err := data.Reds.HDel(context.Background(), setting.AdminShareHkdSubscribe, orderModel.OrderId).Err(); err != nil { + applogger.Error("AdminShareHkdSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("Administrator Hong Kong stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("Administrator cancels Singapore order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubAdminShareHkdSubscribeBySum(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareHkdSumSubscribe { + priceSum, err := memory.ShareHkdFloating.Get(flags.FloatingHkd) + if err != nil { + continue + } + + result := &SymbolSumResult{ + Symbol: psgMsg.Symbol, + Price: string(priceSum), + } + + priceByte, err := json.Marshal(result) + if err != nil { + continue + } + + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + u.msg <- priceByte + } else { + applogger.Info("Administrator cancels Hong Kong stock order subscription.") + return + } + } + + time.Sleep(1 * time.Second) + } +} + +// orderSubAdminShareEurSubscribeByOrder +// +// @Description: 管理员-德股|持仓订单订阅|持仓浮动盈亏订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubAdminShareEurSubscribeByOrder(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareEurSubscribe { + var hashList []share.ShareEurTallyCache + for _, field := range psgMsg.Order { + fieldStr, err := data.Reds.HGet(context.Background(), setting.AdminShareEurSubscribe, field).Result() + if err != nil { + continue + } + var msg share.ShareEurTallyCache + if err = json.Unmarshal([]byte(fieldStr), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + hashList = append(hashList, msg) + } + + for _, value := range hashList { + orderModel := shareData.ShareEurOrderProcessing(setting.AdminShareEurSubscribe, value) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理[撤单|平仓]缓存队列 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + if err := data.Reds.HDel(context.Background(), setting.AdminShareEurSubscribe, orderModel.OrderId).Err(); err != nil { + applogger.Error("AdminShareEurSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("Administrator Eur stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("Administrator cancels Eur order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubAdminShareEurSubscribeBySum(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareEurSumSubscribe { + priceSum, err := memory.ShareEurFloating.Get(flags.FloatingEur) + if err != nil { + continue + } + + result := &SymbolSumResult{ + Symbol: psgMsg.Symbol, + Price: string(priceSum), + } + + priceByte, err := json.Marshal(result) + if err != nil { + continue + } + + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + u.msg <- priceByte + } else { + applogger.Info("Administrator cancels Eur stock order subscription.") + return + } + } + + time.Sleep(1 * time.Second) + } +} + +// orderSubAdminShareFurSubscribeByOrder +// +// @Description: 管理员-法股|持仓订单订阅|持仓浮动盈亏订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubAdminShareFurSubscribeByOrder(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareFurSubscribe { + var hashList []share.ShareFurTallyCache + for _, field := range psgMsg.Order { + fieldStr, err := data.Reds.HGet(context.Background(), setting.AdminShareFurSubscribe, field).Result() + if err != nil { + continue + } + var msg share.ShareFurTallyCache + if err = json.Unmarshal([]byte(fieldStr), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + hashList = append(hashList, msg) + } + + for _, value := range hashList { + orderModel := shareData.ShareFurOrderProcessing(setting.AdminShareFurSubscribe, value) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理[撤单|平仓]缓存队列 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + if err := data.Reds.HDel(context.Background(), setting.AdminShareFurSubscribe, orderModel.OrderId).Err(); err != nil { + applogger.Error("AdminShareFurSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("Administrator Fur stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("Administrator cancels Fur order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubAdminShareFurSubscribeBySum(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareFurSumSubscribe { + priceSum, err := memory.ShareFurFloating.Get(flags.FloatingFur) + if err != nil { + continue + } + + result := &SymbolSumResult{ + Symbol: psgMsg.Symbol, + Price: string(priceSum), + } + + priceByte, err := json.Marshal(result) + if err != nil { + continue + } + + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + u.msg <- priceByte + } else { + applogger.Info("Administrator cancels Fur stock order subscription.") + return + } + } + + time.Sleep(1 * time.Second) + } +} + +// orderSubAdminShareJpySubscribeByOrder +// +// @Description: 管理员-日股|持仓订单订阅|持仓浮动盈亏订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubAdminShareJpySubscribeByOrder(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareJpySubscribe { + var hashList []share.ShareJpyTallyCache + for _, field := range psgMsg.Order { + fieldStr, err := data.Reds.HGet(context.Background(), setting.AdminShareJpySubscribe, field).Result() + if err != nil { + continue + } + var msg share.ShareJpyTallyCache + if err = json.Unmarshal([]byte(fieldStr), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + hashList = append(hashList, msg) + } + + for _, value := range hashList { + orderModel := shareData.ShareJpyOrderProcessing(setting.AdminShareJpySubscribe, value) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理[撤单|平仓]缓存队列 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + if err := data.Reds.HDel(context.Background(), setting.AdminShareJpySubscribe, orderModel.OrderId).Err(); err != nil { + applogger.Error("AdminShareJpySubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("Administrator Jpy stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("Administrator cancels Jpy order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubAdminShareJpySubscribeBySum(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareJpySumSubscribe { + priceSum, err := memory.ShareJpyFloating.Get(flags.FloatingJpy) + if err != nil { + continue + } + + result := &SymbolSumResult{ + Symbol: psgMsg.Symbol, + Price: string(priceSum), + } + + priceByte, err := json.Marshal(result) + if err != nil { + continue + } + + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + u.msg <- priceByte + } else { + applogger.Info("Administrator cancels Jpy stock order subscription.") + return + } + } + + time.Sleep(1 * time.Second) + } +} + +// orderSubAdminShareBrlSubscribeByOrder +// +// @Description: 管理员-巴西股|持仓订单订阅|持仓浮动盈亏订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubAdminShareBrlSubscribeByOrder(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareBrlSubscribe { + var hashList []share.ShareBrlTallyCache + for _, field := range psgMsg.Order { + fieldStr, err := data.Reds.HGet(context.Background(), setting.AdminShareBrlSubscribe, field).Result() + if err != nil { + continue + } + var msg share.ShareBrlTallyCache + if err = json.Unmarshal([]byte(fieldStr), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + hashList = append(hashList, msg) + } + + for _, value := range hashList { + orderModel := shareData.ShareBrlOrderProcessing(setting.AdminShareBrlSubscribe, value) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理[撤单|平仓]缓存队列 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + if err := data.Reds.HDel(context.Background(), setting.AdminShareBrlSubscribe, orderModel.OrderId).Err(); err != nil { + applogger.Error("AdminShareBrlSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("Administrator Brl stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("Administrator cancels Brl order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubAdminShareBrlSubscribeBySum(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminShareBrlSumSubscribe { + priceSum, err := memory.ShareBrlFloating.Get(flags.FloatingBrl) + if err != nil { + continue + } + + result := &SymbolSumResult{ + Symbol: psgMsg.Symbol, + Price: string(priceSum), + } + + priceByte, err := json.Marshal(result) + if err != nil { + continue + } + + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + u.msg <- priceByte + } else { + applogger.Info("Administrator cancels Brl stock order subscription.") + return + } + } + + time.Sleep(1 * time.Second) + } +} diff --git a/internal/data/socket/share_user.go b/internal/data/socket/share_user.go new file mode 100644 index 0000000..0e9e05b --- /dev/null +++ b/internal/data/socket/share_user.go @@ -0,0 +1,2036 @@ +package socket + +import ( + "context" + "encoding/json" + "github.com/shopspring/decimal" + "matchmaking-system/internal/data" + "matchmaking-system/internal/data/socket/shareData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + models "matchmaking-system/internal/pkg/model" + "matchmaking-system/internal/pkg/setting" + "time" +) + +// orderSubShareUsSubscribe +// +// @Description: 用户美股订单订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubShareUsSubscribe(psgMsg *SymbolMessage) { + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareUsSubscribe { + orderTokenKey := virtual.OrderIdListKey(setting.ShareUsSubscribe, userId) + orderList, err := data.Reds.HGetAll(context.Background(), orderTokenKey).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + for _, value := range orderList { + var msg share.ShareUsTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + orderModel := shareData.ShareUsOrderProcessing(setting.ShareUsSubscribe, msg) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理美股订阅缓存订单中(撤单|平仓)状态的订单 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + err = data.Reds.HDel(context.Background(), orderTokenKey, msg.OrderId).Err() + if err != nil { + time.Sleep(5 * time.Second) + applogger.Error("ShareUsSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User's US stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("User cancels subscription to US stock orders.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubShareUsMarketSubscribe(psgMsg *SymbolMessage) { + var n int + var MarketUsCache decimal.Decimal // 缓存记录 + var marketProfitAndLoss decimal.Decimal // 用户市场累计盈亏 + var marketTotalFee decimal.Decimal // 用户市场总手续费 + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + /** 统计用户市场资产数据 + 1、用户市场总资产: 冻结 + 可用 + 总浮动盈亏 + 2、用户市场资产: 可用、冻结 + 3、用户市场累计盈亏(订单表-->平仓状态): + 1、买涨:订单量 * (平仓价 - 开仓价) + 2、买跌:订单量 * (开仓价 - 平仓价) + 4、用户市场总手续费(统计订单表-->【持仓和平仓】状态): + 1、交易手续费 + 2、申购手续费 + */ + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareUsMarketSubscribe { + var marketTotalAssets decimal.Decimal // 用户市场总资产 + var marketAvailable decimal.Decimal // 用户市场可用 + var marketFreeze decimal.Decimal // 用户市场冻结 + var marketFloatingPL decimal.Decimal // 用户市场总浮动盈亏 + + // 统计用户市场可用余额和冻结余额 + var botUserStock []models.BotUserStock + err = data.Msql.Table(flags.BotUserStock).Where("user_id = ?", userId).Where("stock_id = ?", flags.ShareUsBasicUnit).Find(&botUserStock) + if err != nil { + marketAvailable = decimal.Zero + marketFreeze = decimal.Zero + } + for _, value := range botUserStock { + marketAvailable = decimal.RequireFromString(value.UsableNum) + marketFreeze = decimal.RequireFromString(value.FrozenNum) + } + // 判定是否存在订单 + if marketAvailable.IsZero() || marketFreeze.IsZero() { + if n == 0 { + tradeCount, _ := data.Msql.Table(flags.BotStockTrade).Where("user_id = ?", userId).In("status", 1, 3).Count() + if tradeCount > 0 { + n = 1 + } + } + } + if marketAvailable.Cmp(MarketUsCache) != 0 || n == 1 { + // 统计用户市场累计盈亏 + var botStockTrade []models.BotStockTrade + err = data.Msql.Table(flags.BotStockTrade).Where("user_id = ?", userId).Where("status = 3").Find(&botStockTrade) + if err != nil { + marketProfitAndLoss = decimal.Zero + } + for _, value := range botStockTrade { + sumValue := decimal.Zero + openPrice := decimal.RequireFromString(value.DealPrice) + closePrice := decimal.RequireFromString(value.ClosingPrice) + orderNum := decimal.RequireFromString(value.OrderNumber) + switch value.TradeType { + case 1: // 买张 + sumValue = closePrice.Sub(openPrice) + default: // 买跌 + sumValue = openPrice.Sub(closePrice) + } + marketProfitAndLoss = marketProfitAndLoss.Add(sumValue.Mul(orderNum)) + } + // 统计用户市场总手续费 + var botStockTradeFee models.BotStockTrade + totalFee, err := data.Msql.Table(flags.BotStockTrade).Where("user_id = ?", userId).In("status", 1, 3).Sums(botStockTradeFee, "service_cost", "closing_cost") + if err != nil || len(totalFee) != 2 { + marketTotalFee = decimal.Zero + } + marketTotalFee = decimal.NewFromFloat(totalFee[0]).Add(decimal.NewFromFloat(totalFee[1])) + var botUserUsPreStockOrder models.BotUserUsPreStockOrder + totalPreFee, err := data.Msql.Table(flags.BotUserUsPreStockOrder).Where("user_id = ?", userId).Sum(botUserUsPreStockOrder, "get_fee") + if err != nil { + marketTotalFee = decimal.Zero + } + marketTotalFee = marketTotalFee.Add(decimal.NewFromFloat(totalPreFee)) + MarketUsCache = marketAvailable + n = 2 + } + // 用户市场总浮动盈亏 + usPriceSum := GetShareUsByPriceSum(userId, setting.AdminShareUsSubscribe) + // 统计用户市场总资产 + marketTotalAssets = marketAvailable.Add(marketFreeze).Add(usPriceSum) + // 统计用户市场总浮动盈亏 + marketFloatingPL = usPriceSum + orderModel := &UserMarketStatistics{ + UserMarkerSubscribe: psgMsg.Symbol, + UserMarketTotalAssets: marketTotalAssets.String(), + UserMarketAvailable: marketAvailable.String(), + UserMarketFreeze: marketFreeze.String(), + UserMarketProfitAndLoss: marketProfitAndLoss.String(), + UserMarketTotalFee: marketTotalFee.String(), + UserMarketFloatingPL: marketFloatingPL.String(), + } + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User market US stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户市场统计订阅 + } else { + applogger.Info("User market cancels subscription to US stock orders.") + return + } + } + + time.Sleep(800 * time.Millisecond) + } +} + +// orderSubShareMysSubscribe +// +// @Description: 用户马股订单订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubShareMysSubscribe(psgMsg *SymbolMessage) { + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareMysSubscribe { + orderTokenKey := virtual.OrderIdListKey(setting.ShareMysSubscribe, userId) + orderList, err := data.Reds.HGetAll(context.Background(), orderTokenKey).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + for _, value := range orderList { + var msg share.ShareMysTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + orderModel := shareData.ShareMysOrderProcessing(setting.ShareMysSubscribe, msg) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理马股订阅缓存订单中(撤单|平仓)状态的订单 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + err = data.Reds.HDel(context.Background(), orderTokenKey, msg.OrderId).Err() + if err != nil { + time.Sleep(5 * time.Second) + applogger.Error("ShareMysSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User's stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("User cancels subscription to horse stock orders.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubShareMysMarketSubscribe(psgMsg *SymbolMessage) { + var n int + var MarketMysCache decimal.Decimal // 缓存记录 + var marketProfitAndLoss decimal.Decimal // 用户市场累计盈亏 + var marketTotalFee decimal.Decimal // 用户市场总手续费 + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareMysMarketSubscribe { + var marketTotalAssets decimal.Decimal // 用户市场总资产 + var marketAvailable decimal.Decimal // 用户市场可用 + var marketFreeze decimal.Decimal // 用户市场冻结 + var marketFloatingPL decimal.Decimal // 用户市场总浮动盈亏 + + // 统计用户市场可用余额和冻结余额 + var botUserStockMys []models.BotUserStockMys + err = data.Msql.Table(flags.BotUserStockMys).Where("user_id = ?", userId).Where("stock_id = ?", flags.ShareMysBasicUnit).Find(&botUserStockMys) + if err != nil { + marketAvailable = decimal.Zero + marketFreeze = decimal.Zero + } + for _, value := range botUserStockMys { + marketAvailable = decimal.RequireFromString(value.UsableNum) + marketFreeze = decimal.RequireFromString(value.FrozenNum) + } + // 判定是否存在订单 + if marketAvailable.IsZero() || marketFreeze.IsZero() { + if n == 0 { + tradeCount, _ := data.Msql.Table(flags.BotStockMysTrade).Where("user_id = ?", userId).In("status", 1, 3).Count() + if tradeCount > 0 { + n = 1 + } + } + } + if marketAvailable.Cmp(MarketMysCache) != 0 || n == 1 { + // 统计用户市场累计盈亏 + var botStockMysTrade []models.BotStockMysTrade + err = data.Msql.Table(flags.BotStockMysTrade).Where("user_id = ?", userId).Where("status = 3").Find(&botStockMysTrade) + if err != nil { + marketProfitAndLoss = decimal.Zero + } + for _, value := range botStockMysTrade { + sumValue := decimal.Zero + openPrice := decimal.RequireFromString(value.DealPrice) + closePrice := decimal.RequireFromString(value.ClosingPrice) + orderNum := decimal.RequireFromString(value.OrderNumber) + switch value.TradeType { + case 1: // 买张 + sumValue = closePrice.Sub(openPrice) + default: // 买跌 + sumValue = openPrice.Sub(closePrice) + } + marketProfitAndLoss = marketProfitAndLoss.Add(sumValue.Mul(orderNum)) + } + // 统计用户市场总手续费 + var botStockMysTradeFee models.BotStockMysTrade + totalFee, err := data.Msql.Table(flags.BotStockMysTrade).Where("user_id = ?", userId).In("status", 1, 3).Sums(botStockMysTradeFee, "service_cost", "closing_cost") + if err != nil || len(totalFee) != 2 { + marketTotalFee = decimal.Zero + } + marketTotalFee = decimal.NewFromFloat(totalFee[0]).Add(decimal.NewFromFloat(totalFee[1])) + var botUserMysPreStockOrder models.BotUserMysPreStockOrder + totalPreFee, err := data.Msql.Table(flags.BotUserMysPreStockOrder).Where("user_id = ?", userId).Sum(botUserMysPreStockOrder, "get_fee") + if err != nil { + marketTotalFee = decimal.Zero + } + marketTotalFee = marketTotalFee.Add(decimal.NewFromFloat(totalPreFee)) + MarketMysCache = marketAvailable + n = 2 + } + + // 用户市场总浮动盈亏 + pLPriceSum := GetShareMysByPriceSum(userId, setting.AdminShareMysSubscribe) + // 统计用户市场总资产 + marketTotalAssets = marketAvailable.Add(marketFreeze).Add(pLPriceSum) + // 统计用户市场总浮动盈亏 + marketFloatingPL = pLPriceSum + orderModel := &UserMarketStatistics{ + UserMarkerSubscribe: psgMsg.Symbol, + UserMarketTotalAssets: marketTotalAssets.String(), + UserMarketAvailable: marketAvailable.String(), + UserMarketFreeze: marketFreeze.String(), + UserMarketProfitAndLoss: marketProfitAndLoss.String(), + UserMarketTotalFee: marketTotalFee.String(), + UserMarketFloatingPL: marketFloatingPL.String(), + } + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User market Mys stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户市场统计订阅 + } else { + applogger.Info("User market cancels subscription to Mys stock orders.") + return + } + } + + time.Sleep(800 * time.Millisecond) + } +} + +// orderSubShareThaSubscribe +// +// @Description: 用户泰股订单订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubShareThaSubscribe(psgMsg *SymbolMessage) { + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareThaSubscribe { + orderTokenKey := virtual.OrderIdListKey(setting.ShareThaSubscribe, userId) + orderList, err := data.Reds.HGetAll(context.Background(), orderTokenKey).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + for _, value := range orderList { + var msg share.ShareThaTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + orderModel := shareData.ShareThaOrderProcessing(setting.ShareThaSubscribe, msg) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理泰股订阅缓存订单中(撤单|平仓)状态的订单 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + err = data.Reds.HDel(context.Background(), orderTokenKey, msg.OrderId).Err() + if err != nil { + time.Sleep(5 * time.Second) + applogger.Error("ShareUsSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User Tai Stock Subscription Cache Order Error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("User cancels subscription to Thai stock orders.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubShareThaMarketSubscribe(psgMsg *SymbolMessage) { + var n int + var MarketThaCache decimal.Decimal // 缓存记录 + var marketProfitAndLoss decimal.Decimal // 用户市场累计盈亏 + var marketTotalFee decimal.Decimal // 用户市场总手续费 + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareThaMarketSubscribe { + var marketTotalAssets decimal.Decimal // 用户市场总资产 + var marketAvailable decimal.Decimal // 用户市场可用 + var marketFreeze decimal.Decimal // 用户市场冻结 + var marketFloatingPL decimal.Decimal // 用户市场总浮动盈亏 + + // 统计用户市场可用余额和冻结余额 + var botUserStockTha []models.BotUserStockTha + err = data.Msql.Table(flags.BotUserStockTha).Where("user_id = ?", userId).Where("stock_id = ?", flags.ShareThaBasicUnit).Find(&botUserStockTha) + if err != nil { + marketAvailable = decimal.Zero + marketFreeze = decimal.Zero + } + for _, value := range botUserStockTha { + marketAvailable = decimal.RequireFromString(value.UsableNum) + marketFreeze = decimal.RequireFromString(value.FrozenNum) + } + // 判定是否存在订单 + if marketAvailable.IsZero() || marketFreeze.IsZero() { + if n == 0 { + tradeCount, _ := data.Msql.Table(flags.BotStockThaTrade).Where("user_id = ?", userId).In("status", 1, 3).Count() + if tradeCount > 0 { + n = 1 + } + } + } + if marketAvailable.Cmp(MarketThaCache) != 0 || n == 1 { + // 统计用户市场累计盈亏 + var botStockThaTrade []models.BotStockThaTrade + err = data.Msql.Table(flags.BotStockThaTrade).Where("user_id = ?", userId).Where("status = 3").Find(&botStockThaTrade) + if err != nil { + marketProfitAndLoss = decimal.Zero + } + for _, value := range botStockThaTrade { + sumValue := decimal.Zero + openPrice := decimal.RequireFromString(value.DealPrice) + closePrice := decimal.RequireFromString(value.ClosingPrice) + orderNum := decimal.RequireFromString(value.OrderNumber) + switch value.TradeType { + case 1: // 买张 + sumValue = closePrice.Sub(openPrice) + default: // 买跌 + sumValue = openPrice.Sub(closePrice) + } + marketProfitAndLoss = marketProfitAndLoss.Add(sumValue.Mul(orderNum)) + } + // 统计用户市场总手续费 + var botStockThaTradeFee models.BotStockThaTrade + totalFee, err := data.Msql.Table(flags.BotStockThaTrade).Where("user_id = ?", userId).In("status", 1, 3).Sums(botStockThaTradeFee, "service_cost", "closing_cost") + if err != nil || len(totalFee) != 2 { + marketTotalFee = decimal.Zero + } + marketTotalFee = decimal.NewFromFloat(totalFee[0]).Add(decimal.NewFromFloat(totalFee[1])) + var botUserThaPreStockOrder models.BotUserThaPreStockOrder + totalPreFee, err := data.Msql.Table(flags.BotUserThaPreStockOrder).Where("user_id = ?", userId).Sum(botUserThaPreStockOrder, "get_fee") + if err != nil { + marketTotalFee = decimal.Zero + } + marketTotalFee = marketTotalFee.Add(decimal.NewFromFloat(totalPreFee)) + MarketThaCache = marketAvailable + n = 2 + } + + // 用户市场总浮动盈亏 + pLPriceSum := GetShareThaByPriceSum(userId, setting.AdminShareThaSubscribe) + // 统计用户市场总资产 + marketTotalAssets = marketAvailable.Add(marketFreeze).Add(pLPriceSum) + // 统计用户市场总浮动盈亏 + marketFloatingPL = pLPriceSum + orderModel := &UserMarketStatistics{ + UserMarkerSubscribe: psgMsg.Symbol, + UserMarketTotalAssets: marketTotalAssets.String(), + UserMarketAvailable: marketAvailable.String(), + UserMarketFreeze: marketFreeze.String(), + UserMarketProfitAndLoss: marketProfitAndLoss.String(), + UserMarketTotalFee: marketTotalFee.String(), + UserMarketFloatingPL: marketFloatingPL.String(), + } + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User market Tha stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户市场统计订阅 + } else { + applogger.Info("User market cancels subscription to Tha stock orders.") + return + } + } + + time.Sleep(800 * time.Millisecond) + } +} + +// orderSubShareIdnSubscribe +// +// @Description: 用户印尼股订单订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubShareIdnSubscribe(psgMsg *SymbolMessage) { + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareIdnSubscribe { + orderTokenKey := virtual.OrderIdListKey(setting.ShareIdnSubscribe, userId) + orderList, err := data.Reds.HGetAll(context.Background(), orderTokenKey).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + for _, value := range orderList { + var msg share.ShareIdnTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + orderModel := shareData.ShareIdnOrderProcessing(setting.ShareIdnSubscribe, msg) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理印尼股订阅缓存订单中(撤单|平仓)状态的订单 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + err = data.Reds.HDel(context.Background(), orderTokenKey, msg.OrderId).Err() + if err != nil { + time.Sleep(5 * time.Second) + applogger.Error("ShareUsSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User's Indonesian stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("User cancels Indonesian stock order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubShareIdnMarketSubscribe(psgMsg *SymbolMessage) { + var n int + var MarketIdnCache decimal.Decimal // 缓存记录 + var marketProfitAndLoss decimal.Decimal // 用户市场累计盈亏 + var marketTotalFee decimal.Decimal // 用户市场总手续费 + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareIdnMarketSubscribe { + var marketTotalAssets decimal.Decimal // 用户市场总资产 + var marketAvailable decimal.Decimal // 用户市场可用 + var marketFreeze decimal.Decimal // 用户市场冻结 + var marketFloatingPL decimal.Decimal // 用户市场总浮动盈亏 + + // 统计用户市场可用余额和冻结余额 + var botUserStockIdn []models.BotUserStockIdn + err = data.Msql.Table(flags.BotUserStockIdn).Where("user_id = ?", userId).Where("stock_id = ?", flags.ShareIdnBasicUnit).Find(&botUserStockIdn) + if err != nil { + marketAvailable = decimal.Zero + marketFreeze = decimal.Zero + } + for _, value := range botUserStockIdn { + marketAvailable = decimal.RequireFromString(value.UsableNum) + marketFreeze = decimal.RequireFromString(value.FrozenNum) + } + // 判定是否存在订单 + if marketAvailable.IsZero() || marketFreeze.IsZero() { + if n == 0 { + tradeCount, _ := data.Msql.Table(flags.BotStockIdnTrade).Where("user_id = ?", userId).In("status", 1, 3).Count() + if tradeCount > 0 { + n = 1 + } + } + } + if marketAvailable.Cmp(MarketIdnCache) != 0 || n == 1 { + // 统计用户市场累计盈亏 + var botStockIdnTrade []models.BotStockIdnTrade + err = data.Msql.Table(flags.BotStockIdnTrade).Where("user_id = ?", userId).Where("status = 3").Find(&botStockIdnTrade) + if err != nil { + marketProfitAndLoss = decimal.Zero + } + for _, value := range botStockIdnTrade { + sumValue := decimal.Zero + openPrice := decimal.RequireFromString(value.DealPrice) + closePrice := decimal.RequireFromString(value.ClosingPrice) + orderNum := decimal.RequireFromString(value.OrderNumber) + switch value.TradeType { + case 1: // 买张 + sumValue = closePrice.Sub(openPrice) + default: // 买跌 + sumValue = openPrice.Sub(closePrice) + } + marketProfitAndLoss = marketProfitAndLoss.Add(sumValue.Mul(orderNum)) + } + // 统计用户市场总手续费 + var botStockIdnTradeFee models.BotStockIdnTrade + totalFee, err := data.Msql.Table(flags.BotStockIdnTrade).Where("user_id = ?", userId).In("status", 1, 3).Sums(botStockIdnTradeFee, "service_cost", "closing_cost") + if err != nil || len(totalFee) != 2 { + marketTotalFee = decimal.Zero + } + marketTotalFee = decimal.NewFromFloat(totalFee[0]).Add(decimal.NewFromFloat(totalFee[1])) + var botUserIdnPreStockOrder models.BotUserIdnPreStockOrder + totalPreFee, err := data.Msql.Table(flags.BotUserIdnPreStockOrder).Where("user_id = ?", userId).Sum(botUserIdnPreStockOrder, "get_fee") + if err != nil { + marketTotalFee = decimal.Zero + } + marketTotalFee = marketTotalFee.Add(decimal.NewFromFloat(totalPreFee)) + MarketIdnCache = marketAvailable + n = 2 + } + + // 用户市场总浮动盈亏 + pLPriceSum := GetShareIdnByPriceSum(userId, setting.AdminShareIdnSubscribe) + // 统计用户市场总资产 + marketTotalAssets = marketAvailable.Add(marketFreeze).Add(pLPriceSum) + // 统计用户市场总浮动盈亏 + marketFloatingPL = pLPriceSum + orderModel := &UserMarketStatistics{ + UserMarkerSubscribe: psgMsg.Symbol, + UserMarketTotalAssets: marketTotalAssets.String(), + UserMarketAvailable: marketAvailable.String(), + UserMarketFreeze: marketFreeze.String(), + UserMarketProfitAndLoss: marketProfitAndLoss.String(), + UserMarketTotalFee: marketTotalFee.String(), + UserMarketFloatingPL: marketFloatingPL.String(), + } + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User market Idn stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户市场统计订阅 + } else { + applogger.Info("User market cancels subscription to Idn stock orders.") + return + } + } + + time.Sleep(800 * time.Millisecond) + } +} + +// orderSubShareInrSubscribe +// +// @Description: 用户印度股订单订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubShareInrSubscribe(psgMsg *SymbolMessage) { + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareInrSubscribe { + orderTokenKey := virtual.OrderIdListKey(setting.ShareInrSubscribe, userId) + orderList, err := data.Reds.HGetAll(context.Background(), orderTokenKey).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + + for _, value := range orderList { + var msg share.ShareInrTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + orderModel := shareData.ShareInrOrderProcessing(setting.ShareInrSubscribe, msg) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理印度股订阅缓存订单中(撤单|平仓)状态的订单 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + err = data.Reds.HDel(context.Background(), orderTokenKey, msg.OrderId).Err() + if err != nil { + time.Sleep(5 * time.Second) + applogger.Error("ShareInrSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User's Indian stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("User cancels Indian stock order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubShareInrMarketSubscribe(psgMsg *SymbolMessage) { + var n int + var MarketInrCache decimal.Decimal // 缓存记录 + var marketProfitAndLoss decimal.Decimal // 用户市场累计盈亏 + var marketTotalFee decimal.Decimal // 用户市场总手续费 + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareInrMarketSubscribe { + var marketTotalAssets decimal.Decimal // 用户市场总资产 + var marketAvailable decimal.Decimal // 用户市场可用 + var marketFreeze decimal.Decimal // 用户市场冻结 + var marketFloatingPL decimal.Decimal // 用户市场总浮动盈亏 + + // 统计用户市场可用余额和冻结余额 + var botUserStockIn []models.BotUserStockIn + err = data.Msql.Table(flags.BotUserStockIn).Where("user_id = ?", userId).Where("stock_id = ?", flags.ShareInrBasicUnit).Find(&botUserStockIn) + if err != nil { + marketAvailable = decimal.Zero + marketFreeze = decimal.Zero + } + for _, value := range botUserStockIn { + marketAvailable = decimal.RequireFromString(value.UsableNum) + marketFreeze = decimal.RequireFromString(value.FrozenNum) + } + // 判定是否存在订单 + if marketAvailable.IsZero() || marketFreeze.IsZero() { + if n == 0 { + tradeCount, _ := data.Msql.Table(flags.BotStockInTrade).Where("user_id = ?", userId).In("status", 1, 3).Count() + if tradeCount > 0 { + n = 1 + } + } + } + if marketAvailable.Cmp(MarketInrCache) != 0 || n == 1 { + // 统计用户市场累计盈亏 + var botStockInTrade []models.BotStockInTrade + err = data.Msql.Table(flags.BotStockInTrade).Where("user_id = ?", userId).Where("status = 3").Find(&botStockInTrade) + if err != nil { + marketProfitAndLoss = decimal.Zero + } + for _, value := range botStockInTrade { + sumValue := decimal.Zero + openPrice := decimal.RequireFromString(value.DealPrice) + closePrice := decimal.RequireFromString(value.ClosingPrice) + orderNum := decimal.RequireFromString(value.OrderNumber) + switch value.TradeType { + case 1: // 买张 + sumValue = closePrice.Sub(openPrice) + default: // 买跌 + sumValue = openPrice.Sub(closePrice) + } + marketProfitAndLoss = marketProfitAndLoss.Add(sumValue.Mul(orderNum)) + } + // 统计用户市场总手续费 + var botStockInTradeFee models.BotStockInTrade + totalFee, err := data.Msql.Table(flags.BotStockInTrade).Where("user_id = ?", userId).In("status", 1, 3).Sums(botStockInTradeFee, "service_cost", "closing_cost") + if err != nil || len(totalFee) != 2 { + marketTotalFee = decimal.Zero + } + marketTotalFee = decimal.NewFromFloat(totalFee[0]).Add(decimal.NewFromFloat(totalFee[1])) + var botUserInPreStockOrder models.BotUserInPreStockOrder + totalPreFee, err := data.Msql.Table(flags.BotUserInPreStockOrder).Where("user_id = ?", userId).Sum(botUserInPreStockOrder, "get_fee") + if err != nil { + marketTotalFee = decimal.Zero + } + marketTotalFee = marketTotalFee.Add(decimal.NewFromFloat(totalPreFee)) + MarketInrCache = marketAvailable + n = 2 + } + // 用户市场总浮动盈亏 + inrPriceSum := GetShareInrByPriceSum(userId, setting.AdminShareInrSubscribe) + // 统计用户市场总资产 + marketTotalAssets = marketAvailable.Add(marketFreeze).Add(inrPriceSum) + // 统计用户市场总浮动盈亏 + marketFloatingPL = inrPriceSum + orderModel := &UserMarketStatistics{ + UserMarkerSubscribe: psgMsg.Symbol, + UserMarketTotalAssets: marketTotalAssets.String(), + UserMarketAvailable: marketAvailable.String(), + UserMarketFreeze: marketFreeze.String(), + UserMarketProfitAndLoss: marketProfitAndLoss.String(), + UserMarketTotalFee: marketTotalFee.String(), + UserMarketFloatingPL: marketFloatingPL.String(), + } + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User market INR stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户市场统计订阅 + } else { + applogger.Info("User market cancels subscription to INR stock orders.") + return + } + } + + time.Sleep(800 * time.Millisecond) + } +} + +// orderSubShareSgdSubscribe +// +// @Description: 用户新加坡股订单订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubShareSgdSubscribe(psgMsg *SymbolMessage) { + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareSgdSubscribe { + orderTokenKey := virtual.OrderIdListKey(setting.ShareSgdSubscribe, userId) + orderList, err := data.Reds.HGetAll(context.Background(), orderTokenKey).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + + for _, value := range orderList { + var msg share.ShareSgdTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + orderModel := shareData.ShareSgdOrderProcessing(setting.ShareSgdSubscribe, msg) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理股票股订阅缓存订单中(撤单|平仓)状态的订单 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + err = data.Reds.HDel(context.Background(), orderTokenKey, msg.OrderId).Err() + if err != nil { + time.Sleep(5 * time.Second) + applogger.Error("ShareSgdSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User's Singapore stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("User cancels Singapore stock order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubShareSgdMarketSubscribe(psgMsg *SymbolMessage) { + var n int + var MarketSgdCache decimal.Decimal // 缓存记录 + var marketProfitAndLoss decimal.Decimal // 用户市场累计盈亏 + var marketTotalFee decimal.Decimal // 用户市场总手续费 + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareSgdMarketSubscribe { + var marketTotalAssets decimal.Decimal // 用户市场总资产 + var marketAvailable decimal.Decimal // 用户市场可用 + var marketFreeze decimal.Decimal // 用户市场冻结 + var marketFloatingPL decimal.Decimal // 用户市场总浮动盈亏 + + // 统计用户市场可用余额和冻结余额 + var botUserStockSgd []models.BotUserStockSgd + err = data.Msql.Table(flags.BotUserStockSgd).Where("user_id = ?", userId).Where("stock_id = ?", flags.ShareSgdBasicUnit).Find(&botUserStockSgd) + if err != nil { + marketAvailable = decimal.Zero + marketFreeze = decimal.Zero + } + for _, value := range botUserStockSgd { + marketAvailable = decimal.RequireFromString(value.UsableNum) + marketFreeze = decimal.RequireFromString(value.FrozenNum) + } + // 判定是否存在订单 + if marketAvailable.IsZero() || marketFreeze.IsZero() { + if n == 0 { + tradeCount, _ := data.Msql.Table(flags.BotStockSgdTrade).Where("user_id = ?", userId).In("status", 1, 3).Count() + if tradeCount > 0 { + n = 1 + } + } + } + if marketAvailable.Cmp(MarketSgdCache) != 0 || n == 1 { + // 统计用户市场累计盈亏 + var botStockSgdTrade []models.BotStockSgdTrade + err = data.Msql.Table(flags.BotStockSgdTrade).Where("user_id = ?", userId).Where("status = 3").Find(&botStockSgdTrade) + if err != nil { + marketProfitAndLoss = decimal.Zero + } + for _, value := range botStockSgdTrade { + sumValue := decimal.Zero + openPrice := decimal.RequireFromString(value.DealPrice) + closePrice := decimal.RequireFromString(value.ClosingPrice) + orderNum := decimal.RequireFromString(value.OrderNumber) + switch value.TradeType { + case 1: // 买张 + sumValue = closePrice.Sub(openPrice) + default: // 买跌 + sumValue = openPrice.Sub(closePrice) + } + marketProfitAndLoss = marketProfitAndLoss.Add(sumValue.Mul(orderNum)) + } + // 统计用户市场总手续费 + var botStockSgdTradeFee models.BotStockSgdTrade + totalFee, err := data.Msql.Table(flags.BotStockSgdTrade).Where("user_id = ?", userId).In("status", 1, 3).Sums(botStockSgdTradeFee, "service_cost", "closing_cost") + if err != nil || len(totalFee) != 2 { + marketTotalFee = decimal.Zero + } + marketTotalFee = decimal.NewFromFloat(totalFee[0]).Add(decimal.NewFromFloat(totalFee[1])) + var botUserSgdPreStockOrder models.BotUserSgdPreStockOrder + totalPreFee, err := data.Msql.Table(flags.BotUserSgdPreStockOrder).Where("user_id = ?", userId).Sum(botUserSgdPreStockOrder, "get_fee") + if err != nil { + marketTotalFee = decimal.Zero + } + marketTotalFee = marketTotalFee.Add(decimal.NewFromFloat(totalPreFee)) + MarketSgdCache = marketAvailable + n = 2 + } + // 用户市场总浮动盈亏 + pLPriceSum := GetShareSgdByPriceSum(userId, setting.AdminShareSgdSubscribe) + // 统计用户市场总资产 + marketTotalAssets = marketAvailable.Add(marketFreeze).Add(pLPriceSum) + // 统计用户市场总浮动盈亏 + marketFloatingPL = pLPriceSum + orderModel := &UserMarketStatistics{ + UserMarkerSubscribe: psgMsg.Symbol, + UserMarketTotalAssets: marketTotalAssets.String(), + UserMarketAvailable: marketAvailable.String(), + UserMarketFreeze: marketFreeze.String(), + UserMarketProfitAndLoss: marketProfitAndLoss.String(), + UserMarketTotalFee: marketTotalFee.String(), + UserMarketFloatingPL: marketFloatingPL.String(), + } + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User market Sgd stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户市场统计订阅 + } else { + applogger.Info("User market cancels subscription to Sgd stock orders.") + return + } + } + + time.Sleep(800 * time.Millisecond) + } +} + +// orderSubShareHkdSubscribe +// +// @Description: 用户港股订单订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubShareHkdSubscribe(psgMsg *SymbolMessage) { + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.SubscribeShareHkd { + orderTokenKey := virtual.OrderIdListKey(setting.ShareHkdSubscribe, userId) + orderList, err := data.Reds.HGetAll(context.Background(), orderTokenKey).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + + for _, value := range orderList { + var msg share.ShareHkdTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + orderModel := shareData.ShareHkdOrderProcessing(setting.ShareHkdSubscribe, 0, msg) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理股票股订阅缓存订单中(撤单|平仓)状态的订单 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + err = data.Reds.HDel(context.Background(), orderTokenKey, msg.OrderId).Err() + if err != nil { + time.Sleep(5 * time.Second) + applogger.Error("ShareHkdSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User's Hong Kong stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("User cancels Singapore stock order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubShareHkdMarketSubscribe(psgMsg *SymbolMessage) { + var n int + var MarketHkdCache decimal.Decimal // 缓存记录 + var marketProfitAndLoss decimal.Decimal // 用户市场累计盈亏 + var marketTotalFee decimal.Decimal // 用户市场总手续费 + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareHkdMarketSubscribe { + var marketTotalAssets decimal.Decimal // 用户市场总资产 + var marketAvailable decimal.Decimal // 用户市场可用 + var marketFreeze decimal.Decimal // 用户市场冻结 + var marketFloatingPL decimal.Decimal // 用户市场总浮动盈亏 + + // 统计用户市场可用余额和冻结余额 + var botUserStockHkd []models.BotUserStockHkd + err = data.Msql.Table(flags.BotUserStockHkd).Where("user_id = ?", userId).Where("stock_id = ?", flags.ShareHkdBasicUnit).Find(&botUserStockHkd) + if err != nil { + marketAvailable = decimal.Zero + marketFreeze = decimal.Zero + } + for _, value := range botUserStockHkd { + marketAvailable = decimal.RequireFromString(value.UsableNum) + marketFreeze = decimal.RequireFromString(value.FrozenNum) + } + // 判定是否存在订单 + if marketAvailable.IsZero() || marketFreeze.IsZero() { + if n == 0 { + tradeCount, _ := data.Msql.Table(flags.BotStockHkdTrade).Where("user_id = ?", userId).In("status", 1, 3).Count() + if tradeCount > 0 { + n = 1 + } + } + } + if marketAvailable.Cmp(MarketHkdCache) != 0 || n == 1 { + // 统计用户市场累计盈亏 + var botStockHkdTrade []models.BotStockHkdTrade + err = data.Msql.Table(flags.BotStockHkdTrade).Where("user_id = ?", userId).Where("status = 3").Find(&botStockHkdTrade) + if err != nil { + marketProfitAndLoss = decimal.Zero + } + for _, value := range botStockHkdTrade { + sumValue := decimal.Zero + openPrice := decimal.RequireFromString(value.DealPrice) + closePrice := decimal.RequireFromString(value.ClosingPrice) + orderNum := decimal.RequireFromString(value.OrderNumber) + switch value.TradeType { + case 1: // 买张 + sumValue = closePrice.Sub(openPrice) + default: // 买跌 + sumValue = openPrice.Sub(closePrice) + } + marketProfitAndLoss = marketProfitAndLoss.Add(sumValue.Mul(orderNum)) + } + // 统计用户市场总手续费 + var botStockHkdTradeFee models.BotStockHkdTrade + totalFee, err := data.Msql.Table(flags.BotStockHkdTrade).Where("user_id = ?", userId).In("status", 1, 3).Sums(botStockHkdTradeFee, "service_cost", "closing_cost") + if err != nil || len(totalFee) != 2 { + marketTotalFee = decimal.Zero + } + marketTotalFee = decimal.NewFromFloat(totalFee[0]).Add(decimal.NewFromFloat(totalFee[1])) + var botUserHkdPreStockOrder models.BotUserHkdPreStockOrder + totalPreFee, err := data.Msql.Table(flags.BotUserHkdPreStockOrder).Where("user_id = ?", userId).Sum(botUserHkdPreStockOrder, "get_fee") + if err != nil { + marketTotalFee = decimal.Zero + } + marketTotalFee = marketTotalFee.Add(decimal.NewFromFloat(totalPreFee)) + MarketHkdCache = marketAvailable + n = 2 + } + // 用户市场总浮动盈亏 + pLPriceSum := GetShareHkdByPriceSum(userId, setting.AdminShareHkdSubscribe) + // 统计用户市场总资产 + marketTotalAssets = marketAvailable.Add(marketFreeze).Add(pLPriceSum) + // 统计用户市场总浮动盈亏 + marketFloatingPL = pLPriceSum + orderModel := &UserMarketStatistics{ + UserMarkerSubscribe: psgMsg.Symbol, + UserMarketTotalAssets: marketTotalAssets.String(), + UserMarketAvailable: marketAvailable.String(), + UserMarketFreeze: marketFreeze.String(), + UserMarketProfitAndLoss: marketProfitAndLoss.String(), + UserMarketTotalFee: marketTotalFee.String(), + UserMarketFloatingPL: marketFloatingPL.String(), + } + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User market Hkd stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户市场统计订阅 + } else { + applogger.Info("User market cancels subscription to Hkd stock orders.") + return + } + } + + time.Sleep(800 * time.Millisecond) + } +} + +// orderSubShareHkdSubscribe +// +// @Description: 用户英股订单订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubShareGbxSubscribe(psgMsg *SymbolMessage) { + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareGbxSubscribe { + orderTokenKey := virtual.OrderIdListKey(setting.ShareGbxSubscribe, userId) + orderList, err := data.Reds.HGetAll(context.Background(), orderTokenKey).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + + for _, value := range orderList { + var msg share.ShareGbxTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + orderModel := shareData.ShareGbxOrderProcessing(setting.ShareGbxSubscribe, msg) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理股票股订阅缓存订单中(撤单|平仓)状态的订单 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + err = data.Reds.HDel(context.Background(), orderTokenKey, msg.OrderId).Err() + if err != nil { + time.Sleep(5 * time.Second) + applogger.Error("ShareGbxSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User's UK stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("User cancels Uk stock order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubShareGbxMarketSubscribe(psgMsg *SymbolMessage) { + var n int + var MarketGbxCache decimal.Decimal // 缓存记录 + var marketProfitAndLoss decimal.Decimal // 用户市场累计盈亏 + var marketTotalFee decimal.Decimal // 用户市场总手续费 + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareGbxMarketSubscribe { + var marketTotalAssets decimal.Decimal // 用户市场总资产 + var marketAvailable decimal.Decimal // 用户市场可用 + var marketFreeze decimal.Decimal // 用户市场冻结 + var marketFloatingPL decimal.Decimal // 用户市场总浮动盈亏 + + // 统计用户市场可用余额和冻结余额 + var botUserStockGbx []models.BotUserStockGbx + err = data.Msql.Table(flags.BotUserStockGbx).Where("user_id = ?", userId).Where("stock_id = ?", flags.ShareGbxBasicUnit).Find(&botUserStockGbx) + if err != nil { + marketAvailable = decimal.Zero + marketFreeze = decimal.Zero + } + for _, value := range botUserStockGbx { + marketAvailable = decimal.RequireFromString(value.UsableNum) + marketFreeze = decimal.RequireFromString(value.FrozenNum) + } + // 判定是否存在订单 + if marketAvailable.IsZero() || marketFreeze.IsZero() { + if n == 0 { + tradeCount, _ := data.Msql.Table(flags.BotStockGbxTrade).Where("user_id = ?", userId).In("status", 1, 3).Count() + if tradeCount > 0 { + n = 1 + } + } + } + if marketAvailable.Cmp(MarketGbxCache) != 0 || n == 1 { + // 统计用户市场累计盈亏 + var botStockGbxTrade []models.BotStockGbxTrade + err = data.Msql.Table(flags.BotStockGbxTrade).Where("user_id = ?", userId).Where("status = 3").Find(&botStockGbxTrade) + if err != nil { + marketProfitAndLoss = decimal.Zero + } + for _, value := range botStockGbxTrade { + sumValue := decimal.Zero + openPrice := decimal.RequireFromString(value.DealPrice) + closePrice := decimal.RequireFromString(value.ClosingPrice) + orderNum := decimal.RequireFromString(value.OrderNumber) + switch value.TradeType { + case 1: // 买张 + sumValue = closePrice.Sub(openPrice) + default: // 买跌 + sumValue = openPrice.Sub(closePrice) + } + pricePl := sumValue.Mul(orderNum) + marketProfitAndLoss = marketProfitAndLoss.Add(pricePl) + } + // 统计用户市场总手续费 + var botStockGbxTradeFee models.BotStockGbxTrade + totalFee, err := data.Msql.Table(flags.BotStockGbxTrade).Where("user_id = ?", userId).In("status", 1, 3).Sums(botStockGbxTradeFee, "service_cost", "closing_cost") + if err != nil || len(totalFee) != 2 { + marketTotalFee = decimal.Zero + } + marketTotalFee = decimal.NewFromFloat(totalFee[0]).Add(decimal.NewFromFloat(totalFee[1])) + var botUserGbxPreStockOrder models.BotUserGbxPreStockOrder + totalPreFee, err := data.Msql.Table(flags.BotUserGbxPreStockOrder).Where("user_id = ?", userId).Sum(botUserGbxPreStockOrder, "get_fee") + if err != nil { + marketTotalFee = decimal.Zero + } + marketTotalFee = marketTotalFee.Add(decimal.NewFromFloat(totalPreFee)) + MarketGbxCache = marketAvailable + n = 2 + } + // 用户市场总浮动盈亏 + pLPriceSum := GetShareGbxByPriceSum(userId, setting.AdminShareGbxSubscribe) + // 统计用户市场总资产 + marketTotalAssets = marketAvailable.Add(marketFreeze).Add(pLPriceSum) + // 统计用户市场总浮动盈亏 + marketFloatingPL = pLPriceSum + orderModel := &UserMarketStatistics{ + UserMarkerSubscribe: psgMsg.Symbol, + UserMarketTotalAssets: marketTotalAssets.String(), + UserMarketAvailable: marketAvailable.String(), + UserMarketFreeze: marketFreeze.String(), + UserMarketProfitAndLoss: marketProfitAndLoss.String(), + UserMarketTotalFee: marketTotalFee.String(), + UserMarketFloatingPL: marketFloatingPL.String(), + } + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User market Gbx stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户市场统计订阅 + } else { + applogger.Info("User market cancels subscription to Gbx stock orders.") + return + } + } + + time.Sleep(800 * time.Millisecond) + } +} + +// orderSubShareSgdSubscribe +// +// @Description: 用户德股订单订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubShareEurSubscribe(psgMsg *SymbolMessage) { + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareEurSubscribe { + orderTokenKey := virtual.OrderIdListKey(setting.ShareEurSubscribe, userId) + orderList, err := data.Reds.HGetAll(context.Background(), orderTokenKey).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + + for _, value := range orderList { + var msg share.ShareEurTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + orderModel := shareData.ShareEurOrderProcessing(setting.ShareEurSubscribe, msg) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理股票股订阅缓存订单中(撤单|平仓)状态的订单 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + err = data.Reds.HDel(context.Background(), orderTokenKey, msg.OrderId).Err() + if err != nil { + time.Sleep(5 * time.Second) + applogger.Error("ShareEurSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User's Eur stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("User cancels Eur stock order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubShareEurMarketSubscribe(psgMsg *SymbolMessage) { + var n int + var MarketEurCache decimal.Decimal // 缓存记录 + var marketProfitAndLoss decimal.Decimal // 用户市场累计盈亏 + var marketTotalFee decimal.Decimal // 用户市场总手续费 + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareEurMarketSubscribe { + var marketTotalAssets decimal.Decimal // 用户市场总资产 + var marketAvailable decimal.Decimal // 用户市场可用 + var marketFreeze decimal.Decimal // 用户市场冻结 + var marketFloatingPL decimal.Decimal // 用户市场总浮动盈亏 + + // 统计用户市场可用余额和冻结余额 + var botUserStockEur []models.BotUserStockEur + err = data.Msql.Table(flags.BotUserStockEur).Where("user_id = ?", userId).Where("stock_id = ?", flags.ShareEurBasicUnit).Find(&botUserStockEur) + if err != nil { + marketAvailable = decimal.Zero + marketFreeze = decimal.Zero + } + for _, value := range botUserStockEur { + marketAvailable = decimal.RequireFromString(value.UsableNum) + marketFreeze = decimal.RequireFromString(value.FrozenNum) + } + // 判定是否存在订单 + if marketAvailable.IsZero() || marketFreeze.IsZero() { + if n == 0 { + tradeCount, _ := data.Msql.Table(flags.BotStockEurTrade).Where("user_id = ?", userId).In("status", 1, 3).Count() + if tradeCount > 0 { + n = 1 + } + } + } + if marketAvailable.Cmp(MarketEurCache) != 0 || n == 1 { + // 统计用户市场累计盈亏 + var botStockEurTrade []models.BotStockEurTrade + err = data.Msql.Table(flags.BotStockEurTrade).Where("user_id = ?", userId).Where("status = 3").Find(&botStockEurTrade) + if err != nil { + marketProfitAndLoss = decimal.Zero + } + for _, value := range botStockEurTrade { + sumValue := decimal.Zero + openPrice := decimal.RequireFromString(value.DealPrice) + closePrice := decimal.RequireFromString(value.ClosingPrice) + orderNum := decimal.RequireFromString(value.OrderNumber) + switch value.TradeType { + case 1: // 买张 + sumValue = closePrice.Sub(openPrice) + default: // 买跌 + sumValue = openPrice.Sub(closePrice) + } + marketProfitAndLoss = marketProfitAndLoss.Add(sumValue.Mul(orderNum)) + } + // 统计用户市场总手续费 + var botStockEurTradeFee models.BotStockEurTrade + totalFee, err := data.Msql.Table(flags.BotStockEurTrade).Where("user_id = ?", userId).In("status", 1, 3).Sums(botStockEurTradeFee, "service_cost", "closing_cost") + if err != nil || len(totalFee) != 2 { + marketTotalFee = decimal.Zero + } + marketTotalFee = decimal.NewFromFloat(totalFee[0]).Add(decimal.NewFromFloat(totalFee[1])) + var botUserEurPreStockOrder models.BotUserEurPreStockOrder + totalPreFee, err := data.Msql.Table(flags.BotUserEurPreStockOrder).Where("user_id = ?", userId).Sum(botUserEurPreStockOrder, "get_fee") + if err != nil { + marketTotalFee = decimal.Zero + } + marketTotalFee = marketTotalFee.Add(decimal.NewFromFloat(totalPreFee)) + MarketEurCache = marketAvailable + n = 2 + } + // 用户市场总浮动盈亏 + pLPriceSum := GetShareEurByPriceSum(userId, setting.AdminShareEurSubscribe) + // 统计用户市场总资产 + marketTotalAssets = marketAvailable.Add(marketFreeze).Add(pLPriceSum) + // 统计用户市场总浮动盈亏 + marketFloatingPL = pLPriceSum + orderModel := &UserMarketStatistics{ + UserMarkerSubscribe: psgMsg.Symbol, + UserMarketTotalAssets: marketTotalAssets.String(), + UserMarketAvailable: marketAvailable.String(), + UserMarketFreeze: marketFreeze.String(), + UserMarketProfitAndLoss: marketProfitAndLoss.String(), + UserMarketTotalFee: marketTotalFee.String(), + UserMarketFloatingPL: marketFloatingPL.String(), + } + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User market Eur stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户市场统计订阅 + } else { + applogger.Info("User market cancels subscription to Eur stock orders.") + return + } + } + + time.Sleep(800 * time.Millisecond) + } +} + +// orderSubShareFurSubscribe +// +// @Description: 用户法股订单订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubShareFurSubscribe(psgMsg *SymbolMessage) { + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareFurSubscribe { + orderTokenKey := virtual.OrderIdListKey(setting.ShareFurSubscribe, userId) + orderList, err := data.Reds.HGetAll(context.Background(), orderTokenKey).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + + for _, value := range orderList { + var msg share.ShareFurTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + orderModel := shareData.ShareFurOrderProcessing(setting.ShareFurSubscribe, msg) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理股票股订阅缓存订单中(撤单|平仓)状态的订单 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + err = data.Reds.HDel(context.Background(), orderTokenKey, msg.OrderId).Err() + if err != nil { + time.Sleep(5 * time.Second) + applogger.Error("orderSubShareFurSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User's Fur stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("User cancels Fur stock order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubShareFurMarketSubscribe(psgMsg *SymbolMessage) { + var n int + var MarketFurCache decimal.Decimal // 缓存记录 + var marketProfitAndLoss decimal.Decimal // 用户市场累计盈亏 + var marketTotalFee decimal.Decimal // 用户市场总手续费 + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareFurMarketSubscribe { + var marketTotalAssets decimal.Decimal // 用户市场总资产 + var marketAvailable decimal.Decimal // 用户市场可用 + var marketFreeze decimal.Decimal // 用户市场冻结 + var marketFloatingPL decimal.Decimal // 用户市场总浮动盈亏 + + // 统计用户市场可用余额和冻结余额 + var botUserStockFur []models.BotUserStockFur + err = data.Msql.Table(flags.BotUserStockFur).Where("user_id = ?", userId).Where("stock_id = ?", flags.ShareFurBasicUnit).Find(&botUserStockFur) + if err != nil { + marketAvailable = decimal.Zero + marketFreeze = decimal.Zero + } + for _, value := range botUserStockFur { + marketAvailable = decimal.RequireFromString(value.UsableNum) + marketFreeze = decimal.RequireFromString(value.FrozenNum) + } + // 判定是否存在订单 + if marketAvailable.IsZero() || marketFreeze.IsZero() { + if n == 0 { + tradeCount, _ := data.Msql.Table(flags.BotStockFurTrade).Where("user_id = ?", userId).In("status", 1, 3).Count() + if tradeCount > 0 { + n = 1 + } + } + } + if marketAvailable.Cmp(MarketFurCache) != 0 || n == 1 { + // 统计用户市场累计盈亏 + var botStockFurTrade []models.BotStockFurTrade + err = data.Msql.Table(flags.BotStockFurTrade).Where("user_id = ?", userId).Where("status = 3").Find(&botStockFurTrade) + if err != nil { + marketProfitAndLoss = decimal.Zero + } + for _, value := range botStockFurTrade { + sumValue := decimal.Zero + openPrice := decimal.RequireFromString(value.DealPrice) + closePrice := decimal.RequireFromString(value.ClosingPrice) + orderNum := decimal.RequireFromString(value.OrderNumber) + switch value.TradeType { + case 1: // 买张 + sumValue = closePrice.Sub(openPrice) + default: // 买跌 + sumValue = openPrice.Sub(closePrice) + } + marketProfitAndLoss = marketProfitAndLoss.Add(sumValue.Mul(orderNum)) + } + // 统计用户市场总手续费 + var botStockFurTradeFee models.BotStockFurTrade + totalFee, err := data.Msql.Table(flags.BotStockFurTrade).Where("user_id = ?", userId).In("status", 1, 3).Sums(botStockFurTradeFee, "service_cost", "closing_cost") + if err != nil || len(totalFee) != 2 { + marketTotalFee = decimal.Zero + } + marketTotalFee = decimal.NewFromFloat(totalFee[0]).Add(decimal.NewFromFloat(totalFee[1])) + var botUserFurPreStockOrder models.BotUserFurPreStockOrder + totalPreFee, err := data.Msql.Table(flags.BotUserFurPreStockOrder).Where("user_id = ?", userId).Sum(botUserFurPreStockOrder, "get_fee") + if err != nil { + marketTotalFee = decimal.Zero + } + marketTotalFee = marketTotalFee.Add(decimal.NewFromFloat(totalPreFee)) + MarketFurCache = marketAvailable + n = 2 + } + // 用户市场总浮动盈亏 + pLPriceSum := GetShareFurByPriceSum(userId, setting.AdminShareFurSubscribe) + // 统计用户市场总资产 + marketTotalAssets = marketAvailable.Add(marketFreeze).Add(pLPriceSum) + // 统计用户市场总浮动盈亏 + marketFloatingPL = pLPriceSum + orderModel := &UserMarketStatistics{ + UserMarkerSubscribe: psgMsg.Symbol, + UserMarketTotalAssets: marketTotalAssets.String(), + UserMarketAvailable: marketAvailable.String(), + UserMarketFreeze: marketFreeze.String(), + UserMarketProfitAndLoss: marketProfitAndLoss.String(), + UserMarketTotalFee: marketTotalFee.String(), + UserMarketFloatingPL: marketFloatingPL.String(), + } + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User market Fur stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户市场统计订阅 + } else { + applogger.Info("User market cancels subscription to Fur stock orders.") + return + } + } + + time.Sleep(800 * time.Millisecond) + } +} + +// orderSubShareBrlSubscribe +// +// @Description: 用户巴西股订单订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubShareBrlSubscribe(psgMsg *SymbolMessage) { + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareBrlSubscribe { + orderTokenKey := virtual.OrderIdListKey(setting.ShareBrlSubscribe, userId) + orderList, err := data.Reds.HGetAll(context.Background(), orderTokenKey).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + + for _, value := range orderList { + var msg share.ShareBrlTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + orderModel := shareData.ShareBrlOrderProcessing(setting.ShareBrlSubscribe, msg) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理股票股订阅缓存订单中(撤单|平仓)状态的订单 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + err = data.Reds.HDel(context.Background(), orderTokenKey, msg.OrderId).Err() + if err != nil { + time.Sleep(5 * time.Second) + applogger.Error("orderSubShareBrlSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User's Brl stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("User cancels Brl stock order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubShareBrlMarketSubscribe(psgMsg *SymbolMessage) { + var n int + var MarketBrlCache decimal.Decimal // 缓存记录 + var marketProfitAndLoss decimal.Decimal // 用户市场累计盈亏 + var marketTotalFee decimal.Decimal // 用户市场总手续费 + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareBrlMarketSubscribe { + var marketTotalAssets decimal.Decimal // 用户市场总资产 + var marketAvailable decimal.Decimal // 用户市场可用 + var marketFreeze decimal.Decimal // 用户市场冻结 + var marketFloatingPL decimal.Decimal // 用户市场总浮动盈亏 + + // 统计用户市场可用余额和冻结余额 + var botUserStockBrl []models.BotUserStockBrl + err = data.Msql.Table(flags.BotUserStockBrl).Where("user_id = ?", userId).Where("stock_id = ?", flags.ShareBrlBasicUnit).Find(&botUserStockBrl) + if err != nil { + marketAvailable = decimal.Zero + marketFreeze = decimal.Zero + } + for _, value := range botUserStockBrl { + marketAvailable = decimal.RequireFromString(value.UsableNum) + marketFreeze = decimal.RequireFromString(value.FrozenNum) + } + // 判定是否存在订单 + if marketAvailable.IsZero() || marketFreeze.IsZero() { + if n == 0 { + tradeCount, _ := data.Msql.Table(flags.BotStockBrlTrade).Where("user_id = ?", userId).In("status", 1, 3).Count() + if tradeCount > 0 { + n = 1 + } + } + } + if marketAvailable.Cmp(MarketBrlCache) != 0 || n == 1 { + // 统计用户市场累计盈亏 + var botStockBrlTrade []models.BotStockBrlTrade + err = data.Msql.Table(flags.BotStockBrlTrade).Where("user_id = ?", userId).Where("status = 3").Find(&botStockBrlTrade) + if err != nil { + marketProfitAndLoss = decimal.Zero + } + for _, value := range botStockBrlTrade { + sumValue := decimal.Zero + openPrice := decimal.RequireFromString(value.DealPrice) + closePrice := decimal.RequireFromString(value.ClosingPrice) + orderNum := decimal.RequireFromString(value.OrderNumber) + switch value.TradeType { + case 1: // 买张 + sumValue = closePrice.Sub(openPrice) + default: // 买跌 + sumValue = openPrice.Sub(closePrice) + } + marketProfitAndLoss = marketProfitAndLoss.Add(sumValue.Mul(orderNum)) + } + // 统计用户市场总手续费 + var botStockBrlTradeFee models.BotStockBrlTrade + totalFee, err := data.Msql.Table(flags.BotStockBrlTrade).Where("user_id = ?", userId).In("status", 1, 3).Sums(botStockBrlTradeFee, "service_cost", "closing_cost") + if err != nil || len(totalFee) != 2 { + marketTotalFee = decimal.Zero + } + marketTotalFee = decimal.NewFromFloat(totalFee[0]).Add(decimal.NewFromFloat(totalFee[1])) + var botUserBrlPreStockOrder models.BotUserBrlPreStockOrder + totalPreFee, err := data.Msql.Table(flags.BotUserBrlPreStockOrder).Where("user_id = ?", userId).Sum(botUserBrlPreStockOrder, "get_fee") + if err != nil { + marketTotalFee = decimal.Zero + } + marketTotalFee = marketTotalFee.Add(decimal.NewFromFloat(totalPreFee)) + MarketBrlCache = marketAvailable + n = 2 + } + // 用户市场总浮动盈亏 + pLPriceSum := GetShareBrlByPriceSum(userId, setting.AdminShareBrlSubscribe) + // 统计用户市场总资产 + marketTotalAssets = marketAvailable.Add(marketFreeze).Add(pLPriceSum) + // 统计用户市场总浮动盈亏 + marketFloatingPL = pLPriceSum + orderModel := &UserMarketStatistics{ + UserMarkerSubscribe: psgMsg.Symbol, + UserMarketTotalAssets: marketTotalAssets.String(), + UserMarketAvailable: marketAvailable.String(), + UserMarketFreeze: marketFreeze.String(), + UserMarketProfitAndLoss: marketProfitAndLoss.String(), + UserMarketTotalFee: marketTotalFee.String(), + UserMarketFloatingPL: marketFloatingPL.String(), + } + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User market Brl stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户市场统计订阅 + } else { + applogger.Info("User market cancels subscription to Brl stock orders.") + return + } + } + + time.Sleep(800 * time.Millisecond) + } +} + +// orderSubShareFurSubscribe +// +// @Description: 用户日股订单订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubShareJpySubscribe(psgMsg *SymbolMessage) { + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareJpySubscribe { + orderTokenKey := virtual.OrderIdListKey(setting.ShareJpySubscribe, userId) + orderList, err := data.Reds.HGetAll(context.Background(), orderTokenKey).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + + for _, value := range orderList { + var msg share.ShareJpyTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + orderModel := shareData.ShareJpyOrderProcessing(setting.ShareJpySubscribe, msg) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理股票股订阅缓存订单中(撤单|平仓)状态的订单 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + err = data.Reds.HDel(context.Background(), orderTokenKey, msg.OrderId).Err() + if err != nil { + time.Sleep(5 * time.Second) + applogger.Error("orderSubShareJpySubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User's Jpy stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("User cancels Jpy stock order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubShareJpyMarketSubscribe(psgMsg *SymbolMessage) { + var n int + var MarketJpyCache decimal.Decimal // 缓存记录 + var marketProfitAndLoss decimal.Decimal // 用户市场累计盈亏 + var marketTotalFee decimal.Decimal // 用户市场总手续费 + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ShareJpyMarketSubscribe { + var marketTotalAssets decimal.Decimal // 用户市场总资产 + var marketAvailable decimal.Decimal // 用户市场可用 + var marketFreeze decimal.Decimal // 用户市场冻结 + var marketFloatingPL decimal.Decimal // 用户市场总浮动盈亏 + + // 统计用户市场可用余额和冻结余额 + var botUserStockJpy []models.BotUserStockJp + err = data.Msql.Table(flags.BotUserStockJpy).Where("user_id = ?", userId).Where("stock_id = ?", flags.ShareJpyBasicUnit).Find(&botUserStockJpy) + if err != nil { + marketAvailable = decimal.Zero + marketFreeze = decimal.Zero + } + for _, value := range botUserStockJpy { + marketAvailable = decimal.RequireFromString(value.UsableNum) + marketFreeze = decimal.RequireFromString(value.FrozenNum) + } + // 判定是否存在订单 + if marketAvailable.IsZero() || marketFreeze.IsZero() { + if n == 0 { + tradeCount, _ := data.Msql.Table(flags.BotStockJpyTrade).Where("user_id = ?", userId).In("status", 1, 3).Count() + if tradeCount > 0 { + n = 1 + } + } + } + if marketAvailable.Cmp(MarketJpyCache) != 0 || n == 1 { + // 统计用户市场累计盈亏 + var botStockJpyTrade []models.BotStockJpTrade + err = data.Msql.Table(flags.BotStockJpyTrade).Where("user_id = ?", userId).Where("status = 3").Find(&botStockJpyTrade) + if err != nil { + marketProfitAndLoss = decimal.Zero + } + for _, value := range botStockJpyTrade { + sumValue := decimal.Zero + openPrice := decimal.RequireFromString(value.DealPrice) + closePrice := decimal.RequireFromString(value.ClosingPrice) + orderNum := decimal.RequireFromString(value.OrderNumber) + switch value.TradeType { + case 1: // 买张 + sumValue = closePrice.Sub(openPrice) + default: // 买跌 + sumValue = openPrice.Sub(closePrice) + } + marketProfitAndLoss = marketProfitAndLoss.Add(sumValue.Mul(orderNum)) + } + // 统计用户市场总手续费 + var botStockJpyTradeFee models.BotStockJpTrade + totalFee, err := data.Msql.Table(flags.BotStockJpyTrade).Where("user_id = ?", userId).In("status", 1, 3).Sums(botStockJpyTradeFee, "service_cost", "closing_cost") + if err != nil || len(totalFee) != 2 { + marketTotalFee = decimal.Zero + } + marketTotalFee = decimal.NewFromFloat(totalFee[0]).Add(decimal.NewFromFloat(totalFee[1])) + var botUserJpyPreStockOrder models.BotUserJpPreStockOrder + totalPreFee, err := data.Msql.Table(flags.BotUserJpyPreStockOrder).Where("user_id = ?", userId).Sum(botUserJpyPreStockOrder, "get_fee") + if err != nil { + marketTotalFee = decimal.Zero + } + marketTotalFee = marketTotalFee.Add(decimal.NewFromFloat(totalPreFee)) + MarketJpyCache = marketAvailable + n = 2 + } + // 用户市场总浮动盈亏 + pLPriceSum := GetShareJpyByPriceSum(userId, setting.AdminShareJpySubscribe) + // 统计用户市场总资产 + marketTotalAssets = marketAvailable.Add(marketFreeze).Add(pLPriceSum) + // 统计用户市场总浮动盈亏 + marketFloatingPL = pLPriceSum + orderModel := &UserMarketStatistics{ + UserMarkerSubscribe: psgMsg.Symbol, + UserMarketTotalAssets: marketTotalAssets.String(), + UserMarketAvailable: marketAvailable.String(), + UserMarketFreeze: marketFreeze.String(), + UserMarketProfitAndLoss: marketProfitAndLoss.String(), + UserMarketTotalFee: marketTotalFee.String(), + UserMarketFloatingPL: marketFloatingPL.String(), + } + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User market Jpy stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户市场统计订阅 + } else { + applogger.Info("User market cancels subscription to Jpy stock orders.") + return + } + } + + time.Sleep(800 * time.Millisecond) + } +} diff --git a/internal/data/socket/virtualData/contract.go b/internal/data/socket/virtualData/contract.go new file mode 100644 index 0000000..839346c --- /dev/null +++ b/internal/data/socket/virtualData/contract.go @@ -0,0 +1,42 @@ +package virtualData + +import ( + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" +) + +// ContractOrderProcessing +// +// @Description: 合约订单订阅处理 +// @param topIc +// @param msg +// @return *public.OrderSub +func ContractOrderProcessing(topIc string, msg virtual.ContractTallyCache) *publicData.OrderSub { + price, err := publicData.CheckSymbol(topIc, msg.Symbol) + if err != nil { + applogger.Warn("%v ContractOrderProcessing.CheckSymbol.err:%v--%v", common.ErrContract, msg.Symbol, err) + } + + var faceValue string + if msg.Order.System != nil { + faceValue = msg.Order.System.FaceValue.String() + } + + orderM := &publicData.OrderSub{ + OrderId: msg.OrderId, + Price: price, + Status: msg.Status, + Symbol: topIc, + Count: 0, + OpenPrice: msg.OpenPrice, + Market: msg.Symbol, + OrderNumber: msg.Order.OrderNumber, + TradeType: msg.Order.TradeType, + FaceValue: faceValue, + UserId: msg.UserId, + } + + return orderM +} diff --git a/internal/data/socket/virtualData/second.go b/internal/data/socket/virtualData/second.go new file mode 100644 index 0000000..6863341 --- /dev/null +++ b/internal/data/socket/virtualData/second.go @@ -0,0 +1,42 @@ +package virtualData + +import ( + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" +) + +// SecondOrderProcessing +// +// @Description: 秒合约订单订阅处理 +// @param topIc +// @param msg +// @return *public.OrderSub +func SecondOrderProcessing(topIc string, msg virtual.ContractTallyCache) *publicData.OrderSub { + price, err := publicData.CheckSymbol(topIc, msg.Symbol) + if err != nil { + applogger.Warn("%v SecondOrderProcessing.CheckSymbol.err:%v--%v", common.ErrSecond, msg.Symbol, err) + } + + var faceValue string + if msg.Order.System != nil { + faceValue = msg.Order.System.FaceValue.String() + } + + orderM := &publicData.OrderSub{ + OrderId: msg.OrderId, + Price: price, + Status: msg.Status, + Symbol: topIc, + Count: 0, + OpenPrice: msg.OpenPrice, + Market: msg.Symbol, + OrderNumber: msg.Order.OrderNumber, + TradeType: msg.Order.TradeType, + FaceValue: faceValue, + UserId: msg.UserId, + } + + return orderM +} diff --git a/internal/data/socket/virtualData/spots.go b/internal/data/socket/virtualData/spots.go new file mode 100644 index 0000000..e1a3351 --- /dev/null +++ b/internal/data/socket/virtualData/spots.go @@ -0,0 +1,43 @@ +package virtualData + +import ( + "encoding/json" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" +) + +// SpotOrderProcessing +// +// @Description: 现货订单订阅处理 +// @param topIc +// @param msg +// @return []byte +// @return *public.OrderSub +func SpotOrderProcessing(topIc string, msg virtual.SpotsTallyCache) ([]byte, *publicData.OrderSub) { + price, err := publicData.CheckSymbol(topIc, msg.Symbol) + if err != nil { + applogger.Warn("%v SpotOrderProcessing.CheckSymbol.err:%v--%v", common.ErrSpots, msg.Symbol, err) + } + + orderM := &publicData.OrderSub{ + OrderId: msg.OrderId, + Price: price, + Status: msg.Status, + Symbol: topIc, + Count: 0, + OpenPrice: msg.OpenPrice, + Market: msg.Symbol, + OrderNumber: msg.Order.OrderNumber, + TradeType: msg.Order.TradeType, + UserId: msg.UserId, + } + + orderStr, err := json.Marshal(orderM) + if err != nil { + return []byte{}, orderM + } + + return orderStr, orderM +} diff --git a/internal/data/socket/virtual_admin.go b/internal/data/socket/virtual_admin.go new file mode 100644 index 0000000..9e2da70 --- /dev/null +++ b/internal/data/socket/virtual_admin.go @@ -0,0 +1,156 @@ +package socket + +import ( + "context" + "encoding/json" + "matchmaking-system/internal/data" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/socket/virtualData" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/setting" + "time" +) + +// orderSubAdminContractSubscribeByOrder +// +// @Description: 管理员合约|持仓订单订阅|持仓浮动盈亏订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubAdminContractSubscribeByOrder(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminContractSubscribe { + var hashList []virtual.ContractTallyCache + for _, field := range psgMsg.Order { + fieldStr, err := data.Reds.HGet(context.Background(), setting.AdminContractSubscribe, field).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + var msg virtual.ContractTallyCache + if err = json.Unmarshal([]byte(fieldStr), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + hashList = append(hashList, msg) + } + + for _, value := range hashList { + orderModel := virtualData.ContractOrderProcessing(setting.AdminContractSubscribe, value) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理[撤单|平仓]缓存队列 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + if err := data.Reds.HDel(context.Background(), setting.AdminContractSubscribe, orderModel.OrderId).Err(); err != nil { + applogger.Error("AdminContractSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("Administrator contract subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("Administrator cancels contract order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubAdminContractSubscribeBySum(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminContractSumSubscribe { + priceSum, err := memory.ContractFloating.Get(flags.FloatingHy) + if err != nil { + time.Sleep(5 * time.Second) + continue + } + + result := &SymbolSumResult{ + Symbol: psgMsg.Symbol, + Price: string(priceSum), + } + + priceByte, err := json.Marshal(result) + if err != nil { + time.Sleep(3 * time.Second) + continue + } + + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + u.msg <- priceByte + } else { + applogger.Info("Administrator cancels contract order subscription.") + return + } + } + + time.Sleep(2 * time.Second) + } +} + +// orderSubAdminSecondSubscribeByOrder +// +// @Description: 管理员秒合约持仓订单订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubAdminSecondSubscribeByOrder(psgMsg *SymbolMessage) { + for { + if psgMsg.Symbol == setting.AdminSecondSubscribe { + var hashList []virtual.ContractTallyCache + for _, field := range psgMsg.Order { + fieldStr, err := data.Reds.HGet(context.Background(), setting.AdminSecondSubscribe, field).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + var msg virtual.ContractTallyCache + if err = json.Unmarshal([]byte(fieldStr), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + hashList = append(hashList, msg) + } + + for _, value := range hashList { + orderModel := virtualData.SecondOrderProcessing(setting.AdminSecondSubscribe, value) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理[撤单|平仓]缓存队列 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + if err := data.Reds.HDel(context.Background(), setting.AdminSecondSubscribe, orderModel.OrderId).Err(); err != nil { + applogger.Error("AdminSecondSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("Administrator contract subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("Administrator cancels contract order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} diff --git a/internal/data/socket/virtual_user.go b/internal/data/socket/virtual_user.go new file mode 100644 index 0000000..4d8668d --- /dev/null +++ b/internal/data/socket/virtual_user.go @@ -0,0 +1,505 @@ +package socket + +import ( + "context" + "encoding/json" + "github.com/shopspring/decimal" + "matchmaking-system/internal/data" + "matchmaking-system/internal/data/socket/virtualData" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + models "matchmaking-system/internal/pkg/model" + "matchmaking-system/internal/pkg/setting" + "time" +) + +// orderSubSpotsSubscribe +// +// @Description: 用户现货订单订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubSpotsSubscribe(psgMsg *SymbolMessage) { + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.SpotsSubscribe { + orderTokenKey := virtual.OrderIdListKey(setting.SpotsSubscribe, userId) + orderList, err := data.Reds.HGetAll(context.Background(), orderTokenKey).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + for _, value := range orderList { + var msg virtual.SpotsTallyCache + err = json.Unmarshal([]byte(value), &msg) + if err != nil { + applogger.Error("SpotsSubscribe.Unmarshal:%v", err) + time.Sleep(5 * time.Second) + continue + } + orderStr, orderModel := virtualData.SpotOrderProcessing(setting.SpotsSubscribe, msg) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理现货撤单和完成订单状态 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + err = data.Reds.HDel(context.Background(), orderTokenKey, msg.OrderId).Err() + if err != nil { + time.Sleep(5 * time.Second) + applogger.Error("SpotsSubscribe.HDel:%v", err) + continue + } + } + u.msg <- orderStr // 用户(挂单|持仓)订阅 + } else { + applogger.Info("User cancels stock order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubSpotsMarketSubscribe(psgMsg *SymbolMessage) { + var n int + var MarketSpotsCache decimal.Decimal // 缓存记录 + var marketProfitAndLoss decimal.Decimal // 用户市场累计盈亏 + var marketTotalFee decimal.Decimal // 用户市场总手续费 + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.SpotsMarketSubscribe { + var marketTotalAssets decimal.Decimal // 用户市场总资产 + var marketAvailable decimal.Decimal // 用户市场可用 + var marketFreeze decimal.Decimal // 用户市场冻结 + var marketFloatingPL decimal.Decimal // 用户市场总浮动盈亏 + + // 统计用户市场可用余额和冻结余额 + var botUserDigital []models.BotUserDigital + err = data.Msql.Table(flags.BotUserDigital).Where("user_id = ?", userId).Where("digital_id = ?", flags.BasicUnit).Find(&botUserDigital) + if err != nil { + marketAvailable = decimal.Zero + marketFreeze = decimal.Zero + } + for _, value := range botUserDigital { + marketAvailable = decimal.RequireFromString(value.UsableNum) + marketFreeze = decimal.RequireFromString(value.FrozenNum) + } + // 判定是否存在订单 + if marketAvailable.IsZero() || marketFreeze.IsZero() { + if n == 0 { + tradeCount, _ := data.Msql.Table(flags.BotDigitalTrade).Where("user_id = ?", userId).In("status", 1, 3).Count() + if tradeCount > 0 { + n = 1 + } + } + } + if marketAvailable.Cmp(MarketSpotsCache) != 0 || n == 1 { + // 统计用户市场累计盈亏 + var botDigitalTrade []models.BotDigitalTrade + err = data.Msql.Table(flags.BotDigitalTrade).Where("user_id = ?", userId).Where("status = 3").Find(&botDigitalTrade) + if err != nil { + marketProfitAndLoss = decimal.Zero + } + for _, value := range botDigitalTrade { + sumValue := decimal.Zero + openPrice := decimal.RequireFromString(value.DealPrice) + closePrice := decimal.RequireFromString(value.ClosingPrice) + orderNum := decimal.RequireFromString(value.OrderNumber) + switch value.TradeType { + case 1: // 买张 + sumValue = closePrice.Sub(openPrice) + default: // 买跌 + sumValue = openPrice.Sub(closePrice) + } + marketProfitAndLoss = marketProfitAndLoss.Add(sumValue.Mul(orderNum)) + } + // 统计用户市场总手续费 + var botDigitalTradeTradeFee models.BotDigitalTrade + totalFee, err := data.Msql.Table(flags.BotDigitalTrade). + Where("user_id = ?", userId). + In("status", 1, 3). + Sums(botDigitalTradeTradeFee, "service_cost", "closing_cost") + if err != nil || len(totalFee) != 2 { + marketTotalFee = decimal.Zero + } + marketTotalFee = decimal.NewFromFloat(totalFee[0]).Add(decimal.NewFromFloat(totalFee[1])) + MarketSpotsCache = marketAvailable + n = 2 + } + // 用户市场总浮动盈亏 + pLPriceSum := GetSpotsByPriceSum(userId, setting.SpotsSubscribe) + // 统计用户市场总资产 + marketTotalAssets = marketAvailable.Add(marketFreeze).Add(pLPriceSum) + // 统计用户市场总浮动盈亏 + marketFloatingPL = pLPriceSum + orderModel := &UserMarketStatistics{ + UserMarkerSubscribe: psgMsg.Symbol, + UserMarketTotalAssets: marketTotalAssets.String(), + UserMarketAvailable: marketAvailable.String(), + UserMarketFreeze: marketFreeze.String(), + UserMarketProfitAndLoss: marketProfitAndLoss.String(), + UserMarketTotalFee: marketTotalFee.String(), + UserMarketFloatingPL: marketFloatingPL.String(), + } + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User market Spots stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户市场统计订阅 + } else { + applogger.Info("User market cancels subscription to Spots stock orders.") + return + } + } + + time.Sleep(800 * time.Millisecond) + } +} + +// orderSubContractSubscribe +// +// @Description: 用户合约订单订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubContractSubscribe(psgMsg *SymbolMessage) { + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ContractSubscribe { + orderTokenKey := virtual.OrderIdListKey(setting.ContractSubscribe, userId) // 获取订阅Key + orderList, err := data.Reds.HGetAll(context.Background(), orderTokenKey).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + + for _, value := range orderList { + var msg virtual.ContractTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + orderModel := virtualData.ContractOrderProcessing(setting.ContractSubscribe, msg) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理合约订阅缓存订单中(撤单|平仓)状态的订单 + if orderModel.Status == flags.Cancel || orderModel.Status == flags.Close { + err = data.Reds.HDel(context.Background(), orderTokenKey, msg.OrderId).Err() + if err != nil { + time.Sleep(5 * time.Second) + applogger.Error("ContractSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("orderSubContractSubscribe.Marshal:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户合约(挂单|持仓)订阅 + } else { + applogger.Info("User cancels contract order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubContractMarketSubscribe(psgMsg *SymbolMessage) { + var n int + var MarketContractCache decimal.Decimal // 缓存记录 + var marketProfitAndLoss decimal.Decimal // 用户市场累计盈亏 + var marketTotalFee decimal.Decimal // 用户市场总手续费 + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.ContractMarketSubscribe { + var marketTotalAssets decimal.Decimal // 用户市场总资产 + var marketAvailable decimal.Decimal // 用户市场可用 + var marketFreeze decimal.Decimal // 用户市场冻结 + var marketFloatingPL decimal.Decimal // 用户市场总浮动盈亏 + + // 统计用户市场可用余额和冻结余额 + var botUserContract []models.BotUserContract + err = data.Msql.Table(flags.BotUserContract).Where("user_id = ?", userId).Where("contract_id = ?", flags.BasicUnit).Find(&botUserContract) + if err != nil { + marketAvailable = decimal.Zero + marketFreeze = decimal.Zero + } + for _, value := range botUserContract { + marketAvailable = decimal.RequireFromString(value.UsableNum) + marketFreeze = decimal.RequireFromString(value.FrozenNum) + } + // 判定是否存在订单 + if marketAvailable.IsZero() || marketFreeze.IsZero() { + if n == 0 { + tradeCount, _ := data.Msql.Table(flags.BotContractTrade).Where("user_id = ?", userId).In("status", 1, 3).Count() + if tradeCount > 0 { + n = 1 + } + } + } + if marketAvailable.Cmp(MarketContractCache) != 0 || n == 1 { + // 统计用户市场累计盈亏 + var botContractTrade []models.BotContractTrade + err = data.Msql.Table(flags.BotContractTrade).Where("user_id = ?", userId).Where("status = 3").Find(&botContractTrade) + if err != nil { + marketProfitAndLoss = decimal.Zero + } + for _, value := range botContractTrade { + sumValue := decimal.Zero + openPrice := decimal.RequireFromString(value.DealPrice) + closePrice := decimal.RequireFromString(value.ClosingPrice) + orderNum := decimal.RequireFromString(value.OrderNumber) + switch value.TradeType { + case 1: // 买张 + sumValue = closePrice.Sub(openPrice) + default: // 买跌 + sumValue = openPrice.Sub(closePrice) + } + marketProfitAndLoss = marketProfitAndLoss.Add(sumValue.Mul(orderNum)) + } + // 统计用户市场总手续费 + var botContractTradeFee models.BotContractTrade + totalFee, err := data.Msql.Table(flags.BotContractTrade). + Where("user_id = ?", userId). + In("status", 1, 3). + Sums(botContractTradeFee, "service_cost", "closing_cost") + if err != nil || len(totalFee) != 2 { + marketTotalFee = decimal.Zero + } + marketTotalFee = decimal.NewFromFloat(totalFee[0]).Add(decimal.NewFromFloat(totalFee[1])) + MarketContractCache = marketAvailable + n = 2 + } + // 用户市场总浮动盈亏 + pLPriceSum := GetContractByPriceSum(userId, setting.AdminContractSubscribe) + // 统计用户市场总资产 + marketTotalAssets = marketAvailable.Add(marketFreeze).Add(pLPriceSum) + // 统计用户市场总浮动盈亏 + marketFloatingPL = pLPriceSum + orderModel := &UserMarketStatistics{ + UserMarkerSubscribe: psgMsg.Symbol, + UserMarketTotalAssets: marketTotalAssets.String(), + UserMarketAvailable: marketAvailable.String(), + UserMarketFreeze: marketFreeze.String(), + UserMarketProfitAndLoss: marketProfitAndLoss.String(), + UserMarketTotalFee: marketTotalFee.String(), + UserMarketFloatingPL: marketFloatingPL.String(), + } + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User market Contract stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户市场统计订阅 + } else { + applogger.Info("User market cancels subscription to Contract stock orders.") + return + } + } + + time.Sleep(800 * time.Millisecond) + } +} + +// orderSubSecondSubscribe +// +// @Description: 用户秒合约订单订阅 +// @receiver u +// @param psgMsg +func (u *Client) orderSubSecondSubscribe(psgMsg *SymbolMessage) { + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.SecondSubscribe { + orderTokenKey := virtual.OrderIdListKey(setting.SecondSubscribe, userId) // 获取订阅Key + orderList, err := data.Reds.HGetAll(context.Background(), orderTokenKey).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + + for _, value := range orderList { + var msg virtual.ContractTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + orderModel := virtualData.ContractOrderProcessing(setting.SecondSubscribe, msg) + if orderModel != nil { + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + // 清理秒合约订阅缓存订单中(平仓)状态的订单 + if orderModel.Status == flags.Close { + err = data.Reds.HDel(context.Background(), orderTokenKey, msg.OrderId).Err() + if err != nil { + time.Sleep(5 * time.Second) + applogger.Error("orderSubSecondSubscribe.HDel:%v", err) + continue + } + } + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("orderSubSecondSubscribe.Marshal:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户合约(挂单|持仓)订阅 + } else { + applogger.Info("User cancels contract order subscription.") + return + } + } + } + } + + time.Sleep(600 * time.Millisecond) + } +} +func (u *Client) orderSubSecondMarketSubscribe(psgMsg *SymbolMessage) { + var n int + var MarketSecondCache decimal.Decimal // 缓存记录 + var marketProfitAndLoss decimal.Decimal // 用户市场累计盈亏 + var marketTotalFee decimal.Decimal // 用户市场总手续费 + for { + userId, err := GetUserIdByToken(u.token) + if err != nil { + time.Sleep(5 * time.Second) + cleanSubscriptionKey(u) + break + } + + if userId != flags.AdministratorsId && psgMsg.Symbol == setting.SecondMarketSubscribe { + var marketTotalAssets decimal.Decimal // 用户市场总资产 + var marketAvailable decimal.Decimal // 用户市场可用 + var marketFreeze decimal.Decimal // 用户市场冻结 + var marketFloatingPL decimal.Decimal // 用户市场总浮动盈亏 + + // 统计用户市场可用余额和冻结余额 + var botUserContractSec []models.BotUserContractSec + err = data.Msql.Table(flags.BotUserContractSec).Where("user_id = ?", userId).Where("contract_id = ?", flags.BasicUnit).Find(&botUserContractSec) + if err != nil { + marketAvailable = decimal.Zero + marketFreeze = decimal.Zero + } + for _, value := range botUserContractSec { + marketAvailable = decimal.RequireFromString(value.UsableNum) + marketFreeze = decimal.RequireFromString(value.FrozenNum) + } + // 判定是否存在订单 + if marketAvailable.IsZero() || marketFreeze.IsZero() { + if n == 0 { + tradeCount, _ := data.Msql.Table(flags.BotContractSecTrade).Where("user_id = ?", userId).In("status", 1, 3).Count() + if tradeCount > 0 { + n = 1 + } + } + } + if marketAvailable.Cmp(MarketSecondCache) != 0 || n == 1 { + // 统计用户市场累计盈亏 + var botContractSecTrade []models.BotContractSecTrade + err = data.Msql.Table(flags.BotContractSecTrade).Where("user_id = ?", userId).Where("status = 3").Find(&botContractSecTrade) + if err != nil { + marketProfitAndLoss = decimal.Zero + } + for _, value := range botContractSecTrade { + sumValue := decimal.Zero + openPrice := decimal.RequireFromString(value.DealPrice) + closePrice := decimal.RequireFromString(value.ClosingPrice) + orderNum := decimal.RequireFromString(value.OrderNumber) + switch value.TradeType { + case 1: // 买张 + sumValue = closePrice.Sub(openPrice) + default: // 买跌 + sumValue = openPrice.Sub(closePrice) + } + marketProfitAndLoss = marketProfitAndLoss.Add(sumValue.Mul(orderNum)) + } + // 统计用户市场总手续费 + var botContractSecTradeFee models.BotContractSecTrade + totalFee, err := data.Msql.Table(flags.BotContractSecTrade). + Where("user_id = ?", userId). + In("status", 1, 3). + Sums(botContractSecTradeFee, "service_cost", "closing_cost") + if err != nil || len(totalFee) != 2 { + marketTotalFee = decimal.Zero + } + marketTotalFee = decimal.NewFromFloat(totalFee[0]).Add(decimal.NewFromFloat(totalFee[1])) + MarketSecondCache = marketAvailable + n = 2 + } + // 用户市场总浮动盈亏 + pLPriceSum := GetSecondByPriceSum(userId, setting.AdminSecondSubscribe) + // 统计用户市场总资产 + marketTotalAssets = marketAvailable.Add(marketFreeze).Add(pLPriceSum) + // 统计用户市场总浮动盈亏 + marketFloatingPL = pLPriceSum + orderModel := &UserMarketStatistics{ + UserMarkerSubscribe: psgMsg.Symbol, + UserMarketTotalAssets: marketTotalAssets.String(), + UserMarketAvailable: marketAvailable.String(), + UserMarketFreeze: marketFreeze.String(), + UserMarketProfitAndLoss: marketProfitAndLoss.String(), + UserMarketTotalFee: marketTotalFee.String(), + UserMarketFloatingPL: marketFloatingPL.String(), + } + _, ok := u.symbol.Load(psgMsg.Symbol) + if ok { + orderStr, err := json.Marshal(orderModel) + if err != nil { + applogger.Error("User market Second stock subscription cache order error:%v", err) + time.Sleep(5 * time.Second) + continue + } + u.msg <- orderStr // 用户市场统计订阅 + } else { + applogger.Info("User market cancels subscription to Second stock orders.") + return + } + } + + time.Sleep(800 * time.Millisecond) + } +} diff --git a/internal/data/subscribe_forex.go b/internal/data/subscribe_forex.go new file mode 100644 index 0000000..d1aa2d0 --- /dev/null +++ b/internal/data/subscribe_forex.go @@ -0,0 +1,853 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/mq/consumer" + "matchmaking-system/internal/data/socket/forexData" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "strconv" + "sync" + "time" + + forexd "matchmaking-system/internal/data/tradedeal/forex" +) + +/* +外汇行情订阅 +1、初始化现货订阅信息 +2、接收用户现货下单的交易对 +3、根据交易对订阅现货行情数据 +4、写入内存中用于并发计算 +5、记录在热缓存中 +*/ + +// QuitesForex +// @Description: +type QuitesForex struct { + Ev string `json:"ev"` // 事件类型 + P string `json:"p"` // 交易对 + A float64 `json:"a"` // 买价 + X int `json:"x"` // 交易所标识符 + B float64 `json:"b"` // 卖价 + T int64 `json:"t"` // 时间 +} +type ForexJsonData struct { + Event string `json:"ev"` // 事件类型(实时数据) + Pair string `json:"pair"` // 货币对 + Open float64 `json:"o"` // 开盘价 + Close float64 `json:"c"` // 收盘价 + High float64 `json:"h"` // 最高价 + Low float64 `json:"l"` // 最低价 + Volume int `json:"v"` // 交易量 + Timestamp int64 `json:"s"` // 时间戳 +} + +// ForexSymbol +// @Description: +type ForexSymbol struct { + ForexMap chan []byte // 外汇订单交易对 -- 用户外汇下单通知订阅 + ForexMapSymbol sync.Map // 外汇订阅交易对簿 +} + +// InitCacheSymbolForex +// +// @Description: +// @param ctx +// @param uo +func InitCacheSymbolForex(ctx context.Context, uo *Data) { + contractList, err := GetBotForexList(ctx, uo) + if err != nil { + return + } + + for _, value := range contractList { + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := uo.redisDB.HExists(context.Background(), setting.MarketForex, value).Result() + if err != nil { + applogger.Error("%v InitCacheSymbolSpots.MarketForex.HExists:%v", common.ErrForex, err) + return + } + applogger.Info("初始化外汇交易对:%v", value) + + if !checkBool { + if err = uo.redisDB.HSet(context.Background(), setting.MarketForex, value, value).Err(); err != nil { + applogger.Error("%v InitCacheSymbolSpots.HSet:%v", common.ErrForex, err) + return + } + } + } +} + +// InitSubscribeQuotesForex +// +// @Description: +// @param ctx +// @param uo +// @param contract +func InitSubscribeQuotesForex(contract *ForexSymbol) { + for { + listSpots, err := LoadLRangeList(setting.MarketForex) + if err != nil { + applogger.Error("%v InitSubscribeQuotesForex.LoadLRangeList:%v", common.ErrForex, err) + return + } + + for _, value := range listSpots { + // Prevent duplicate subscription to CtrIp + _, ok := contract.ForexMapSymbol.Load(value) + if ok { + continue + } + + contract.ForexMap <- []byte(value) + } + + time.Sleep(10 * time.Second) + } +} + +// SubscribeQuotesForex +// +// @Description: 外汇订阅 +// @param ctx +// @param uo +// @param contract +func SubscribeQuotesForex(ctx context.Context, uo *Data, forex *ForexSymbol) { + for { + select { + case symbol, _ := <-forex.ForexMap: + symbolStr := string(symbol) + + // Prevent duplicate subscription to CtrIp + _, ok := forex.ForexMapSymbol.Load(symbolStr) + if ok { + time.Sleep(5 * time.Second) + continue + } + + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := uo.redisDB.HExists(context.Background(), setting.MarketForex, symbolStr).Result() + if err != nil { + applogger.Error("%v SubscribeQuotesForex.MarketForex.HExists:%v", common.ErrForex, err) + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err = uo.redisDB.HSet(context.Background(), setting.MarketForex, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeQuotesForex.MarketForex.HSet:%v", common.ErrForex, err) + time.Sleep(5 * time.Second) + continue + } + } + + // 订阅买一卖一报价 + go func() { + topIc := fmt.Sprintf("%v.LastForex", symbolStr) + pubSub := uo.redisDB.Subscribe(ctx, topIc) + defer pubSub.Close() + if _, err = pubSub.Receive(ctx); err != nil { + applogger.Error("%v SubscribeQuotesForex.Receive:%v", common.ErrForex, err) + return + } + chp := pubSub.Channel() + for msg := range chp { + var subMsg QuitesForex + if err = json.Unmarshal([]byte(msg.Payload), &subMsg); err != nil { + applogger.Error("%v SubscribeQuotesForex.QuitesForex.Unmarshal:%v", common.ErrForex, err) + close(forex.ForexMap) + return + } + // 交易类型:0最新价,1买入,2卖出 + askPriceKey := publicData.SymbolCache(flags.Wh, symbolStr, flags.TradeTypeBuy) + askPrice := strconv.FormatFloat(subMsg.A, 'g', -1, 64) + if err = memory.ForexCache.Set(askPriceKey, []byte(askPrice)); err != nil { + applogger.Error("%v askPriceKey Set:%v", common.ErrForex, err) + continue + } + bidPriceKey := publicData.SymbolCache(flags.Wh, symbolStr, flags.TradeTypeSell) + bidPrice := strconv.FormatFloat(subMsg.B, 'g', -1, 64) + if err = memory.ForexCache.Set(bidPriceKey, []byte(bidPrice)); err != nil { + applogger.Error("%v bidPriceKey Set:%v", common.ErrForex, err) + continue + } + if !flags.CheckSetting { + applogger.Info("当前写入外汇卖一买一最新报价:%v,%v,%v", symbolStr, askPrice, bidPrice) + } + } + }() + + // 订阅实时报价 + go func() { + topIc := fmt.Sprintf("%v.Forex", symbolStr) + pubSub := uo.redisDB.Subscribe(ctx, topIc) + defer pubSub.Close() + if _, err = pubSub.Receive(ctx); err != nil { + applogger.Error("%v SubscribeQuotesForex.Receive:%v", common.ErrForex, err) + return + } + chp := pubSub.Channel() + for msg := range chp { + var subMsg ForexJsonData + if err = json.Unmarshal([]byte(msg.Payload), &subMsg); err != nil { + applogger.Error("%v SubscribeQuotesForex.QuitesForex.Unmarshal:%v", common.ErrForex, err) + close(forex.ForexMap) + return + } + // 交易类型:0最新价,1买入,2卖出 + priceKey := publicData.SymbolCache(flags.Wh, symbolStr, flags.TradeTypePrice) + price := strconv.FormatFloat(subMsg.Close, 'g', -1, 64) + if err = memory.ForexImmediateCache.Set(priceKey, []byte(price)); err != nil { + applogger.Error("%v priceKey Set:%v", common.ErrForex, err) + continue + } + if !flags.CheckSetting { + applogger.Info("当前写入外汇即时最新报价:%v,%v,%v", symbolStr, priceKey, price) + } + } + }() + + // Write in the map to determine whether to repeat subscription + forex.ForexMapSymbol.Store(symbolStr, symbolStr) + } + } +} + +// OrderSubAdminForexSubscribeBySum +// +// @Description: 持仓订单浮动盈亏计算 +// @param ctx +// @param uo +func OrderSubAdminForexSubscribeBySum(uo *Data) { + for { + topIc := setting.AdminForexSubscribe + hashMap, err := uo.redisDB.HGetAll(context.Background(), topIc).Result() + if err != nil { + applogger.Error("orderSubAdminForexSubscribe.HGetAll:%v", err) + time.Sleep(5 * time.Second) + continue + } + var hashList []forexd.ForexTallyCache + for _, value := range hashMap { + var msg forexd.ForexTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + switch msg.Status { + case flags.Entrust: // 挂单 + case flags.Position: // 持仓 + hashList = append(hashList, msg) + default: // 平仓|撤单 + err = uo.redisDB.HDel(context.Background(), topIc, msg.OrderId).Err() + if err != nil { + applogger.Error("AdminForexSubscribe.HDel:%v", err) + continue + } + } + } + applogger.Info("外汇数据量统计:%v", len(hashList)) + // 统计外汇总持仓订单浮动盈亏 + priceSum := decimal.Zero + for _, value := range hashList { + orderModel := forexData.ForexOrderProcessing(topIc, value) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch value.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + orderNumber := decimal.RequireFromString(value.Order.OrderNumber) + pryNum := decimal.RequireFromString(value.Order.PryNum) + price := subPrice.Mul(orderNumber).Mul(pryNum) // 外汇浮动盈亏计算 + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + // 写入缓存 + if err = memory.ForexFloating.Set(flags.FloatingWh, []byte(priceSum.String())); err != nil { + applogger.Error("统计外汇持仓订单浮动盈亏错误:%v", err) + time.Sleep(5 * time.Second) + continue + } + applogger.Info("统计外汇持仓订单浮动盈亏:%v", priceSum) + + time.Sleep(600 * time.Millisecond) + } +} + +// ForexTransactionEntrust +// +// @Description: 外汇委托订单 +// @param ctx +func ForexTransactionEntrust(ctx context.Context) { + for { + ForexTransactionCalculationEntrust(ctx) + time.Sleep(400 * time.Millisecond) + } +} + +// ForexTransactionCalculationEntrust +// +// @Description: +// @param ctx +func ForexTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + entrustList, err := Reds.HGetAll(context.Background(), setting.MarketForexEntrust).Result() + if err != nil { + applogger.Error("%v ForexTransactionCalculationEntrust.HGetAll:%v", common.ErrForex, err) + return + } + + for _, value := range entrustList { + var msg = make(chan forexd.ForexTallyCache, 1) + var entrust forexd.ForexTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ForexTransactionCalculationEntrust.Unmarshal:%v", common.ErrForex, err) + continue + } + + var newPrice decimal.Decimal + newPrice, err = GetForexPrice(entrust.Symbol, entrust.Order.TradeType) + if err != nil { + applogger.Error("%v ForexTransactionCalculationPosition.GetForexPrice:%v", common.ErrForex, err) + continue + } + + wg.Add(1) + go func(value string) { + resultMsg := ForexConcurrentComputingEntrust(&entrust, newPrice, &wg) + msg <- resultMsg // 通知管道异步处理订单操作 + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Info("从信道接收外汇挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Info("从信道接收到外汇持仓信息:%v", resultMsg) + } + + // 处理开仓逻辑 + if err = ForexLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ForexTransactionCalculationEntrust.ForexLiquidationEntrust:%v", common.ErrForex, err) + continue + } + // 写入持仓缓存列表 + data, err := json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v ForexTransactionCalculationEntrust.Marshal:%v", common.ErrForex, err) + continue + } + + // TODO: 写入持仓消息列表 + //if err = uo.mqProducer.Entrust.PushNotice(data); err != nil { + // applogger.Error("%v ForexTransactionCalculationEntrust.PushNotice:%v", common.ForexError, err) + // continue + //} + + // 写入外汇持仓缓存队列 + if err = Reds.HSet(context.Background(), setting.MarketForexPosition, resultMsg.OrderId, string(data)).Err(); err != nil { + applogger.Error("%v ForexTransactionCalculationEntrust.MarketForexPosition.HSet:%v", common.ErrForex, err) + continue + } + } + } + } + + wg.Wait() + applogger.Info("外汇挂单并发计算执行完毕......") +} + +// ForexConcurrentComputingEntrust +// +// @Description: 外汇挂单缓存列表业务处理 +// @param order +// @param orderOld +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ForexTallyCache +func ForexConcurrentComputingEntrust(order *forexd.ForexTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) forexd.ForexTallyCache { + var deleteCache bool + var dealPrice string + var limitPrice = decimal.RequireFromString(order.Order.LimitPrice) // 限价-价格 + var status = order.Status // 原始价格 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Info("用户ID:%v,限价买入下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + // 限价买入逻辑判定 -> 挂单金额 > 当前价格 + if limitPrice.Cmp(newPrice) > 0 { + deleteCache = true + dealPrice = limitPrice.String() // 开仓价格 + } + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Info("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + // 限价卖入逻辑判定 -> 挂单金额 < 当前价格 + if limitPrice.Cmp(newPrice) < 0 { + deleteCache = true + dealPrice = limitPrice.String() // 开仓价格 + } + default: + } + + if deleteCache { + order.Status = flags.Position + // 删除挂单缓存列表 + if err := Reds.HDel(context.Background(), setting.MarketForexEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ForexConcurrentComputingEntrust.MarketForexEntrust.HDel:%v", common.ErrForex, err) + order.Status = status + dealPrice = decimal.Zero.String() + } + } + + wg.Done() + return forexd.ForexTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + } +} + +// ForexMqOpenBusiness +// +// @Description: TODO: 外汇持仓消息队列 +// @param ctx +// @param uo +func ForexMqOpenBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Entrust.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerEntrustMq.ForexMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ForexMqOpenBusiness.ForexMq err....", common.ErrForex) + continue + } + + // 持仓订单缓存数据序列化解析 + var resultMsg forexd.ForexTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ForexMqOpenBusiness.Unmarshal:%v", common.ErrForex, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ForexLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ForexMqOpenBusiness.ForexLiquidationEntrust:%v", common.ErrForex, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + applogger.Error("这里没有监控到持仓mq队列消息.........") + time.Sleep(2 * time.Second) + } + } +} + +// ForexLiquidationEntrust +// +// @Description: 外汇挂单-->开仓业务处理 +// @param ctx +// @param order +// @return error +func ForexLiquidationEntrust(ctx context.Context, order *forexd.ForexTallyCache) error { + // 1、外汇开仓操作 + err := ForexOpenPosition(ctx, Msql, order.UserId, order.OrderId, order.OpenPrice, order.Order) + if err != nil { + applogger.Error("%v ForexLiquidationEntrust.ForexOpenPosition:%v", common.ErrForex, err) + return err + } + + // 2、开仓更新用户外汇订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(setting.ForexSubscribe, order.UserId) + if err = UpdateForexSubscribeHashStatusByOrderId(order.OrderId, userSubKey, flags.Position, order.ClosingPrice); err != nil { + applogger.Error("%v ForexLiquidationEntrust.ForexSubscribe:%v", common.ErrForex, err) + return err + } + + // 3、开仓更新管理员外汇订阅缓存订单状态 + if err = UpdateForexSubscribeHashStatusByOrderId(order.OrderId, setting.AdminForexSubscribe, flags.Position, order.ClosingPrice); err != nil { + applogger.Error("%v ForexLiquidationEntrust.AdminForexSubscribe:%v", common.ErrForex, err) + return err + } + + return nil +} + +// ForexTransactionPosition +// +// @Description: 外汇-持仓业务处理 +// @param ctx +func ForexTransactionPosition(ctx context.Context) { + for { + ForexTransactionCalculationPosition(ctx) + time.Sleep(400 * time.Millisecond) + } +} + +// ForexTransactionCalculationPosition +// +// @Description: 监控外汇持仓缓存列表(注意:止盈止损|强行平仓) +// @param ctx +func ForexTransactionCalculationPosition(ctx context.Context) { + var wg sync.WaitGroup + + entrustList, err := Reds.HGetAll(context.Background(), setting.MarketForexPosition).Result() + if err != nil { + applogger.Error("%v ForexTransactionCalculationPosition.LRange:%v", common.ErrForex, err) + return + } + + for _, value := range entrustList { + var msg = make(chan forexd.ForexTallyCache, 1) + var entrust forexd.ForexTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ForexTransactionCalculationPosition.Unmarshal:%v", common.ErrForex, err) + continue + } + + var newPrice decimal.Decimal + newPrice, err = GetForexPriceNew(entrust.Symbol, entrust.Order.TradeType) + if err != nil { + applogger.Warn("%v ForexTransactionCalculationPosition.GetForexPrice:%v", common.ErrForex, err) + continue + } + + wg.Add(1) + go func(value string) { + resultMsg := ForexConcurrentComputingPosition(&entrust, newPrice, &wg) + msg <- resultMsg + }(value) + + // 处理并发结果 + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Position: // 持仓 + if !flags.CheckSetting { + applogger.Info("从信道接收到外汇持仓信息:%v", resultMsg) + } + case flags.Close: // 平仓 + if !flags.CheckSetting { + applogger.Info("从信道接收到外汇平仓信息:%v", resultMsg) + } + + // TODO: 平仓操作(优化写入队列中等待平仓) + //var byteStr []byte + //byteStr, err = json.Marshal(resultMsg) + //if err != nil { + // applogger.Error("%v ForexTransactionCalculationPosition.Marshal:%v", common.ForexError, err) + // continue + //} + //if err = uo.mqProducer.Position.PushNotice(byteStr); err != nil { + // applogger.Error("%v ForexTransactionCalculationPosition.PushNotice:%v", common.ForexError, err) + // continue + //} + + if err = ForexLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ForexTransactionCalculationPosition.ForexLiquidationPosition:%v", common.ErrForex, err) + continue + } + } + } + } + + wg.Wait() + applogger.Info("外汇持仓并发计算执行完毕......") +} + +// ForexConcurrentComputingPosition +// +// @Description: 外汇持仓缓存列表业务处理 +// @param order +// @param newPrice +// @param wg +// @return tradedeal.ForexTallyCache +func ForexConcurrentComputingPosition(order *forexd.ForexTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) forexd.ForexTallyCache { + var deleteCache, checkBool bool + var dealPrice string + var sellShort decimal.Decimal + var openPrice = decimal.RequireFromString(order.OpenPrice) // 限价 + var orderNumber = decimal.RequireFromString(order.Order.OrderNumber) // 仓位 + var status = order.Status // 原始状态 + var pryNum = decimal.RequireFromString(order.Order.PryNum) // 杠杆 + + // 下单判定设置(false无设置|true止盈止损) + _, stopWinPrice, stopLossPrice, _ := ForexVoteStopType(order.Order) + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨(强平) + if !flags.CheckSetting { + applogger.Info("用户ID:%v,持仓开仓价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买涨挂止损止盈,止盈价必须<当前价,止损价必须>当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) < 0 { + checkBool = true + dealPrice = newPrice.String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) > 0 { + checkBool = true + dealPrice = newPrice.String() // 平仓价格 + } + } + // 强行平仓(做多) + if !checkBool { + sellShort = newPrice.Sub(openPrice).Mul(orderNumber).Mul(order.Order.System.FaceValue).Mul(pryNum) + } + case flags.TradeTypeSell: // 买跌(存在强行平仓) + if !flags.CheckSetting { + applogger.Info("用户ID:%v,限价持仓买跌下单价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买跌挂止损止盈,止盈价必须>当前价,止损价必须<当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) > 0 { + checkBool = true + dealPrice = newPrice.String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) < 0 { + checkBool = true + dealPrice = newPrice.String() // 平仓价格 + } + } + // 强行平仓(做空) + if !checkBool { + sellShort = openPrice.Sub(newPrice).Mul(orderNumber).Mul(order.Order.System.FaceValue).Mul(pryNum) + } + default: + } + /* 强行平仓(做多|做空) + 1、做多:(最新成交价-开仓成交价)*仓位 + 1、做空:(开仓成交价-最新成交价)*仓位 + 2、当浮动盈亏 >= 保证金的70%订单强行平仓 + */ + if sellShort.IsNegative() { + orderAmount := decimal.RequireFromString(order.Order.EarnestMoney) + floatPrice := orderAmount.Mul(order.Order.System.CompelNum) + if !flags.CheckSetting { + applogger.Info("强平保证金:%v,强平浮动70%:%v,强行平仓判定:%v", orderAmount, floatPrice, sellShort.Abs().Cmp(floatPrice)) + } + if sellShort.Abs().Cmp(floatPrice) >= 0 { + checkBool = true + dealPrice = newPrice.String() + } + } + // 判定订单状态 + if checkBool { + deleteCache = true + order.Status = flags.Close + } + + if deleteCache { + // 删除持仓缓存列表数据 + if err := Reds.HDel(context.Background(), setting.MarketForexPosition, order.OrderId).Err(); err != nil { + applogger.Error("%v ForexConcurrentComputingPosition.MarketForexPosition.HDel:%v", common.ErrForex, err) + order.Status = status + } + } + + wg.Done() + return forexd.ForexTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + ClosingPrice: dealPrice, // 平仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + } +} + +// ForexMqClosingBusiness +// +// @Description: TODO: 处理外汇平仓消息队列 +// @param ctx +// @param uo +func ForexMqClosingBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Position.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerPositionMq.ForexMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ForexMqClosingBusiness.ForexMq err....", common.ErrForex) + continue + } + applogger.Info("接收到平仓信息:%v", string(message)) + + // 持仓订单缓存数据序列化解析 + var resultMsg forexd.ForexTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ForexMqClosingBusiness.Unmarshal:%v", common.ErrForex, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ForexLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ForexMqClosingBusiness.ForexLiquidationPosition:%v", common.ErrForex, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + time.Sleep(2 * time.Second) + } + } +} + +// ForexLiquidationPosition +// +// @Description: 外汇平仓操作 +// @param ctx +// @param order +// @return error +func ForexLiquidationPosition(ctx context.Context, order *forexd.ForexTallyCache) error { + // 1、平仓操作 + err := ForexClosingPosition(ctx, Msql, order.OrderId, order.ClosingPrice, order.Order) + if err != nil { + applogger.Error("%v ForexLiquidationPosition.ForexClosingPosition:%v", common.ErrForex, err) + return err + } + + // 2、平仓更新用户外汇订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ForexSubscribe, order.UserId) + if err = UpdateForexSubscribeHashStatusByOrderId(order.OrderId, userSubKey, flags.Close, order.ClosingPrice); err != nil { + applogger.Error("%v ForexLiquidationPosition.ForexSubscribe:%v", common.ErrForex, err) + return err + } + + // 3、平仓更新管理员外汇订阅订单状态 + if err = UpdateForexSubscribeHashStatusByOrderId(order.OrderId, setting.AdminForexSubscribe, flags.Close, order.ClosingPrice); err != nil { + applogger.Error("%v ForexLiquidationPosition.AdminForexSubscribe:%v", common.ErrForex, err) + return err + } + + return nil +} + +// ForexVoteStopType +// +// @Description: 设置外汇止盈止损 +// @param order +// @return bool +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func ForexVoteStopType(order structure.ForexOrder) (bool, decimal.Decimal, decimal.Decimal, error) { + var checkBool bool + var stopWinPrice, stopLossPrice decimal.Decimal + switch order.StopType { + case flags.StopTypeNone: // 暂无设置止盈止损 + checkBool = false + case flags.StopTypeSet: // 设置止盈止损 + checkBool = true + if len(order.StopWinPrice) != 0 { + stopWinPrice = decimal.RequireFromString(order.StopWinPrice) + } + if len(order.StopLossPrice) != 0 { + stopLossPrice = decimal.RequireFromString(order.StopLossPrice) + } + default: + return checkBool, stopWinPrice, stopLossPrice, flags.ErrContractThirteen + } + + return checkBool, stopWinPrice, stopLossPrice, nil +} + +// GetForexPrice +// +// @Description: 外汇交易对卖一买一最新报价 +// @param symbol +// @return decimal.Decimal +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func GetForexPrice(symbol string, tradeType int64) (decimal.Decimal, error) { + var err error + var newPrice []byte + var cacheKey string + + switch tradeType { + case 1: // 外汇交易对买一最新报价 + cacheKey = publicData.SymbolCache(flags.Wh, symbol, flags.TradeTypeBuy) + newPrice, err = memory.GetForexCache(cacheKey) + case 2: // 外汇交易对卖一最新报价 + cacheKey = publicData.SymbolCache(flags.Wh, symbol, flags.TradeTypeSell) + newPrice, err = memory.GetForexCache(cacheKey) + } + if err != nil { + applogger.Error("%v GetForexPrice.Get:%v", common.ErrForex, err) + return decimal.Decimal{}, err + } + + priceList, err := decimal.NewFromString(string(newPrice)) + if err != nil { + applogger.Error("%v ForexTransactionCalculationPosition.Get:%v", common.ErrForex, err) + return decimal.Decimal{}, err + } + + applogger.Info("ForexCode:%v,topIc:%v,ForexPrice:%v", symbol, cacheKey, priceList) + + return priceList, nil +} +func GetForexPriceNew(symbol string, tradeType int64) (decimal.Decimal, error) { + cacheKey := SymbolCache(flags.Wh, symbol, flags.TradeTypePrice) + priceNew, err := memory.GetForexImmediateCache(cacheKey) + if err != nil { + return decimal.Decimal{}, err + } + + priceList, err := decimal.NewFromString(string(priceNew)) + if err != nil { + applogger.Error("%v ForexTransactionCalculationPosition.Get:%v", common.ErrForex, err) + return decimal.Decimal{}, err + } + + applogger.Info("ForexCode:%v,topIc:%v,ForexPrice:%v", symbol, cacheKey, priceList) + + return priceList, nil +} diff --git a/internal/data/subscribe_money.go b/internal/data/subscribe_money.go new file mode 100644 index 0000000..9b876a5 --- /dev/null +++ b/internal/data/subscribe_money.go @@ -0,0 +1,1143 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/socket/moneyData" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/money" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "regexp" + "strconv" + "strings" + "sync" + "time" +) + +/* +综合(现货|合约|外汇)行情订阅 +1、初始化订阅信息 +2、接收用户下单的交易对 +3、根据交易对订阅行情数据 +4、写入内存中用于并发计算 +5、记录在热缓存中 +*/ + +// QuitesMoneyJsonStruct +// @Description: 现货|合约|外汇 +type QuitesMoneySpots struct { + ServersID string `json:"serversId"` + Content struct { + Ch string `json:"ch"` + Ts int64 `json:"ts"` + Tick struct { + Open string `json:"open"` + High string `json:"high"` + Low string `json:"low"` + Close string `json:"close"` + Amount string `json:"amount"` + Count int `json:"count"` + Bid string `json:"bid"` + BidSize string `json:"bidSize"` + Ask string `json:"ask"` + AskSize string `json:"askSize"` + LastPrice string `json:"lastPrice"` + LastSize string `json:"lastSize"` + } `json:"Tick"` + Data any `json:"Data"` + } `json:"content"` + Symbol string `json:"symbol"` +} +type QuitesMoneyContract struct { + ServersID string `json:"serversId"` + Content struct { + Ch string `json:"ch"` + Ts int64 `json:"ts"` + Tick struct { + ID int `json:"id"` + Mrid int64 `json:"mrid"` + Open string `json:"open"` + Close string `json:"close"` + High string `json:"high"` + Low string `json:"low"` + Amount string `json:"amount"` + Vol string `json:"vol"` + TradeTurnover string `json:"trade_turnover"` + Count int `json:"count"` + Asks any `json:"asks"` + Bids any `json:"bids"` + } `json:"Tick"` + } `json:"content"` + Symbol string `json:"symbol"` +} +type MoneyContractSetUp struct { + SelfContractCode string `json:"selfContractCode"` // 合约交易对 + BeginTime string `json:"BeginTime"` // 开始时间 + Step int `json:"Step"` // 设置时间间隔 + EndTime string `json:"EndTime"` // 结束时间 + Price string `json:"Price"` // 设置价格 +} +type QuitesMoneyForex struct { + Ev string `json:"ev"` // 事件类型 + P string `json:"p"` // 交易对 + A float64 `json:"a"` // 买价 + X int `json:"x"` // 交易所标识符 + B float64 `json:"b"` // 卖价 + T int64 `json:"t"` // 时间 +} +type MoneyForexJsonData struct { + Event string `json:"ev"` // 事件类型(实时数据) + Pair string `json:"pair"` // 货币对 + Open float64 `json:"o"` // 开盘价 + Close float64 `json:"c"` // 收盘价 + High float64 `json:"h"` // 最高价 + Low float64 `json:"l"` // 最低价 + Volume int `json:"v"` // 交易量 + Timestamp int64 `json:"s"` // 时间戳 +} + +// MoneySymbol +// @Description: 综合-(现货|合约|外汇)订阅交易簿 +type MoneySymbol struct { + MoneySpotsMap chan []byte // 现货订单交易对 -- 用户现货下单通知订阅 + MoneySpotsMapSymbol sync.Map // 现货订阅交易对簿 + MoneyContractMap chan []byte // 合约订单交易对 -- 用户合约下单通知订阅 + MoneyContractMapSymbol sync.Map // 合约订阅交易对簿 + MoneyForexMap chan []byte // 外汇订单交易对 -- 用户外汇下单通知订阅 + MoneyForexMapSymbol sync.Map // 外汇订阅交易对簿 +} + +// JsonData +// @Description: 综合-(现货|合约|外汇)用户总资产 +type JsonData struct { + UserId int64 `json:"user_id"` + TotalAmount string `json:"total_amount"` +} + +// 综合-(现货|合约|外汇)下单交易对订阅 +func InitSubscribeQuotesMoneySpots(sp *MoneySymbol) { + for { + listSpots, err := LoadLRangeList(setting.MarketSpots) + if err != nil { + applogger.Error("%v InitSubscribeQuotesMoneySpots.LoadLRangeList:%v", common.ErrMoney, err) + return + } + for _, value := range listSpots { + _, ok := sp.MoneySpotsMapSymbol.Load(value) + if ok { + continue + } + sp.MoneySpotsMap <- []byte(value) + } + time.Sleep(10 * time.Second) + } +} +func InitSubscribeQuotesMoneyContract(ct *MoneySymbol) { + for { + listContract, err := LoadLRangeList(setting.MarketContract) + if err != nil { + applogger.Error("%v InitSubscribeQuotesMoneyContract.LoadLRangeList:%v", common.ErrMoney, err) + return + } + for _, value := range listContract { + usdtToUsd := strings.Replace(value, "USDT", "USD", -1) + _, ok := ct.MoneyContractMapSymbol.Load(usdtToUsd) + if ok { + continue + } + ct.MoneyContractMap <- []byte(usdtToUsd) + } + time.Sleep(10 * time.Second) + } +} +func InitSubscribeQuotesMoneyForex(mf *MoneySymbol) { + for { + listForex, err := LoadLRangeList(setting.MarketForex) + if err != nil { + applogger.Error("%v InitSubscribeQuotesMoneyForex.LoadLRangeList:%v", common.ErrMoney, err) + return + } + re := regexp.MustCompile(`USD$`) + for _, value := range listForex { + if !re.MatchString(value) { + continue + } + _, ok := mf.MoneyForexMapSymbol.Load(value) + if ok { + continue + } + mf.MoneyForexMap <- []byte(value) + } + time.Sleep(10 * time.Second) + } +} + +// 综合-(现货|合约|外汇)交易对行情订阅 +func SubscribeQuotesMoneySpots(ctx context.Context, uo *Data, ms *MoneySymbol) { + for { + select { + case symbol, _ := <-ms.MoneySpotsMap: + symbolStr := string(symbol) + + // Prevent duplicate subscription to CtrIp + _, ok := ms.MoneySpotsMapSymbol.Load(symbolStr) + if ok { + time.Sleep(5 * time.Second) + continue + } + + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := uo.redisDB.HExists(context.Background(), setting.MarketSpots, symbolStr).Result() + if err != nil { + applogger.Error("%v SubscribeQuotesMoneySpots.MarketSpots.HExists:%v", common.ErrMoney, err) + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err = uo.redisDB.HSet(context.Background(), setting.MarketSpots, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeQuotesMoneySpots.HSet:%v", common.ErrMoney, err) + time.Sleep(5 * time.Second) + continue + } + } + + go func() { + topIc := fmt.Sprintf("market.%vusdt.ticker", symbolStr) + pubSub := uo.redisDB.Subscribe(ctx, topIc) + defer pubSub.Close() + if _, err = pubSub.Receive(ctx); err != nil { + applogger.Error("%v SubscribeQuotesMoneySpots.Receive:%v", common.ErrMoney, err) + return + } + ch := pubSub.Channel() + for msg := range ch { + var subMsg QuitesMoneySpots + if err = json.Unmarshal([]byte(msg.Payload), &subMsg); err != nil { + applogger.Error("%v SubscribeQuotesMoneySpots.Unmarshal:%v", common.ErrMoney, err) + close(ms.MoneySpotsMap) + return + } + // 交易类型:0最新价,1买入,2卖出 xh-symbol-0 + var keyPrice string + if flags.CheckEnvironment == flags.CheckAdmin { + keyPrice = publicData.SymbolCache(flags.Xh, symbolStr, flags.TradeTypeAdminPrice) + } else { + keyPrice = publicData.SymbolCache(flags.Xh, symbolStr, flags.TradeTypePrice) + } + if err = memory.MoneySpotsCache.Set(keyPrice, []byte(subMsg.Content.Tick.Close)); err != nil { + applogger.Error("%v SubscribeQuotesMoneySpots.Set.price:%v", common.ErrMoney, err) + return + } + if !flags.CheckSetting { + applogger.Info("当前写入最新价格:%v,%v", keyPrice, subMsg.Content.Tick.Close) + } + } + }() + + // Write in the map to determine whether to repeat subscription + ms.MoneySpotsMapSymbol.Store(symbolStr, symbolStr) + } + } +} +func SubscribeQuotesMoneyContract(ctx context.Context, uo *Data, ms *MoneySymbol) { + for { + select { + case symbol, _ := <-ms.MoneyContractMap: + symbolStr := string(symbol) + usdToUsdt := strings.Replace(symbolStr, "USD", "USDT", -1) + + // Prevent duplicate subscription to CtrIp + _, ok := ms.MoneyContractMapSymbol.Load(symbolStr) + if ok { + time.Sleep(5 * time.Second) + continue + } + + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := uo.redisDB.HExists(context.Background(), setting.MarketContract, symbolStr).Result() + if err != nil { + applogger.Error("%v SubscribeQuotesMoneyContract.MarketContract.HExists:%v", common.ErrMoney, err) + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err = uo.redisDB.HSet(context.Background(), setting.MarketContract, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeQuotesMoneyContract.MarketContract.HSet:%v", common.ErrMoney, err) + time.Sleep(5 * time.Second) + continue + } + } + + // 订阅插针价格 + go func() { + for { + var data string + data, err = uo.redisDB.Get(context.Background(), flags.ContractSystemPriceSetUp).Result() + if err != nil || data == "[]" { + time.Sleep(5 * time.Second) + continue + } + var dataList []MoneyContractSetUp + if err = json.Unmarshal([]byte(data), &dataList); err != nil { + time.Sleep(5 * time.Second) + continue + } + for _, value := range dataList { + checkStart := len(utils.StrReplace(value.BeginTime)) + checkEnd := len(utils.StrReplace(value.EndTime)) + if checkStart == 0 || checkEnd == 0 { + continue + } + if value.SelfContractCode == symbolStr { + // Determine if it is the current subscription type + var keyPrice string + if flags.CheckEnvironment == flags.CheckAdmin { + keyPrice = publicData.SymbolCache(flags.Hy, symbolStr, flags.TradeTypeAdminPrice) + } else { + keyPrice = publicData.SymbolCache(flags.Hy, symbolStr, flags.TradeTypePrice) + } + if !utils.CheckTimeUTC(value.BeginTime, value.EndTime) { + continue + } + if err = memory.MoneyContractPriceSetUp.Set(keyPrice, []byte(utils.DecimalsPrice(value.Price))); err != nil { + applogger.Error("%v SubscribeQuotesMoneyContract.MoneyContractPriceSetUp.set:%v", common.ErrMoney, err) + continue + } + if !flags.CheckSetting { + applogger.Info("当前写入插针最新价格:%v,%v", keyPrice, value.Price) + } + } + } + time.Sleep(2 * time.Second) + } + }() + + // 订阅实时价格 + go func() { + topIc := fmt.Sprintf("market.%v.detail", usdToUsdt) + pubSub := uo.redisDB.Subscribe(ctx, topIc) + defer pubSub.Close() + if _, err = pubSub.Receive(ctx); err != nil { + applogger.Error("%v SubscribeQuotesMoneyContract.Receive:%v", common.ErrMoney, err) + return + } + chp := pubSub.Channel() + for msg := range chp { + var subMsg QuitesMoneyContract + if err = json.Unmarshal([]byte(msg.Payload), &subMsg); err != nil { + applogger.Error("%v SubscribeQuotesMoneyContract.QuitesMoneyContract.Unmarshal:%v", common.ErrMoney, err) + close(ms.MoneyContractMap) + return + } + // 交易类型:0最新价,1买入,2卖出 + var keyPrice string + if flags.CheckEnvironment == flags.CheckAdmin { + keyPrice = publicData.SymbolCache(flags.Hy, symbolStr, flags.TradeTypeAdminPrice) + } else { + keyPrice = publicData.SymbolCache(flags.Hy, symbolStr, flags.TradeTypePrice) + } + if err = memory.MoneyContractCache.Set(keyPrice, []byte(subMsg.Content.Tick.Close)); err != nil { + applogger.Error("%v SubscribeQuotesMoneyContract.Set:%v", common.ErrMoney, err) + continue + } + if !flags.CheckSetting { + applogger.Info("当前写入最新价格:%v,%v", keyPrice, subMsg.Content.Tick.Close) + } + } + }() + // Write in the map to determine whether to repeat subscription + ms.MoneyContractMapSymbol.Store(symbolStr, symbolStr) + } + } +} +func SubscribeQuotesMoneyForex(ctx context.Context, uo *Data, ms *MoneySymbol) { + for { + select { + case symbol, _ := <-ms.MoneyForexMap: + symbolStr := string(symbol) + + // Prevent duplicate subscription to CtrIp + _, ok := ms.MoneyForexMapSymbol.Load(symbolStr) + if ok { + time.Sleep(5 * time.Second) + continue + } + + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := uo.redisDB.HExists(context.Background(), setting.MarketForex, symbolStr).Result() + if err != nil { + applogger.Error("%v SubscribeQuotesMoney.MarketMoney.HExists:%v", common.ErrMoney, err) + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err = uo.redisDB.HSet(context.Background(), setting.MarketForex, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeQuotesMoney.MarketMoney.HSet:%v", common.ErrMoney, err) + time.Sleep(5 * time.Second) + continue + } + } + + // 订阅实时报价 + go func() { + topIc := fmt.Sprintf("%v.Forex", symbolStr) + pubSub := uo.redisDB.Subscribe(ctx, topIc) + defer pubSub.Close() + if _, err = pubSub.Receive(ctx); err != nil { + applogger.Error("%v SubscribeQuotesMoney.Receive:%v", common.ErrMoney, err) + return + } + chp := pubSub.Channel() + for msg := range chp { + var subMsg MoneyForexJsonData + if err = json.Unmarshal([]byte(msg.Payload), &subMsg); err != nil { + applogger.Error("%v SubscribeQuotesMoney.QuitesMoney.Unmarshal:%v", common.ErrMoney, err) + close(ms.MoneyForexMap) + return + } + // 交易类型:0最新价,1买入,2卖出 + var keyPrice string + if flags.CheckEnvironment == flags.CheckAdmin { + keyPrice = publicData.SymbolCache(flags.Wh, symbolStr, flags.TradeTypeAdminPrice) + } else { + keyPrice = publicData.SymbolCache(flags.Wh, symbolStr, flags.TradeTypePrice) + } + price := strconv.FormatFloat(subMsg.Close, 'g', -1, 64) + if err = memory.MoneyForexImmediateCache.Set(keyPrice, []byte(price)); err != nil { + applogger.Error("%v priceKey Set:%v", common.ErrMoney, err) + continue + } + if !flags.CheckSetting { + applogger.Info("当前写入外汇即时最新报价:%v,%v,%v", symbolStr, keyPrice, price) + } + } + }() + + // Write in the map to determine whether to repeat subscription + ms.MoneyForexMapSymbol.Store(symbolStr, symbolStr) + } + } +} + +// OrderSubAdminMoneySubscribeBySum +// +// @Description: 综合-(现货|合约|外汇)持仓订单浮动盈亏计算 +// @param ctx +// @param uo +func OrderSubAdminMoneySubscribeBySum(uo *Data) { + for { + topIc := setting.AdminMoneySubscribe + hashMap, err := uo.redisDB.HGetAll(context.Background(), topIc).Result() + if err != nil { + applogger.Error("orderSubAdminMoneySubscribe.HGetAll:%v", err) + time.Sleep(5 * time.Second) + continue + } + var hashList []money.MoneyTallyCache + for _, value := range hashMap { + var msg money.MoneyTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + switch msg.Status { + case flags.Entrust: // 挂单 + case flags.Position: // 持仓 + hashList = append(hashList, msg) + default: // 平仓|撤单 + err = uo.redisDB.HDel(context.Background(), topIc, msg.OrderId).Err() + if err != nil { + applogger.Error("AdminMoneySubscribe.HDel:%v", err) + continue + } + } + } + applogger.Info("综合(现货|合约|外汇)数据量统计:%v", len(hashList)) + // 统计外汇总持仓订单浮动盈亏 + priceSum := decimal.Zero + for _, value := range hashList { + orderModel := moneyData.MoneyOrderProcessing(topIc, value) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch value.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + orderNumber := decimal.RequireFromString(value.Order.OrderNumber) + pryNum := decimal.RequireFromString(value.Order.PryNum) + price := subPrice.Mul(orderNumber).Mul(pryNum) // 外汇浮动盈亏计算 + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + // 写入缓存 + if err = memory.MoneyTotalFloating.Set(flags.FloatingZh, []byte(priceSum.String())); err != nil { + applogger.Error("统计(现货|合约|外汇)持仓订单浮动盈亏错误:%v", err) + time.Sleep(5 * time.Second) + continue + } + applogger.Info("统计(现货|合约|外汇)持仓订单浮动盈亏:%v", priceSum) + + time.Sleep(600 * time.Millisecond) + } +} + +// MoneyTransactionEntrust +// +// @Description: 综合-(现货|合约|外汇)委托订单 +// @param ctx +func MoneyTransactionEntrust(ctx context.Context) { + for { + MoneyTransactionCalculationEntrust(ctx) + time.Sleep(400 * time.Millisecond) + } +} + +// MoneyTransactionCalculationEntrust +// +// @Description: +// @param ctx +func MoneyTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + entrustList, err := Reds.HGetAll(context.Background(), setting.MarketMoneyEntrust).Result() + if err != nil { + applogger.Error("%v MoneyTransactionCalculationEntrust.HGetAll:%v", common.ErrMoney, err) + return + } + + for _, value := range entrustList { + var msg = make(chan money.MoneyTallyCache, 1) + var entrust money.MoneyTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v MoneyTransactionCalculationEntrust.Unmarshal:%v", common.ErrMoney, err) + continue + } + + // 不同市场的即时价格 + var newPrice decimal.Decimal + switch entrust.Order.Type { + case flags.SpotsMarketType: // 现货 + newPrice, err = GetMoneySpotsPrice(entrust.Symbol) + if err != nil { + applogger.Error("%v MoneyTransactionCalculationPosition.GetMoneySpotsPrice:%v", common.ErrMoney, err) + continue + } + case flags.ContractMarketType: // 合约 + newPrice, err = GetMoneyContractPrice(entrust.Symbol) + if err != nil { + applogger.Error("%v MoneyTransactionCalculationPosition.GetMoneyContractPrice:%v", common.ErrMoney, err) + continue + } + case flags.ForexMarketType: // 外汇 + newPrice, err = GetMoneyForexPriceNew(entrust.Symbol) + if err != nil { + applogger.Error("%v MoneyTransactionCalculationPosition.GetMoneyForexPriceNew:%v", common.ErrMoney, err) + continue + } + default: + continue + } + + wg.Add(1) + go func(value string) { + resultMsg := MoneyConcurrentComputingEntrust(&entrust, newPrice, &wg) + msg <- resultMsg + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Info("从信道接收综合(现货|合约|外汇)挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Info("从信道接收到综合(现货|合约|外汇)持仓信息:%v", resultMsg) + } + // 处理开仓逻辑 + if err = MoneyLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v MoneyTransactionCalculationEntrust.MoneyLiquidationEntrust:%v", common.ErrMoney, err) + continue + } + // 写入持仓缓存列表 + data, err := json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v MoneyTransactionCalculationEntrust.Marshal:%v", common.ErrMoney, err) + continue + } + // 写入外汇持仓缓存队列 + if err = Reds.HSet(context.Background(), setting.MarketMoneyPosition, resultMsg.OrderId, string(data)).Err(); err != nil { + applogger.Error("%v MoneyTransactionCalculationEntrust.MarketMoneyPosition.HSet:%v", common.ErrMoney, err) + continue + } + case flags.Close: // 平仓(现货) + if !flags.CheckSetting { + applogger.Info("从信道接收到综合(现货|合约|外汇)平仓信息:%v", resultMsg) + } + _, err = MoneyOrdersClosingDB(ctx, Msql, resultMsg.UserId, resultMsg.Order, resultMsg.OrderId, resultMsg.ClosingPrice) + if err != nil { + applogger.Error("%v MoneyTransactionCalculationEntrust.MoneyClosingPosition:%v", common.ErrMoney, err) + } + } + } + } + + wg.Wait() + applogger.Info("综合(现货|合约|外汇)挂单并发计算执行完毕......") +} + +// MoneyConcurrentComputingEntrust +// +// @Description: 综合-(现货|合约|外汇)监控挂单缓存列表业务处理 +// @param order +// @param orderOld +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return money.MoneyTallyCache +func MoneyConcurrentComputingEntrust(order *money.MoneyTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) money.MoneyTallyCache { + var deleteCache bool + var dealPrice, closePrice string + var limitPrice = decimal.RequireFromString(order.Order.LimitPrice) // 限价-价格 + var status = order.Status // 原始状态 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Info("用户ID:%v,限价买入下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + // 限价买入逻辑判定 -> 挂单金额 > 当前价格 + if limitPrice.Cmp(newPrice) > 0 { + deleteCache = true + dealPrice = limitPrice.String() // 开仓价格 + } + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Info("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + // 限价卖入逻辑判定 -> 挂单金额 < 当前价格 + if limitPrice.Cmp(newPrice) < 0 { + deleteCache = true + dealPrice = limitPrice.String() // 开仓价格 + } + default: + } + + if deleteCache { + switch order.Order.Type { + case flags.SpotsMarketType: // 现货 + order.Status = flags.Close + closePrice = dealPrice + default: // 合约|外汇 + order.Status = flags.Position + closePrice = decimal.Zero.String() + } + // 删除挂单缓存列表 + if err := Reds.HDel(context.Background(), setting.MarketMoneyEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v MoneyConcurrentComputingEntrust.MarketMoneyEntrust.HDel:%v", common.ErrMoney, err) + order.Status = status + dealPrice = decimal.Zero.String() + } + } + + wg.Done() + return money.MoneyTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + ClosingPrice: closePrice, // 平仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + } +} + +// MoneyLiquidationEntrust +// +// @Description: 综合-(现货|合约|外汇)挂单-->开仓业务处理 +// @param ctx +// @param order +// @return error +func MoneyLiquidationEntrust(ctx context.Context, order *money.MoneyTallyCache) error { + // 1、外汇开仓操作 + err := MoneyOpenPosition(ctx, Msql, order.UserId, order.OrderId, order.OpenPrice, order.Order) + if err != nil { + applogger.Error("%v MoneyLiquidationEntrust.MoneyOpenPosition:%v", common.ErrMoney, err) + return err + } + + // 2、开仓更新用户外汇订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(setting.MoneySubscribe, order.UserId) + if err = UpdateMoneySubscribeHashStatusByOrderId(order.OrderId, userSubKey, flags.Position, order.ClosingPrice); err != nil { + applogger.Error("%v MoneyLiquidationEntrust.MoneySubscribe:%v", common.ErrMoney, err) + return err + } + + // 3、开仓更新管理员外汇订阅缓存订单状态 + if err = UpdateMoneySubscribeHashStatusByOrderId(order.OrderId, setting.AdminMoneySubscribe, flags.Position, order.ClosingPrice); err != nil { + applogger.Error("%v MoneyLiquidationEntrust.AdminMoneySubscribe:%v", common.ErrMoney, err) + return err + } + + return nil +} + +// MoneyTransactionPosition +// +// @Description: 综合-(现货|合约|外汇)持仓业务处理 +// @param ctx +func MoneyTransactionPosition(ctx context.Context) { + for { + MoneyTransactionCalculationPosition(ctx) + time.Sleep(400 * time.Millisecond) + } +} + +// GetUserAmountByUserId +// +// @Description: 查询:用户-资产-订单 +func GetUserAmountByUserId() (map[int64]decimal.Decimal, map[int64][]money.MoneyTallyCache, error) { + var userAmountMap = make(map[int64]decimal.Decimal) + var userOrderMap = make(map[int64][]money.MoneyTallyCache) + // 分组查询用户总资产 + var userMoneyList []JsonData + if err := Msql.Table(flags.BotUserMoney). + Select("user_id,sum(usable_num+frozen_num) as total_amount"). + Where("stock_id = ?", flags.MoneyUnit). + GroupBy("user_id"). + Find(&userMoneyList); err != nil { + applogger.Error("GetUserAmountByUserId err:%v", common.ErrMoney, err) + return userAmountMap, userOrderMap, err + } + for _, value := range userMoneyList { + userAmountMap[value.UserId] = decimal.RequireFromString(value.TotalAmount) + } + // 查询缓存订单 + entrustList, err := Reds.HGetAll(context.Background(), setting.MarketMoneyPosition).Result() + if err != nil { + applogger.Error("%v MoneyTransactionCalculationPosition.LRange:%v", common.ErrMoney, err) + return userAmountMap, userOrderMap, err + } + for _, value := range entrustList { + var entrust money.MoneyTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + continue + } + userOrderMap[entrust.UserId] = append(userOrderMap[entrust.UserId], entrust) + } + return userAmountMap, userOrderMap, err +} + +// MoneyTransactionCalculationPosition +// +// @Description: 综合-(现货|合约|外汇)监控持仓缓存列表(注意:止盈止损|强行平仓) +// @param ctx +func MoneyTransactionCalculationPosition(ctx context.Context) { + userByAmount, userByOrder, err := GetUserAmountByUserId() + if err != nil { + return + } + + //applogger.Debug("用户资产:%v,用户持仓订单:%v", userByAmount, userByOrder) + + var wg sync.WaitGroup + for key, value := range userByAmount { + var msg = make(chan map[bool][]money.MoneyTallyCache, 1) + orderList, ok := userByOrder[key] + if ok { + wg.Add(1) + go func(value decimal.Decimal) { + var check bool // 判定是否爆仓 + var floatingPLSum decimal.Decimal // 浮动盈亏 + var resultListMsg []money.MoneyTallyCache // 订单信息 + var resultMapMsg = make(map[bool][]money.MoneyTallyCache, 1) // 推送订单信息-状态判定(持仓|平仓) + for _, vOrder := range orderList { + var newPrice decimal.Decimal + switch vOrder.Order.Type { + case flags.ContractMarketType: // 合约 + newPrice, err = GetMoneyContractPrice(vOrder.Symbol) + if err != nil { + applogger.Warn("%v MoneyTransactionCalculationPosition.GetMoneyContractPrice:%v", common.ErrMoney, err) + continue + } + case flags.ForexMarketType: // 外汇 + newPrice, err = GetMoneyForexPriceNew(vOrder.Symbol) + if err != nil { + applogger.Warn("%v MoneyTransactionCalculationPosition.GetMoneyForexPriceNew:%v", common.ErrMoney, err) + continue + } + default: + continue + } + result, floatingPL := MoneyConcurrentComputingPosition(&vOrder, newPrice, value) + floatingPLSum = floatingPLSum.Add(floatingPL) + resultListMsg = append(resultListMsg, result) + } + // TODO: 判定当前用户订单总浮动盈亏是否触发爆仓 + if value.Sub(floatingPLSum.Abs()).Cmp(decimal.Zero) <= 0 { + check = true + } else { + check = false + } + resultMapMsg[check] = resultListMsg + wg.Done() + // 返回处理消息 + msg <- resultMapMsg + }(value) + + // 处理并发结果 + select { + case resultMsg, _ := <-msg: + // check为true全部平仓,反之循环判定订单是否要平仓 + for check, message := range resultMsg { + if check { + for _, moneyStr := range message { + moneyStr.Status = flags.StrongParity + moneyStr.ClosingPrice = moneyStr.StrongParity + // 清理缓存订单 + if err = Reds.HDel(context.Background(), setting.MarketMoneyPosition, moneyStr.OrderId).Err(); err != nil { + applogger.Error("%v MoneyConcurrentComputingPosition.MarketMoneyPosition.HDel:%v", common.ErrMoney, err) + continue + } + // 用户订单平仓 + if err = MoneyLiquidationPosition(ctx, &moneyStr); err != nil { + applogger.Error("%v MoneyTransactionCalculationPosition.MoneyLiquidationPosition:%v", common.ErrMoney, err) + continue + } + } + } else { + for _, moneyStr := range message { + switch moneyStr.Status { + case flags.Position: // 持仓 + if !flags.CheckSetting { + applogger.Info("从信道接收到综合(现货|合约|外汇)持仓信息:%v", resultMsg) + } + case flags.Close: // 平仓 + if !flags.CheckSetting { + applogger.Info("从信道接收到综合(现货|合约|外汇)平仓信息:%v", resultMsg) + } + // 清理缓存订单 + if err = Reds.HDel(context.Background(), setting.MarketMoneyPosition, moneyStr.OrderId).Err(); err != nil { + applogger.Error("%v MoneyConcurrentComputingPosition.MarketMoneyPosition.HDel:%v", common.ErrMoney, err) + continue + } + // 用户订单平仓 + if err = MoneyLiquidationPosition(ctx, &moneyStr); err != nil { + applogger.Error("%v MoneyTransactionCalculationPosition.MoneyLiquidationPosition:%v", common.ErrMoney, err) + continue + } + } + } + } + } + } + } + } + + wg.Wait() + applogger.Info("综合(现货|合约|外汇)持仓并发计算执行完毕......") +} + +// MoneyConcurrentComputingPosition +// +// @Description: 综合-(现货|合约|外汇)持仓缓存列表业务处理 +// @param order +// @param newPrice +// @param totalAmount +// @return money.MoneyTallyCache +// @return decimal.Decimal +func MoneyConcurrentComputingPosition(order *money.MoneyTallyCache, newPrice, totalAmount decimal.Decimal) (money.MoneyTallyCache, decimal.Decimal) { + var checkBool bool // 标识是否平仓 + var dealPrice string // 平仓价 + var floatingPL decimal.Decimal // 浮动盈亏 + var openPrice = decimal.RequireFromString(order.OpenPrice) // 限价 + var orderNumber = decimal.RequireFromString(order.Order.OrderNumber) // 仓位 + var pryNum = decimal.RequireFromString(order.Order.PryNum) // 杠杆 + + // 下单判定设置(false无设置|true止盈止损) + _, stopWinPrice, stopLossPrice, _ := MoneyVoteStopType(order.Order) + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨(强平) + if !flags.CheckSetting { + applogger.Info("用户ID:%v,持仓开仓价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买涨挂止损止盈,止盈价必须<当前价,止损价必须>当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) < 0 { + checkBool = true + dealPrice = newPrice.String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) > 0 { + checkBool = true + dealPrice = newPrice.String() // 平仓价格 + } + } + // 强行平仓(做多) + if !checkBool { + floatingPL = newPrice.Sub(openPrice).Mul(orderNumber).Mul(order.Order.System.FaceValue).Mul(pryNum) + } + case flags.TradeTypeSell: // 买跌(存在强行平仓) + if !flags.CheckSetting { + applogger.Info("用户ID:%v,限价持仓买跌下单价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买跌挂止损止盈,止盈价必须>当前价,止损价必须<当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) > 0 { + checkBool = true + dealPrice = newPrice.String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) < 0 { + checkBool = true + dealPrice = newPrice.String() // 平仓价格 + } + } + // 强行平仓(做空) + if !checkBool { + floatingPL = openPrice.Sub(newPrice).Mul(orderNumber).Mul(order.Order.System.FaceValue).Mul(pryNum) + } + default: + } + /* 强行平仓(做多|做空) + 1、做多:(最新成交价-开仓成交价)*仓位 + 1、做空:(开仓成交价-最新成交价)*仓位 + 2、当浮动盈亏 >= 保证金的70%订单强行平仓 + */ + if floatingPL.IsNegative() { + explosiveAssets := totalAmount.Mul(order.Order.System.CompelNum) // 保证金(order.Order.EarnestMoney) = 总资产 + if !flags.CheckSetting { + applogger.Info("总资产:%v,强平资产:%v,浮动盈亏:%v,强行平仓判定:%v", totalAmount, explosiveAssets, floatingPL, floatingPL.Abs().Cmp(explosiveAssets)) + } + if floatingPL.Abs().Cmp(explosiveAssets) >= 0 { + checkBool = true + dealPrice = newPrice.String() + } + } + + // 判定订单状态 + if checkBool { + order.Status = flags.Close + } + + return money.MoneyTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + ClosingPrice: dealPrice, // 平仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + StrongParity: newPrice.String(), // 强平价格 + }, floatingPL +} + +// MoneyLiquidationPosition +// +// @Description: 综合-(现货|合约|外汇)平仓操作 +// @param ctx +// @param order +// @return error +func MoneyLiquidationPosition(ctx context.Context, order *money.MoneyTallyCache) error { + // 1、平仓操作 + status, err := strconv.Atoi(order.Status) + if err != nil { + status = 3 + } + err = MoneyClosingPosition(ctx, Msql, order.OrderId, order.ClosingPrice, order.Order, status) + if err != nil { + applogger.Error("%v MoneyLiquidationPosition.MoneyClosingPosition:%v", common.ErrMoney, err) + return err + } + + // 2、平仓更新用户外汇订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.MoneySubscribe, order.UserId) + if err = UpdateMoneySubscribeHashStatusByOrderId(order.OrderId, userSubKey, flags.Close, order.ClosingPrice); err != nil { + applogger.Error("%v MoneyLiquidationPosition.MoneySubscribe:%v", common.ErrMoney, err) + return err + } + + // 3、平仓更新管理员外汇订阅订单状态 + if err = UpdateMoneySubscribeHashStatusByOrderId(order.OrderId, setting.AdminMoneySubscribe, flags.Close, order.ClosingPrice); err != nil { + applogger.Error("%v MoneyLiquidationPosition.AdminMoneySubscribe:%v", common.ErrMoney, err) + return err + } + + return nil +} + +// MoneyVoteStopType +// +// @Description: 设置综合-(现货|合约|外汇)止盈止损 +// @param order +// @return bool +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func MoneyVoteStopType(order structure.MoneyOrder) (bool, decimal.Decimal, decimal.Decimal, error) { + var checkBool bool + var stopWinPrice, stopLossPrice decimal.Decimal + switch order.StopType { + case flags.StopTypeNone: // 暂无设置止盈止损 + checkBool = false + case flags.StopTypeSet: // 设置止盈止损 + checkBool = true + if len(order.StopWinPrice) != 0 { + stopWinPrice = decimal.RequireFromString(order.StopWinPrice) + } + if len(order.StopLossPrice) != 0 { + stopLossPrice = decimal.RequireFromString(order.StopLossPrice) + } + default: + return checkBool, stopWinPrice, stopLossPrice, flags.ErrContractThirteen + } + + return checkBool, stopWinPrice, stopLossPrice, nil +} + +// GetMoneyForexPrice +// +// @Description: TODO: 综合-外汇交易对卖一买一最新报价 +// @param symbol +// @param tradeType +// @return decimal.Decimal +// @return error +func GetMoneyForexPrice(symbol string, tradeType int64) (decimal.Decimal, error) { + var err error + var newPrice []byte + var cacheKey string + + switch tradeType { + case 1: // 外汇交易对买一最新报价 + cacheKey = publicData.SymbolCache(flags.Wh, symbol, flags.TradeTypeBuy) + newPrice, err = memory.GetMoneyForexCache(cacheKey) + case 2: // 外汇交易对卖一最新报价 + cacheKey = publicData.SymbolCache(flags.Wh, symbol, flags.TradeTypeSell) + newPrice, err = memory.GetMoneyForexCache(cacheKey) + } + if err != nil { + applogger.Error("%v GetMoneyForexPrice.Get:%v", common.ErrMoney, err) + return decimal.Decimal{}, err + } + + priceList, err := decimal.NewFromString(string(newPrice)) + if err != nil { + applogger.Error("%v GetMoneyForexPrice.Get:%v", common.ErrMoney, err) + return decimal.Decimal{}, err + } + + applogger.Info("MoneyCode:%v,topIc:%v,MoneyPrice:%v", symbol, cacheKey, priceList) + + return priceList, nil +} + +// GetMoneyForexPriceNew +// +// @Description: 综合-外汇交易对即时报价 +// @param symbol +// @return decimal.Decimal +// @return error +func GetMoneyForexPriceNew(symbol string) (decimal.Decimal, error) { + var keyPrice string + if flags.CheckEnvironment == flags.CheckAdmin { + keyPrice = SymbolCache(flags.Wh, symbol, flags.TradeTypeAdminPrice) + } else { + keyPrice = SymbolCache(flags.Wh, symbol, flags.TradeTypePrice) + } + priceNew, err := memory.GetMoneyForexImmediateCache(keyPrice) + if err != nil { + return decimal.Decimal{}, err + } + + priceList, err := decimal.NewFromString(string(priceNew)) + if err != nil { + applogger.Error("%v GetMoneyForexPriceNew.Get:%v", common.ErrMoney, err) + return decimal.Decimal{}, err + } + + applogger.Info("MoneyCode:%v,topIc:%v,MoneyPrice:%v", symbol, keyPrice, priceList) + + return priceList, nil +} + +// GetMoneySpotsPrice +// +// @Description: 综合-现货即时报价 +// @param symbol +// @return decimal.Decimal +// @return error +func GetMoneySpotsPrice(symbol string) (decimal.Decimal, error) { + var err error + var newByte []byte + var keyPrice string + if flags.CheckEnvironment == flags.CheckAdmin { + keyPrice = publicData.SymbolCache(flags.Xh, symbol, flags.TradeTypeAdminPrice) + } else { + keyPrice = publicData.SymbolCache(flags.Xh, symbol, flags.TradeTypePrice) + } + newByte, err = memory.MoneySpotsCache.Get(keyPrice) + if err != nil { + applogger.Warn("%v GetMoneySpotsPrice.Get:%v", common.ErrMoney, err) + return decimal.Decimal{}, err + } + + priceNew := decimal.RequireFromString(string(newByte)) + + return priceNew, nil +} + +// GetMoneyContractPrice +// +// @Description: 综合-合约即时报价 +// @param symbol +// @return decimal.Decimal +// @return error +func GetMoneyContractPrice(symbol string) (decimal.Decimal, error) { + var newPrice decimal.Decimal + var keyPrice string + if flags.CheckEnvironment == flags.CheckAdmin { + keyPrice = publicData.SymbolCache(flags.Hy, symbol, flags.TradeTypeAdminPrice) + } else { + keyPrice = publicData.SymbolCache(flags.Hy, symbol, flags.TradeTypePrice) + } + priceByte, err := memory.GetMoneyContractCache(keyPrice) + if err != nil { + applogger.Error("%v GetMoneyContractPrice.Get:%v", common.ErrMoney, err) + return decimal.Decimal{}, err + } + + newPrice, err = decimal.NewFromString(string(priceByte)) + if err != nil { + return decimal.Decimal{}, err + } + + applogger.Info("contractCode:%v,topIc:%v,contractPrice:%v", symbol, keyPrice, newPrice) + + return newPrice, nil +} diff --git a/internal/data/subscribe_option_inr.go b/internal/data/subscribe_option_inr.go new file mode 100644 index 0000000..bb9a767 --- /dev/null +++ b/internal/data/subscribe_option_inr.go @@ -0,0 +1,1123 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/mq/consumer" + "matchmaking-system/internal/data/socket/optionData" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/option" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "sync" + "time" +) + +/** +期权-交易计算相关公式 +一、手续费(Total Fee) + 1> 固定费用:Total Fee = Total Fee Fix Value(固定费用) + 2> 按比例结算:Total Fee = Total Fee Ratio(总费用比例) * Option Filled Price(开仓价格) * Quantity(订单数量) + 3> 按张结算:Total Fee = Total Fee Per Contract(每份费用) * Quantity(订单数量) +三、浮动盈亏(P/L) + 1>buy call & buy put + 1> bid买一价为0, P/L显示为 - + 2> bid买一价大于0, P/L =(bid买一价 - Cost Price)*Contracts Quantity + 2>sell call & sell put + 1> ask卖一价为0, P/L显示为 - + 2> ask卖一价大于0, P/L =(Cost Price - ASK卖一价)*Contracts Quantity +四、保证金(Margin Ratio) + 1> sell call 和 sell put:Margin =(Stock Price(行权价) * Option Multiplier(期权乘数)) * Margin Ratio(保证金比率) * Quantity + 2> buy call 和 buy put:Margin = Open Filled Price(开仓价格) * Quantity(订单数量) +五、结算价值(Settlement Value) + 1> Margin + P/L +*/ + +// OptionInrMessage +// @Description: +type OptionInrMessage struct { + Price string `json:"price"` + Bid string `json:"bid"` + Ask string `json:"ask"` + Code string `json:"code"` + BeforeClose string `json:"before_close"` + YesterdayClose string `json:"yesterday_close"` + CloseDate string `json:"option_date"` +} + +// OptionInrSymbol +// @Description: +type OptionInrSymbol struct { + OpiMap chan []byte // 订单交易对 -- 用户下单通知订阅 + OpiSetMap chan []byte // 订单交易对 -- 用户盘前|盘后行情订阅 + OpiMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 + OpiSetMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 +} + +// InitCacheSymbolOptionInr +// +// @Description: +// @param ctx +// @param uo +func InitCacheSymbolOptionInr(ctx context.Context, uo *Data) { + for { + thaList, err := GetBotStockOptionInrListByStockId(ctx, uo) + if err != nil { + return + } + + for _, value := range thaList { + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), setting.MarketOptionInr, value).Result() + if err != nil { + applogger.Error("%v InitCacheSymbolOptionInr.MarketOptionInr.HExists:%v", common.ErrOptionInr, err) + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err := Reds.HSet(context.Background(), setting.MarketOptionInr, value, value).Err(); err != nil { + applogger.Error("%v InitCacheSymbolOptionInr.MarketOptionInr.HSet:%v", common.ErrOptionInr, err) + time.Sleep(5 * time.Second) + continue + } + } + if !flags.CheckSetting { + applogger.Info("初始化印度期权股票代码:%v", value) + } + } + + time.Sleep(10 * time.Second) + } +} + +// InitSubscribeOptionInr +// +// @Description: 状态机加载行情 - 订单表预加载 +// @param ctx +// @param uo +// @param shareTha +func InitSubscribeOptionInr(OptionInr *OptionInrSymbol) { + for { + listSpots, err := LoadLRangeList(setting.AdminOptionInrSubscribe) + if err != nil { + applogger.Error("%v InitSubscribeOptionInr.LoadLRangeList:%v", common.ErrOptionInr, err) + return + } + + for _, value := range listSpots { + var entrust option.OptionInrTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v InitSubscribeOptionInr.Unmarshal:%v", common.ErrOptionInr, err) + continue + } + _, ok := OptionInr.OpiMapSymbol.Load(entrust.Order.StockCode) + if ok { + continue + } + OptionInr.OpiMap <- []byte(entrust.Order.StockCode) + } + + time.Sleep(20 * time.Second) + } +} + +// SubscriptionDataInformation +// +// @Description: 循环处理数据 +// @param ctx +func SubscriptionDataInformation(ctx context.Context) { + for { + optionInr.OpiMapSymbol.Range(func(key, value interface{}) bool { + topIc, ok := key.(string) + if ok { + symbolStr := utils.ExtractSubstringBeforeFirstDigit(topIc) + _ = OptionInrMessageSet(symbolStr, topIc) + } + return true + }) + + time.Sleep(600 * time.Millisecond) + } +} + +// SubscribeOptionInr +// +// @Description: 期权-印度股订阅 +// @param ctx +// @param uo +// @param shareIdn +func SubscribeOptionInr(ctx context.Context, uo *Data, optionInr *OptionInrSymbol) { + for { + select { + case symbol, _ := <-optionInr.OpiMap: + // 期权标识:BEL20240425216000PE + topIc := string(symbol) + // 构造股票(BEL) + symbolStr := utils.ExtractSubstringBeforeFirstDigit(topIc) + // 处理重复订阅的情况 + _, ok := optionInr.OpiMapSymbol.Load(topIc) + if ok { + time.Sleep(5 * time.Second) + continue + } + // 将订阅的主题写入Redis的hot-cache列表 + checkBool, err := Reds.HExists(context.Background(), setting.MarketOptionInr, symbolStr).Result() + if err != nil { + continue + } + if !checkBool { + if err := Reds.HSet(context.Background(), setting.MarketOptionInr, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeOptionInr.MarketOptionInr.HSet:%v", common.ErrOptionInr, err) + time.Sleep(5 * time.Second) + continue + } + } + // 获取设置价格 + if err := OptionInrMessageSet(symbolStr, topIc); err != nil { + applogger.Error("OptionInrMessageSet err:%v", topIc) + continue + } + // 将订阅的主题存入map中,用于判断是否重复订阅 + optionInr.OpiMapSymbol.Store(topIc, topIc) + default: + Reds.Ping(ctx) // 如果没有消息,发送 PING 命令以维护连接 + time.Sleep(10 * time.Second) + } + } +} + +// OptionInrMessageSet +// +// @Description: 设置股票交易价格|买一卖一价格|闭盘价格 +// @param topIc +// @return error +func OptionInrMessageSet(symbolStr, topIc string) error { + // 查询订单 + keyCache := fmt.Sprintf("%v%v", flags.CountryOptionInr, symbolStr) + msg, err := Reds.HGet(context.Background(), keyCache, topIc).Result() + if err != nil { + return err + } + // 交易数据解析 + var subMsg OptionInrMessage + if err = json.Unmarshal([]byte(msg), &subMsg); err != nil { + applogger.Error("%v SubscribeOptionInr.Unmarshal:%v", common.ErrOptionInr, err) + close(optionInr.OpiMap) + return err + } + // 处理订阅实时行情数据(订阅Key|交易价格|买一价|卖一价) + SubscribeOptionInrPrice(subMsg, topIc) + + return nil +} + +// SubscribeOptionInrPrice +// +// @Description: 期权-订阅获取印度股实时价格或者[盘前|盘后]设置价格 +// @param setPrice +// @param symbolStr +// @param check +func SubscribeOptionInrPrice(optionInr OptionInrMessage, topIc string) { + // 交易类型: 期权最新价格-0,期权买一价-1,期权卖一价-2 + // 缓存期权交易价格 + keyPrice := publicData.SymbolCache(flags.Opi, topIc, flags.OptionPrice) + if err := memory.OptionInrCache.Set(keyPrice, []byte(optionInr.Price)); err != nil { + applogger.Error("%v SubscribeOptionInrPrice.OptionInrCache.Set.price:%v", common.ErrOptionInr, err) + } + // 缓存期权买一价格 + keyBid := publicData.SymbolCache(flags.Opi, topIc, flags.OptionBid) + if err := memory.OptionInrBid.Set(keyBid, []byte(optionInr.Bid)); err != nil { + applogger.Error("%v SubscribeOptionInrPrice.OptionInrBid.Set.price:%v", common.ErrOptionInr, err) + } + // 缓存期权卖一价格 + keyAsk := publicData.SymbolCache(flags.Opi, topIc, flags.OptionAsk) + if err := memory.OptionInrAsk.Set(keyAsk, []byte(optionInr.Ask)); err != nil { + applogger.Error("%v SubscribeOptionInrPrice.OptionInrAsk.Set.price:%v", common.ErrOptionInr, err) + } + + // 设置闭盘价格 + var price decimal.Decimal + closeStr := utils.ReplaceStr(optionInr.Price) == "" + yesterdayStr := utils.ReplaceStr(optionInr.YesterdayClose) == "" + beforeStr := utils.ReplaceStr(optionInr.BeforeClose) == "" + if closeStr { + optionInr.Price = decimal.Zero.String() + } + if yesterdayStr { + optionInr.YesterdayClose = decimal.Zero.String() + } + if beforeStr { + optionInr.BeforeClose = decimal.Zero.String() + } + closePrice := decimal.RequireFromString(optionInr.Price) + yesterdayClosePrice := decimal.RequireFromString(optionInr.YesterdayClose) + beforeClose := decimal.RequireFromString(optionInr.BeforeClose) + // 判定如果close为zero则取值yesterdayClosePrice,否取closePrice + if closePrice.IsZero() { + if !yesterdayClosePrice.IsZero() { + price = yesterdayClosePrice + } + } else { + price = closePrice + } + // 判定如果price为zero则取值beforeClose值,否取price + if price.IsZero() { + if !beforeClose.IsZero() { + price = beforeClose + } + } + // 闭盘价格 + closeKey := publicData.SymbolCache(flags.Opi, topIc, flags.TradeTypeClosePrice) + if err := memory.OptionInrClosePrice.Set(closeKey, []byte(price.String())); err != nil { + applogger.Error("%v OptionInrClosePrice.Set.price:%v", common.ErrOptionInr, err) + } + + if !flags.CheckSetting { + applogger.Info("期权股票交易代码:%v,交易价格:%v,买一价:%v,卖一价:%v,闭盘价:%v", topIc, optionInr.Price, optionInr.Bid, optionInr.Ask, price) + } +} + +// OrderSubAdminOptionInrSubscribeBySum +// +// @Description: 期权-持仓订单浮动盈亏计算 +// @param ctx +// @param uo +func OrderSubAdminOptionInrSubscribeBySum(uo *Data) { + for { + topIc := setting.AdminOptionInrSubscribe + hashMap, err := Reds.HGetAll(context.Background(), topIc).Result() + if err != nil { + applogger.Error("OrderSubAdminOptionInrSubscribeBySum.HGetAll:%v", err) + time.Sleep(5 * time.Second) + continue + } + var hashList []option.OptionInrTallyCache + for _, value := range hashMap { + var msg option.OptionInrTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + switch msg.Status { + case flags.Entrust: // 挂单 + case flags.Position: // 持仓 + hashList = append(hashList, msg) + default: // 平仓|撤单 + err = Reds.HDel(context.Background(), topIc, msg.OrderId).Err() + if err != nil { + applogger.Error("OrderSubAdminOptionInrSubscribeBySum.HDel:%v", err) + continue + } + } + } + applogger.Info("统计印度期权股数据量统计:%v", len(hashList)) + // 统计印度股持仓订单浮动盈亏 + priceSum := decimal.Zero + for _, value := range hashList { + orderModel := optionData.OptionInrOrderProcessing(1, value) + if orderModel != nil { + if len(orderModel.Price) == 0 || len(orderModel.OpenPrice) == 0 { + continue + } + var newPrice, openPrice, orderNumber, subPrice, resultPrice decimal.Decimal + newPrice = decimal.RequireFromString(orderModel.Price) // 股票实时价格 + openPrice = decimal.RequireFromString(orderModel.OpenPrice) // 订单开仓价格 + orderNumber = decimal.RequireFromString(orderModel.OrderNumber) // 订单量 + subPrice = OptionResultPrice(value.Order.TradeType, value.Order.TradingType, openPrice, newPrice) // 计算浮动盈亏 + resultPrice = subPrice.Mul(orderNumber) // 计算订单浮动总盈亏 + priceSum = priceSum.Add(resultPrice) // 累加盈亏统计 + } + } + // 写入持仓订单浮动盈亏缓存 + if err = memory.OptionInrFloating.Set(flags.FloatingOpi, []byte(priceSum.String())); err != nil { + applogger.Error("统计印度期权股持仓订单浮动盈亏错误:%v", err) + time.Sleep(5 * time.Second) + continue + } + applogger.Info("统计印度期权股持仓订单浮动盈亏:%v", priceSum) + + time.Sleep(3 * time.Second) + } +} + +// OptionResultPrice +// +// @Description: 期权-浮动盈亏 +// @param tradeType +// @param tradingType +// @param openPrice +// @param newPrice +// @return decimal.Decimal +func OptionResultPrice(tradeType, tradingType int64, openPrice, newPrice decimal.Decimal) decimal.Decimal { + //浮动盈亏(P/L) + //1>buy call & buy put + // 1> bid买一价为0, P/L显示为 - + // 2> bid买一价大于0, P/L =(bid买一价 - Cost Price)*Contracts Quantity + //2>sell call & sell put + // 1> ask卖一价为0, P/L显示为 - + // 2> ask卖一价大于0, P/L =(Cost Price - ASK卖一价)*Contracts Quantity + var subPrice decimal.Decimal + switch tradeType { + case flags.OptionCalls: // Call + switch tradingType { + case flags.OptionBuy: // buy - call + subPrice = newPrice.Sub(openPrice) + case flags.OptionSell: // sell - call + subPrice = openPrice.Sub(newPrice) + } + case flags.OptionPuts: // PUT + switch tradingType { + case flags.OptionBuy: // buy - put + subPrice = newPrice.Sub(openPrice) + case flags.OptionSell: // sell - put + subPrice = openPrice.Sub(newPrice) + } + default: + subPrice = decimal.Zero + } + return subPrice +} + +// OptionInrTransactionEntrust +// +// @Description: 期权-印度股委托订单 +// @param ctx +func OptionInrTransactionEntrust(ctx context.Context, uo *Data) { + for { + OptionInrTransactionCalculationEntrust(ctx, uo) + time.Sleep(400 * time.Millisecond) + } +} + +// OptionInrTransactionCalculationEntrust +// +// @Description: 期权-印度股挂单缓存队列计算 +// @param ctx +// @param uo +func OptionInrTransactionCalculationEntrust(ctx context.Context, uo *Data) { + var wg sync.WaitGroup + + // 全局变量处理 + if CheckGlobalTread(flags.OpiMarket) { + time.Sleep(5 * time.Second) + return + } + + // 获取印度期权股挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketOptionInrEntrust).Result() + if err != nil { + applogger.Error("%v OptionInrTransactionCalculationEntrust.HGetAll:%v", common.ErrOptionInr, err) + return + } + + for _, value := range orderMap { + var msg = make(chan option.OptionInrTallyCache, 1) + var entrust option.OptionInrTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v OptionInrTransactionCalculationEntrust.Unmarshal:%v", common.ErrOptionInr, err) + continue + } + // 到期时间小于当前时间-永远不给成交(撤单操作) + if CheckShareSystemTime(entrust.ClosingTime) { + applogger.Warn("%v 订单已超过到期时间不在成交:%v---%v", common.ErrOptionInr, entrust.Symbol, entrust.ClosingTime) + _, err = UpdateBotStockOptionInrCancelByOrderId(ctx, uo.mysqlDB, entrust.OrderId) + if err != nil { + applogger.Warn("%v 订单已超过到期时间不在成交,订单撤单失败:%v---%v", common.ErrOptionInr, entrust.Symbol, entrust.ClosingTime) + } + continue + } + // 期权交易价格|买一价|卖一价 + var newPrice, bid, ask decimal.Decimal + newPrice, bid, ask, err = GetOptionInrPrice(entrust.Order.StockCode) + if err != nil { + applogger.Warn("%v OptionInrTransactionCalculationEntrust.GetOptionInrPrice:%v---%v", common.ErrOptionInr, entrust.Symbol, err) + continue + } + + wg.Add(1) + go func(value string) { + var resultMsg option.OptionInrTallyCache + switch entrust.Order.DealType { + case flags.DealTypeLimited: // 限价-挂单 + resultMsg = OptionInrConcurrentComputingEntrustLimited(&entrust, newPrice, bid, ask, &wg) + case flags.DealTypeMarket: // 市价-挂单(开盘即成交) + resultMsg = OptionInrConcurrentComputingEntrustMarket(&entrust, bid, ask, &wg) + } + msg <- resultMsg + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收期权-印度股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到期权-印度股持仓信息:%v", resultMsg) + } + // 开盘逻辑 + if err = OptionInrLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Warn("%v OptionInrTransactionCalculationEntrust.OptionInrLiquidationEntrust:%v", common.ErrOptionInr, err) + continue + } + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v OptionInrTransactionCalculationEntrust.Marshal:%v", common.ErrOptionInr, err) + continue + } + + // TODO: 写入持仓消息队列 + //if err = uo.mqProducer.Entrust.PushNotice(byteStr); err != nil { + // applogger.Error("%v OptionInrTransactionCalculationEntrust.EntrustPushNotice:%v", common.ErrOptionInr, err) + // continue + //} + + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketOptionInrPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("期权-印度股挂单并发计算执行完毕......") +} + +// OptionInrConcurrentComputingEntrustLimited +// +// @Description: 期权-印度股挂单(限价|市价)缓存列表业务处理 +// @param order +// @param newPrice +// @param wg +// @return option.OptionInrTallyCache +func OptionInrConcurrentComputingEntrustLimited(order *option.OptionInrTallyCache, newPrice, bid, ask decimal.Decimal, wg *sync.WaitGroup) option.OptionInrTallyCache { + var deleteCache bool + var dealPrice string + var status = order.Status // 订单状态 + var limitPrice = decimal.RequireFromString(order.Order.LimitPrice) // 限价-价格 + + //限价单成交逻辑 + //1>buy-call 和 buy-put 当卖一价(aks) <= 下单价 会成交即为下单价 + //2>sell-call 和 sell-put 当买一价(bid) >= 下单价 会成交即为下单价 + switch order.Order.TradeType { + case flags.OptionCalls: // call + switch order.Order.TradingType { + case flags.OptionBuy: // buy - call + if ask.Cmp(limitPrice) <= 0 { + deleteCache = true + dealPrice = limitPrice.String() + } + case flags.OptionSell: // sell - call + if bid.Cmp(limitPrice) >= 0 { + deleteCache = true + dealPrice = limitPrice.String() + } + } + case flags.OptionPuts: // put + switch order.Order.TradingType { + case flags.OptionBuy: // buy - put + if ask.Cmp(limitPrice) <= 0 { + deleteCache = true + dealPrice = limitPrice.String() + } + case flags.OptionSell: // sell - put + if bid.Cmp(limitPrice) >= 0 { + deleteCache = true + dealPrice = limitPrice.String() + } + } + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketOptionInrEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v OptionInrConcurrentComputingEntrustLimited.HDel:%v", common.ErrOptionInr, err) + order.Status = status + } + } + + wg.Done() + return option.OptionInrTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// OptionInrConcurrentComputingEntrustMarket +// +// @Description: 期权-印度股市价下单进入挂单队列(休市) +// @param order +// @param newPrice +// @param wg +// @return option.OptionInrTallyCache +func OptionInrConcurrentComputingEntrustMarket(order *option.OptionInrTallyCache, bid, ask decimal.Decimal, wg *sync.WaitGroup) option.OptionInrTallyCache { + var deleteCache bool + var dealPrice string + var status = order.Status // 原始状态 + //市价单交易 + //1>buy-call 和 buy-put 以卖一价(ask)成交 + //2>sell-call 和 sell-put 以买一价(bid)成交 + switch order.Order.TradeType { + case flags.OptionCalls: // call + switch order.Order.TradingType { + case flags.OptionBuy: // buy - call + if !ask.IsZero() { + deleteCache = true + dealPrice = ask.String() + } + case flags.OptionSell: // sell - call + if !bid.IsZero() { + deleteCache = true + dealPrice = bid.String() + } + } + case flags.OptionPuts: // put + switch order.Order.TradingType { + case flags.OptionBuy: // buy - put + if !ask.IsZero() { + deleteCache = true + dealPrice = ask.String() + } + case flags.OptionSell: // sell - put + if !bid.IsZero() { + deleteCache = true + dealPrice = bid.String() + } + } + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketOptionInrEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v OptionInrConcurrentComputingEntrustMarket.HDel:%v", common.ErrOptionInr, err) + order.Status = status + } + } + + wg.Done() + return option.OptionInrTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// OptionInrMqOpenBusiness +// +// @Description: TODO: 期权-印度股持仓消息队列 +// @param ctx +// @param uo +func OptionInrMqOpenBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Entrust.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerEntrustMq.OptionInrMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v OptionInrMqOpenBusiness.OptionInrMq err....", common.ErrOptionInr) + continue + } + + // 持仓订单缓存数据序列化解析 + var resultMsg option.OptionInrTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v OptionInrMqOpenBusiness.Unmarshal:%v", common.ErrOptionInr, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := OptionInrLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v OptionInrMqOpenBusiness.OptionInrLiquidationEntrust:%v", common.ErrOptionInr, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + applogger.Error("这里没有监控到持仓mq队列消息.........") + time.Sleep(2 * time.Second) + } + } +} + +// OptionInrLiquidationEntrust +// +// @Description: 期权-印度股挂单-->开仓业务处理 +// @param ctx +// @param order +// @return error +func OptionInrLiquidationEntrust(ctx context.Context, order *option.OptionInrTallyCache) error { + // 1、开盘 + err := OptionInrOpenOrder(ctx, Msql, order.UserId, order.OrderId, order.OpenPrice, order.Order) + if err != nil { + applogger.Error("%v OptionInrLiquidationEntrust.OptionInrOpenOrder:%v", common.ErrOptionInr, err) + return err + } + + // 2、更新用户订阅缓存列表订单状态 + updateKey := virtual.OrderIdListKey(setting.OptionInrSubscribe, order.UserId) + if err = UpdateOptionInrSubscribeHashStatusByOrderId(order.OrderId, updateKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v OptionInrLiquidationEntrust.Entrust.OptionInrSubscribe:%v", common.ErrOptionInr, err) + return err + } + + // 3、更新管理员订阅缓存列表订单状态 + if err = UpdateOptionInrSubscribeHashStatusByOrderId(order.OrderId, setting.AdminOptionInrSubscribe, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v OptionInrLiquidationEntrust.Entrust.AdminOptionInrSubscribe:%v", common.ErrOptionInr, err) + return err + } + + return nil +} + +// OptionInrTransactionPosition +// +// @Description: 期权-印度股持仓订单 +// @param ctx +func OptionInrTransactionPosition(ctx context.Context) { + for { + OptionInrTransactionCalculationPosition(ctx) + time.Sleep(400 * time.Millisecond) + } +} + +// OptionInrTransactionCalculationPosition +// +// @Description: 期权-印度股持仓缓存队列计算 +// @param ctx +func OptionInrTransactionCalculationPosition(ctx context.Context) { + var wg sync.WaitGroup + + // 判定是否交易 + if CheckGlobalTread(flags.OpiMarket) { + time.Sleep(5 * time.Second) + return + } + + // TODO: 获取IPO未支付订单缓存 + userIdMap, _ := GetBotUserArrears(ctx) + + // 持仓缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketOptionInrPosition).Result() + if err != nil { + applogger.Error("%v OptionInrTransactionCalculationPosition.HGetAll:%v", common.ErrOptionInr, err) + return + } + + for _, value := range orderMap { + var msg = make(chan option.OptionInrTallyCache, 1) + var entrust option.OptionInrTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v OptionInrTransactionCalculationPosition.Unmarshal:%v", common.ErrOptionInr, err) + continue + } + + // TODO: 判定是否未IPO未支付订单-不能平仓 + _, isOk := userIdMap[entrust.UserId] + if isOk { + continue + } + + // 期权交易价格|买一价|卖一价 + var newPrice, bid, ask decimal.Decimal + newPrice, bid, ask, err = GetOptionInrPrice(entrust.Order.StockCode) + if err != nil { + applogger.Warn("%v OptionInrTransactionCalculationPosition.Get:%v--%v", common.ErrOptionInr, entrust.Symbol, err) + continue + } + + // 期权到期时间日内停盘前一个小时平仓 + checkClosingTime := utils.TimeComparison(entrust.ClosingTime) + + wg.Add(1) + go func(value string) { + resultMsg := OptionInrConcurrentComputingPosition(&entrust, newPrice, bid, ask, &wg, checkClosingTime) + msg <- resultMsg + }(value) + + // 处理并发结果 + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Position: // 持仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到期权-印度股持仓信息:%v", resultMsg) + } + case flags.Close: // 平仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到期权-印度股平仓信息:%v", resultMsg) + } + + // TODO: 平仓操作(优化写入队列中等待平仓) + //var byteStr []byte + //byteStr, err = json.Marshal(resultMsg) + //if err != nil { + // applogger.Error("%v OptionInrTransactionCalculationPosition.Marshal:%v", common.ErrOptionInr, err) + // continue + //} + //if err = uo.mqProducer.Position.PushNotice(byteStr); err != nil { + // applogger.Error("%v OptionInrTransactionCalculationPosition.DealPublish:%v", common.ErrOptionInr, err) + // continue + //} + + if err = OptionInrLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v OptionInrTransactionCalculationPosition.OptionInrLiquidationPosition:%v", common.ErrOptionInr, err) + continue + } + } + } + } + + wg.Wait() + applogger.Info("期权-印度股持仓并发计算执行完毕......") +} + +// OptionInrConcurrentComputingPosition +// +// @Description: 期权-印度股持仓缓存列表业务处理 +// @param order +// @param newPrice +// @param wg +// @param checkFlattening +// @return option.OptionInrTallyCache +func OptionInrConcurrentComputingPosition(order *option.OptionInrTallyCache, newPrice, bid, ask decimal.Decimal, wg *sync.WaitGroup, checkClosingTime bool) option.OptionInrTallyCache { + var deleteCache bool + var openPrice = decimal.RequireFromString(order.OpenPrice) // 限价 + var orderNumber = decimal.RequireFromString(order.Order.OrderNumber) // 仓位 + + // 下单判定设置(false无设置|true止盈止损) + _, stopWinPrice, stopLossPrice, _ := OptionInrVoteStopType(order.Order) + + // 平仓 + //1>buy-call 和 buy-put 平仓价格以买一价(bid)成交 + //2>sell-call 和 sell-put 平仓价格以卖一价(ask)成交 + + // 期权:止盈止损 + //一、call-buy 和 put-buy + //1>止盈:买一价 >= 止盈价 + //2>止损:卖一价 <= 止损价 + //二、call-sell 和 put-sell + //1>止盈:卖一价 <= 止盈价 + //2>止损:买一价 >= 止损价 + dealPrice, sellShort, checkBool := ClosePriceStopWinOrStopLossPrice(order.Order.TradingType, newPrice, stopWinPrice, stopLossPrice, bid, ask, openPrice, orderNumber) + + /* 强行平仓(做多|做空) + 1、做多:(最新成交价-开仓成交价)*仓位 + 2、做空:(开仓成交价-最新成交价)*仓位 + 3、当浮动盈亏 >= 保证金的70%订单强行平仓 + */ + if sellShort.IsNegative() { + //保证金(Margin Ratio) + //1> buy call 和 buy put:Margin = Open Filled Price(当前价格) * Quantity(订单数量) + //2> sell call 和 sell put:Margin = (Stock Price(行权价) * Option Multiplier(期权乘数)) * Margin Ratio(保证金比率) * Quantity(订单数量) + var orderAmount, strikePrice, multiplier, ratio decimal.Decimal + ratio = decimal.RequireFromString(order.Order.Ratio) + multiplier = decimal.RequireFromString(order.Order.Multiplier) + strikePrice = decimal.RequireFromString(order.Order.StrikePrice) + switch order.Order.TradeType { + case flags.OptionCalls: // CallS + switch order.Order.TradingType { + case flags.OptionBuy: // buy + orderAmount = openPrice.Mul(orderNumber) + case flags.OptionSell: // sell + orderAmount = strikePrice.Mul(multiplier).Mul(ratio).Mul(orderNumber) + } + case flags.OptionPuts: // PUTS + switch order.Order.TradingType { + case flags.OptionBuy: // buy + orderAmount = openPrice.Mul(orderNumber) + case flags.OptionSell: // sell + orderAmount = strikePrice.Mul(multiplier).Mul(ratio).Mul(orderNumber) + } + default: + + } + floatPrice := orderAmount.Mul(decimal.RequireFromString(order.Order.System.StrongFlatRatio)) + if !flags.CheckSetting { + applogger.Debug("强平保证金:%v,强平浮动70:%v,强行平仓判定:%v", orderAmount, floatPrice, sellShort.Abs().Cmp(floatPrice)) + } + if sellShort.Abs().Cmp(floatPrice) >= 0 { + checkBool = true + dealPrice = newPrice // 平仓价格 + } + } + + // 符合: 1、强平条件 2、到达到期时间 + if checkBool || checkClosingTime { + deleteCache = true + order.Status = flags.Close + } + // 清理持仓缓存订单 + if deleteCache { + if err := Reds.HDel(context.Background(), setting.MarketOptionInrPosition, order.OrderId).Err(); err != nil { + applogger.Error("%v OptionInrConcurrentComputingPosition.Position.HDel:%v", common.ErrOptionInr, err) + } + } + + wg.Done() + return option.OptionInrTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + ClosingPrice: dealPrice.String(), // 平仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ClosePriceStopWinOrStopLossPrice +// +// @Description: 持仓平仓-止盈止损设置判定 +// @param tradingType +// @param newPrice +// @param stopWinPrice +// @param stopLossPrice +// @param bid +// @param ask +// @param openPrice +// @param orderNumber +// @return decimal.Decimal +// @return decimal.Decimal +// @return bool +func ClosePriceStopWinOrStopLossPrice(tradingType int64, newPrice, stopWinPrice, stopLossPrice, bid, ask, openPrice, orderNumber decimal.Decimal) (decimal.Decimal, decimal.Decimal, bool) { + var checkBool bool + var dealPrice, sellShort decimal.Decimal + + switch tradingType { + case flags.OptionBuy: // call - buy + if !stopWinPrice.IsZero() { + if bid.Cmp(stopWinPrice) >= 0 { + checkBool = true + dealPrice = newPrice + } + } + if !stopLossPrice.IsZero() { + if ask.Cmp(stopLossPrice) <= 0 { + checkBool = true + dealPrice = newPrice + } + } + if !newPrice.IsZero() { + if !checkBool { // 强行平仓(做多) + sellShort = newPrice.Sub(openPrice).Mul(orderNumber) + } + } + case flags.OptionSell: // call -sell + if !stopWinPrice.IsZero() { + if ask.Cmp(stopWinPrice) <= 0 { + checkBool = true + dealPrice = newPrice + } + } + if !stopLossPrice.IsZero() { + if bid.Cmp(stopLossPrice) >= 0 { + checkBool = true + dealPrice = newPrice + } + } + if !newPrice.IsZero() { + if !checkBool { // 强行平仓(做空) + sellShort = openPrice.Sub(newPrice).Mul(orderNumber) + } + } + } + return dealPrice, sellShort, checkBool +} + +// OptionInrMqClosingBusiness +// +// @Description: TODO: 期权-印度股平仓消息队列 +// @param ctx +// @param uo +func OptionInrMqClosingBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Position.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerPositionMq.OptionInrMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v OptionInrMqClosingBusiness.OptionInrMq err....", common.ErrOptionInr) + continue + } + applogger.Info("接收到平仓信息:%v", string(message)) + + // 持仓订单缓存数据序列化解析 + var resultMsg option.OptionInrTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v OptionInrMqClosingBusiness.Unmarshal:%v", common.ErrOptionInr, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := OptionInrLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v OptionInrMqClosingBusiness.OptionInrLiquidationPosition:%v", common.ErrOptionInr, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + time.Sleep(2 * time.Second) + } + } +} + +// OptionInrLiquidationPosition +// +// @Description: 期权-印度股持仓-->平仓业务处理 +// @param ctx +// @param order +// @return error +func OptionInrLiquidationPosition(ctx context.Context, order *option.OptionInrTallyCache) error { + // 1、平仓操作 + err := OptionInrClosingOrder(ctx, Msql, order.OrderId, order.ClosingPrice, order.Order) + if err != nil { + applogger.Error("%v OptionInrLiquidationPosition.OptionInrClosingOrder:%v", common.ErrOptionInr, err) + return err + } + + // 2、平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.OptionInrSubscribe, order.UserId) + if err = UpdateOptionInrSubscribeHashStatusByOrderId(order.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v OptionInrLiquidationPosition.Position.OptionInrSubscribe:%v", common.ErrOptionInr, err) + return err + } + + // 3、平仓更新管理员订阅订单状态 + if err = UpdateOptionInrSubscribeHashStatusByOrderId(order.OrderId, setting.AdminOptionInrSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v OptionInrLiquidationPosition.Position.AdminOptionInrSubscribe:%v", common.ErrOptionInr, err) + return err + } + + return nil +} + +// OptionInrVoteStopType +// +// @Description: 期权-印度股交易下单判定 +// @param order +// @return bool +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func OptionInrVoteStopType(order structure.ShareOrder) (bool, decimal.Decimal, decimal.Decimal, error) { + var checkBool bool + var stopWinPrice, stopLossPrice decimal.Decimal + switch order.StopType { + case flags.StopTypeNone: // 暂无设置止盈止损 + checkBool = false + case flags.StopTypeSet: // 设置止盈止损 + checkBool = true + if len(order.StopWinPrice) != 0 { + stopWinPrice = decimal.RequireFromString(order.StopWinPrice) + } + if len(order.StopLossPrice) != 0 { + stopLossPrice = decimal.RequireFromString(order.StopLossPrice) + } + default: + return checkBool, stopWinPrice, stopLossPrice, flags.ErrContractThirteen + } + + return checkBool, stopWinPrice, stopLossPrice, nil +} + +// GetOptionInrPrice +// +// @Description: 期权-印度股股票价格 +// @param symbol +// @return decimal.Decimal +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func GetOptionInrPrice(stockCode string) (decimal.Decimal, decimal.Decimal, decimal.Decimal, error) { + var err error + var priceByte, priceBid, priceAsk []byte + var newPrice, bidPrice, askPrice decimal.Decimal + + // 交易价格 + priceKey := publicData.SymbolCache(flags.Opi, stockCode, flags.OptionPrice) + priceByte, err = memory.GetOptionInrCache(priceKey) + if err != nil { + return decimal.Decimal{}, decimal.Decimal{}, decimal.Decimal{}, err + } + newPrice, _ = decimal.NewFromString(string(priceByte)) + + // 买一价格 + bidKey := publicData.SymbolCache(flags.Opi, stockCode, flags.OptionBid) + priceBid, err = memory.GetOptionInrBid(bidKey) + if err != nil { + return decimal.Decimal{}, decimal.Decimal{}, decimal.Decimal{}, err + } + bidPrice, _ = decimal.NewFromString(string(priceBid)) + + // 卖一价格 + askKey := publicData.SymbolCache(flags.Opi, stockCode, flags.OptionAsk) + priceAsk, err = memory.GetOptionInrAsk(askKey) + if err != nil { + return decimal.Decimal{}, decimal.Decimal{}, decimal.Decimal{}, err + } + askPrice, _ = decimal.NewFromString(string(priceAsk)) + + applogger.Info("optionInrCode:%v,optionInrPrice:%v,optionInrBid:%v,optionInrAsk:%v", stockCode, newPrice, bidPrice, askPrice) + + return newPrice, bidPrice, askPrice, nil +} + +// GetOptionInrStrike +// +// @Description: 期权-印度获取股票行权价 +// @param symbol +// @param Expiry +// @return decimal.Decimal +// @return error +func GetOptionInrStrike(symbol, Expiry string) (decimal.Decimal, error) { + var err error + var priceByte []byte + key := publicData.SymbolCache(flags.OpiStk, symbol, flags.TradeTypePrice) + priceByte, err = memory.GetOptionInrStrike(key) + if err != nil { + return decimal.Decimal{}, err + } + + var strikePrice map[string]decimal.Decimal + if err = json.Unmarshal(priceByte, &strikePrice); err != nil { + return decimal.Decimal{}, err + } + + var strike decimal.Decimal + for day, value := range strikePrice { + if day == Expiry { + strike = value + } + } + + applogger.Info("optionInrCode:%v,topIc:%v,optionInrStrikePrice:%v", symbol, key, strikePrice) + + return strike, nil +} diff --git a/internal/data/subscribe_share_blk.go b/internal/data/subscribe_share_blk.go new file mode 100644 index 0000000..b2f51f0 --- /dev/null +++ b/internal/data/subscribe_share_blk.go @@ -0,0 +1,1439 @@ +package data + +import ( + "context" + "encoding/json" + "github.com/shopspring/decimal" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/socket/shareData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "sync" + "time" +) + +/* +大宗(美股|泰股|马股|印尼股|印度股|新加坡股|港股|英股)交易股票行情订阅 +1、接收用户大宗交易股下单的交易对大宗交易股行情 +2、将订阅行情写入内存中用于并发计算 +3、挂单(市价|限价)缓存队列处理-开仓 +4、持仓缓存队列处理-平仓 +*/ + +// InitCacheSymbolShareBlk +// +// @Description: 初始化大宗交易代码列表 +// @param ctx +// @param uo +func InitCacheSymbolShareBlk(ctx context.Context, uo *Data) { + for { + idnList, err := GetBotStockBlockListByStockId(ctx, uo) + if err != nil { + return + } + + for key, value := range idnList { + var cacheKey string + switch key { + case flags.ShareUsMarketType: // 美股 + cacheKey = setting.MarketShareBlkUs + case flags.ShareThaMarketType: // 泰股 + cacheKey = setting.MarketShareBlkTha + case flags.ShareMysMarketType: // 马股 + cacheKey = setting.MarketShareBlkMys + case flags.ShareIdnMarketType: // 印尼股 + cacheKey = setting.MarketShareBlkIdn + case flags.ShareInrMarketType: // 印度股 + cacheKey = setting.MarketShareBlkInr + case flags.ShareSgdMarketType: // 新加坡股 + cacheKey = setting.MarketShareBlkSgd + case flags.ShareHkdMarketType: // 港股 + cacheKey = setting.MarketShareBlkHkd + case flags.ShareGbxMarketType: // 英股 + cacheKey = setting.MarketShareBlkGbx + case flags.ShareEurMarketType: // 德股 + cacheKey = setting.MarketShareBlkEur + case flags.ShareFurMarketType: // 法股 + cacheKey = setting.MarketShareBlkFur + case flags.ShareBrlMarketType: // 巴西股 + cacheKey = setting.MarketShareBlkBrl + case flags.ShareJpyMarketType: // 日股 + cacheKey = setting.MarketShareBlkJpy + default: + continue + } + for _, vue := range value { + if err = InitRedisBlk(uo, vue, cacheKey); err != nil { + continue + } + } + } + + time.Sleep(10 * time.Second) + } +} + +// InitRedisBlk +// +// @Description: +// @param uo +// @param vue +// @param key +// @return error +func InitRedisBlk(uo *Data, vue, key string) error { + checkBool, err := Reds.HExists(context.Background(), key, vue).Result() + if err != nil { + applogger.Error("%v InitCacheSymbolShareBlk.%v.HExists:%v", common.ErrShareBlk, key, err) + return err + } + if !checkBool { + if err = uo.redisDB.HSet(context.Background(), key, vue, vue).Err(); err != nil { + applogger.Error("%v InitCacheSymbolShareBlk.%v.HSet:%v", common.ErrShareBlk, key, err) + return err + } + } + if !flags.CheckSetting { + applogger.Info("初始化大宗交易股票代码:%v", vue) + } + + return nil +} + +// InitSubscribeShareBlk +// +// @Description: 初始化大宗交易代码缓存 +// @param shareBlk +func InitSubscribeShareBlk( + shareUs *ShareUsSymbol, shareTha *ShareThaSymbol, + shareMys *ShareMysSymbol, shareIdn *ShareIdnSymbol, + shareInr *ShareInrSymbol, shareSgd *ShareSgdSymbol, + shareHkd *ShareHkdSymbol, shareGbx *ShareGbxSymbol, + shareEur *ShareEurSymbol, shareFur *ShareFurSymbol, + shareBrl *ShareBrlSymbol, shareJpy *ShareJpySymbol) { + go InitSubscribeShareUs(shareUs, true) // 初始化美股交易代码缓存 + go InitSubscribeShareTha(shareTha, true) // 初始化泰股交易代码缓存 + go InitSubscribeShareMys(shareMys, true) // 初始化马股交易代码缓存 + go InitSubscribeShareIdn(shareIdn, true) // 初始化印尼股交易代码缓存 + go InitSubscribeShareInr(shareInr, true) // 初始化印度股交易代码缓存 + go InitSubscribeShareSgd(shareSgd, true) // 初始化新加坡股交易代码缓存 + go InitSubscribeShareHkd(shareHkd, true) // 初始化港股交易代码缓存 + go InitSubscribeShareGbx(shareGbx, true) // 初始化英股交易代码缓存 + go InitSubscribeShareEur(shareEur, true) // 初始化德股交易代码缓存 + go InitSubscribeShareFur(shareFur, true) // 初始化法股交易代码缓存 + go InitSubscribeShareBrl(shareBrl, true) // 初始化巴西股交易代码缓存 + go InitSubscribeShareJpy(shareJpy, true) // 初始化日本股交易代码缓存 +} + +// InitShareBlkCloseCachePrice +// +// @Description: +// @param shareUs +// @param shareTha +// @param shareMys +// @param shareIdn +// @param shareInr +// @param shareSgd +// @param shareHkd +func InitShareBlkCloseCachePrice() { + go InitShareUsCloseCachePrice(true) // 初始化美股交易代码闭盘价缓存 + go InitShareThaCloseCachePrice(true) // 初始化泰股交易代码闭盘价缓存 + go InitShareMysCloseCachePrice(true) // 初始化马股交易代码闭盘价缓存 + go InitShareIdnCloseCachePrice(true) // 初始化印尼股交易代码闭盘价缓存 + go InitShareInrCloseCachePrice(true) // 初始化印度股交易代码闭盘价缓存 + go InitShareSgdCloseCachePrice(true) // 初始化新加坡股交易代码闭盘价缓存 + go InitShareHkdCloseCachePrice(true) // 初始化港股交易代码闭盘价缓存 + go InitShareGbxCloseCachePrice(true) // 初始化英股交易代码闭盘价缓存 + go InitShareEurCloseCachePrice(true) // 初始化德股交易代码闭盘价缓存 + go InitShareFurCloseCachePrice(true) // 初始化法股交易代码闭盘价缓存 + go InitShareBrlCloseCachePrice(true) // 初始化巴西股交易代码闭盘价缓存 + go InitShareJpyCloseCachePrice(true) // 初始化日本股交易代码闭盘价缓存 +} + +// InitShareBlkSetUpPrice +// +// @Description: +func InitShareBlkSetUpPrice() { + go InitShareUsPriceSetUp(true) // 初始化美股交易代码插针价缓存 + go InitShareThaPriceSetUp(true) // 初始化泰股交易代码插针价缓存 + go InitShareMysPriceSetUp(true) // 初始化马股交易代码插针价缓存 + go InitShareIdnPriceSetUp(true) // 初始化印尼股交易代码插针价缓存 + go InitShareInrPriceSetUp(true) // 初始化印度股交易代码插针价缓存 + go InitShareSgdPriceSetUp(true) // 初始化新加坡股交易代码插针价缓存 + go InitShareHkdPriceSetUp(true) // 初始化港股交易代码插针价缓存 + go InitShareGbxPriceSetUp(true) // 初始化英股交易代码插针价缓存 + go InitShareEurPriceSetUp(true) // 初始化德股交易代码插针价缓存 + go InitShareFurPriceSetUp(true) // 初始化法股交易代码插针价缓存 + go InitShareBrlPriceSetUp(true) // 初始化巴西股交易代码插针价缓存 + go InitShareJpyPriceSetUp(true) // 初始化日本股交易代码插针价缓存 +} + +// SubscribeShareBlk +// +// @Description: 大宗交易下单交易对行情订阅 +// @param ctx +// @param data +// @param shareUs 美股 +// @param shareTha 泰股 +// @param shareMys 马股 +// @param shareIdn 印尼股 +// @param shareInr 印度股 +// @param shareSgd 新加坡股 +// @param shareHkd 港股 +// @param shareGbx 英股 +func SubscribeShareBlk() { + go InitShareUsCloseNewPrice(true) + go InitShareThaCloseNewPrice(true) + go InitShareMysCloseNewPrice(true) + go InitShareIdnCloseNewPrice(true) + go InitShareInrCloseNewPrice(true) + go InitShareSgdCloseNewPrice(true) + go InitShareHkdCloseNewPrice(true) + go InitShareGbxCloseNewPrice(true) + go InitShareFurCloseNewPrice(true) + go InitShareEurCloseNewPrice(true) + go InitShareBrlCloseNewPrice(true) + go InitShareJpyCloseNewPrice(true) +} + +// OrderSubAdminShareBlkSubscribeBySum +// +// @Description: 大宗交易持仓订单浮动盈亏 +// @param uo +func OrderSubAdminShareBlkSubscribeBySum() { + for { + var topIc = setting.AdminShareBlkSubscribe + hashMap, err := Reds.HGetAll(context.Background(), topIc).Result() + if err != nil { + applogger.Error("OrderSubAdminShareBlkSubscribeBySum.HGetAll:%v", err) + time.Sleep(5 * time.Second) + continue + } + var hashList []share.ShareBlkTallyCache + for _, value := range hashMap { + var msg share.ShareBlkTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + switch msg.Status { + case flags.Entrust: // 挂单 + case flags.Position: // 持仓 + hashList = append(hashList, msg) + default: // 平仓|撤单 + err = Reds.HDel(context.Background(), topIc, msg.OrderId).Err() + if err != nil { + applogger.Error("OrderSubAdminShareBlkSubscribeBySum.HDel:%v", err) + continue + } + } + } + applogger.Info("大宗交易股数据量统计:%v", len(hashList)) + // 统计泰股总持仓订单浮动盈亏 + priceSum := decimal.Zero + for _, value := range hashList { + orderModel := shareData.ShareBlkOrderProcessing(topIc, 1, value) + if orderModel != nil { + if len(orderModel.Price) == 0 || len(orderModel.OpenPrice) == 0 { + continue + } + var subPrice decimal.Decimal + newPrice := decimal.RequireFromString(orderModel.Price) + openPrice := decimal.RequireFromString(orderModel.OpenPrice) + switch value.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + price := subPrice.Mul(decimal.RequireFromString(value.Order.OrderNumber)) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + // 写入缓存 + if err = memory.ShareBlkFloating.Set(flags.FloatingBlk, []byte(priceSum.String())); err != nil { + applogger.Error("统计大宗交易股持仓订单浮动盈亏错误:%v", err) + time.Sleep(5 * time.Second) + continue + } + applogger.Info("统计大宗交易股持仓订单浮动盈亏:%v", priceSum) + + time.Sleep(1 * time.Second) + } +} + +// ShareBlkTransactionEntrust +// +// @Description: 大宗(美股|泰股|马股|印尼股|印度股|新加坡股|港股|英股|巴西股|日本股)交易挂单信息缓存队列 +// @param ctx +func ShareBlkTransactionEntrust(ctx context.Context) { + go ShareBlkUsTransactionEntrust(ctx) + go ShareBlkThaTransactionEntrust(ctx) + go ShareBlkMysTransactionEntrust(ctx) + go ShareBlkIdnTransactionEntrust(ctx) + go ShareBlkInrTransactionEntrust(ctx) + go ShareBlkSgdTransactionEntrust(ctx) + go ShareBlkHkdTransactionEntrust(ctx) + go ShareBlkGbxTransactionEntrust(ctx) + go ShareBlkEurTransactionEntrust(ctx) + go ShareBlkFurTransactionEntrust(ctx) + go ShareBlkBrlTransactionEntrust(ctx) + go ShareBlkJpyTransactionEntrust(ctx) +} + +// ShareBlkUsTransactionEntrust +// +// @Description: 大宗(美股)交易 +// @param ctx +func ShareBlkUsTransactionEntrust(ctx context.Context) { + for { + ShareBlkUsTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareBlkThaTransactionEntrust +// +// @Description: 大宗(泰股)交易 +// @param ctx +func ShareBlkThaTransactionEntrust(ctx context.Context) { + for { + ShareBlkThaTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareBlkMysTransactionEntrust +// +// @Description: 大宗(马股)交易 +// @param ctx +func ShareBlkMysTransactionEntrust(ctx context.Context) { + for { + ShareBlkMysTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareBlkIdnTransactionEntrust +// +// @Description: 大宗(印尼股)交易 +// @param ctx +func ShareBlkIdnTransactionEntrust(ctx context.Context) { + for { + ShareBlkIdnTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareBlkInrTransactionEntrust +// +// @Description: 大宗(印度股)交易 +// @param ctx +func ShareBlkInrTransactionEntrust(ctx context.Context) { + for { + ShareBlkInrTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareBlkSgdTransactionEntrust +// +// @Description: 大宗(新加坡股)交易 +// @param ctx +func ShareBlkSgdTransactionEntrust(ctx context.Context) { + for { + ShareBlkSgdTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareBlkHkdTransactionEntrust +// +// @Description: 大宗(港股)交易 +// @param ctx +func ShareBlkHkdTransactionEntrust(ctx context.Context) { + for { + ShareBlkHkdTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareBlkGbxTransactionEntrust +// +// @Description: 大宗(英股)交易 +// @param ctx +func ShareBlkGbxTransactionEntrust(ctx context.Context) { + for { + ShareBlkGbxTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareBlkEurTransactionEntrust +// +// @Description: 大宗(德股)交易 +// @param ctx +func ShareBlkEurTransactionEntrust(ctx context.Context) { + for { + ShareBlkEurTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareBlkFurTransactionEntrust +// +// @Description: 大宗(德股)交易 +// @param ctx +func ShareBlkFurTransactionEntrust(ctx context.Context) { + for { + ShareBlkFurTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareBlkBrlTransactionEntrust +// +// @Description: 大宗(巴西股)交易 +// @param ctx +func ShareBlkBrlTransactionEntrust(ctx context.Context) { + for { + ShareBlkBrlTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareBlkJpyTransactionEntrust +// +// @Description: 大宗(日本股)交易 +// @param ctx +func ShareBlkJpyTransactionEntrust(ctx context.Context) { + for { + ShareBlkJpyTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareBlkUsTransactionCalculationEntrust +// +// @Description: 大宗(美股)交易挂单业务逻辑处理 +// @param ctx +func ShareBlkUsTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareBlkEntrust).Result() + if err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.HGetAll:%v", common.ErrShareBlk, err) + return + } + + for _, value := range orderMap { + var newPrice decimal.Decimal + var entrustUs share.ShareUsTallyCache + var entrust share.ShareBlkTallyCache + var msg = make(chan share.ShareUsTallyCache, 1) + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareBlk, err) + continue + } + if entrust.Order.Type != flags.ShareUsMarketType { + continue + } + newPrice = decimal.RequireFromString(entrust.OpenPrice) // 固定开仓设置价格 + entrustUs = share.ShareUsTallyCache{ + UserId: entrust.UserId, + OrderId: entrust.OrderId, + Symbol: entrust.Symbol, + Status: entrust.Status, + OpenPrice: entrust.OpenPrice, + ClosingPrice: entrust.ClosingPrice, + ClosingTime: entrust.ClosingTime, + Order: entrust.Order, + } + + wg.Add(1) + go func(value string) { + resultMsg := ShareBlockUsConcurrentComputingEntrustMarket(&entrustUs, newPrice, &wg) + msg <- resultMsg + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收大宗(美股)交易股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到大宗(美股)交易股持仓信息:%v", resultMsg) + } + // 开盘逻辑 + if err = ShareUsLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.ShareUsLiquidationEntrust:%v", common.ErrShareBlk, err) + + resultMsg.Status = flags.Entrust + resultMsg.OpenPrice = decimal.Zero.String() + byteStr, _ := json.Marshal(resultMsg) + _ = Reds.HSet(context.Background(), setting.MarketShareBlkEntrust, resultMsg.OrderId, string(byteStr)).Err() + continue + } + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.Marshal:%v", common.ErrShareBlk, err) + continue + } + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareBlkPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("大宗(美股)交易股挂单并发计算执行完毕......") +} + +// ShareBlkThaTransactionCalculationEntrust +// +// @Description: 大宗(泰股)交易挂单业务逻辑处理 +// @param ctx +func ShareBlkThaTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareBlkEntrust).Result() + if err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.HGetAll:%v", common.ErrShareBlk, err) + return + } + + for _, value := range orderMap { + var newPrice decimal.Decimal + var entrustTha share.ShareThaTallyCache + var entrust share.ShareBlkTallyCache + var msg = make(chan share.ShareThaTallyCache, 1) + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareBlk, err) + continue + } + if entrust.Order.Type != flags.ShareThaMarketType { + continue + } + newPrice = decimal.RequireFromString(entrust.OpenPrice) // 固定开仓设置价格 + entrustTha = share.ShareThaTallyCache{ + UserId: entrust.UserId, + OrderId: entrust.OrderId, + Symbol: entrust.Symbol, + Status: entrust.Status, + OpenPrice: entrust.OpenPrice, + ClosingPrice: entrust.ClosingPrice, + ClosingTime: entrust.ClosingTime, + Order: entrust.Order, + } + + wg.Add(1) + go func(value string) { + resultMsg := ShareBlockThaConcurrentComputingEntrustMarket(&entrustTha, newPrice, &wg) + msg <- resultMsg + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收大宗(泰股)交易股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到大宗(泰股)交易股持仓信息:%v", resultMsg) + } + // 开盘逻辑 + if err = ShareThaLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.ShareThaLiquidationEntrust:%v", common.ErrShareBlk, err) + + resultMsg.Status = flags.Entrust + resultMsg.OpenPrice = decimal.Zero.String() + byteStr, _ := json.Marshal(resultMsg) + _ = Reds.HSet(context.Background(), setting.MarketShareBlkEntrust, resultMsg.OrderId, string(byteStr)).Err() + continue + } + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.Marshal:%v", common.ErrShareBlk, err) + continue + } + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareBlkPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("大宗(泰股)交易股挂单并发计算执行完毕......") +} + +// ShareBlkMysTransactionCalculationEntrust +// +// @Description: 大宗(马股)交易挂单业务逻辑处理 +// @param ctx +func ShareBlkMysTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareBlkEntrust).Result() + if err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.HGetAll:%v", common.ErrShareBlk, err) + return + } + + for _, value := range orderMap { + var newPrice decimal.Decimal + var entrustMys share.ShareMysTallyCache + var entrust share.ShareBlkTallyCache + var msg = make(chan share.ShareMysTallyCache, 1) + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareBlk, err) + continue + } + if entrust.Order.Type != flags.ShareMysMarketType { + continue + } + newPrice = decimal.RequireFromString(entrust.OpenPrice) // 固定开仓设置价格 + entrustMys = share.ShareMysTallyCache{ + UserId: entrust.UserId, + OrderId: entrust.OrderId, + Symbol: entrust.Symbol, + Status: entrust.Status, + OpenPrice: entrust.OpenPrice, + ClosingPrice: entrust.ClosingPrice, + ClosingTime: entrust.ClosingTime, + Order: entrust.Order, + } + + wg.Add(1) + go func(value string) { + resultMsg := ShareBlockMysConcurrentComputingEntrustMarket(&entrustMys, newPrice, &wg) + msg <- resultMsg + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收大宗(马股)交易股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到大宗(马股)交易股持仓信息:%v", resultMsg) + } + // 开盘逻辑 + if err = ShareMysLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.ShareMysLiquidationEntrust:%v", common.ErrShareBlk, err) + + resultMsg.Status = flags.Entrust + resultMsg.OpenPrice = decimal.Zero.String() + byteStr, _ := json.Marshal(resultMsg) + _ = Reds.HSet(context.Background(), setting.MarketShareBlkEntrust, resultMsg.OrderId, string(byteStr)).Err() + continue + } + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.Marshal:%v", common.ErrShareBlk, err) + continue + } + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareBlkPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("大宗(马股)交易股挂单并发计算执行完毕......") +} + +// ShareBlkIdnTransactionCalculationEntrust +// +// @Description: 大宗(印尼股)交易挂单业务逻辑处理 +// @param ctx +func ShareBlkIdnTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareBlkEntrust).Result() + if err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.HGetAll:%v", common.ErrShareBlk, err) + return + } + + for _, value := range orderMap { + var newPrice decimal.Decimal + var entrustIdn share.ShareIdnTallyCache + var entrust share.ShareBlkTallyCache + var msg = make(chan share.ShareIdnTallyCache, 1) + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareBlk, err) + continue + } + if entrust.Order.Type != flags.ShareIdnMarketType { + continue + } + newPrice = decimal.RequireFromString(entrust.OpenPrice) // 固定开仓设置价格 + entrustIdn = share.ShareIdnTallyCache{ + UserId: entrust.UserId, + OrderId: entrust.OrderId, + Symbol: entrust.Symbol, + Status: entrust.Status, + OpenPrice: entrust.OpenPrice, + ClosingPrice: entrust.ClosingPrice, + ClosingTime: entrust.ClosingTime, + Order: entrust.Order, + } + + wg.Add(1) + go func(value string) { + resultMsg := ShareBlockIdnConcurrentComputingEntrustMarket(&entrustIdn, newPrice, &wg) + msg <- resultMsg + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收大宗(印尼股)交易股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到大宗(印尼股)交易股持仓信息:%v", resultMsg) + } + // 开盘逻辑 + if err = ShareIdnLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.ShareIdnLiquidationEntrust:%v", common.ErrShareBlk, err) + + resultMsg.Status = flags.Entrust + resultMsg.OpenPrice = decimal.Zero.String() + byteStr, _ := json.Marshal(resultMsg) + _ = Reds.HSet(context.Background(), setting.MarketShareBlkEntrust, resultMsg.OrderId, string(byteStr)).Err() + continue + } + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.Marshal:%v", common.ErrShareBlk, err) + continue + } + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareBlkPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("大宗(印尼股)交易股挂单并发计算执行完毕......") +} + +// ShareBlkInrTransactionCalculationEntrust +// +// @Description: 大宗(印度股)交易挂单业务逻辑处理 +// @param ctx +func ShareBlkInrTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareBlkEntrust).Result() + if err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.HGetAll:%v", common.ErrShareBlk, err) + return + } + + for _, value := range orderMap { + var newPrice decimal.Decimal + var entrustInr share.ShareInrTallyCache + var entrust share.ShareBlkTallyCache + var msg = make(chan share.ShareInrTallyCache, 1) + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareBlk, err) + continue + } + if entrust.Order.Type != flags.ShareInrMarketType { + continue + } + newPrice = decimal.RequireFromString(entrust.OpenPrice) // 固定开仓设置价格 + entrustInr = share.ShareInrTallyCache{ + UserId: entrust.UserId, + OrderId: entrust.OrderId, + Symbol: entrust.Symbol, + Status: entrust.Status, + OpenPrice: entrust.OpenPrice, + ClosingPrice: entrust.ClosingPrice, + ClosingTime: entrust.ClosingTime, + Order: entrust.Order, + } + + wg.Add(1) + go func(value string) { + resultMsg := ShareBlockInrConcurrentComputingEntrustMarket(&entrustInr, newPrice, &wg) + msg <- resultMsg + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收大宗(印度股)交易股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到大宗(印度股)交易股持仓信息:%v", resultMsg) + } + // 开盘逻辑 + if err = ShareInrLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.ShareInrLiquidationEntrust:%v", common.ErrShareBlk, err) + + resultMsg.Status = flags.Entrust + resultMsg.OpenPrice = decimal.Zero.String() + byteStr, _ := json.Marshal(resultMsg) + _ = Reds.HSet(context.Background(), setting.MarketShareBlkEntrust, resultMsg.OrderId, string(byteStr)).Err() + continue + } + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.Marshal:%v", common.ErrShareBlk, err) + continue + } + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareBlkPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("大宗(印度股)交易股挂单并发计算执行完毕......") +} + +// ShareBlkSgdTransactionCalculationEntrust +// +// @Description: 大宗(新加坡股)交易挂单业务逻辑处理 +// @param ctx +func ShareBlkSgdTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareBlkEntrust).Result() + if err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.HGetAll:%v", common.ErrShareBlk, err) + return + } + + for _, value := range orderMap { + var newPrice decimal.Decimal + var entrustSgd share.ShareSgdTallyCache + var entrust share.ShareBlkTallyCache + var msg = make(chan share.ShareSgdTallyCache, 1) + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareBlk, err) + continue + } + if entrust.Order.Type != flags.ShareSgdMarketType { + continue + } + newPrice = decimal.RequireFromString(entrust.OpenPrice) // 固定开仓设置价格 + entrustSgd = share.ShareSgdTallyCache{ + UserId: entrust.UserId, + OrderId: entrust.OrderId, + Symbol: entrust.Symbol, + Status: entrust.Status, + OpenPrice: entrust.OpenPrice, + ClosingPrice: entrust.ClosingPrice, + ClosingTime: entrust.ClosingTime, + Order: entrust.Order, + } + + wg.Add(1) + go func(value string) { + resultMsg := ShareBlockSgdConcurrentComputingEntrustMarket(&entrustSgd, newPrice, &wg) + msg <- resultMsg + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收大宗(新加坡股)交易股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到大宗(新加坡股)交易股持仓信息:%v", resultMsg) + } + // 开盘逻辑 + if err = ShareSgdLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.ShareSgdLiquidationEntrust:%v", common.ErrShareBlk, err) + + resultMsg.Status = flags.Entrust + resultMsg.OpenPrice = decimal.Zero.String() + byteStr, _ := json.Marshal(resultMsg) + _ = Reds.HSet(context.Background(), setting.MarketShareBlkEntrust, resultMsg.OrderId, string(byteStr)).Err() + continue + } + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.Marshal:%v", common.ErrShareBlk, err) + continue + } + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareBlkPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("大宗(新加坡股)交易股挂单并发计算执行完毕......") +} + +// ShareBlkHkdTransactionCalculationEntrust +// +// @Description: 大宗(港股)交易挂单业务逻辑处理 +// @param ctx +func ShareBlkHkdTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareBlkEntrust).Result() + if err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.HGetAll:%v", common.ErrShareBlk, err) + return + } + + for _, value := range orderMap { + var newPrice decimal.Decimal + var entrust share.ShareBlkTallyCache + var entrustHkd share.ShareHkdTallyCache + var msg = make(chan share.ShareHkdTallyCache, 1) + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareBlk, err) + continue + } + if entrust.Order.Type != flags.ShareHkdMarketType { + continue + + } + newPrice = decimal.RequireFromString(entrust.OpenPrice) // 固定开仓设置价格 + entrustHkd = share.ShareHkdTallyCache{ + UserId: entrust.UserId, + OrderId: entrust.OrderId, + Symbol: entrust.Symbol, + Status: entrust.Status, + OpenPrice: entrust.OpenPrice, + ClosingPrice: entrust.ClosingPrice, + ClosingTime: entrust.ClosingTime, + Order: entrust.Order, + } + + wg.Add(1) + go func(value string) { + resultMsg := ShareBlockHkdConcurrentComputingEntrustMarket(&entrustHkd, newPrice, &wg) + msg <- resultMsg + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收大宗(港股)交易股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到大宗(港股)交易股持仓信息:%v", resultMsg) + } + // 开盘逻辑 + if err = ShareHkdLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.ShareHkdLiquidationEntrust:%v", common.ErrShareBlk, err) + + resultMsg.Status = flags.Entrust + resultMsg.OpenPrice = decimal.Zero.String() + byteStr, _ := json.Marshal(resultMsg) + _ = Reds.HSet(context.Background(), setting.MarketShareBlkEntrust, resultMsg.OrderId, string(byteStr)).Err() + continue + } + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.Marshal:%v", common.ErrShareBlk, err) + continue + } + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareBlkPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("大宗(港股)交易股挂单并发计算执行完毕......") +} + +// ShareBlkGbxTransactionCalculationEntrust +// +// @Description: 大宗(英股)交易挂单业务逻辑处理 +// @param ctx +func ShareBlkGbxTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareBlkEntrust).Result() + if err != nil { + applogger.Error("%v ShareBlkGbxTransactionCalculationEntrust.HGetAll:%v", common.ErrShareBlk, err) + return + } + + for _, value := range orderMap { + var newPrice decimal.Decimal + var entrustSgd share.ShareGbxTallyCache + var entrust share.ShareBlkTallyCache + var msg = make(chan share.ShareGbxTallyCache, 1) + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareBlk, err) + continue + } + if entrust.Order.Type != flags.ShareGbxMarketType { + continue + } + newPrice = decimal.RequireFromString(entrust.OpenPrice) // 固定开仓设置价格 + entrustSgd = share.ShareGbxTallyCache{ + UserId: entrust.UserId, + OrderId: entrust.OrderId, + Symbol: entrust.Symbol, + Status: entrust.Status, + OpenPrice: entrust.OpenPrice, + ClosingPrice: entrust.ClosingPrice, + ClosingTime: entrust.ClosingTime, + Order: entrust.Order, + } + + wg.Add(1) + go func(value string) { + resultMsg := ShareBlockGbxConcurrentComputingEntrustMarket(&entrustSgd, newPrice, &wg) + msg <- resultMsg + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收大宗(英股)交易股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到大宗(英股)交易股持仓信息:%v", resultMsg) + } + // 开盘逻辑 + if err = ShareGbxLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.ShareGbxLiquidationEntrust:%v", common.ErrShareBlk, err) + + resultMsg.Status = flags.Entrust + resultMsg.OpenPrice = decimal.Zero.String() + byteStr, _ := json.Marshal(resultMsg) + _ = Reds.HSet(context.Background(), setting.MarketShareBlkEntrust, resultMsg.OrderId, string(byteStr)).Err() + continue + } + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v ShareBlkTransactionCalculationEntrust.Marshal:%v", common.ErrShareBlk, err) + continue + } + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareBlkPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("大宗(英股)交易股挂单并发计算执行完毕......") +} + +// ShareBlkEurTransactionCalculationEntrust +// +// @Description: 大宗(德股)交易挂单业务逻辑处理 +// @param ctx +func ShareBlkEurTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareBlkEntrust).Result() + if err != nil { + applogger.Error("%v ShareBlkEurTransactionCalculationEntrust.HGetAll:%v", common.ErrShareBlk, err) + return + } + + for _, value := range orderMap { + var newPrice decimal.Decimal + var entrustSgd share.ShareEurTallyCache + var entrust share.ShareBlkTallyCache + var msg = make(chan share.ShareEurTallyCache, 1) + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareBlkEurTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareBlk, err) + continue + } + if entrust.Order.Type != flags.ShareEurMarketType { + continue + } + newPrice = decimal.RequireFromString(entrust.OpenPrice) // 固定开仓设置价格 + entrustSgd = share.ShareEurTallyCache{ + UserId: entrust.UserId, + OrderId: entrust.OrderId, + Symbol: entrust.Symbol, + Status: entrust.Status, + OpenPrice: entrust.OpenPrice, + ClosingPrice: entrust.ClosingPrice, + ClosingTime: entrust.ClosingTime, + Order: entrust.Order, + } + + wg.Add(1) + go func(value string) { + resultMsg := ShareBlockEurConcurrentComputingEntrustMarket(&entrustSgd, newPrice, &wg) + msg <- resultMsg + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收大宗(德股)交易股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到大宗(德股)交易股持仓信息:%v", resultMsg) + } + // 开盘逻辑 + if err = ShareEurLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareBlkEurTransactionCalculationEntrust.ShareEurLiquidationEntrust:%v", common.ErrShareBlk, err) + + resultMsg.Status = flags.Entrust + resultMsg.OpenPrice = decimal.Zero.String() + byteStr, _ := json.Marshal(resultMsg) + _ = Reds.HSet(context.Background(), setting.MarketShareBlkEntrust, resultMsg.OrderId, string(byteStr)).Err() + continue + } + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v ShareBlkEurTransactionCalculationEntrust.Marshal:%v", common.ErrShareBlk, err) + continue + } + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareBlkPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("大宗(德股)交易股挂单并发计算执行完毕......") +} + +// ShareBlkFurTransactionCalculationEntrust +// +// @Description: 大宗(法股)交易挂单业务逻辑处理 +// @param ctx +func ShareBlkFurTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareBlkEntrust).Result() + if err != nil { + applogger.Error("%v ShareBlkFurTransactionCalculationEntrust.HGetAll:%v", common.ErrShareBlk, err) + return + } + + for _, value := range orderMap { + var newPrice decimal.Decimal + var entrustSgd share.ShareFurTallyCache + var entrust share.ShareBlkTallyCache + var msg = make(chan share.ShareFurTallyCache, 1) + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareBlkFurTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareBlk, err) + continue + } + if entrust.Order.Type != flags.ShareFurMarketType { + continue + } + newPrice = decimal.RequireFromString(entrust.OpenPrice) // 固定开仓设置价格 + entrustSgd = share.ShareFurTallyCache{ + UserId: entrust.UserId, + OrderId: entrust.OrderId, + Symbol: entrust.Symbol, + Status: entrust.Status, + OpenPrice: entrust.OpenPrice, + ClosingPrice: entrust.ClosingPrice, + ClosingTime: entrust.ClosingTime, + Order: entrust.Order, + } + + wg.Add(1) + go func(value string) { + resultMsg := ShareBlockFurConcurrentComputingEntrustMarket(&entrustSgd, newPrice, &wg) + msg <- resultMsg + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收大宗(法股)交易股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到大宗(法股)交易股持仓信息:%v", resultMsg) + } + // 开盘逻辑 + if err = ShareFurLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareBlkFurTransactionCalculationEntrust.ShareFurLiquidationEntrust:%v", common.ErrShareBlk, err) + + resultMsg.Status = flags.Entrust + resultMsg.OpenPrice = decimal.Zero.String() + byteStr, _ := json.Marshal(resultMsg) + _ = Reds.HSet(context.Background(), setting.MarketShareBlkEntrust, resultMsg.OrderId, string(byteStr)).Err() + continue + } + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v ShareBlkFurTransactionCalculationEntrust.Marshal:%v", common.ErrShareBlk, err) + continue + } + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareBlkPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("大宗(法股)交易股挂单并发计算执行完毕......") +} + +// ShareBlkBrlTransactionCalculationEntrust +// +// @Description: 大宗(巴西股)交易挂单业务逻辑处理 +// @param ctx +func ShareBlkBrlTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareBlkEntrust).Result() + if err != nil { + applogger.Error("%v ShareBlkBrlTransactionCalculationEntrust.HGetAll:%v", common.ErrShareBlk, err) + return + } + + for _, value := range orderMap { + var newPrice decimal.Decimal + var entrustSgd share.ShareBrlTallyCache + var entrust share.ShareBlkTallyCache + var msg = make(chan share.ShareBrlTallyCache, 1) + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareBlkBrlTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareBlk, err) + continue + } + if entrust.Order.Type != flags.ShareBrlMarketType { + continue + } + newPrice = decimal.RequireFromString(entrust.OpenPrice) // 固定开仓设置价格 + entrustSgd = share.ShareBrlTallyCache{ + UserId: entrust.UserId, + OrderId: entrust.OrderId, + Symbol: entrust.Symbol, + Status: entrust.Status, + OpenPrice: entrust.OpenPrice, + ClosingPrice: entrust.ClosingPrice, + ClosingTime: entrust.ClosingTime, + Order: entrust.Order, + } + + wg.Add(1) + go func(value string) { + resultMsg := ShareBlockBrlConcurrentComputingEntrustMarket(&entrustSgd, newPrice, &wg) + msg <- resultMsg + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收大宗(巴西股)交易股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到大宗(巴西股)交易股持仓信息:%v", resultMsg) + } + // 开盘逻辑 + if err = ShareBrlLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareBlkBrlTransactionCalculationEntrust.ShareBrlLiquidationEntrust:%v", common.ErrShareBlk, err) + + resultMsg.Status = flags.Entrust + resultMsg.OpenPrice = decimal.Zero.String() + byteStr, _ := json.Marshal(resultMsg) + _ = Reds.HSet(context.Background(), setting.MarketShareBlkEntrust, resultMsg.OrderId, string(byteStr)).Err() + continue + } + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v ShareBlkBrlTransactionCalculationEntrust.Marshal:%v", common.ErrShareBlk, err) + continue + } + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareBlkPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("大宗(巴西股)交易股挂单并发计算执行完毕......") +} + +// ShareBlkJpyTransactionCalculationEntrust +// +// @Description: 大宗(日股)交易挂单业务逻辑处理 +// @param ctx +func ShareBlkJpyTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareBlkEntrust).Result() + if err != nil { + applogger.Error("%v ShareBlkJpyTransactionCalculationEntrust.HGetAll:%v", common.ErrShareBlk, err) + return + } + + for _, value := range orderMap { + var newPrice decimal.Decimal + var entrustJpy share.ShareJpyTallyCache + var entrust share.ShareBlkTallyCache + var msg = make(chan share.ShareJpyTallyCache, 1) + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareBlkJpyTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareBlk, err) + continue + } + if entrust.Order.Type != flags.ShareJpyMarketType { + continue + } + newPrice = decimal.RequireFromString(entrust.OpenPrice) // 固定开仓设置价格 + entrustJpy = share.ShareJpyTallyCache{ + UserId: entrust.UserId, + OrderId: entrust.OrderId, + Symbol: entrust.Symbol, + Status: entrust.Status, + OpenPrice: entrust.OpenPrice, + ClosingPrice: entrust.ClosingPrice, + ClosingTime: entrust.ClosingTime, + Order: entrust.Order, + } + + wg.Add(1) + go func(value string) { + resultMsg := ShareBlockJpyConcurrentComputingEntrustMarket(&entrustJpy, newPrice, &wg) + msg <- resultMsg + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收大宗(日股)交易股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到大宗(日股)交易股持仓信息:%v", resultMsg) + } + // 开盘逻辑 + if err = ShareJpyLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareBlkJpyTransactionCalculationEntrust.ShareJpyLiquidationEntrust:%v", common.ErrShareBlk, err) + + resultMsg.Status = flags.Entrust + resultMsg.OpenPrice = decimal.Zero.String() + byteStr, _ := json.Marshal(resultMsg) + _ = Reds.HSet(context.Background(), setting.MarketShareBlkEntrust, resultMsg.OrderId, string(byteStr)).Err() + continue + } + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v ShareBlkJpyTransactionCalculationEntrust.Marshal:%v", common.ErrShareBlk, err) + continue + } + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareBlkPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("大宗(日股)交易股挂单并发计算执行完毕......") +} diff --git a/internal/data/subscribe_share_brl.go b/internal/data/subscribe_share_brl.go new file mode 100644 index 0000000..6b1e542 --- /dev/null +++ b/internal/data/subscribe_share_brl.go @@ -0,0 +1,1250 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/mq/consumer" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/socket/shareData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "sync" + "time" +) + +/* +巴西国股行情订阅 +1、接收用户巴西国股下单的交易对巴西国股行情 +2、将订阅行情写入内存中用于并发计算 +3、挂单(市价|限价)缓存队列处理-开仓 +4、持仓缓存队列处理-平仓 +*/ + +// ShareBrlMessage +// @Description: +type ShareBrlMessage struct { + Symbol string `json:"symbol,omitempty"` // 交易所:股票代码 + StockCode string `json:"stock_code,omitempty"` // 股票代码 + StockName string `json:"stock_name,omitempty"` // 股票名,可能为空 + Price decimal.Decimal `json:"price,omitempty"` // 实时价格 + UpDownRate decimal.Decimal `json:"up_down_rate,omitempty"` // 涨跌% + UpDown decimal.Decimal `json:"up_down,omitempty"` // 涨跌额 + TradeV decimal.Decimal `json:"trade_v,omitempty"` // 技术评级指标值 + TradeK string `json:"trade_k,omitempty"` // 技术评级 + Vol int64 `json:"vol,omitempty"` // 成交量 + TurnoverPriceTotal decimal.Decimal `json:"turnover_price_total,omitempty"` // 成交量*价格 + PriceTotal string `json:"price_total,omitempty"` // 总市值 + PE string `json:"p_e,omitempty"` // pe + Eps string `json:"eps,omitempty"` // EPS + EmployeesNumber string `json:"employees_number,omitempty"` // 雇员 + Plate string `json:"plate,omitempty"` // 板块 + Desc string `json:"desc,omitempty"` // 描述 + PriceCode string `json:"price_code,omitempty"` // 价格类型 + Country string `json:"country,omitempty"` // 国家 + Ts int64 `json:"ts,omitempty"` // 时间 + Token string `json:"token,omitempty"` // Token 令牌 +} + +// ShareBrlSymbol +// @Description: +type ShareBrlSymbol struct { + BrlMap chan []byte // 订单交易对 -- 用户下单通知订阅 + BrlSetMap chan []byte // 订单交易对 -- 用户盘前|盘后行情订阅 + BrlMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 + BrlSetMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 +} + +// InitCacheSymbolShareBrl +// +// @Description: +// @param ctx +// @param uo +func InitCacheSymbolShareBrl(ctx context.Context, uo *Data) { + for { + thaList, err := GetBotStockBrlListByStockId(ctx, uo) + if err != nil { + return + } + + for _, value := range thaList { + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := uo.redisDB.HExists(context.Background(), setting.MarketShareBrl, value).Result() + if err != nil { + applogger.Error("%v InitCacheSymbolShareBrl.MarketShareBrl.HExists:%v", common.ErrShareBrl, err) + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err = uo.redisDB.HSet(context.Background(), setting.MarketShareBrl, value, value).Err(); err != nil { + applogger.Error("%v InitCacheSymbolShareBrl.MarketShareBrl.HSet:%v", common.ErrShareBrl, err) + time.Sleep(5 * time.Second) + continue + } + } + if !flags.CheckSetting { + applogger.Info("初始化巴西股票代码:%v", value) + } + } + + time.Sleep(10 * time.Second) + } +} + +// InitSubscribeShareBrl +// +// @Description: 状态机加载订阅 +// @param ctx +// @param uo +// @param shareTha +func InitSubscribeShareBrl(shareBrl *ShareBrlSymbol, check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkBrl + } else { + key = setting.MarketShareBrl + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareBrl.LoadLRangeList:%v", common.ErrShareBrl, err) + return + } + + for _, value := range listSpots { + // Handling duplicate subscriptions + _, ok := shareBrl.BrlMapSymbol.Load(value) + if ok { + continue + } + + shareBrl.BrlMap <- []byte(value) + } + + time.Sleep(10 * time.Second) + } +} + +// InitShareBrlCloseCachePrice +// +// @Description: +// @param shareSgd +// @param check +func InitShareBrlCloseCachePrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkBrl + } else { + key = setting.MarketShareBrl + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareBrlCloseCachePrice.LoadLRangeList:%v", common.ErrShareBrl, err) + return + } + + for _, value := range listSpots { + SubscribeBrlClosePrice(value) // 处理闭盘取价 + } + + time.Sleep(20 * time.Second) + } +} + +// InitShareBrlCloseNewPrice +// +// @Description: 同步实时行情 +// @param check +func InitShareBrlCloseNewPrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkBrl + } else { + key = setting.MarketShareBrl + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareUs.LoadLRangeList:%v", common.ErrShareBrl, err) + time.Sleep(20 * time.Second) + continue + } + for _, value := range listSpots { + SubscribeBrlCloseNewPrice(value) + } + + time.Sleep(500 * time.Millisecond) + } +} + +// InitShareBrlPriceSetUp +// +// @Description: 同步插针行情 +// @param check +func InitShareBrlPriceSetUp(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkBrl + } else { + key = setting.MarketShareBrl + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareBrlPriceSetUp.LoadLRangeList:%v", common.ErrShareBrl, err) + time.Sleep(20 * time.Second) + continue + } + + for _, value := range listSpots { + brlKey := publicData.SymbolCache(flags.Brl, value, flags.TradeTypePrice) + brlSetCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareBrlMarketType, value) + vw, err := GetBeforeAndAfterSetPrice(brlSetCache) + if err != nil || len(vw) == 0 { + _ = memory.ShareBrlPriceSetUp.Delete(brlKey) + continue + } + if err = memory.ShareBrlPriceSetUp.Set(brlKey, []byte(vw)); err != nil { + applogger.Error("%v InitShareBrlPriceSetUp.ShareBrlPriceSetUp:%v", common.ErrShareBrl, err) + } + } + + time.Sleep(500 * time.Millisecond) + } +} + +// SubscribeBrlHSetCodeList +// +// @Description: 同步列表缓存 +// @param symbolStr +// @param check +func SubscribeBrlHSetCodeList(symbolStr string, check bool) { + var key string + if check { + key = setting.MarketShareBlkBrl + } else { + key = setting.MarketShareBrl + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + return + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeBrlHSetCodeList.%v.HSet:%v", common.ErrShareBrl, key, err) + return + } + } +} + +// SubscribeBrlCloseNewPrice +// +// @Description: 获取实时行情价 +// @param symbolStr +// @param check +func SubscribeBrlCloseNewPrice(symbolStr string) { + // 获取市场真实开闭盘时间 + timeValue, checkWeekday := MarketCheckOpenAndCloseTime(flags.ShareBrlMarketType) + // 判定是否盘中 + if utils.CheckInPlateTime(timeValue) && checkWeekday { + // 盘中实时价格 + realTimePrice, err := Reds.HGet(context.Background(), flags.ShareBrazilClosingNewPriceKey, symbolStr).Result() + if err != nil { + realTimePrice = decimal.Zero.String() + } + if realTimePrice != decimal.Zero.String() { + keys := publicData.SymbolCache(flags.Brl, symbolStr, flags.TradeTypePrice) + if err = memory.ShareBrlCache.Set(keys, []byte(realTimePrice)); err != nil { + applogger.Error("%v SubscribeBrlCloseNewPrice.ShareBrlCache:%v", common.ErrShareBrl, err) + } + } + } +} + +// SubscribeBrlClosePrice +// +// @Description: 获取闭盘价 +// @param symbolStr +func SubscribeBrlClosePrice(symbolStr string) { + var err error + var sub = decimal.Zero + var closeNewPrice, closingPrice, price string + + // 闭盘价格 + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareBrazilClosingNewPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareBrazilClosingPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice = decimal.Zero.String() + } + } + + // 市价(实时价格) + closingPrice, err = Reds.HGet(context.Background(), flags.ShareBrazilBeforeClose, symbolStr).Result() + if err != nil { + closingPrice = decimal.Zero.String() + } + + // 判定取值数据 + if closeNewPrice != decimal.Zero.String() { + price = closeNewPrice + } else { + price = closingPrice + } + closeKey := publicData.SymbolCache(flags.Brl, symbolStr, flags.TradeTypeClosePrice) + if err = memory.ShareBrlClosePrice.Set(closeKey, []byte(price)); err != nil { + applogger.Error("%v SubscribeBrlClosePrice.Set.price:%v", common.ErrShareBrl, err) + } + + // 写入涨跌幅价格判定缓存(计算涨跌幅 = 最新价格 - 闭盘价格(昨天关闭价格或者上次毕盘价格)) + cn := closeNewPrice != decimal.Zero.String() + cp := closingPrice != decimal.Zero.String() + lcn := utils.IsNumber(closeNewPrice) + lcp := utils.IsNumber(closingPrice) + if cn && cp && lcn && lcp { + sub = decimal.RequireFromString(closingPrice).Sub(decimal.RequireFromString(closeNewPrice)) + } + chgKey := publicData.SymbolCache(flags.Brl, symbolStr, flags.TradeTypeChg) // 涨跌幅标识Key + if err = memory.ShareBrlChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v SubscribeBrlClosePrice.Set.price:%v", common.ErrShareBrl, err) + } +} + +// OrderSubAdminShareBrlSubscribeBySum +// +// @Description: 持仓订单浮动盈亏计算 +// @param ctx +// @param uo +func OrderSubAdminShareBrlSubscribeBySum(uo *Data) { + for { + var topIc = setting.AdminShareBrlSubscribe + hashMap, err := uo.redisDB.HGetAll(context.Background(), topIc).Result() + if err != nil { + applogger.Error("OrderSubAdminShareBrlSubscribeBySum.HGetAll:%v", err) + time.Sleep(5 * time.Second) + continue + } + var hashList []share.ShareBrlTallyCache + for _, value := range hashMap { + var msg share.ShareBrlTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + switch msg.Status { + case flags.Entrust: // 挂单 + case flags.Position: // 持仓 + hashList = append(hashList, msg) + default: // 平仓|撤单 + err = uo.redisDB.HDel(context.Background(), topIc, msg.OrderId).Err() + if err != nil { + applogger.Error("OrderSubAdminShareBrlSubscribeBySum.HDel:%v", err) + continue + } + } + } + applogger.Info("巴西股数据量统计:%v", len(hashList)) + // 统计巴西股总持仓订单浮动盈亏 + priceSum := decimal.Zero + for _, value := range hashList { + orderModel := shareData.ShareBrlOrderProcessing(topIc, value) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch value.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + price := subPrice.Mul(decimal.RequireFromString(value.Order.OrderNumber)) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + + // 写入缓存 + if err = memory.ShareBrlFloating.Set(flags.FloatingBrl, []byte(priceSum.String())); err != nil { + applogger.Error("统计巴西股持仓订单浮动盈亏错误:%v", err) + time.Sleep(5 * time.Second) + continue + } + applogger.Info("统计的巴西股持仓订单浮动盈亏:%v", priceSum) + + time.Sleep(1 * time.Second) + } +} + +// SubscribeShareBrl +// +// @Description: TODO: 订阅 +// @param ctx +// @param uo +// @param shareBrl +func SubscribeShareBrl(ctx context.Context, shareBrl *ShareBrlSymbol, check bool) { + for { + select { + case symbol, _ := <-shareBrl.BrlMap: + symbolStr := string(symbol) + topIc := fmt.Sprintf("%v.%v", symbolStr, flags.CountryBrl) + // Handling duplicate subscriptions + _, ok := shareBrl.BrlMapSymbol.Load(symbolStr) + if ok { + time.Sleep(5 * time.Second) + continue + } + // Transaction determination + var key string + if check { + key = setting.MarketShareBlkBrl // 大宗股交易 + } else { + key = setting.MarketShareBrl // 巴西股交易 + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeShareBrl.%v.HSet:%v", common.ErrShareBrl, key, err) + time.Sleep(5 * time.Second) + continue + } + } + + // 处理订阅实时行情数据 + go func() { + symbolStrCache := symbolStr + pubSub := Reds.Subscribe(ctx, topIc) + defer pubSub.Close() + if _, err := pubSub.Receive(ctx); err != nil { + shareBrl.BrlMapSymbol.Delete(symbolStrCache) + return + } + ch := pubSub.Channel() + for { + select { + case msg, _ := <-ch: + var subMsg ShareBrlMessage + if err := json.Unmarshal([]byte(msg.Payload), &subMsg); err != nil { + applogger.Error("%v SubscribeShareBrl.Unmarshal:%v", common.ErrShareBrl, err) + time.Sleep(5 * time.Second) + continue + } + SubscribeBrlPrice(subMsg.Price.String(), symbolStr, flags.RealTime) + default: + Reds.Ping(ctx) // 如果没有消息,发送 PING 命令以维护连接 + time.Sleep(10 * time.Second) + } + } + }() + + // 监控盘前|盘后设置价格 + _, okc := shareBrl.BrlSetMapSymbol.Load(symbolStr) + if !okc { + go func() { + for { + keyCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareBrlMarketType, symbolStr) + vw, err := GetBeforeAndAfterSetPrice(keyCache) + if err != nil || len(vw) == 0 { + priceCache := publicData.SymbolCache(flags.Brl, symbolStr, flags.TradeTypePrice) + memory.ShareBrlPriceSetUp.Delete(priceCache) + time.Sleep(15 * time.Second) + continue + } + SubscribeBrlPrice(vw, symbolStr, flags.SetUp) + time.Sleep(10 * time.Second) + } + }() + // Write cache to determine whether to repeatedly open the protocol + shareBrl.BrlSetMapSymbol.Store(symbolStr, symbolStr) + } + + // Write in the map to determine whether to repeat subscription + shareBrl.BrlMapSymbol.Store(symbolStr, symbolStr) + } + } +} + +// SubscribeBrlPrice +// +// @Description: TODO: 订阅获取股实时价格或者[盘前|盘后]设置价格 +// @param setPrice +// @param symbolStr +// @param check +func SubscribeBrlPrice(setPrice, symbolStr string, check int) { + var err error + var sub = decimal.Zero + + // 计算涨跌幅 + yClosingPrice, err := Reds.HGet(context.Background(), flags.ShareBrazilClosingPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice, err = Reds.HGet(context.Background(), flags.ShareBrazilClosingNewPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice = setPrice + sub = decimal.Zero + } + } + + // 写入涨跌幅缓存数据 + yc := yClosingPrice != decimal.Zero.String() + sp := setPrice != decimal.Zero.String() + lyc := utils.IsNumber(yClosingPrice) + lsp := utils.IsNumber(setPrice) + if yc && sp && lyc && lsp { + sub = decimal.RequireFromString(setPrice).Sub(decimal.RequireFromString(yClosingPrice)) + } + chgKey := publicData.SymbolCache(flags.Brl, symbolStr, flags.TradeTypeChg) + if err = memory.ShareBrlChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v SubscribeBrlPrice.ShareBrlChgMark.Set.price:%v", common.ErrShareBrl, err) + } + if !flags.CheckSetting { + applogger.Debug("涨跌幅交易对内存key:%v,涨跌幅数值:%v", symbolStr, sub) + } + + // 交易类型:0最新价,1买入,2卖出 + price := publicData.SymbolCache(flags.Brl, symbolStr, flags.TradeTypePrice) + switch check { + case flags.RealTime: // 实时价格(优先级高) + if err = memory.ShareBrlCache.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeBrlPrice.ShareBrlCache.Set.price:%v", common.ErrShareBrl, err) + } + case flags.SetUp: // 设置[盘前|盘后]价格 + if err = memory.ShareBrlPriceSetUp.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeBrlPrice.ShareBrlPriceSetUp:%v", common.ErrShareBrl, err) + } + } + if !flags.CheckSetting { + applogger.Debug("股票交易对内存Key:%v,最新价格:%v", price, setPrice) + } +} + +// SubscribeBrlSetForcedClosure +// +// @Description: TODO: 处理股强平阈值 +// @param symbolStr +func SubscribeBrlSetForcedClosure(symbolStr string) { + flatRatio := GetCacheForcedClosure(flags.StockBRLSystemSetUpKey, symbolStr) + chgKey := publicData.SymbolCache(flags.Brl, symbolStr, flags.TradeTypeForcedClosure) + if err := memory.ShareBrlForcedClosure.Set(chgKey, []byte(flatRatio.String())); err != nil { + applogger.Error("%v SubscribeBrlSetForcedClosure.ShareBrlForcedClosure err:%v", common.ErrShareBrl, err) + return + } +} + +// ShareBrlTransactionEntrust +// +// @Description: 巴西股委托订单 +// @param ctx +func ShareBrlTransactionEntrust(ctx context.Context) { + for { + ShareBrlTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareBrlTransactionCalculationEntrust +// +// @Description: 巴西股挂单缓存队列计算 +// @param ctx +func ShareBrlTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 全局变量处理 + if CheckGlobalTread(flags.BrlMarket) { + time.Sleep(5 * time.Second) + return + } + + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareBrlEntrust).Result() + if err != nil { + applogger.Error("%v ShareBrlTransactionCalculationEntrust.HGetAll:%v", common.ErrShareBrl, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareBrlTallyCache, 1) + var entrust share.ShareBrlTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareBrlTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareBrl, err) + continue + } + + // 股票实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareBrlPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareBrlTransactionCalculationEntrust.GetShareBrlPrice:%v---%v", common.ErrShareBrl, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + chg := GetShareChgBrl(flags.Brl, entrust.Symbol) // 涨跌幅标识 + if share.CheckOrderBrlByChg(setting.MarketShareBrlEntrust, entrust, chg) { + continue + } + + wg.Add(1) + go func(value string) { + var resultMsg share.ShareBrlTallyCache + switch entrust.Order.DealType { + case flags.DealTypeLimited: // 限价挂单 + resultMsg = ShareBrlConcurrentComputingEntrustLimited(&entrust, newPrice, &wg) + case flags.DealTypeMarket: // 市价挂单(开盘即成交) + resultMsg = ShareBrlConcurrentComputingEntrustMarket(&entrust, newPrice, &wg) + } + msg <- resultMsg // 通知管道异步处理订单操作 + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收巴西股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到巴西股持仓信息:%v", resultMsg) + } + + // 开盘逻辑 + if err = ShareBrlLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Warn("%v ShareBrlTransactionCalculationEntrust.ShareBrlLiquidationEntrust:%v", common.ErrShareBrl, err) + continue + } + + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Warn("%v ShareBrlTransactionCalculationEntrust.Marshal:%v", common.ErrShareBrl, err) + continue + } + + // TODO: 写入持仓消息队列 + //if err = uo.mqProducer.Entrust.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareBrlTransactionCalculationEntrust.PushNotice:%v", common.ErrShareBrl, err) + // continue + //} + + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareBrlPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("巴西股挂单并发计算执行完毕......") +} + +// ShareBrlConcurrentComputingEntrustLimited +// +// @Description: 巴西股挂单(限价|市价)缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareBrlTallyCache +func ShareBrlConcurrentComputingEntrustLimited(order *share.ShareBrlTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareBrlTallyCache { + var deleteCache bool + var dealPrice string + var limitPrice = decimal.RequireFromString(order.Order.LimitPrice) // 限价-价格 + var status = order.Status // 原始价格 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价买入逻辑判定 -> 挂单金额 > 当前价格 + if limitPrice.Cmp(newPrice) > 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + } + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价卖入逻辑判定 -> 挂单金额 < 当前价格 + if limitPrice.Cmp(newPrice) < 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareBrlEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareSgdConcurrentComputingEntrustLimited.MarketShareSgdEntrust.HDel:%v", common.ErrShareBrl, err) + order.Status = status + } + } + + wg.Done() + return share.ShareBrlTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareBrlConcurrentComputingEntrustMarket +// +// @Description: 巴西股市价下单进入挂单队列(休市) +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareBrlTallyCache +func ShareBrlConcurrentComputingEntrustMarket(order *share.ShareBrlTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareBrlTallyCache { + var deleteCache bool + var dealPrice string + var marketPrice = decimal.RequireFromString(order.Order.MarketPrice) // 市价-价格 + var status = order.Status // 原始价格记录 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareBrlEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareBrlConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareBrl, err) + order.Status = status + } + } + + wg.Done() + return share.ShareBrlTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareBlockBrlConcurrentComputingEntrustMarket +// +// @Description: 大宗(巴西股)交易 +// @param order +// @param newPrice +// @param wg +// @return share.ShareSgdTallyCache +func ShareBlockBrlConcurrentComputingEntrustMarket(order *share.ShareBrlTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareBrlTallyCache { + var status = order.Status // 原始状态 + + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareBlkEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareBlockBrlConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareBlk, err) + order.Status = status + } + + wg.Done() + return share.ShareBrlTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: newPrice.String(), // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareBrlMqOpenBusiness +// +// @Description: TODO: 巴西股持仓消息队列 +// @param ctx +// @param uo +func ShareBrlMqOpenBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Entrust.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerEntrustMq.ShareBrlMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareBrlMqOpenBusiness.ShareBrlMq err....", common.ErrShareSgd) + continue + } + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareBrlTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareBrlMqOpenBusiness.Unmarshal:%v", common.ErrShareSgd, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareBrlLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareBrlMqOpenBusiness.ShareBrlLiquidationEntrust:%v", common.ErrShareSgd, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + applogger.Info("这里没有监控到持仓mq队列消息.........") + time.Sleep(2 * time.Second) + } + } +} + +// ShareBrlLiquidationEntrust +// +// @Description: 巴西股挂单-->开仓业务处理 +// @param ctx +// @param order +// @return error +func ShareBrlLiquidationEntrust(ctx context.Context, order *share.ShareBrlTallyCache) error { + // 1、开盘 + err := StockBrlOpenOrder(ctx, Msql, order.UserId, order.OrderId, order.OpenPrice, order.Order) + if err != nil { + applogger.Error("%v ShareBrlLiquidationEntrust.StockBrlOpenOrder:%v", common.ErrShareBrl, err) + return err + } + + // 大宗(新加坡股)交易判定 + var entrustKey, adminKey string + if !CheckTypeStatus(order.Order.Type) { + entrustKey = setting.ShareBrlSubscribe + adminKey = setting.AdminShareBrlSubscribe + } else { + entrustKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // 2、更新用户订阅缓存列表订单状态 + updateKey := virtual.OrderIdListKey(entrustKey, order.UserId) + if err = UpdateShareBrlSubscribeHashStatusByOrderId(order.OrderId, updateKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareBrlLiquidationEntrust.Entrust.%v:%v", common.ErrShareBrl, entrustKey, err) + return err + } + + // 3、更新管理员订阅缓存列表订单状态 + if err = UpdateShareBrlSubscribeHashStatusByOrderId(order.OrderId, adminKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareBrlLiquidationEntrust.Entrust.%v:%v", common.ErrShareBrl, adminKey, err) + return err + } + + return nil +} + +// ShareBrlTransactionPosition +// +// @Description: 巴西股持仓订单 +// @param ctx +func ShareBrlTransactionPosition(ctx context.Context) { + for { + ShareBrlTransactionCalculationPosition(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareBrlTransactionCalculationPosition +// +// @Description: 巴西股持仓缓存队列计算 +// @param ctx +func ShareBrlTransactionCalculationPosition(ctx context.Context) { + var wg sync.WaitGroup + + // 判定是否交易 + if CheckGlobalTread(flags.BrlMarket) { + time.Sleep(5 * time.Second) + return + } + + // TODO: 获取IPO未支付订单缓存 + userIdMap, _ := GetBotUserArrears(ctx) + + // 获取持仓缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareBrlPosition).Result() + if err != nil { + applogger.Error("%v ShareBrlTransactionCalculationPosition.HGetAll:%v", common.ErrShareBrl, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareBrlTallyCache, 1) + var entrust share.ShareBrlTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareBrlTransactionCalculationPosition.Unmarshal:%v", common.ErrShareBrl, err) + continue + } + + // TODO: 判定是否未IPO未支付订单-不能平仓 + _, isOk := userIdMap[entrust.UserId] + if isOk { + continue + } + + // 处理时间 + if !CheckShareSystemTime(entrust.ClosingTime) { + applogger.Debug("巴西股:%v,平仓时间:%v暂未到达...", entrust.Symbol, entrust.ClosingTime) + continue + } + + // TODO: 实时获取强平阈值 + //entrust.Order.System.StrongFlatRatio = GetForcedClosureValue(flags.Sgd, entrust.Symbol) + + // 股票实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareBrlPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareBrlTransactionCalculationPosition.GetShareBrlPrice:%v--%v", common.ErrShareBrl, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + chg := GetShareChgBrl(flags.Brl, entrust.Symbol) // 涨跌幅标识 + if share.CheckOrderBrlByChg(setting.MarketShareBrlEntrust, entrust, chg) { + continue + } + + // 判定配额强平 + checkFlattening := GetStrongFlatteningThreshold(entrust.UserId) + + wg.Add(1) + go func(value string) { + resultMsg := ShareBrlConcurrentComputingPosition(&entrust, newPrice, &wg, checkFlattening) + msg <- resultMsg + }(value) + + // 处理并发结果 + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Position: // 持仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到巴西股持仓信息:%v", resultMsg) + } + case flags.Close: // 平仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到巴西股平仓信息:%v", resultMsg) + } + + // TODO: 平仓操作(优化写入队列中等待平仓) + //var byteStr []byte + //byteStr, err = json.Marshal(resultMsg) + //if err != nil { + // applogger.Error("%v ShareBrlTransactionCalculationPosition.Marshal:%v", common.ErrShareBrl, err) + // continue + //} + //if err = uo.mqProducer.Position.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareBrlTransactionCalculationPosition.PushNotice:%v", common.ErrShareBrl, err) + // continue + //} + + // 平仓操作 + if err = ShareBrlLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareBrlTransactionCalculationPosition.ShareBrlLiquidationPosition:%v", common.ErrShareBrl, err) + continue + } + } + } + } + + wg.Wait() + applogger.Info("巴西股持仓并发计算执行完毕......") +} + +// ShareBrlConcurrentComputingPosition +// +// @Description: 巴西股持仓缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareBrlTallyCache +func ShareBrlConcurrentComputingPosition(order *share.ShareBrlTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup, checkFlattening bool) share.ShareBrlTallyCache { + var deleteCache, checkBool bool + var dealPrice string + var sellShort decimal.Decimal + var openPrice = decimal.RequireFromString(order.OpenPrice) // 限价 + var orderNumber = decimal.RequireFromString(order.Order.OrderNumber) // 仓位 + + var pryNum decimal.Decimal + lenPryNum := len(utils.ReplaceStr(order.Order.PryNum)) == 0 + if lenPryNum || order.Order.PryNum == flags.SetZero || order.Order.System.UserStatus != flags.SetThree || !utils.IsNumberInt(order.Order.PryNum) { + pryNum = decimal.RequireFromString(flags.SetOne) + } else { + pryNum = decimal.RequireFromString(order.Order.PryNum) + } + + // 下单判定设置(false无设置|true止盈止损) + _, stopWinPrice, stopLossPrice, _ := StockBrlVoteStopType(order.Order) + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨(强平) + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,持仓开仓价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买涨:挂止损止盈,止盈价必须<当前价,止损价必须>当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + // 强行平仓(做多) + if !checkBool { + sellShort = newPrice.Sub(openPrice).Mul(orderNumber) + } + case flags.TradeTypeSell: // 买跌(存在强行平仓) + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价持仓买跌下单价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买跌:挂止损止盈,止盈价必须>当前价,止损价必须<当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + // 强行平仓(做空) + if !checkBool { + sellShort = openPrice.Sub(newPrice).Mul(orderNumber) + } + } + /* 强行平仓(做多|做空) + 1、做多:(最新成交价-开仓成交价)*仓位 + 2、做空:(开仓成交价-最新成交价)*仓位 + 3、当浮动盈亏 >= 保证金的70%订单强行平仓 + */ + if sellShort.IsNegative() && checkFlattening { + orderAmount := newPrice.Mul(decimal.RequireFromString(order.Order.OrderNumber)).Div(pryNum) // 订单金额 = 当前价格 * 订单数量 / 杠杆 + floatPrice := orderAmount.Mul(decimal.RequireFromString(order.Order.System.StrongFlatRatio)) + if !flags.CheckSetting { + applogger.Debug("强平保证金:%v,强平浮动70:%v,强行平仓判定:%v", orderAmount, floatPrice, sellShort.Abs().Cmp(floatPrice)) + } + + if sellShort.Abs().Cmp(floatPrice) >= 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + switch order.Order.TradeType { + case flags.TradeTypeBuy: //买涨 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + case flags.TradeTypeSell: // 买跌 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + } + + if checkBool { + deleteCache = true + order.Status = flags.Close + } + + if deleteCache { + // 根据订单ID-删除持仓列表缓存订单 + if err := Reds.HDel(context.Background(), setting.MarketShareBrlPosition, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareBrlConcurrentComputingPosition.Position.HDel:%v", common.ErrShareBrl, err) + } + } + + wg.Done() + return share.ShareBrlTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + ClosingPrice: dealPrice, // 平仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareBrlMqClosingBusiness +// +// @Description: TODO: 处理巴西股平仓消息队列 +// @param ctx +// @param uo +func ShareBrlMqClosingBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Position.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerPositionMq.ShareBrlMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareBrlMqClosingBusiness.ShareBrlMq err....", common.ErrShareSgd) + continue + } + applogger.Info("接收到平仓信息:%v", string(message)) + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareBrlTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareBrlMqClosingBusiness.Unmarshal:%v", common.ErrShareSgd, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareBrlLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareBrlMqClosingBusiness.ShareBrlLiquidationPosition:%v", common.ErrShareSgd, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + time.Sleep(2 * time.Second) + } + } +} + +// ShareBrlLiquidationPosition +// +// @Description: 巴西股持仓-->平仓业务处理 +// @param ctx +// @param order +// @return error +func ShareBrlLiquidationPosition(ctx context.Context, order *share.ShareBrlTallyCache) error { + // 1、平仓操作 + err := StockBrlClosingOrder(ctx, Msql, order.OrderId, order.ClosingPrice, order.Order) + if err != nil { + applogger.Error("%v ShareBrlLiquidationPosition.StockBrlClosingOrder:%v", common.ErrShareBrl, err) + return err + } + + // 2、平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareBrlSubscribe, order.UserId) + if err = UpdateShareBrlSubscribeHashStatusByOrderId(order.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v ShareBrlLiquidationPosition.Position.ShareBrlSubscribe:%v", common.ErrShareBrl, err) + return err + } + + // 3、平仓更新管理员订阅订单状态 + if err = UpdateShareBrlSubscribeHashStatusByOrderId(order.OrderId, setting.AdminShareBrlSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v ShareBrlLiquidationPosition.Position.AdminShareBrlSubscribe:%v", common.ErrShareBrl, err) + return err + } + + return nil +} + +// StockBrlVoteStopType +// +// @Description: 巴西股判定取值止损止盈 +// @param order +// @return bool +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func StockBrlVoteStopType(order structure.ShareOrder) (bool, decimal.Decimal, decimal.Decimal, error) { + var checkBool bool + var stopWinPrice, stopLossPrice decimal.Decimal + switch order.StopType { + case flags.StopTypeNone: // 暂无设置止盈止损 + checkBool = false + case flags.StopTypeSet: // 设置止盈止损 + checkBool = true + stopWinPrice, _ = decimal.NewFromString(order.StopWinPrice) + stopLossPrice, _ = decimal.NewFromString(order.StopLossPrice) + default: + return checkBool, stopWinPrice, stopLossPrice, flags.ErrContractThirteen + } + + return checkBool, stopWinPrice, stopLossPrice, nil +} + +// GetShareBrlPrice +// +// @Description: 巴西股票价格 +// @param symbol +// @return decimal.Decimal +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func GetShareBrlPrice(symbol string) (decimal.Decimal, error) { + var err error + var priceByte []byte + var newPrice decimal.Decimal + + key := publicData.SymbolCache(flags.Brl, symbol, flags.TradeTypePrice) + priceByte, err = memory.GetShareBrlCache(key) + if err != nil { + return decimal.Decimal{}, err + } + + newPrice, err = decimal.NewFromString(string(priceByte)) + if err != nil { + return decimal.Decimal{}, err + } + + applogger.Info("GetShareBrlPrice:%v,topIc:%v,shareBrlPrice:%v", symbol, key, newPrice) + + return newPrice, nil +} diff --git a/internal/data/subscribe_share_eur.go b/internal/data/subscribe_share_eur.go new file mode 100644 index 0000000..56bc67b --- /dev/null +++ b/internal/data/subscribe_share_eur.go @@ -0,0 +1,1250 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/mq/consumer" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/socket/shareData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "sync" + "time" +) + +/* +德国股行情订阅 +1、接收用户德国股下单的交易对德国股行情 +2、将订阅行情写入内存中用于并发计算 +3、挂单(市价|限价)缓存队列处理-开仓 +4、持仓缓存队列处理-平仓 +*/ + +// ShareEurMessage +// @Description: +type ShareEurMessage struct { + Symbol string `json:"symbol,omitempty"` // 交易所:股票代码 + StockCode string `json:"stock_code,omitempty"` // 股票代码 + StockName string `json:"stock_name,omitempty"` // 股票名,可能为空 + Price decimal.Decimal `json:"price,omitempty"` // 实时价格 + UpDownRate decimal.Decimal `json:"up_down_rate,omitempty"` // 涨跌% + UpDown decimal.Decimal `json:"up_down,omitempty"` // 涨跌额 + TradeV decimal.Decimal `json:"trade_v,omitempty"` // 技术评级指标值 + TradeK string `json:"trade_k,omitempty"` // 技术评级 + Vol int64 `json:"vol,omitempty"` // 成交量 + TurnoverPriceTotal decimal.Decimal `json:"turnover_price_total,omitempty"` // 成交量*价格 + PriceTotal string `json:"price_total,omitempty"` // 总市值 + PE string `json:"p_e,omitempty"` // pe + Eps string `json:"eps,omitempty"` // EPS + EmployeesNumber string `json:"employees_number,omitempty"` // 雇员 + Plate string `json:"plate,omitempty"` // 板块 + Desc string `json:"desc,omitempty"` // 描述 + PriceCode string `json:"price_code,omitempty"` // 价格类型 + Country string `json:"country,omitempty"` // 国家 + Ts int64 `json:"ts,omitempty"` // 时间 + Token string `json:"token,omitempty"` // Token 令牌 +} + +// ShareEurSymbol +// @Description: +type ShareEurSymbol struct { + EurMap chan []byte // 订单交易对 -- 用户下单通知订阅 + EurSetMap chan []byte // 订单交易对 -- 用户盘前|盘后行情订阅 + EurMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 + EurSetMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 +} + +// InitCacheSymbolShareEur +// +// @Description: +// @param ctx +// @param uo +func InitCacheSymbolShareEur(ctx context.Context, uo *Data) { + for { + thaList, err := GetBotStockEurListByStockId(ctx, uo) + if err != nil { + return + } + + for _, value := range thaList { + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := uo.redisDB.HExists(context.Background(), setting.MarketShareEur, value).Result() + if err != nil { + applogger.Error("%v InitCacheSymbolShareEur.MarketShareEur.HExists:%v", common.ErrShareEur, err) + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err = uo.redisDB.HSet(context.Background(), setting.MarketShareEur, value, value).Err(); err != nil { + applogger.Error("%v InitCacheSymbolShareEur.MarketShareEur.HSet:%v", common.ErrShareEur, err) + time.Sleep(5 * time.Second) + continue + } + } + if !flags.CheckSetting { + applogger.Info("初始化德股票代码:%v", value) + } + } + + time.Sleep(10 * time.Second) + } +} + +// InitSubscribeShareEur +// +// @Description: 状态机加载订阅 +// @param ctx +// @param uo +// @param shareTha +func InitSubscribeShareEur(shareEur *ShareEurSymbol, check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkEur + } else { + key = setting.MarketShareEur + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareEur.LoadLRangeList:%v", common.ErrShareEur, err) + return + } + + for _, value := range listSpots { + // Handling duplicate subscriptions + _, ok := shareEur.EurMapSymbol.Load(value) + if ok { + continue + } + + shareEur.EurMap <- []byte(value) + } + + time.Sleep(10 * time.Second) + } +} + +// InitShareEurCloseCachePrice +// +// @Description: +// @param shareSgd +// @param check +func InitShareEurCloseCachePrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkEur + } else { + key = setting.MarketShareEur + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareEurCloseCachePrice.LoadLRangeList:%v", common.ErrShareEur, err) + return + } + + for _, value := range listSpots { + SubscribeEurClosePrice(value) // 处理闭盘取价 + } + + time.Sleep(20 * time.Second) + } +} + +// InitShareEurCloseNewPrice +// +// @Description: 同步实时行情 +// @param check +func InitShareEurCloseNewPrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkEur + } else { + key = setting.MarketShareEur + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareEurCloseNewPrice.LoadLRangeList:%v", common.ErrShareEur, err) + time.Sleep(20 * time.Second) + continue + } + for _, value := range listSpots { + SubscribeEurCloseNewPrice(value) + } + + time.Sleep(500 * time.Millisecond) + } +} + +// InitShareEurPriceSetUp +// +// @Description: 同步插针行情 +// @param check +func InitShareEurPriceSetUp(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkEur + } else { + key = setting.MarketShareEur + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareEurPriceSetUp.LoadLRangeList:%v", common.ErrShareEur, err) + time.Sleep(20 * time.Second) + continue + } + + for _, value := range listSpots { + eurKey := publicData.SymbolCache(flags.Eur, value, flags.TradeTypePrice) + eurSetCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareEurMarketType, value) + vw, err := GetBeforeAndAfterSetPrice(eurSetCache) + if err != nil || len(vw) == 0 { + _ = memory.ShareEurPriceSetUp.Delete(eurKey) + continue + } + if err = memory.ShareEurPriceSetUp.Set(eurKey, []byte(vw)); err != nil { + applogger.Error("%v InitShareEurPriceSetUp.ShareEurPriceSetUp:%v", common.ErrShareEur, err) + } + } + + time.Sleep(500 * time.Millisecond) + } +} + +// SubscribeEurHSetCodeList +// +// @Description: 同步列表缓存 +// @param symbolStr +// @param check +func SubscribeEurHSetCodeList(symbolStr string, check bool) { + var key string + if check { + key = setting.MarketShareBlkEur + } else { + key = setting.MarketShareEur + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + return + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeEurHSetCodeList.%v.HSet:%v", common.ErrShareEur, key, err) + return + } + } +} + +// SubscribeEurCloseNewPrice +// +// @Description: 获取行情价 +// @param symbolStr +// @param check +func SubscribeEurCloseNewPrice(symbolStr string) { + // 获取市场真实开闭盘时间 + timeValue, checkWeekday := MarketCheckOpenAndCloseTime(flags.ShareEurMarketType) + // 判定是否盘中 + if utils.CheckInPlateTime(timeValue) && checkWeekday { + // 盘中实时价格 + realTimePrice, err := Reds.HGet(context.Background(), flags.ShareGermanyClosingNewPriceKey, symbolStr).Result() + if err != nil { + realTimePrice = decimal.Zero.String() + } + if realTimePrice != decimal.Zero.String() { + keys := publicData.SymbolCache(flags.Eur, symbolStr, flags.TradeTypePrice) + if err = memory.ShareEurCache.Set(keys, []byte(realTimePrice)); err != nil { + applogger.Error("%v SubscribeEurCloseNewPrice.ShareUsCache:%v", common.ErrShareEur, err) + } + } + } +} + +// SubscribeEurClosePrice +// +// @Description: 获取闭盘价 +// @param symbolStr +func SubscribeEurClosePrice(symbolStr string) { + var err error + var sub = decimal.Zero + var closeNewPrice, closingPrice, price string + + // 闭盘价格 + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareGermanyClosingNewPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareGermanyClosingPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice = decimal.Zero.String() + } + } + + // 市价(实时价格) + closingPrice, err = Reds.HGet(context.Background(), flags.ShareGermanyBeforeClose, symbolStr).Result() + if err != nil { + closingPrice = decimal.Zero.String() + } + + // 判定取值数据 + if closeNewPrice != decimal.Zero.String() { + price = closeNewPrice + } else { + price = closingPrice + } + closeKey := publicData.SymbolCache(flags.Eur, symbolStr, flags.TradeTypeClosePrice) + if err = memory.ShareEurClosePrice.Set(closeKey, []byte(price)); err != nil { + applogger.Error("%v SubscribeEurClosePrice.Set.price:%v", common.ErrShareEur, err) + } + + // 写入涨跌幅价格判定缓存(计算涨跌幅 = 最新价格 - 闭盘价格(昨天关闭价格或者上次毕盘价格)) + cn := closeNewPrice != decimal.Zero.String() + cp := closingPrice != decimal.Zero.String() + lcn := utils.IsNumber(closeNewPrice) + lcp := utils.IsNumber(closingPrice) + if cn && cp && lcn && lcp { + sub = decimal.RequireFromString(closingPrice).Sub(decimal.RequireFromString(closeNewPrice)) + } + chgKey := publicData.SymbolCache(flags.Eur, symbolStr, flags.TradeTypeChg) // 涨跌幅标识Key + if err = memory.ShareEurChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v SubscribeEurClosePrice.Set.price:%v", common.ErrShareEur, err) + } +} + +// OrderSubAdminShareEurSubscribeBySum +// +// @Description: 持仓订单浮动盈亏计算 +// @param ctx +// @param uo +func OrderSubAdminShareEurSubscribeBySum(uo *Data) { + for { + var topIc = setting.AdminShareEurSubscribe + hashMap, err := uo.redisDB.HGetAll(context.Background(), topIc).Result() + if err != nil { + applogger.Error("OrderSubAdminShareEurSubscribeBySum.HGetAll:%v", err) + time.Sleep(5 * time.Second) + continue + } + var hashList []share.ShareEurTallyCache + for _, value := range hashMap { + var msg share.ShareEurTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + switch msg.Status { + case flags.Entrust: // 挂单 + case flags.Position: // 持仓 + hashList = append(hashList, msg) + default: // 平仓|撤单 + err = uo.redisDB.HDel(context.Background(), topIc, msg.OrderId).Err() + if err != nil { + applogger.Error("OrderSubAdminShareEurSubscribeBySum.HDel:%v", err) + continue + } + } + } + applogger.Info("德股数据量统计:%v", len(hashList)) + // 统计德股总持仓订单浮动盈亏 + priceSum := decimal.Zero + for _, value := range hashList { + orderModel := shareData.ShareEurOrderProcessing(topIc, value) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch value.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + price := subPrice.Mul(decimal.RequireFromString(value.Order.OrderNumber)) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + + // 写入缓存 + if err = memory.ShareEurFloating.Set(flags.FloatingEur, []byte(priceSum.String())); err != nil { + applogger.Error("统计德股持仓订单浮动盈亏错误:%v", err) + time.Sleep(5 * time.Second) + continue + } + applogger.Info("统计的德股持仓订单浮动盈亏:%v", priceSum) + + time.Sleep(1 * time.Second) + } +} + +// SubscribeShareEur +// +// @Description: TODO: 订阅 +// @param ctx +// @param uo +// @param shareEur +func SubscribeShareEur(ctx context.Context, shareEur *ShareEurSymbol, check bool) { + for { + select { + case symbol, _ := <-shareEur.EurMap: + symbolStr := string(symbol) + topIc := fmt.Sprintf("%v.%v", symbolStr, flags.CountryEur) + // Handling duplicate subscriptions + _, ok := shareEur.EurMapSymbol.Load(symbolStr) + if ok { + time.Sleep(5 * time.Second) + continue + } + // Transaction determination + var key string + if check { + key = setting.MarketShareBlkEur // 大宗股交易 + } else { + key = setting.MarketShareEur // 德股交易 + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeShareEur.%v.HSet:%v", common.ErrShareEur, key, err) + time.Sleep(5 * time.Second) + continue + } + } + + // 处理订阅实时行情数据 + go func() { + symbolStrCache := symbolStr + pubSub := Reds.Subscribe(ctx, topIc) + defer pubSub.Close() + if _, err := pubSub.Receive(ctx); err != nil { + shareEur.EurMapSymbol.Delete(symbolStrCache) + return + } + ch := pubSub.Channel() + for { + select { + case msg, _ := <-ch: + var subMsg ShareEurMessage + if err := json.Unmarshal([]byte(msg.Payload), &subMsg); err != nil { + applogger.Error("%v SubscribeShareEur.Unmarshal:%v", common.ErrShareEur, err) + time.Sleep(5 * time.Second) + continue + } + SubscribeEurPrice(subMsg.Price.String(), symbolStr, flags.RealTime) + default: + Reds.Ping(ctx) // 如果没有消息,发送 PING 命令以维护连接 + time.Sleep(10 * time.Second) + } + } + }() + + // 监控盘前|盘后设置价格 + _, okc := shareEur.EurSetMapSymbol.Load(symbolStr) + if !okc { + go func() { + for { + keyCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareEurMarketType, symbolStr) + vw, err := GetBeforeAndAfterSetPrice(keyCache) + if err != nil || len(vw) == 0 { + priceCache := publicData.SymbolCache(flags.Eur, symbolStr, flags.TradeTypePrice) + memory.ShareEurPriceSetUp.Delete(priceCache) + time.Sleep(15 * time.Second) + continue + } + SubscribeEurPrice(vw, symbolStr, flags.SetUp) + time.Sleep(10 * time.Second) + } + }() + // Write cache to determine whether to repeatedly open the protocol + shareEur.EurSetMapSymbol.Store(symbolStr, symbolStr) + } + + // Write in the map to determine whether to repeat subscription + shareEur.EurMapSymbol.Store(symbolStr, symbolStr) + } + } +} + +// SubscribeEurPrice +// +// @Description: TODO: 订阅获取德股实时价格或者[盘前|盘后]设置价格 +// @param setPrice +// @param symbolStr +// @param check +func SubscribeEurPrice(setPrice, symbolStr string, check int) { + var err error + var sub = decimal.Zero + + // 计算涨跌幅 + yClosingPrice, err := Reds.HGet(context.Background(), flags.ShareGermanyClosingPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice, err = Reds.HGet(context.Background(), flags.ShareGermanyClosingNewPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice = setPrice + sub = decimal.Zero + } + } + + // 写入涨跌幅缓存数据 + yc := yClosingPrice != decimal.Zero.String() + sp := setPrice != decimal.Zero.String() + lyc := utils.IsNumber(yClosingPrice) + lsp := utils.IsNumber(setPrice) + if yc && sp && lyc && lsp { + sub = decimal.RequireFromString(setPrice).Sub(decimal.RequireFromString(yClosingPrice)) + } + chgKey := publicData.SymbolCache(flags.Eur, symbolStr, flags.TradeTypeChg) + if err = memory.ShareEurChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v SubscribeEurPrice.ShareEurChgMark.Set.price:%v", common.ErrShareEur, err) + } + if !flags.CheckSetting { + applogger.Debug("涨跌幅交易对内存key:%v,涨跌幅数值:%v", symbolStr, sub) + } + + // 交易类型:0最新价,1买入,2卖出 + price := publicData.SymbolCache(flags.Eur, symbolStr, flags.TradeTypePrice) + switch check { + case flags.RealTime: // 实时价格(优先级高) + if err = memory.ShareEurCache.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeEurPrice.ShareEurCache.Set.price:%v", common.ErrShareEur, err) + } + case flags.SetUp: // 设置[盘前|盘后]价格 + if err = memory.ShareEurPriceSetUp.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeEurPrice.ShareEurPriceSetUp:%v", common.ErrShareEur, err) + } + } + if !flags.CheckSetting { + applogger.Debug("股票交易对内存Key:%v,最新价格:%v", price, setPrice) + } +} + +// SubscribeEurSetForcedClosure +// +// @Description: TODO: 处理德股强平阈值 +// @param symbolStr +func SubscribeEurSetForcedClosure(symbolStr string) { + flatRatio := GetCacheForcedClosure(flags.StockEURSystemSetUpKey, symbolStr) + chgKey := publicData.SymbolCache(flags.Eur, symbolStr, flags.TradeTypeForcedClosure) + if err := memory.ShareEurForcedClosure.Set(chgKey, []byte(flatRatio.String())); err != nil { + applogger.Error("%v SubscribeEurSetForcedClosure.ShareEurForcedClosure err:%v", common.ErrShareEur, err) + return + } +} + +// ShareEurTransactionEntrust +// +// @Description: 德股委托订单 +// @param ctx +func ShareEurTransactionEntrust(ctx context.Context) { + for { + ShareEurTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareEurTransactionCalculationEntrust +// +// @Description: 德股挂单缓存队列计算 +// @param ctx +func ShareEurTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 全局变量处理 + if CheckGlobalTread(flags.EurMarket) { + time.Sleep(5 * time.Second) + return + } + + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareEurEntrust).Result() + if err != nil { + applogger.Error("%v ShareEurTransactionCalculationEntrust.HGetAll:%v", common.ErrShareEur, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareEurTallyCache, 1) + var entrust share.ShareEurTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareEurTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareEur, err) + continue + } + + // 股票实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareEurPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareEurTransactionCalculationEntrust.GetShareEurPrice:%v---%v", common.ErrShareEur, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + //chg := GetShareChgEur(flags.Eur, entrust.Symbol) // 涨跌幅标识 + //if share.CheckOrderEurByChg(setting.MarketShareEurEntrust, entrust, chg) { + // continue + //} + + wg.Add(1) + go func(value string) { + var resultMsg share.ShareEurTallyCache + switch entrust.Order.DealType { + case flags.DealTypeLimited: // 限价挂单 + resultMsg = ShareEurConcurrentComputingEntrustLimited(&entrust, newPrice, &wg) + case flags.DealTypeMarket: // 市价挂单(开盘即成交) + resultMsg = ShareEurConcurrentComputingEntrustMarket(&entrust, newPrice, &wg) + } + msg <- resultMsg // 通知管道异步处理订单操作 + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收德股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到德股持仓信息:%v", resultMsg) + } + + // 开盘逻辑 + if err = ShareEurLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Warn("%v ShareEurTransactionCalculationEntrust.ShareEurLiquidationEntrust:%v", common.ErrShareEur, err) + continue + } + + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Warn("%v ShareEurTransactionCalculationEntrust.Marshal:%v", common.ErrShareEur, err) + continue + } + + // TODO: 写入持仓消息队列 + //if err = uo.mqProducer.Entrust.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareEurTransactionCalculationEntrust.PushNotice:%v", common.ErrShareEur, err) + // continue + //} + + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareEurPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("德股挂单并发计算执行完毕......") +} + +// ShareEurConcurrentComputingEntrustLimited +// +// @Description: 德股挂单(限价|市价)缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareEurTallyCache +func ShareEurConcurrentComputingEntrustLimited(order *share.ShareEurTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareEurTallyCache { + var deleteCache bool + var dealPrice string + var limitPrice = decimal.RequireFromString(order.Order.LimitPrice) // 限价-价格 + var status = order.Status // 原始价格 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价买入逻辑判定 -> 挂单金额 > 当前价格 + if limitPrice.Cmp(newPrice) > 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + } + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价卖入逻辑判定 -> 挂单金额 < 当前价格 + if limitPrice.Cmp(newPrice) < 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareEurEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareSgdConcurrentComputingEntrustLimited.MarketShareSgdEntrust.HDel:%v", common.ErrShareEur, err) + order.Status = status + } + } + + wg.Done() + return share.ShareEurTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareEurConcurrentComputingEntrustMarket +// +// @Description: 德股市价下单进入挂单队列(休市) +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareEurTallyCache +func ShareEurConcurrentComputingEntrustMarket(order *share.ShareEurTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareEurTallyCache { + var deleteCache bool + var dealPrice string + var marketPrice = decimal.RequireFromString(order.Order.MarketPrice) // 市价-价格 + var status = order.Status // 原始价格记录 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareEurEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareEurConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareEur, err) + order.Status = status + } + } + + wg.Done() + return share.ShareEurTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareBlockEurConcurrentComputingEntrustMarket +// +// @Description: 大宗(德股)交易 +// @param order +// @param newPrice +// @param wg +// @return share.ShareSgdTallyCache +func ShareBlockEurConcurrentComputingEntrustMarket(order *share.ShareEurTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareEurTallyCache { + var status = order.Status // 原始状态 + + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareBlkEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareBlockEurConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareBlk, err) + order.Status = status + } + + wg.Done() + return share.ShareEurTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: newPrice.String(), // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareEurMqOpenBusiness +// +// @Description: TODO: 德股持仓消息队列 +// @param ctx +// @param uo +func ShareEurMqOpenBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Entrust.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerEntrustMq.ShareEurMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareEurMqOpenBusiness.ShareEurMq err....", common.ErrShareSgd) + continue + } + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareEurTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareEurMqOpenBusiness.Unmarshal:%v", common.ErrShareSgd, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareEurLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareEurMqOpenBusiness.ShareEurLiquidationEntrust:%v", common.ErrShareSgd, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + applogger.Info("这里没有监控到持仓mq队列消息.........") + time.Sleep(2 * time.Second) + } + } +} + +// ShareEurLiquidationEntrust +// +// @Description: 德股挂单-->开仓业务处理 +// @param ctx +// @param order +// @return error +func ShareEurLiquidationEntrust(ctx context.Context, order *share.ShareEurTallyCache) error { + // 1、开盘 + err := StockEurOpenOrder(ctx, Msql, order.UserId, order.OrderId, order.OpenPrice, order.Order) + if err != nil { + applogger.Error("%v ShareEurLiquidationEntrust.StockEurOpenOrder:%v", common.ErrShareEur, err) + return err + } + + // 大宗(新加坡股)交易判定 + var entrustKey, adminKey string + if !CheckTypeStatus(order.Order.Type) { + entrustKey = setting.ShareEurSubscribe + adminKey = setting.AdminShareEurSubscribe + } else { + entrustKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // 2、更新用户订阅缓存列表订单状态 + updateKey := virtual.OrderIdListKey(entrustKey, order.UserId) + if err = UpdateShareEurSubscribeHashStatusByOrderId(order.OrderId, updateKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareEurLiquidationEntrust.Entrust.%v:%v", common.ErrShareEur, entrustKey, err) + return err + } + + // 3、更新管理员订阅缓存列表订单状态 + if err = UpdateShareEurSubscribeHashStatusByOrderId(order.OrderId, adminKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareEurLiquidationEntrust.Entrust.%v:%v", common.ErrShareEur, adminKey, err) + return err + } + + return nil +} + +// ShareEurTransactionPosition +// +// @Description: 德股持仓订单 +// @param ctx +func ShareEurTransactionPosition(ctx context.Context) { + for { + ShareEurTransactionCalculationPosition(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareEurTransactionCalculationPosition +// +// @Description: 德股持仓缓存队列计算 +// @param ctx +func ShareEurTransactionCalculationPosition(ctx context.Context) { + var wg sync.WaitGroup + + // 判定是否交易 + if CheckGlobalTread(flags.EurMarket) { + time.Sleep(5 * time.Second) + return + } + + // TODO: 获取IPO未支付订单缓存 + userIdMap, _ := GetBotUserArrears(ctx) + + // 获取持仓缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareEurPosition).Result() + if err != nil { + applogger.Error("%v ShareEurTransactionCalculationPosition.HGetAll:%v", common.ErrShareEur, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareEurTallyCache, 1) + var entrust share.ShareEurTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareEurTransactionCalculationPosition.Unmarshal:%v", common.ErrShareEur, err) + continue + } + + // TODO: 判定是否未IPO未支付订单-不能平仓 + _, isOk := userIdMap[entrust.UserId] + if isOk { + continue + } + + // 处理时间 + if !CheckShareSystemTime(entrust.ClosingTime) { + applogger.Debug("德股:%v,平仓时间:%v暂未到达...", entrust.Symbol, entrust.ClosingTime) + continue + } + + // TODO: 实时获取强平阈值 + //entrust.Order.System.StrongFlatRatio = GetForcedClosureValue(flags.Sgd, entrust.Symbol) + + // 股票实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareEurPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareEurTransactionCalculationPosition.GetShareEurPrice:%v--%v", common.ErrShareEur, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + //chg := GetShareChgEur(flags.Eur, entrust.Symbol) // 涨跌幅标识 + //if share.CheckOrderEurByChg(setting.MarketShareEurEntrust, entrust, chg) { + // continue + //} + + // 判定配额强平 + checkFlattening := GetStrongFlatteningThreshold(entrust.UserId) + + wg.Add(1) + go func(value string) { + resultMsg := ShareEurConcurrentComputingPosition(&entrust, newPrice, &wg, checkFlattening) + msg <- resultMsg + }(value) + + // 处理并发结果 + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Position: // 持仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到德股持仓信息:%v", resultMsg) + } + case flags.Close: // 平仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到德股平仓信息:%v", resultMsg) + } + + // TODO: 平仓操作(优化写入队列中等待平仓) + //var byteStr []byte + //byteStr, err = json.Marshal(resultMsg) + //if err != nil { + // applogger.Error("%v ShareEurTransactionCalculationPosition.Marshal:%v", common.ErrShareEur, err) + // continue + //} + //if err = uo.mqProducer.Position.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareEurTransactionCalculationPosition.PushNotice:%v", common.ErrShareEur, err) + // continue + //} + + // 平仓操作 + if err = ShareEurLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareEurTransactionCalculationPosition.ShareEurLiquidationPosition:%v", common.ErrShareEur, err) + continue + } + } + } + } + + wg.Wait() + applogger.Info("德股持仓并发计算执行完毕......") +} + +// ShareEurConcurrentComputingPosition +// +// @Description: 德股持仓缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareEurTallyCache +func ShareEurConcurrentComputingPosition(order *share.ShareEurTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup, checkFlattening bool) share.ShareEurTallyCache { + var deleteCache, checkBool bool + var dealPrice string + var sellShort decimal.Decimal + var openPrice = decimal.RequireFromString(order.OpenPrice) // 限价 + var orderNumber = decimal.RequireFromString(order.Order.OrderNumber) // 仓位 + + var pryNum decimal.Decimal + lenPryNum := len(utils.ReplaceStr(order.Order.PryNum)) == 0 + if lenPryNum || order.Order.PryNum == flags.SetZero || order.Order.System.UserStatus != flags.SetThree || !utils.IsNumberInt(order.Order.PryNum) { + pryNum = decimal.RequireFromString(flags.SetOne) + } else { + pryNum = decimal.RequireFromString(order.Order.PryNum) + } + + // 下单判定设置(false无设置|true止盈止损) + _, stopWinPrice, stopLossPrice, _ := StockEurVoteStopType(order.Order) + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨(强平) + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,持仓开仓价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买涨:挂止损止盈,止盈价必须<当前价,止损价必须>当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + // 强行平仓(做多) + if !checkBool { + sellShort = newPrice.Sub(openPrice).Mul(orderNumber) + } + case flags.TradeTypeSell: // 买跌(存在强行平仓) + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价持仓买跌下单价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买跌:挂止损止盈,止盈价必须>当前价,止损价必须<当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + // 强行平仓(做空) + if !checkBool { + sellShort = openPrice.Sub(newPrice).Mul(orderNumber) + } + } + /* 强行平仓(做多|做空) + 1、做多:(最新成交价-开仓成交价)*仓位 + 2、做空:(开仓成交价-最新成交价)*仓位 + 3、当浮动盈亏 >= 保证金的70%订单强行平仓 + */ + if sellShort.IsNegative() && checkFlattening { + orderAmount := newPrice.Mul(decimal.RequireFromString(order.Order.OrderNumber)).Div(pryNum) // 订单金额 = 当前价格 * 订单数量 / 杠杆 + floatPrice := orderAmount.Mul(decimal.RequireFromString(order.Order.System.StrongFlatRatio)) + if !flags.CheckSetting { + applogger.Debug("强平保证金:%v,强平浮动70:%v,强行平仓判定:%v", orderAmount, floatPrice, sellShort.Abs().Cmp(floatPrice)) + } + + if sellShort.Abs().Cmp(floatPrice) >= 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + switch order.Order.TradeType { + case flags.TradeTypeBuy: //买涨 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + case flags.TradeTypeSell: // 买跌 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + } + + if checkBool { + deleteCache = true + order.Status = flags.Close + } + + if deleteCache { + // 根据订单ID-删除持仓列表缓存订单 + if err := Reds.HDel(context.Background(), setting.MarketShareEurPosition, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareEurConcurrentComputingPosition.Position.HDel:%v", common.ErrShareEur, err) + } + } + + wg.Done() + return share.ShareEurTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + ClosingPrice: dealPrice, // 平仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareEurMqClosingBusiness +// +// @Description: TODO: 处理德股平仓消息队列 +// @param ctx +// @param uo +func ShareEurMqClosingBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Position.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerPositionMq.ShareEurMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareEurMqClosingBusiness.ShareEurMq err....", common.ErrShareSgd) + continue + } + applogger.Info("接收到平仓信息:%v", string(message)) + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareEurTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareEurMqClosingBusiness.Unmarshal:%v", common.ErrShareSgd, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareEurLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareEurMqClosingBusiness.ShareEurLiquidationPosition:%v", common.ErrShareSgd, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + time.Sleep(2 * time.Second) + } + } +} + +// ShareEurLiquidationPosition +// +// @Description: 德股持仓-->平仓业务处理 +// @param ctx +// @param order +// @return error +func ShareEurLiquidationPosition(ctx context.Context, order *share.ShareEurTallyCache) error { + // 1、平仓操作 + err := StockEurClosingOrder(ctx, Msql, order.OrderId, order.ClosingPrice, order.Order) + if err != nil { + applogger.Error("%v ShareEurLiquidationPosition.StockEurClosingOrder:%v", common.ErrShareEur, err) + return err + } + + // 2、平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareEurSubscribe, order.UserId) + if err = UpdateShareEurSubscribeHashStatusByOrderId(order.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v ShareEurLiquidationPosition.Position.ShareEurSubscribe:%v", common.ErrShareEur, err) + return err + } + + // 3、平仓更新管理员订阅订单状态 + if err = UpdateShareEurSubscribeHashStatusByOrderId(order.OrderId, setting.AdminShareEurSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v ShareEurLiquidationPosition.Position.AdminShareEurSubscribe:%v", common.ErrShareEur, err) + return err + } + + return nil +} + +// StockEurVoteStopType +// +// @Description: 德股判定取值止损止盈 +// @param order +// @return bool +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func StockEurVoteStopType(order structure.ShareOrder) (bool, decimal.Decimal, decimal.Decimal, error) { + var checkBool bool + var stopWinPrice, stopLossPrice decimal.Decimal + switch order.StopType { + case flags.StopTypeNone: // 暂无设置止盈止损 + checkBool = false + case flags.StopTypeSet: // 设置止盈止损 + checkBool = true + stopWinPrice, _ = decimal.NewFromString(order.StopWinPrice) + stopLossPrice, _ = decimal.NewFromString(order.StopLossPrice) + default: + return checkBool, stopWinPrice, stopLossPrice, flags.ErrContractThirteen + } + + return checkBool, stopWinPrice, stopLossPrice, nil +} + +// GetShareEurPrice +// +// @Description: 德股票价格 +// @param symbol +// @return decimal.Decimal +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func GetShareEurPrice(symbol string) (decimal.Decimal, error) { + var err error + var priceByte []byte + var newPrice decimal.Decimal + + key := publicData.SymbolCache(flags.Eur, symbol, flags.TradeTypePrice) + priceByte, err = memory.GetShareEurCache(key) + if err != nil { + return decimal.Decimal{}, err + } + + newPrice, err = decimal.NewFromString(string(priceByte)) + if err != nil { + return decimal.Decimal{}, err + } + + applogger.Info("GetShareEurPrice:%v,topIc:%v,shareEurPrice:%v", symbol, key, newPrice) + + return newPrice, nil +} diff --git a/internal/data/subscribe_share_fur.go b/internal/data/subscribe_share_fur.go new file mode 100644 index 0000000..8dead65 --- /dev/null +++ b/internal/data/subscribe_share_fur.go @@ -0,0 +1,1250 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/mq/consumer" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/socket/shareData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "sync" + "time" +) + +/* +法国股行情订阅 +1、接收用户法国股下单的交易对法国股行情 +2、将订阅行情写入内存中用于并发计算 +3、挂单(市价|限价)缓存队列处理-开仓 +4、持仓缓存队列处理-平仓 +*/ + +// ShareFurMessage +// @Description: +type ShareFurMessage struct { + Symbol string `json:"symbol,omitempty"` // 交易所:股票代码 + StockCode string `json:"stock_code,omitempty"` // 股票代码 + StockName string `json:"stock_name,omitempty"` // 股票名,可能为空 + Price decimal.Decimal `json:"price,omitempty"` // 实时价格 + UpDownRate decimal.Decimal `json:"up_down_rate,omitempty"` // 涨跌% + UpDown decimal.Decimal `json:"up_down,omitempty"` // 涨跌额 + TradeV decimal.Decimal `json:"trade_v,omitempty"` // 技术评级指标值 + TradeK string `json:"trade_k,omitempty"` // 技术评级 + Vol int64 `json:"vol,omitempty"` // 成交量 + TurnoverPriceTotal decimal.Decimal `json:"turnover_price_total,omitempty"` // 成交量*价格 + PriceTotal string `json:"price_total,omitempty"` // 总市值 + PE string `json:"p_e,omitempty"` // pe + Eps string `json:"eps,omitempty"` // EPS + EmployeesNumber string `json:"employees_number,omitempty"` // 雇员 + Plate string `json:"plate,omitempty"` // 板块 + Desc string `json:"desc,omitempty"` // 描述 + PriceCode string `json:"price_code,omitempty"` // 价格类型 + Country string `json:"country,omitempty"` // 国家 + Ts int64 `json:"ts,omitempty"` // 时间 + Token string `json:"token,omitempty"` // Token 令牌 +} + +// ShareEurSymbol +// @Description: +type ShareFurSymbol struct { + FurMap chan []byte // 订单交易对 -- 用户下单通知订阅 + FurSetMap chan []byte // 订单交易对 -- 用户盘前|盘后行情订阅 + FurMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 + FurSetMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 +} + +// InitCacheSymbolShareFur +// +// @Description: +// @param ctx +// @param uo +func InitCacheSymbolShareFur(ctx context.Context, uo *Data) { + for { + thaList, err := GetBotStockFurListByStockId(ctx, uo) + if err != nil { + return + } + + for _, value := range thaList { + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := uo.redisDB.HExists(context.Background(), setting.MarketShareFur, value).Result() + if err != nil { + applogger.Error("%v InitCacheSymbolShareFur.MarketShareEur.HExists:%v", common.ErrShareFur, err) + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err = uo.redisDB.HSet(context.Background(), setting.MarketShareFur, value, value).Err(); err != nil { + applogger.Error("%v InitCacheSymbolShareFur.MarketShareEur.HSet:%v", common.ErrShareFur, err) + time.Sleep(5 * time.Second) + continue + } + } + if !flags.CheckSetting { + applogger.Info("初始化法股票代码:%v", value) + } + } + + time.Sleep(10 * time.Second) + } +} + +// InitSubscribeShareFur +// +// @Description: 状态机加载订阅 +// @param ctx +// @param uo +// @param shareTha +func InitSubscribeShareFur(shareFur *ShareFurSymbol, check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkFur + } else { + key = setting.MarketShareFur + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareEur.LoadLRangeList:%v", common.ErrShareFur, err) + return + } + + for _, value := range listSpots { + // Handling duplicate subscriptions + _, ok := shareFur.FurMapSymbol.Load(value) + if ok { + continue + } + + shareFur.FurMap <- []byte(value) + } + + time.Sleep(10 * time.Second) + } +} + +// InitShareFurCloseCachePrice +// +// @Description: +// @param shareSgd +// @param check +func InitShareFurCloseCachePrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkFur + } else { + key = setting.MarketShareFur + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareFurCloseCachePrice.LoadLRangeList:%v", common.ErrShareFur, err) + return + } + + for _, value := range listSpots { + SubscribeFurClosePrice(value) // 处理闭盘取价 + } + + time.Sleep(20 * time.Second) + } +} + +// InitShareFurCloseNewPrice +// +// @Description: 同步实时行情 +// @param check +func InitShareFurCloseNewPrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkFur + } else { + key = setting.MarketShareFur + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareFurCloseNewPrice.LoadLRangeList:%v", common.ErrShareFur, err) + time.Sleep(20 * time.Second) + continue + } + for _, value := range listSpots { + SubscribeFurCloseNewPrice(value) + } + + time.Sleep(500 * time.Millisecond) + } +} + +// InitShareFurPriceSetUp +// +// @Description: 同步插针价 +// @param check +func InitShareFurPriceSetUp(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkFur + } else { + key = setting.MarketShareFur + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareFurPriceSetUp.LoadLRangeList:%v", common.ErrShareFur, err) + time.Sleep(20 * time.Second) + continue + } + + for _, value := range listSpots { + furKey := publicData.SymbolCache(flags.Fur, value, flags.TradeTypePrice) + furSetCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareFurMarketType, value) + vw, err := GetBeforeAndAfterSetPrice(furSetCache) + if err != nil || len(vw) == 0 { + _ = memory.ShareFurPriceSetUp.Delete(furKey) + continue + } + if err = memory.ShareFurPriceSetUp.Set(furKey, []byte(vw)); err != nil { + applogger.Error("%v InitShareFurPriceSetUp.ShareFurPriceSetUp:%v", common.ErrShareFur, err) + } + } + + time.Sleep(500 * time.Millisecond) + } +} + +// SubscribeFurHSetCodeList +// +// @Description: 同步列表缓存 +// @param symbolStr +// @param check +func SubscribeFurHSetCodeList(symbolStr string, check bool) { + var key string + if check { + key = setting.MarketShareBlkFur + } else { + key = setting.MarketShareFur + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + return + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeFurHSetCodeList.%v.HSet:%v", common.ErrShareFur, key, err) + return + } + } +} + +// SubscribeFurCloseNewPrice +// +// @Description: 获取行情价 +// @param symbolStr +// @param check +func SubscribeFurCloseNewPrice(symbolStr string) { + // 获取市场真实开闭盘时间 + timeValue, checkWeekday := MarketCheckOpenAndCloseTime(flags.ShareFurMarketType) + // 判定是否盘中 + if utils.CheckInPlateTime(timeValue) && checkWeekday { + // 盘中实时价格 + realTimePrice, err := Reds.HGet(context.Background(), flags.ShareFranceClosingNewPriceKey, symbolStr).Result() + if err != nil { + realTimePrice = decimal.Zero.String() + } + if realTimePrice != decimal.Zero.String() { + keys := publicData.SymbolCache(flags.Fur, symbolStr, flags.TradeTypePrice) + if err = memory.ShareFurCache.Set(keys, []byte(realTimePrice)); err != nil { + applogger.Error("%v SubscribeFurCloseNewPrice.ShareFurCache:%v", common.ErrShareFur, err) + } + } + } +} + +// SubscribeFurClosePrice +// +// @Description: 获取闭盘价 +// @param symbolStr +func SubscribeFurClosePrice(symbolStr string) { + var err error + var sub = decimal.Zero + var closeNewPrice, closingPrice, price string + + // 闭盘价格 + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareFranceClosingNewPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareFranceClosingPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice = decimal.Zero.String() + } + } + + // 市价(实时价格) + closingPrice, err = Reds.HGet(context.Background(), flags.ShareFranceBeforeClose, symbolStr).Result() + if err != nil { + closingPrice = decimal.Zero.String() + } + + // 判定取值数据 + if closeNewPrice != decimal.Zero.String() { + price = closeNewPrice + } else { + price = closingPrice + } + closeKey := publicData.SymbolCache(flags.Fur, symbolStr, flags.TradeTypeClosePrice) + if err = memory.ShareFurClosePrice.Set(closeKey, []byte(price)); err != nil { + applogger.Error("%v SubscribeFurClosePrice.Set.price:%v", common.ErrShareFur, err) + } + + // 写入涨跌幅价格判定缓存(计算涨跌幅 = 最新价格 - 闭盘价格(昨天关闭价格或者上次毕盘价格)) + cn := closeNewPrice != decimal.Zero.String() + cp := closingPrice != decimal.Zero.String() + lcn := utils.IsNumber(closeNewPrice) + lcp := utils.IsNumber(closingPrice) + if cn && cp && lcn && lcp { + sub = decimal.RequireFromString(closingPrice).Sub(decimal.RequireFromString(closeNewPrice)) + } + chgKey := publicData.SymbolCache(flags.Fur, symbolStr, flags.TradeTypeChg) // 涨跌幅标识Key + if err = memory.ShareFurChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v SubscribeFurClosePrice.Set.price:%v", common.ErrShareFur, err) + } +} + +// OrderSubAdminShareFurSubscribeBySum +// +// @Description: 持仓订单浮动盈亏计算 +// @param ctx +// @param uo +func OrderSubAdminShareFurSubscribeBySum(uo *Data) { + for { + var topIc = setting.AdminShareFurSubscribe + hashMap, err := uo.redisDB.HGetAll(context.Background(), topIc).Result() + if err != nil { + applogger.Error("OrderSubAdminShareFurSubscribeBySum.HGetAll:%v", err) + time.Sleep(5 * time.Second) + continue + } + var hashList []share.ShareFurTallyCache + for _, value := range hashMap { + var msg share.ShareFurTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + switch msg.Status { + case flags.Entrust: // 挂单 + case flags.Position: // 持仓 + hashList = append(hashList, msg) + default: // 平仓|撤单 + err = uo.redisDB.HDel(context.Background(), topIc, msg.OrderId).Err() + if err != nil { + applogger.Error("OrderSubAdminShareFurSubscribeBySum.HDel:%v", err) + continue + } + } + } + applogger.Info("法股数据量统计:%v", len(hashList)) + // 统计德股总持仓订单浮动盈亏 + priceSum := decimal.Zero + for _, value := range hashList { + orderModel := shareData.ShareFurOrderProcessing(topIc, value) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch value.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + price := subPrice.Mul(decimal.RequireFromString(value.Order.OrderNumber)) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + + // 写入缓存 + if err = memory.ShareFurFloating.Set(flags.FloatingFur, []byte(priceSum.String())); err != nil { + applogger.Error("统计法股持仓订单浮动盈亏错误:%v", err) + time.Sleep(5 * time.Second) + continue + } + applogger.Info("统计的法股持仓订单浮动盈亏:%v", priceSum) + + time.Sleep(1 * time.Second) + } +} + +// SubscribeShareFur +// +// @Description: TODO: 订阅 +// @param ctx +// @param uo +// @param shareFur +func SubscribeShareFur(ctx context.Context, shareFur *ShareFurSymbol, check bool) { + for { + select { + case symbol, _ := <-shareFur.FurMap: + symbolStr := string(symbol) + topIc := fmt.Sprintf("%v.%v", symbolStr, flags.CountryFur) + // Handling duplicate subscriptions + _, ok := shareFur.FurMapSymbol.Load(symbolStr) + if ok { + time.Sleep(5 * time.Second) + continue + } + // Transaction determination + var key string + if check { + key = setting.MarketShareBlkFur // 大宗股交易 + } else { + key = setting.MarketShareFur // 法股交易 + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeShareFur.%v.HSet:%v", common.ErrShareFur, key, err) + time.Sleep(5 * time.Second) + continue + } + } + + // 处理订阅实时行情数据 + go func() { + symbolStrCache := symbolStr + pubSub := Reds.Subscribe(ctx, topIc) + defer pubSub.Close() + if _, err := pubSub.Receive(ctx); err != nil { + shareFur.FurMapSymbol.Delete(symbolStrCache) + return + } + ch := pubSub.Channel() + for { + select { + case msg, _ := <-ch: + var subMsg ShareFurMessage + if err := json.Unmarshal([]byte(msg.Payload), &subMsg); err != nil { + applogger.Error("%v SubscribeShareFur.Unmarshal:%v", common.ErrShareFur, err) + time.Sleep(5 * time.Second) + continue + } + SubscribeFurPrice(subMsg.Price.String(), symbolStr, flags.RealTime) + default: + Reds.Ping(ctx) // 如果没有消息,发送 PING 命令以维护连接 + time.Sleep(10 * time.Second) + } + } + }() + + // 监控盘前|盘后设置价格 + _, okc := shareFur.FurSetMapSymbol.Load(symbolStr) + if !okc { + go func() { + for { + keyCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareFurMarketType, symbolStr) + vw, err := GetBeforeAndAfterSetPrice(keyCache) + if err != nil || len(vw) == 0 { + priceCache := publicData.SymbolCache(flags.Fur, symbolStr, flags.TradeTypePrice) + memory.ShareFurPriceSetUp.Delete(priceCache) + time.Sleep(15 * time.Second) + continue + } + SubscribeFurPrice(vw, symbolStr, flags.SetUp) + time.Sleep(10 * time.Second) + } + }() + // Write cache to determine whether to repeatedly open the protocol + shareFur.FurSetMapSymbol.Store(symbolStr, symbolStr) + } + + // Write in the map to determine whether to repeat subscription + shareFur.FurMapSymbol.Store(symbolStr, symbolStr) + } + } +} + +// SubscribeFurPrice +// +// @Description: TODO: 订阅获取法股实时价格或者[盘前|盘后]设置价格 +// @param setPrice +// @param symbolStr +// @param check +func SubscribeFurPrice(setPrice, symbolStr string, check int) { + var err error + var sub = decimal.Zero + + // 计算涨跌幅 + yClosingPrice, err := Reds.HGet(context.Background(), flags.ShareFranceClosingPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice, err = Reds.HGet(context.Background(), flags.ShareFranceClosingNewPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice = setPrice + sub = decimal.Zero + } + } + + // 写入涨跌幅缓存数据 + yc := yClosingPrice != decimal.Zero.String() + sp := setPrice != decimal.Zero.String() + lyc := utils.IsNumber(yClosingPrice) + lsp := utils.IsNumber(setPrice) + if yc && sp && lyc && lsp { + sub = decimal.RequireFromString(setPrice).Sub(decimal.RequireFromString(yClosingPrice)) + } + chgKey := publicData.SymbolCache(flags.Fur, symbolStr, flags.TradeTypeChg) + if err = memory.ShareFurChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v SubscribeFurPrice.ShareEurChgMark.Set.price:%v", common.ErrShareFur, err) + } + if !flags.CheckSetting { + applogger.Debug("涨跌幅交易对内存key:%v,涨跌幅数值:%v", symbolStr, sub) + } + + // 交易类型:0最新价,1买入,2卖出 + price := publicData.SymbolCache(flags.Fur, symbolStr, flags.TradeTypePrice) + switch check { + case flags.RealTime: // 实时价格(优先级高) + if err = memory.ShareFurCache.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeFurPrice.ShareEurCache.Set.price:%v", common.ErrShareFur, err) + } + case flags.SetUp: // 设置[盘前|盘后]价格 + if err = memory.ShareFurPriceSetUp.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeFurPrice.ShareEurPriceSetUp:%v", common.ErrShareFur, err) + } + } + if !flags.CheckSetting { + applogger.Debug("股票交易对内存Key:%v,最新价格:%v", price, setPrice) + } +} + +// SubscribeFurSetForcedClosure +// +// @Description: TODO: 处理法股强平阈值 +// @param symbolStr +func SubscribeFurSetForcedClosure(symbolStr string) { + flatRatio := GetCacheForcedClosure(flags.StockFURSystemSetUpKey, symbolStr) + chgKey := publicData.SymbolCache(flags.Fur, symbolStr, flags.TradeTypeForcedClosure) + if err := memory.ShareFurForcedClosure.Set(chgKey, []byte(flatRatio.String())); err != nil { + applogger.Error("%v SubscribeFurSetForcedClosure.ShareFurForcedClosure err:%v", common.ErrShareFur, err) + return + } +} + +// ShareFurTransactionCalculationEntrust +// +// @Description: 法股委托订单 +// @param ctx +func ShareFurTransactionEntrust(ctx context.Context) { + for { + ShareFurTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareFurTransactionCalculationEntrust +// +// @Description: 法股挂单缓存队列计算 +// @param ctx +func ShareFurTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 全局变量处理 + if CheckGlobalTread(flags.FurMarket) { + time.Sleep(5 * time.Second) + return + } + + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareFurEntrust).Result() + if err != nil { + applogger.Error("%v ShareFurTransactionCalculationEntrust.HGetAll:%v", common.ErrShareFur, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareFurTallyCache, 1) + var entrust share.ShareFurTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareFurTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareFur, err) + continue + } + + // 股票实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareFurPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareEurTransactionCalculationEntrust.GetShareFurPrice:%v---%v", common.ErrShareFur, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + //chg := GetShareChgFur(flags.Fur, entrust.Symbol) // 涨跌幅标识 + //if share.CheckOrderFurByChg(setting.MarketShareFurEntrust, entrust, chg) { + // continue + //} + + wg.Add(1) + go func(value string) { + var resultMsg share.ShareFurTallyCache + switch entrust.Order.DealType { + case flags.DealTypeLimited: // 限价挂单 + resultMsg = ShareFurConcurrentComputingEntrustLimited(&entrust, newPrice, &wg) + case flags.DealTypeMarket: // 市价挂单(开盘即成交) + resultMsg = ShareFurConcurrentComputingEntrustMarket(&entrust, newPrice, &wg) + } + msg <- resultMsg // 通知管道异步处理订单操作 + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收法股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到法股持仓信息:%v", resultMsg) + } + + // 开盘逻辑 + if err = ShareFurLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Warn("%v ShareFurTransactionCalculationEntrust.ShareFurLiquidationEntrust:%v", common.ErrShareFur, err) + continue + } + + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Warn("%v ShareFurTransactionCalculationEntrust.Marshal:%v", common.ErrShareFur, err) + continue + } + + // TODO: 写入持仓消息队列 + //if err = uo.mqProducer.Entrust.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareFurTransactionCalculationEntrust.PushNotice:%v", common.ErrShareFur, err) + // continue + //} + + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareFurPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("法股挂单并发计算执行完毕......") +} + +// ShareFurConcurrentComputingEntrustLimited +// +// @Description: 法股挂单(限价|市价)缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareFurTallyCache +func ShareFurConcurrentComputingEntrustLimited(order *share.ShareFurTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareFurTallyCache { + var deleteCache bool + var dealPrice string + var limitPrice = decimal.RequireFromString(order.Order.LimitPrice) // 限价-价格 + var status = order.Status // 原始价格 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价买入逻辑判定 -> 挂单金额 > 当前价格 + if limitPrice.Cmp(newPrice) > 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + } + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价卖入逻辑判定 -> 挂单金额 < 当前价格 + if limitPrice.Cmp(newPrice) < 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareFurEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareFurConcurrentComputingEntrustLimited.MarketShareFurEntrust.HDel:%v", common.ErrShareFur, err) + order.Status = status + } + } + + wg.Done() + return share.ShareFurTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareFurConcurrentComputingEntrustMarket +// +// @Description: 法股市价下单进入挂单队列(休市) +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareFurTallyCache +func ShareFurConcurrentComputingEntrustMarket(order *share.ShareFurTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareFurTallyCache { + var deleteCache bool + var dealPrice string + var marketPrice = decimal.RequireFromString(order.Order.MarketPrice) // 市价-价格 + var status = order.Status // 原始价格记录 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareFurEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareFurConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareFur, err) + order.Status = status + } + } + + wg.Done() + return share.ShareFurTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareBlockFurConcurrentComputingEntrustMarket +// +// @Description: 大宗(法股)交易 +// @param order +// @param newPrice +// @param wg +// @return share.ShareFurTallyCache +func ShareBlockFurConcurrentComputingEntrustMarket(order *share.ShareFurTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareFurTallyCache { + var status = order.Status // 原始状态 + + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareBlkEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareBlockFurConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareBlk, err) + order.Status = status + } + + wg.Done() + return share.ShareFurTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: newPrice.String(), // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareFurMqOpenBusiness +// +// @Description: TODO: 法股持仓消息队列 +// @param ctx +// @param uo +func ShareFurMqOpenBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Entrust.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerEntrustMq.ShareFurMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareFurMqOpenBusiness.ShareFurMq err....", common.ErrShareFur) + continue + } + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareFurTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareFurMqOpenBusiness.Unmarshal:%v", common.ErrShareFur, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareFurLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareFurMqOpenBusiness.ShareFurLiquidationEntrust:%v", common.ErrShareFur, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + applogger.Info("这里没有监控到持仓mq队列消息.........") + time.Sleep(2 * time.Second) + } + } +} + +// ShareFurLiquidationEntrust +// +// @Description: 法股挂单-->开仓业务处理 +// @param ctx +// @param order +// @return error +func ShareFurLiquidationEntrust(ctx context.Context, order *share.ShareFurTallyCache) error { + // 1、开盘 + err := StockFurOpenOrder(ctx, Msql, order.UserId, order.OrderId, order.OpenPrice, order.Order) + if err != nil { + applogger.Error("%v ShareFurLiquidationEntrust.StockFurOpenOrder:%v", common.ErrShareFur, err) + return err + } + + // 大宗(新加坡股)交易判定 + var entrustKey, adminKey string + if !CheckTypeStatus(order.Order.Type) { + entrustKey = setting.ShareFurSubscribe + adminKey = setting.AdminShareFurSubscribe + } else { + entrustKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // 2、更新用户订阅缓存列表订单状态 + updateKey := virtual.OrderIdListKey(entrustKey, order.UserId) + if err = UpdateShareFurSubscribeHashStatusByOrderId(order.OrderId, updateKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareFurLiquidationEntrust.Entrust.%v:%v", common.ErrShareFur, entrustKey, err) + return err + } + + // 3、更新管理员订阅缓存列表订单状态 + if err = UpdateShareFurSubscribeHashStatusByOrderId(order.OrderId, adminKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareFurLiquidationEntrust.Entrust.%v:%v", common.ErrShareFur, adminKey, err) + return err + } + + return nil +} + +// ShareFurTransactionPosition +// +// @Description: 法股持仓订单 +// @param ctx +func ShareFurTransactionPosition(ctx context.Context) { + for { + ShareFurTransactionCalculationPosition(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareFurTransactionCalculationPosition +// +// @Description: 法股持仓缓存队列计算 +// @param ctx +func ShareFurTransactionCalculationPosition(ctx context.Context) { + var wg sync.WaitGroup + + // 判定是否交易 + if CheckGlobalTread(flags.FurMarket) { + time.Sleep(5 * time.Second) + return + } + + // TODO: 获取IPO未支付订单缓存 + userIdMap, _ := GetBotUserArrears(ctx) + + // 获取持仓缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareFurPosition).Result() + if err != nil { + applogger.Error("%v ShareFurTransactionCalculationPosition.HGetAll:%v", common.ErrShareFur, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareFurTallyCache, 1) + var entrust share.ShareFurTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareFurTransactionCalculationPosition.Unmarshal:%v", common.ErrShareFur, err) + continue + } + + // TODO: 判定是否未IPO未支付订单-不能平仓 + _, isOk := userIdMap[entrust.UserId] + if isOk { + continue + } + + // 处理时间 + if !CheckShareSystemTime(entrust.ClosingTime) { + applogger.Debug("法股:%v,平仓时间:%v暂未到达...", entrust.Symbol, entrust.ClosingTime) + continue + } + + // TODO: 实时获取强平阈值 + //entrust.Order.System.StrongFlatRatio = GetForcedClosureValue(flags.Sgd, entrust.Symbol) + + // 股票实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareFurPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareFurTransactionCalculationPosition.GetShareFurPrice:%v--%v", common.ErrShareFur, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + //chg := GetShareChgFur(flags.Fur, entrust.Symbol) // 涨跌幅标识 + //if share.CheckOrderFurByChg(setting.MarketShareFurEntrust, entrust, chg) { + // continue + //} + + // 判定配额强平 + checkFlattening := GetStrongFlatteningThreshold(entrust.UserId) + + wg.Add(1) + go func(value string) { + resultMsg := ShareFurConcurrentComputingPosition(&entrust, newPrice, &wg, checkFlattening) + msg <- resultMsg + }(value) + + // 处理并发结果 + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Position: // 持仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到法股持仓信息:%v", resultMsg) + } + case flags.Close: // 平仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到法股平仓信息:%v", resultMsg) + } + + // TODO: 平仓操作(优化写入队列中等待平仓) + //var byteStr []byte + //byteStr, err = json.Marshal(resultMsg) + //if err != nil { + // applogger.Error("%v ShareFurTransactionCalculationPosition.Marshal:%v", common.ErrShareFur, err) + // continue + //} + //if err = uo.mqProducer.Position.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareFurTransactionCalculationPosition.PushNotice:%v", common.ErrShareFur, err) + // continue + //} + + // 平仓操作 + if err = ShareFurLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareFurTransactionCalculationPosition.ShareFurLiquidationPosition:%v", common.ErrShareFur, err) + continue + } + } + } + } + + wg.Wait() + applogger.Info("法股持仓并发计算执行完毕......") +} + +// ShareFurConcurrentComputingPosition +// +// @Description: 法股持仓缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareFurTallyCache +func ShareFurConcurrentComputingPosition(order *share.ShareFurTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup, checkFlattening bool) share.ShareFurTallyCache { + var deleteCache, checkBool bool + var dealPrice string + var sellShort decimal.Decimal + var openPrice = decimal.RequireFromString(order.OpenPrice) // 限价 + var orderNumber = decimal.RequireFromString(order.Order.OrderNumber) // 仓位 + + var pryNum decimal.Decimal + lenPryNum := len(utils.ReplaceStr(order.Order.PryNum)) == 0 + if lenPryNum || order.Order.PryNum == flags.SetZero || order.Order.System.UserStatus != flags.SetThree || !utils.IsNumberInt(order.Order.PryNum) { + pryNum = decimal.RequireFromString(flags.SetOne) + } else { + pryNum = decimal.RequireFromString(order.Order.PryNum) + } + + // 下单判定设置(false无设置|true止盈止损) + _, stopWinPrice, stopLossPrice, _ := StockEurVoteStopType(order.Order) + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨(强平) + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,持仓开仓价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买涨:挂止损止盈,止盈价必须<当前价,止损价必须>当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + // 强行平仓(做多) + if !checkBool { + sellShort = newPrice.Sub(openPrice).Mul(orderNumber) + } + case flags.TradeTypeSell: // 买跌(存在强行平仓) + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价持仓买跌下单价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买跌:挂止损止盈,止盈价必须>当前价,止损价必须<当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + // 强行平仓(做空) + if !checkBool { + sellShort = openPrice.Sub(newPrice).Mul(orderNumber) + } + } + /* 强行平仓(做多|做空) + 1、做多:(最新成交价-开仓成交价)*仓位 + 2、做空:(开仓成交价-最新成交价)*仓位 + 3、当浮动盈亏 >= 保证金的70%订单强行平仓 + */ + if sellShort.IsNegative() && checkFlattening { + orderAmount := newPrice.Mul(decimal.RequireFromString(order.Order.OrderNumber)).Div(pryNum) // 订单金额 = 当前价格 * 订单数量 / 杠杆 + floatPrice := orderAmount.Mul(decimal.RequireFromString(order.Order.System.StrongFlatRatio)) + if !flags.CheckSetting { + applogger.Debug("强平保证金:%v,强平浮动70:%v,强行平仓判定:%v", orderAmount, floatPrice, sellShort.Abs().Cmp(floatPrice)) + } + + if sellShort.Abs().Cmp(floatPrice) >= 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + switch order.Order.TradeType { + case flags.TradeTypeBuy: //买涨 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + case flags.TradeTypeSell: // 买跌 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + } + + if checkBool { + deleteCache = true + order.Status = flags.Close + } + + if deleteCache { + // 根据订单ID-删除持仓列表缓存订单 + if err := Reds.HDel(context.Background(), setting.MarketShareFurPosition, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareFurConcurrentComputingPosition.Position.HDel:%v", common.ErrShareFur, err) + } + } + + wg.Done() + return share.ShareFurTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + ClosingPrice: dealPrice, // 平仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareFurMqClosingBusiness +// +// @Description: TODO: 处理法股平仓消息队列 +// @param ctx +// @param uo +func ShareFurMqClosingBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Position.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerPositionMq.ShareFurMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareFurMqClosingBusiness.ShareFurMq err....", common.ErrShareFur) + continue + } + applogger.Info("接收到平仓信息:%v", string(message)) + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareFurTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareFurMqClosingBusiness.Unmarshal:%v", common.ErrShareFur, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareFurLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareFurMqClosingBusiness.ShareFurLiquidationPosition:%v", common.ErrShareFur, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + time.Sleep(2 * time.Second) + } + } +} + +// ShareFurLiquidationPosition +// +// @Description: 法股持仓-->平仓业务处理 +// @param ctx +// @param order +// @return error +func ShareFurLiquidationPosition(ctx context.Context, order *share.ShareFurTallyCache) error { + // 1、平仓操作 + err := StockFurClosingOrder(ctx, Msql, order.OrderId, order.ClosingPrice, order.Order) + if err != nil { + applogger.Error("%v ShareEurLiquidationPosition.StockFurClosingOrder:%v", common.ErrShareFur, err) + return err + } + + // 2、平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareFurSubscribe, order.UserId) + if err = UpdateShareFurSubscribeHashStatusByOrderId(order.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v ShareFurLiquidationPosition.Position.ShareFurSubscribe:%v", common.ErrShareFur, err) + return err + } + + // 3、平仓更新管理员订阅订单状态 + if err = UpdateShareFurSubscribeHashStatusByOrderId(order.OrderId, setting.AdminShareFurSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v ShareFurLiquidationPosition.Position.AdminShareFurSubscribe:%v", common.ErrShareFur, err) + return err + } + + return nil +} + +// StockFurVoteStopType +// +// @Description: 法股判定取值止损止盈 +// @param order +// @return bool +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func StockFurVoteStopType(order structure.ShareOrder) (bool, decimal.Decimal, decimal.Decimal, error) { + var checkBool bool + var stopWinPrice, stopLossPrice decimal.Decimal + switch order.StopType { + case flags.StopTypeNone: // 暂无设置止盈止损 + checkBool = false + case flags.StopTypeSet: // 设置止盈止损 + checkBool = true + stopWinPrice, _ = decimal.NewFromString(order.StopWinPrice) + stopLossPrice, _ = decimal.NewFromString(order.StopLossPrice) + default: + return checkBool, stopWinPrice, stopLossPrice, flags.ErrContractThirteen + } + + return checkBool, stopWinPrice, stopLossPrice, nil +} + +// GetShareFurPrice +// +// @Description: 法股票价格 +// @param symbol +// @return decimal.Decimal +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func GetShareFurPrice(symbol string) (decimal.Decimal, error) { + var err error + var priceByte []byte + var newPrice decimal.Decimal + + key := publicData.SymbolCache(flags.Fur, symbol, flags.TradeTypePrice) + priceByte, err = memory.GetShareFurCache(key) + if err != nil { + return decimal.Decimal{}, err + } + + newPrice, err = decimal.NewFromString(string(priceByte)) + if err != nil { + return decimal.Decimal{}, err + } + + applogger.Info("GetShareFurPrice:%v,topIc:%v,shareFurPrice:%v", symbol, key, newPrice) + + return newPrice, nil +} diff --git a/internal/data/subscribe_share_gbx.go b/internal/data/subscribe_share_gbx.go new file mode 100644 index 0000000..d0a24bb --- /dev/null +++ b/internal/data/subscribe_share_gbx.go @@ -0,0 +1,1241 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/mq/consumer" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/socket/shareData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "sync" + "time" +) + +/* +英股行情订阅 +1、接收用户英股下单的交易对英股行情 +2、将订阅行情写入内存中用于并发计算 +3、挂单(市价|限价)缓存队列处理-开仓 +4、持仓缓存队列处理-平仓 +*/ + +// ShareGbxMessage +// @Description: +type ShareGbxMessage struct { + Symbol string `json:"symbol,omitempty"` // 交易所:股票代码 + StockCode string `json:"stock_code,omitempty"` // 股票代码 + StockName string `json:"stock_name,omitempty"` // 股票名,可能为空 + Price decimal.Decimal `json:"price,omitempty"` // 实时价格 + UpDownRate decimal.Decimal `json:"up_down_rate,omitempty"` // 涨跌% + UpDown decimal.Decimal `json:"up_down,omitempty"` // 涨跌额 + TradeV decimal.Decimal `json:"trade_v,omitempty"` // 技术评级指标值 + TradeK string `json:"trade_k,omitempty"` // 技术评级 + Vol int64 `json:"vol,omitempty"` // 成交量 + TurnoverPriceTotal decimal.Decimal `json:"turnover_price_total,omitempty"` // 成交量*价格 + PriceTotal string `json:"price_total,omitempty"` // 总市值 + PE string `json:"p_e,omitempty"` // pe + Eps string `json:"eps,omitempty"` // EPS + EmployeesNumber string `json:"employees_number,omitempty"` // 雇员 + Plate string `json:"plate,omitempty"` // 板块 + Desc string `json:"desc,omitempty"` // 描述 + PriceCode string `json:"price_code,omitempty"` // 价格类型 + Country string `json:"country,omitempty"` // 国家 + Ts int64 `json:"ts,omitempty"` // 时间 + Token string `json:"token,omitempty"` // Token 令牌 +} + +// ShareGbxSymbol +// @Description: +type ShareGbxSymbol struct { + GbxMap chan []byte // 订单交易对 -- 用户下单通知订阅 + GbxSetMap chan []byte // 订单交易对 -- 用户盘前|盘后行情订阅 + GbxMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 + GbxSetMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 +} + +// InitCacheSymbolShareGbx +// +// @Description: +// @param ctx +// @param uo +func InitCacheSymbolShareGbx(ctx context.Context, uo *Data) { + for { + thaList, err := GetBotStockGbxListByStockId(ctx, uo) + if err != nil { + return + } + + for _, value := range thaList { + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := uo.redisDB.HExists(context.Background(), setting.MarketShareGbx, value).Result() + if err != nil { + applogger.Error("%v InitCacheSymbolShareGbx.MarketShareGbx.HExists:%v", common.ErrShareGbx, err) + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err := uo.redisDB.HSet(context.Background(), setting.MarketShareGbx, value, value).Err(); err != nil { + applogger.Error("%v InitCacheSymbolShareGbx.MarketShareGbx.HSet:%v", common.ErrShareGbx, err) + time.Sleep(5 * time.Second) + continue + } + } + if !flags.CheckSetting { + applogger.Info("初始化英国股票代码:%v", value) + } + } + + time.Sleep(10 * time.Second) + } +} + +// InitSubscribeShareGbx +// +// @Description: 状态机加载订阅 +// @param shareGbx +// @param check +func InitSubscribeShareGbx(shareGbx *ShareGbxSymbol, check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkGbx + } else { + key = setting.MarketShareGbx + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareGbx.LoadLRangeList:%v", common.ErrShareGbx, err) + return + } + + for _, value := range listSpots { + // Handling duplicate subscriptions + _, ok := shareGbx.GbxMapSymbol.Load(value) + if ok { + continue + } + + shareGbx.GbxMap <- []byte(value) + } + + time.Sleep(10 * time.Second) + } +} + +// InitShareGbxCloseCachePrice +// +// @Description: 同步闭盘价 +// @param shareGbx +// @param check +func InitShareGbxCloseCachePrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkGbx + } else { + key = setting.MarketShareGbx + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareGbx.LoadLRangeList:%v", common.ErrShareGbx, err) + return + } + + for _, value := range listSpots { + SubscribeGbxClosePrice(value) // 处理闭盘数据 + } + + time.Sleep(20 * time.Second) + } +} + +// SubscribeGbxCloseNewPrice +// +// @Description: 同步实时行情价 +// @param symbolStr +func SubscribeGbxCloseNewPrice(symbolStr string) { + // 获取市场真实开闭盘时间 + timeValue, checkWeekday := MarketCheckOpenAndCloseTime(flags.ShareGbxMarketType) + // 判定是否盘中 + if utils.CheckInPlateTime(timeValue) && checkWeekday { + // 盘中实时价格 + realTimePrice, err := Reds.HGet(context.Background(), flags.ShareUkClosingNewPriceKey, symbolStr).Result() + if err != nil { + realTimePrice = decimal.Zero.String() + } + if realTimePrice != decimal.Zero.String() { + keys := publicData.SymbolCache(flags.Gbx, symbolStr, flags.TradeTypePrice) + if err = memory.ShareGbxCache.Set(keys, []byte(realTimePrice)); err != nil { + applogger.Error("%v SubscribeGbxCloseNewPrice.ShareGbxCache:%v", common.ErrShareGbx, err) + } + } + } +} + +// InitShareGbxPriceSetUp +// +// @Description: 同步插针价 +// @param check +func InitShareGbxPriceSetUp(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkGbx + } else { + key = setting.MarketShareGbx + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareGbxPriceSetUp.LoadLRangeList:%v", common.ErrShareGbx, err) + time.Sleep(20 * time.Second) + continue + } + + for _, value := range listSpots { + gbxKey := publicData.SymbolCache(flags.Gbx, value, flags.TradeTypePrice) + gbxSetCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareGbxMarketType, value) + vw, err := GetBeforeAndAfterSetPrice(gbxSetCache) + if err != nil || len(vw) == 0 { + _ = memory.ShareGbxPriceSetUp.Delete(gbxKey) + continue + } + if err = memory.ShareGbxPriceSetUp.Set(gbxKey, []byte(vw)); err != nil { + applogger.Error("%v InitShareGbxPriceSetUp.ShareGbxPriceSetUp:%v", common.ErrShareGbx, err) + } + } + + time.Sleep(500 * time.Millisecond) + } +} + +// SubscribeGbxHSetCodeList +// +// @Description: 同步列表缓存 +// @param symbolStr +// @param check +func SubscribeGbxHSetCodeList(symbolStr string, check bool) { + var key string + if check { + key = setting.MarketShareBlkGbx + } else { + key = setting.MarketShareGbx + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + return + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeGbxHSetCodeList.%v.HSet:%v", common.ErrShareGbx, key, err) + return + } + } +} + +// InitShareGbxCloseNewPrice +// +// @Description: 获取行情价 +// @param check +func InitShareGbxCloseNewPrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkGbx + } else { + key = setting.MarketShareGbx + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareGbx.LoadLRangeList:%v", common.ErrShareGbx, err) + return + } + for _, value := range listSpots { + SubscribeGbxCloseNewPrice(value) + } + + time.Sleep(500 * time.Millisecond) + } +} + +// SubscribeGbxClosePrice +// +// @Description: 获取闭盘价 +// @param symbolStr +func SubscribeGbxClosePrice(symbolStr string) { + var err error + var sub = decimal.Zero + var closeNewPrice, closingPrice, price string + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareUkClosingNewPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareUkClosingPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice = decimal.Zero.String() + } + } + + // 写入闭盘价格 + closingPrice, err = Reds.HGet(context.Background(), flags.ShareUkBeforeClose, symbolStr).Result() + if err != nil { + closingPrice = decimal.Zero.String() + } + + // 判定取值数据 + if closeNewPrice != decimal.Zero.String() { + price = closeNewPrice + } else { + price = closingPrice + } + closeKey := publicData.SymbolCache(flags.Gbx, symbolStr, flags.TradeTypeClosePrice) + if err = memory.ShareGbxClosePrice.Set(closeKey, []byte(price)); err != nil { + applogger.Error("%v SubscribeGbxClosePrice.Set.price:%v", common.ErrShareGbx, err) + } + + // 写入涨跌幅价格判定缓存 + cn := closeNewPrice != decimal.Zero.String() + cp := closingPrice != decimal.Zero.String() + lcn := utils.IsNumber(closeNewPrice) + lcp := utils.IsNumber(closingPrice) + if cn && cp && lcn && lcp { + sub = decimal.RequireFromString(closingPrice).Sub(decimal.RequireFromString(closeNewPrice)) + } + chgKey := publicData.SymbolCache(flags.Gbx, symbolStr, flags.TradeTypeChg) // 涨跌幅标识Key + if err = memory.ShareGbxChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v SubscribeGbxClosePrice.Set.price:%v", common.ErrShareGbx, err) + } +} + +// OrderSubAdminShareGbxSubscribeBySum +// +// @Description: 持仓订单浮动盈亏计算 +// @param uo +func OrderSubAdminShareGbxSubscribeBySum(uo *Data) { + for { + var topIc = setting.AdminShareGbxSubscribe + hashMap, err := uo.redisDB.HGetAll(context.Background(), topIc).Result() + if err != nil { + applogger.Error("OrderSubAdminShareGbxSubscribeBySum.HGetAll:%v", err) + time.Sleep(5 * time.Second) + continue + } + var hashList []share.ShareGbxTallyCache + for _, value := range hashMap { + var msg share.ShareGbxTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + switch msg.Status { + case flags.Entrust: // 挂单 + case flags.Position: // 持仓 + hashList = append(hashList, msg) + default: // 平仓|撤单 + err = uo.redisDB.HDel(context.Background(), topIc, msg.OrderId).Err() + if err != nil { + applogger.Error("OrderSubAdminShareGbxSubscribeBySum.HDel:%v", err) + continue + } + } + } + applogger.Info("英股数据量统计:%v", len(hashList)) + // 统计英股总持仓订单浮动盈亏 + priceSum := decimal.Zero + for _, value := range hashList { + orderModel := shareData.ShareGbxOrderProcessing(topIc, value) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch orderModel.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + price := subPrice.Mul(decimal.RequireFromString(value.Order.OrderNumber)) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + // 写入缓存 + if err = memory.ShareGbxFloating.Set(flags.FloatingGbx, []byte(priceSum.String())); err != nil { + applogger.Error("统计英股持仓订单浮动盈亏错误:%v", err) + time.Sleep(5 * time.Second) + continue + } + applogger.Info("统计英股持仓订单浮动盈亏:%v", priceSum) + + time.Sleep(1 * time.Second) + } +} + +// SubscribeShareGbx +// +// @Description: TODO: 英股订阅 +// @param ctx +// @param uo +// @param shareGbx +// @param check +func SubscribeShareGbx(ctx context.Context, shareGbx *ShareGbxSymbol, check bool) { + for { + select { + case symbol, _ := <-shareGbx.GbxMap: + symbolStr := string(symbol) + topIc := fmt.Sprintf("%v.%v", symbolStr, flags.CountryGbx) + // Handling duplicate subscriptions + _, ok := shareGbx.GbxMapSymbol.Load(symbolStr) + if ok { + time.Sleep(5 * time.Second) + continue + } + // Transaction determination + var key string + if check { + key = setting.MarketShareBlkGbx // 大宗股交易 + } else { + key = setting.MarketShareGbx // 英股交易 + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeShareGbx.%v.HSet:%v", common.ErrShareGbx, key, err) + time.Sleep(5 * time.Second) + continue + } + } + + // 处理订阅实时行情数据 + go func() { + symbolStrCache := symbolStr + pubSub := Reds.Subscribe(ctx, topIc) + defer pubSub.Close() + if _, err := pubSub.Receive(ctx); err != nil { + shareGbx.GbxMapSymbol.Delete(symbolStrCache) + return + } + ch := pubSub.Channel() + for { + select { + case msg, _ := <-ch: + var subMsg ShareGbxMessage + if err := json.Unmarshal([]byte(msg.Payload), &subMsg); err != nil { + applogger.Error("%v SubscribeShareGbx.Unmarshal:%v", common.ErrShareGbx, err) + time.Sleep(5 * time.Second) + return + } + SubscribeGbxPrice(subMsg.Price.String(), symbolStr, flags.RealTime) + default: + Reds.Ping(ctx) // 如果没有消息,发送 PING 命令以维护连接 + time.Sleep(10 * time.Second) + } + } + }() + + // 盘前|盘后价格设置 + _, okc := shareGbx.GbxSetMapSymbol.Load(symbolStr) + if !okc { + go func() { + for { + keyCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareGbxMarketType, symbolStr) + vw, err := GetBeforeAndAfterSetPrice(keyCache) + if err != nil || len(vw) == 0 { + priceCache := publicData.SymbolCache(flags.Gbx, symbolStr, flags.TradeTypePrice) + memory.ShareGbxPriceSetUp.Delete(priceCache) + time.Sleep(15 * time.Second) + continue + } + SubscribeGbxPrice(vw, symbolStr, flags.SetUp) + time.Sleep(10 * time.Second) + } + }() + // Write cache to determine whether to repeatedly open the protocol + shareGbx.GbxSetMapSymbol.Store(symbolStr, symbolStr) + } + + // Write in the map to determine whether to repeat subscription + shareGbx.GbxMapSymbol.Store(symbolStr, symbolStr) + } + } +} + +// SubscribeGbxPrice +// +// @Description: TODO: 订阅获取英股实时价格或者[盘前|盘后]设置价格 +// @param setPrice +// @param symbolStr +// @param check +func SubscribeGbxPrice(setPrice, symbolStr string, check int) { + var err error + var sub = decimal.Zero + + // 计算涨跌幅 + yClosingPrice, err := Reds.HGet(context.Background(), flags.ShareUkClosingPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice, err = Reds.HGet(context.Background(), flags.ShareUkClosingNewPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice = setPrice + } + } + + // 写入涨跌幅缓存数据 + yc := yClosingPrice != decimal.Zero.String() + sp := setPrice != decimal.Zero.String() + lyc := utils.IsNumber(yClosingPrice) + lsp := utils.IsNumber(setPrice) + if yc && sp && lyc && lsp { + sub = decimal.RequireFromString(setPrice).Sub(decimal.RequireFromString(yClosingPrice)) + } + chgKey := publicData.SymbolCache(flags.Gbx, symbolStr, flags.TradeTypeChg) // 涨跌幅标识Key + if err = memory.ShareGbxChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v SubscribeGbxPrice.ShareGbxChgMark.Set.price:%v", common.ErrShareGbx, err) + } + if !flags.CheckSetting { + applogger.Debug("涨跌幅交易对内存key:%v,涨跌幅数值:%v", symbolStr, sub) + } + + // 交易类型:0最新价,1买入,2卖出 + price := publicData.SymbolCache(flags.Gbx, symbolStr, flags.TradeTypePrice) + switch check { + case flags.RealTime: // 实时价格(优先级高) + if err = memory.ShareGbxCache.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeGbxPrice.ShareGbxCache.Set.price:%v", common.ErrShareGbx, err) + } + case flags.SetUp: // 设置[盘前|盘后]价格 + if err = memory.ShareGbxPriceSetUp.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeGbxPrice.ShareGbxPriceSetUp:%v", common.ErrShareGbx, err) + } + } + if !flags.CheckSetting { + applogger.Debug("股票交易对内存Key:%v,最新价格:%v", price, setPrice) + } +} + +// SubscribeGbxSetForcedClosure +// +// @Description: TODO: 处理英股强平阈值 +// @param symbolStr +func SubscribeGbxSetForcedClosure(symbolStr string) { + flatRatio := GetCacheForcedClosure(flags.StockUkSystemSetUpKey, symbolStr) + chgKey := publicData.SymbolCache(flags.Gbx, symbolStr, flags.TradeTypeForcedClosure) + if err := memory.ShareGbxForcedClosure.Set(chgKey, []byte(flatRatio.String())); err != nil { + applogger.Error("%v SubscribeGbxSetForcedClosure.ShareGbxForcedClosure err:%v", common.ErrShareGbx, err) + return + } +} + +// ShareGbxTransactionEntrust +// +// @Description: 英股委托订单 +// @param ctx +func ShareGbxTransactionEntrust(ctx context.Context) { + for { + ShareGbxTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareGbxTransactionCalculationEntrust +// +// @Description: 英股挂单缓存队列计算 +// @param ctx +// @param uo +func ShareGbxTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 全局变量处理 + if CheckGlobalTread(flags.GbxMarket) { + time.Sleep(5 * time.Second) + return + } + + // 获取股票挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareGbxEntrust).Result() + if err != nil { + applogger.Error("%v ShareGbxTransactionCalculationEntrust.HGetAll:%v", common.ErrShareGbx, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareGbxTallyCache, 1) + var entrust share.ShareGbxTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareGbxTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareGbx, err) + continue + } + + // 股票实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareGbxPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareGbxTransactionCalculationEntrust.Get:%v---%v", common.ErrShareGbx, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + //chg := GetShareChgGbx(flags.Gbx, entrust.Symbol) // 涨跌幅标识 + //if share.CheckGbxOrderByChg(setting.MarketShareGbxEntrust, entrust, chg) { + // continue + //} + + wg.Add(1) + go func(value string) { + var resultMsg share.ShareGbxTallyCache + switch entrust.Order.DealType { + case flags.DealTypeLimited: // 限价挂单 + resultMsg = ShareGbxConcurrentComputingEntrustLimited(&entrust, newPrice, &wg) + case flags.DealTypeMarket: // 市价挂单(开盘即成交) + resultMsg = ShareGbxConcurrentComputingEntrustMarket(&entrust, newPrice, &wg) + } + msg <- resultMsg // 通知管道异步处理订单操作 + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到英股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到英股持仓信息:%v", resultMsg) + } + + // 开盘逻辑 + if err = ShareGbxLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Warn("%v ShareGbxTransactionCalculationEntrust.ShareGbxLiquidationEntrust:%v", common.ErrShareGbx, err) + continue + } + + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v ShareGbxTransactionCalculationEntrust.Marshal:%v", common.ErrShareGbx, err) + continue + } + + // TODO: 写入持仓消息队列 + //if err = uo.mqProducer.Entrust.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareGbxTransactionCalculationEntrust.EntrustPushNotice:%v", common.ErrShareGbx, err) + // continue + //} + + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareGbxPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("英股挂单并发计算执行完毕......") +} + +// ShareGbxConcurrentComputingEntrustLimited +// +// @Description: 英股挂单(限价|市价)缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareGbxTallyCache +func ShareGbxConcurrentComputingEntrustLimited(order *share.ShareGbxTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareGbxTallyCache { + var deleteCache bool + var dealPrice string + var limitPrice = decimal.RequireFromString(order.Order.LimitPrice) // 限价-价格 + var status = order.Status // 原始价格 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价买入逻辑判定 -> 挂单金额 > 当前价格 + if limitPrice.Cmp(newPrice) > 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + } + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价卖入逻辑判定 -> 挂单金额 < 当前价格 + if limitPrice.Cmp(newPrice) < 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareGbxEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareGbxConcurrentComputingEntrustLimited.HDel:%v", common.ErrShareGbx, err) + order.Status = status + } + } + + wg.Done() + return share.ShareGbxTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareGbxConcurrentComputingEntrustMarket +// +// @Description: 英股市价下单进入挂单队列(休市) +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareGbxTallyCache +func ShareGbxConcurrentComputingEntrustMarket(order *share.ShareGbxTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareGbxTallyCache { + var deleteCache bool + var dealPrice string + var marketPrice = decimal.RequireFromString(order.Order.MarketPrice) // 市价-价格 + var status = order.Status // 原始价格 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareGbxEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareGbxConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareGbx, err) + order.Status = status + } + } + + wg.Done() + return share.ShareGbxTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareBlockGbxConcurrentComputingEntrustMarket +// +// @Description: 大宗(英股)交易 +// @param order +// @param newPrice +// @param wg +// @return share.ShareInrTallyCache +func ShareBlockGbxConcurrentComputingEntrustMarket(order *share.ShareGbxTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareGbxTallyCache { + var status = order.Status // 原始状态 + + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareBlkEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareBlockGbxConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareBlk, err) + order.Status = status + } + + wg.Done() + return share.ShareGbxTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: newPrice.String(), // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareGbxMqOpenBusiness +// +// @Description: TODO: 英股持仓消息队列 +// @param ctx +// @param uo +func ShareGbxMqOpenBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Entrust.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerEntrustMq.ShareGbxMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareGbxMqOpenBusiness.ShareGbxMq err....", common.ErrShareGbx) + continue + } + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareGbxTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareGbxMqOpenBusiness.Unmarshal:%v", common.ErrShareGbx, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareGbxLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareGbxMqOpenBusiness.ShareGbxLiquidationEntrust:%v", common.ErrShareGbx, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + applogger.Error("这里没有监控到持仓mq队列消息.........") + time.Sleep(2 * time.Second) + } + } +} + +// ShareGbxLiquidationEntrust +// +// @Description: 英股挂单-->开仓业务处理 +// @param ctx +// @param order +// @return error +func ShareGbxLiquidationEntrust(ctx context.Context, order *share.ShareGbxTallyCache) error { + // 1、开盘 + err := StockGbxOpenOrder(ctx, Msql, order.UserId, order.OrderId, order.OpenPrice, order.Order) + if err != nil { + applogger.Error("%v ShareGbxLiquidationEntrust.StockGbxOpenOrder:%v", common.ErrShareGbx, err) + return err + } + + // 大宗(英股)交易判定 + var entrustKey, adminKey string + if !CheckTypeStatus(order.Order.Type) { + entrustKey = setting.ShareGbxSubscribe + adminKey = setting.AdminShareGbxSubscribe + } else { + entrustKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // 2、更新用户订阅缓存列表订单状态 + updateKey := virtual.OrderIdListKey(entrustKey, order.UserId) + if err = UpdateShareGbxSubscribeHashStatusByOrderId(order.OrderId, updateKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareGbxLiquidationEntrust.Entrust.%v:%v", common.ErrShareGbx, entrustKey, err) + return err + } + + // 3、更新管理员订阅缓存列表订单状态 + if err = UpdateShareGbxSubscribeHashStatusByOrderId(order.OrderId, adminKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareGbxLiquidationEntrust.Entrust.%v:%v", common.ErrShareGbx, adminKey, err) + return err + } + + return nil +} + +// ShareGbxTransactionPosition +// +// @Description: 英股持仓订单 +// @param ctx +func ShareGbxTransactionPosition(ctx context.Context) { + for { + ShareGbxTransactionCalculationPosition(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareGbxTransactionCalculationPosition +// +// @Description: 英股持仓缓存队列计算 +// @param ctx +func ShareGbxTransactionCalculationPosition(ctx context.Context) { + var wg sync.WaitGroup + + // 判定是否交易 + if CheckGlobalTread(flags.GbxMarket) { + time.Sleep(5 * time.Second) + return + } + + // TODO: 获取IPO未支付订单缓存 + userIdMap, _ := GetBotUserArrears(ctx) + + // 获取持仓缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareGbxPosition).Result() + if err != nil { + applogger.Error("%v ShareGbxTransactionCalculationPosition.HGetAll:%v", common.ErrShareGbx, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareGbxTallyCache, 1) + var entrust share.ShareGbxTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareGbxTransactionCalculationPosition.Unmarshal:%v", common.ErrShareGbx, err) + continue + } + + // TODO: 判定是否未IPO未支付订单-不能平仓 + _, isOk := userIdMap[entrust.UserId] + if isOk { + continue + } + + // 处理时间 + if !CheckShareSystemTime(entrust.ClosingTime) { + applogger.Info("英股:%v,平仓时间:%v暂未到达...", entrust.Symbol, entrust.ClosingTime) + continue + } + + // TODO: 实时获取强平阈值 + //entrust.Order.System.StrongFlatRatio = GetForcedClosureValue(flags.Gbx, entrust.Symbol) + + // 实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareGbxPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareGbxTransactionCalculationPosition.Get:%v--%v", common.ErrShareGbx, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + //chg := GetShareChgGbx(flags.Gbx, entrust.Symbol) // 涨跌幅标识 + //if share.CheckGbxOrderByChg(setting.MarketShareGbxEntrust, entrust, chg) { + // continue + //} + + // 判定配额强平 + checkFlattening := GetStrongFlatteningThreshold(entrust.UserId) + + wg.Add(1) + go func(value string) { + resultMsg := ShareGbxConcurrentComputingPosition(&entrust, newPrice, &wg, checkFlattening) + msg <- resultMsg + }(value) + + // 处理并发结果 + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Position: // 持仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到英股持仓信息:%v", resultMsg) + } + case flags.Close: // 平仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到英股平仓信息:%v", resultMsg) + } + + // TODO: 平仓操作(优化写入队列中等待平仓) + //var byteStr []byte + //byteStr, err = json.Marshal(resultMsg) + //if err != nil { + // applogger.Error("%v ShareGbxTransactionCalculationPosition.Marshal:%v", common.ErrShareGbx, err) + // continue + //} + //if err = uo.mqProducer.Position.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareGbxTransactionCalculationPosition.DealPublish:%v", common.ErrShareGbx, err) + // continue + //} + + if err = ShareGbxLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareGbxTransactionCalculationPosition.ShareGbxLiquidationPosition:%v", common.ErrShareGbx, err) + continue + } + } + } + } + + wg.Wait() + applogger.Info("英股持仓并发计算执行完毕......") +} + +// ShareGbxConcurrentComputingPosition +// +// @Description: 英股持仓缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareGbxTallyCache +func ShareGbxConcurrentComputingPosition(order *share.ShareGbxTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup, checkFlattening bool) share.ShareGbxTallyCache { + var deleteCache, checkBool bool + var dealPrice string + var sellShort decimal.Decimal + var openPrice = decimal.RequireFromString(order.OpenPrice) // 限价 + var orderNumber = decimal.RequireFromString(order.Order.OrderNumber) // 仓位 + + var pryNum decimal.Decimal + lenPryNum := len(utils.ReplaceStr(order.Order.PryNum)) == 0 + if lenPryNum || order.Order.PryNum == flags.SetZero || order.Order.System.UserStatus != flags.SetThree || !utils.IsNumberInt(order.Order.PryNum) { + pryNum = decimal.RequireFromString(flags.SetOne) + } else { + pryNum = decimal.RequireFromString(order.Order.PryNum) + } + + // 下单判定设置(false无设置|true止盈止损) + _, stopWinPrice, stopLossPrice, _ := StockGbxVoteStopType(order.Order) + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨(强平) + if !flags.CheckSetting { + applogger.Info("用户ID:%v,持仓开仓价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买涨:挂止损止盈,止盈价必须<当前价,止损价必须>当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + // 强行平仓(做多) + if !checkBool { + sellShort = newPrice.Sub(openPrice).Mul(orderNumber) + } + case flags.TradeTypeSell: // 买跌(存在强行平仓) + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价持仓买跌下单价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买跌:挂止损止盈,止盈价必须>当前价,止损价必须<当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + // 强行平仓(做空) + if !checkBool { + sellShort = openPrice.Sub(newPrice).Mul(orderNumber) + } + } + /* 强行平仓(做多|做空) + 1、做多:(最新成交价-开仓成交价)*仓位 + 2、做空:(开仓成交价-最新成交价)*仓位 + 3、当浮动盈亏 >= 保证金的70%订单强行平仓 + */ + if sellShort.IsNegative() && checkFlattening { + orderAmount := newPrice.Mul(decimal.RequireFromString(order.Order.OrderNumber)).Div(pryNum) // 订单金额 = 当前价格 * 订单数量 / 杠杆 + floatPrice := orderAmount.Mul(decimal.RequireFromString(order.Order.System.StrongFlatRatio)) + if !flags.CheckSetting { + applogger.Debug("强平保证金:%v,强平浮动70:%v,强行平仓判定:%v", orderAmount, floatPrice, sellShort.Abs().Cmp(floatPrice)) + } + if sellShort.Abs().Cmp(floatPrice) >= 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + switch order.Order.TradeType { + case flags.TradeTypeBuy: //买涨 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + case flags.TradeTypeSell: // 买跌 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + } + // 交易状态判定 + if checkBool { + deleteCache = true + order.Status = flags.Close + } + if deleteCache { + // 根据订单ID-删除持仓列表缓存订单 + if err := Reds.HDel(context.Background(), setting.MarketShareGbxPosition, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareGbxConcurrentComputingPosition.Position.HDel:%v", common.ErrShareGbx, err) + } + } + + wg.Done() + return share.ShareGbxTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + ClosingPrice: dealPrice, // 平仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareGbxMqClosingBusiness +// +// @Description: TODO: 处理印英股平仓消息队列 +// @param ctx +// @param uo +func ShareGbxMqClosingBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Position.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerPositionMq.ShareGbxMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareGbxMqClosingBusiness.ShareGbxMq err....", common.ErrShareGbx) + continue + } + applogger.Info("接收到平仓信息:%v", string(message)) + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareGbxTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareGbxMqClosingBusiness.Unmarshal:%v", common.ErrShareGbx, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareGbxLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareGbxMqClosingBusiness.ShareGbxLiquidationPosition:%v", common.ErrShareGbx, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + time.Sleep(2 * time.Second) + } + } +} + +// ShareInrLiquidationPosition +// +// @Description: 英股持仓-->平仓业务处理 +// @param ctx +// @param order +// @return error +func ShareGbxLiquidationPosition(ctx context.Context, order *share.ShareGbxTallyCache) error { + // 1、平仓操作 + err := StockGbxClosingOrder(ctx, Msql, order.OrderId, order.ClosingPrice, order.Order) + if err != nil { + applogger.Error("%v ShareGbxLiquidationPosition.StockGbxClosingOrder:%v", common.ErrShareGbx, err) + return err + } + + // 2、平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareGbxSubscribe, order.UserId) + if err = UpdateShareGbxSubscribeHashStatusByOrderId(order.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v ShareGbxLiquidationPosition.Position.entrustKey:%v", common.ErrShareGbx, err) + return err + } + + // 3、平仓更新管理员订阅订单状态 + if err = UpdateShareGbxSubscribeHashStatusByOrderId(order.OrderId, setting.AdminShareGbxSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v ShareGbxLiquidationPosition.Position.adminKey:%v", common.ErrShareGbx, err) + return err + } + + return nil +} + +// StockInrVoteStopType +// +// @Description: 英股判定取值止损止盈 +// @param order +// @return bool +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func StockGbxVoteStopType(order structure.ShareOrder) (bool, decimal.Decimal, decimal.Decimal, error) { + var checkBool bool + var stopWinPrice, stopLossPrice decimal.Decimal + switch order.StopType { + case flags.StopTypeNone: // 暂无设置止盈止损 + checkBool = false + case flags.StopTypeSet: // 设置止盈止损 + checkBool = true + stopWinPrice, _ = decimal.NewFromString(order.StopWinPrice) + stopLossPrice, _ = decimal.NewFromString(order.StopLossPrice) + default: + return checkBool, stopWinPrice, stopLossPrice, flags.ErrContractThirteen + } + + return checkBool, stopWinPrice, stopLossPrice, nil +} + +// GetShareGbxPrice +// +// @Description: 英股价格 +// @param symbol +// @return decimal.Decimal +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func GetShareGbxPrice(symbol string) (decimal.Decimal, error) { + var err error + var priceByte []byte + var newPrice decimal.Decimal + + key := publicData.SymbolCache(flags.Gbx, symbol, flags.TradeTypePrice) + priceByte, err = memory.GetShareGbxCache(key) + if err != nil { + return decimal.Decimal{}, err + } + + newPrice, err = decimal.NewFromString(string(priceByte)) + if err != nil { + return decimal.Decimal{}, err + } + + applogger.Info("GetShareGbxPrice:%v,topIc:%v,shareGbxPrice:%v", symbol, key, newPrice) + + return newPrice, nil +} diff --git a/internal/data/subscribe_share_hkd.go b/internal/data/subscribe_share_hkd.go new file mode 100644 index 0000000..1179273 --- /dev/null +++ b/internal/data/subscribe_share_hkd.go @@ -0,0 +1,1241 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/mq/consumer" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/socket/shareData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "sync" + "time" +) + +/* +港股票行情订阅 +1、接收用户港股下单的交易对港股行情 +2、将订阅行情写入内存中用于并发计算 +3、挂单(市价|限价)缓存队列处理-开仓 +4、持仓缓存队列处理-平仓 +*/ + +// ShareHkdMessage +// @Description: +type ShareHkdMessage struct { + Symbol string `json:"symbol,omitempty"` // 交易所:股票代码 + StockCode string `json:"stock_code,omitempty"` // 股票代码 + StockName string `json:"stock_name,omitempty"` // 股票名,可能为空 + Price decimal.Decimal `json:"price,omitempty"` // 实时价格 + UpDownRate decimal.Decimal `json:"up_down_rate,omitempty"` // 涨跌% + UpDown decimal.Decimal `json:"up_down,omitempty"` // 涨跌额 + TradeV decimal.Decimal `json:"trade_v,omitempty"` // 技术评级指标值 + TradeK string `json:"trade_k,omitempty"` // 技术评级 + Vol int64 `json:"vol,omitempty"` // 成交量 + TurnoverPriceTotal decimal.Decimal `json:"turnover_price_total,omitempty"` // 成交量*价格 + PriceTotal string `json:"price_total,omitempty"` // 总市值 + PE string `json:"p_e,omitempty"` // pe + Eps string `json:"eps,omitempty"` // EPS + EmployeesNumber string `json:"employees_number,omitempty"` // 雇员 + Plate string `json:"plate,omitempty"` // 板块 + Desc string `json:"desc,omitempty"` // 描述 + PriceCode string `json:"price_code,omitempty"` // 价格类型 + Country string `json:"country,omitempty"` // 国家 + Ts int64 `json:"ts,omitempty"` // 时间 + Token string `json:"token,omitempty"` // Token 令牌 +} + +// ShareHkdSymbol +// @Description: +type ShareHkdSymbol struct { + HkdMap chan []byte // 订单交易对 -- 用户下单通知订阅 + HkdSetMap chan []byte // 订单交易对 -- 用户盘前|盘后行情订阅 + HkdMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 + HkdSetMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 +} + +// InitCacheSymbolShareHkd +// +// @Description: +// @param ctx +// @param uo +func InitCacheSymbolShareHkd(ctx context.Context, uo *Data) { + for { + idnList, err := GetBotStockHkdListByStockId(ctx, uo) + if err != nil { + return + } + + for _, value := range idnList { + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), setting.MarketShareHkd, value).Result() + if err != nil { + applogger.Error("%v InitCacheSymbolShareHkd.MarketShareHkd.HExists:%v", common.ErrShareHkd, err) + continue + } + if !checkBool { + if err = uo.redisDB.HSet(context.Background(), setting.MarketShareHkd, value, value).Err(); err != nil { + applogger.Error("%v InitCacheSymbolShareHkd.MarketShareHkd.HSet:%v", common.ErrShareHkd, err) + continue + } + } + if !flags.CheckSetting { + applogger.Info("初始化港股票代码:%v", value) + } + } + + time.Sleep(10 * time.Second) + } +} + +// InitSubscribeShareHkd +// +// @Description: 港股订阅 +// @param ctx +// @param uo +// @param shareIdn +func InitSubscribeShareHkd(shareHkd *ShareHkdSymbol, check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkHkd + } else { + key = setting.MarketShareHkd + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareHkd.LoadLRangeList:%v", common.ErrShareHkd, err) + return + } + + for _, value := range listSpots { + // Handling duplicate subscriptions + _, ok := shareHkd.HkdMapSymbol.Load(value) + if ok { + continue + } + + shareHkd.HkdMap <- []byte(value) + } + + time.Sleep(10 * time.Second) + } +} + +// InitShareHkdCloseCachePrice +// +// @Description: +// @param shareHkd +// @param check +func InitShareHkdCloseCachePrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkHkd + } else { + key = setting.MarketShareHkd + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareHkd.LoadLRangeList:%v", common.ErrShareHkd, err) + return + } + + for _, value := range listSpots { + SubscribeHkdClosePrice(value) // 处理闭盘数据 + } + + time.Sleep(20 * time.Second) + } +} + +// InitShareHkdCloseNewPrice +// +// @Description: 同步实时行情 +// @param check +func InitShareHkdCloseNewPrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkHkd + } else { + key = setting.MarketShareHkd + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareHkdCloseNewPrice.LoadLRangeList:%v", common.ErrShareHkd, err) + time.Sleep(20 * time.Second) + continue + } + for _, value := range listSpots { + SubscribeHkdCloseNewPrice(value) + } + time.Sleep(500 * time.Millisecond) + } +} + +// InitShareHkdPriceSetUp +// +// @Description: 同步插针行情 +// @param check +func InitShareHkdPriceSetUp(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkHkd + } else { + key = setting.MarketShareHkd + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareHkdPriceSetUp.LoadLRangeList:%v", common.ErrShareHkd, err) + time.Sleep(20 * time.Second) + continue + } + + for _, value := range listSpots { + hkdKey := publicData.SymbolCache(flags.Hkd, value, flags.TradeTypePrice) + hkdSetCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareHkdMarketType, value) + vw, err := GetBeforeAndAfterSetPrice(hkdSetCache) + if err != nil || len(vw) == 0 { + _ = memory.ShareHkdPriceSetUp.Delete(hkdKey) + continue + } + if err = memory.ShareHkdPriceSetUp.Set(hkdKey, []byte(vw)); err != nil { + applogger.Error("%v InitShareHkdPriceSetUp.ShareHkdPriceSetUp:%v", common.ErrShareHkd, err) + } + } + + time.Sleep(500 * time.Millisecond) + } +} + +// SubscribeHkdHSetCodeList +// +// @Description: 同步列表缓存 +// @param symbolStr +// @param check +func SubscribeHkdHSetCodeList(symbolStr string, check bool) { + var key string + if check { + key = setting.MarketShareBlkHkd + } else { + key = setting.MarketShareHkd + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + return + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeHkdHSetCodeList.%v.HSet:%v", common.ErrShareHkd, key, err) + return + } + } +} + +// SubscribeHkdCloseNewPrice +// +// @Description: 获取行情价 +// @param symbolStr +// @param check +func SubscribeHkdCloseNewPrice(symbolStr string) { + // 获取市场真实开闭盘时间 + timeValue, checkWeekday := MarketCheckOpenAndCloseTime(flags.ShareHkdMarketType) + // 判定是否盘中 + if utils.CheckInPlateTime(timeValue) && checkWeekday { + // 盘中实时价格 + realTimePrice, err := Reds.HGet(context.Background(), flags.ShareHongKongClosingNewPriceKey, symbolStr).Result() + if err != nil { + realTimePrice = decimal.Zero.String() + } + if realTimePrice != decimal.Zero.String() { + keys := publicData.SymbolCache(flags.Hkd, symbolStr, flags.TradeTypePrice) + if err = memory.ShareHkdCache.Set(keys, []byte(realTimePrice)); err != nil { + applogger.Error("%v SubscribeHkdCloseNewPrice.ShareHkdCache:%v", common.ErrShareHkd, err) + } + } + } +} + +// SubscribeHkdClosePrice +// +// @Description: 获取闭盘价 +// @param symbolStr +func SubscribeHkdClosePrice(symbolStr string) { + var err error + var sub = decimal.Zero + var closeNewPrice, closingPrice, price string + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareHongKongClosingNewPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareHongKongClosingPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice = decimal.Zero.String() + } + } + + // 写入闭盘价格 + closingPrice, err = Reds.HGet(context.Background(), flags.ShareHongKongBeforeClose, symbolStr).Result() + if err != nil { + closingPrice = decimal.Zero.String() + } + + // 判定取值数据 + if closeNewPrice != decimal.Zero.String() { + price = closeNewPrice + } else { + price = closingPrice + } + closeKey := publicData.SymbolCache(flags.Hkd, symbolStr, flags.TradeTypeClosePrice) + if err = memory.ShareHkdClosePrice.Set(closeKey, []byte(price)); err != nil { + applogger.Error("%v ShareHkdClosePrice.Set.price:%v", common.ErrShareHkd, err) + } + + // 写入涨跌幅价格判定缓存 + cn := closeNewPrice != decimal.Zero.String() + cp := closingPrice != decimal.Zero.String() + lcn := utils.IsNumber(closeNewPrice) + lcp := utils.IsNumber(closingPrice) + if cn && cp && lcn && lcp { + sub = decimal.RequireFromString(closingPrice).Sub(decimal.RequireFromString(closeNewPrice)) + } + chgKey := publicData.SymbolCache(flags.Hkd, symbolStr, flags.TradeTypeChg) // 涨跌幅标识Key + if err = memory.ShareHkdChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v ShareHkdChgMark.Set.price:%v", common.ErrShareHkd, err) + } +} + +// OrderSubAdminShareHkdSubscribeBySum +// +// @Description: 持仓订单浮动盈亏计算 +// @param ctx +// @param uo +func OrderSubAdminShareHkdSubscribeBySum(uo *Data) { + for { + topIc := setting.AdminShareHkdSubscribe + hashMap, err := uo.redisDB.HGetAll(context.Background(), topIc).Result() + if err != nil { + applogger.Error("OrderSubAdminShareHkdSubscribeBySum.HGetAll:%v", err) + time.Sleep(5 * time.Second) + continue + } + var hashList []share.ShareHkdTallyCache + for _, value := range hashMap { + var msg share.ShareHkdTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + switch msg.Status { + case flags.Entrust: // 挂单 + case flags.Position: // 持仓 + hashList = append(hashList, msg) + default: // 平仓|撤单 + err = uo.redisDB.HDel(context.Background(), topIc, msg.OrderId).Err() + if err != nil { + applogger.Error("OrderSubAdminShareHkdSubscribeBySum.HDel:%v", err) + continue + } + } + } + applogger.Info("港股数据量统计:%v", len(hashList)) + // 统计印尼股总持仓订单浮动盈亏 + priceSum := decimal.Zero + for _, value := range hashList { + orderModel := shareData.ShareHkdOrderProcessing(topIc, 1, value) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch value.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 买跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + price := subPrice.Mul(decimal.RequireFromString(value.Order.OrderNumber)) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + // 写入缓存 + if err = memory.ShareHkdFloating.Set(flags.FloatingHkd, []byte(priceSum.String())); err != nil { + applogger.Error("统计港股持仓订单浮动盈亏错误:%v", err) + time.Sleep(5 * time.Second) + continue + } + applogger.Info("统计港股持仓订单浮动盈亏:%v", priceSum) + + time.Sleep(1 * time.Second) + } +} + +// SubscribeShareHkd +// +// @Description: TODO: 港股订阅 +// @param ctx +// @param uo +// @param shareIdn +func SubscribeShareHkd(ctx context.Context, shareHkd *ShareHkdSymbol, check bool) { + for { + select { + case symbol, _ := <-shareHkd.HkdMap: + symbolStr := string(symbol) + topIc := fmt.Sprintf("%v.%v", symbolStr, flags.CountryHkd) + _, ok := shareHkd.HkdMapSymbol.Load(symbolStr) + if ok { + time.Sleep(5 * time.Second) + continue + } + // Transaction determination + var key string + if check { + key = setting.MarketShareBlkHkd // 大宗股交易 + } else { + key = setting.MarketShareHkd // 港股交易 + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err = Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeShareHkd.%v.HSet:%v", common.ErrShareHkd, key, err) + time.Sleep(5 * time.Second) + continue + } + } + + // 处理订阅实时行情数据 + go func() { + symbolStrCache := symbolStr + pubSub := Reds.Subscribe(ctx, topIc) + defer pubSub.Close() + if _, err = pubSub.Receive(ctx); err != nil { + shareHkd.HkdMapSymbol.Delete(symbolStrCache) + return + } + ch := pubSub.Channel() + for { + select { + case msg, _ := <-ch: + var subMsg ShareHkdMessage + if err = json.Unmarshal([]byte(msg.Payload), &subMsg); err != nil { + applogger.Error("%v SubscribeShareHkd.Unmarshal:%v", common.ErrShareHkd, err) + time.Sleep(5 * time.Second) + continue + } + SubscribeHkdPrice(subMsg.Price.String(), symbolStr, flags.RealTime) + default: + Reds.Ping(ctx) // 如果没有消息,发送 PING 命令以维护连接 + time.Sleep(10 * time.Second) + } + } + }() + + // 监控盘前|盘后设置价格 + _, okc := shareHkd.HkdSetMapSymbol.Load(symbolStr) + if !okc { + go func() { + for { + keyCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareHkdMarketType, symbolStr) + vw, err := GetBeforeAndAfterSetPrice(keyCache) + if err != nil || len(vw) == 0 { + priceCache := publicData.SymbolCache(flags.Hkd, symbolStr, flags.TradeTypePrice) + memory.ShareHkdPriceSetUp.Delete(priceCache) + time.Sleep(15 * time.Second) + continue + } + SubscribeHkdPrice(vw, symbolStr, flags.SetUp) + time.Sleep(10 * time.Second) + } + }() + // Write cache to determine whether to repeatedly open the protocol + shareHkd.HkdSetMapSymbol.Store(symbolStr, symbolStr) + } + + // Write in the map to determine whether to repeat subscription + shareHkd.HkdMapSymbol.Store(symbolStr, symbolStr) + } + } +} + +// SubscribeHkdPrice +// +// @Description: TODO: 订阅获取港股实时价格或者[盘前|盘后]设置价格 +// @param setPrice +// @param symbolStr +// @param check +func SubscribeHkdPrice(setPrice, symbolStr string, check int) { + var err error + var sub = decimal.Zero + + yClosingPrice, err := Reds.HGet(context.Background(), flags.ShareHongKongClosingPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice, err = Reds.HGet(context.Background(), flags.ShareHongKongClosingNewPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice = setPrice + } + } + + // 计算涨跌幅并写入内存缓存 + yc := yClosingPrice != decimal.Zero.String() + sp := setPrice != decimal.Zero.String() + lyc := utils.IsNumber(yClosingPrice) + lsp := utils.IsNumber(setPrice) + if yc && sp && lyc && lsp { + sub = decimal.RequireFromString(setPrice).Sub(decimal.RequireFromString(yClosingPrice)) + } + // 涨跌幅标识Key + chgKey := publicData.SymbolCache(flags.Hkd, symbolStr, flags.TradeTypeChg) // 涨跌幅标识Key + if err = memory.ShareHkdChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v SubscribeHkdPrice.ShareHkdChgMark.Set.price:%v", common.ErrShareHkd, err) + } + if !flags.CheckSetting { + applogger.Debug("涨跌幅交易对内存key:%v,涨跌幅数值:%v", symbolStr, sub) + } + + // 交易类型:0最新价,1买入,2卖出 + price := publicData.SymbolCache(flags.Hkd, symbolStr, flags.TradeTypePrice) + switch check { + case flags.RealTime: // 实时价格(优先级高) + if err = memory.ShareHkdCache.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeShareHkd.ShareHkdCache.Set.price:%v", common.ErrShareHkd, err) + } + case flags.SetUp: // 设置[盘前|盘后]价格 + if err = memory.ShareHkdPriceSetUp.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeShareHkd.ShareHkdPriceSetUp:%v", common.ErrShareHkd, err) + } + } + if !flags.CheckSetting { + applogger.Debug("股票交易对内存Key:%v,最新价格:%v", price, setPrice) + } +} + +// SubscribeHkdSetForcedClosure +// +// @Description: TODO: 处理港股强平阈值 +// @param symbolStr +func SubscribeHkdSetForcedClosure(symbolStr string) { + flatRatio := GetCacheForcedClosure(flags.StockHKDSystemSetUpKey, symbolStr) + chgKey := publicData.SymbolCache(flags.Hkd, symbolStr, flags.TradeTypeForcedClosure) + if err := memory.ShareHkdForcedClosure.Set(chgKey, []byte(flatRatio.String())); err != nil { + applogger.Error("%v SubscribeHkdSetForcedClosure.StockHKDSystemSetUpKey err:%v", common.ErrShareHkd, err) + return + } +} + +// ShareHkdTransactionEntrust +// +// @Description: 港股委托订单 +// @param ctx +func ShareHkdTransactionEntrust(ctx context.Context) { + for { + ShareHkdTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareHkdTransactionCalculationEntrust +// +// @Description: 港股挂单缓存队列计算 +// @param ctx +func ShareHkdTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 全局变量处理 + if CheckGlobalTread(flags.HkdMarket) { + time.Sleep(5 * time.Second) + return + } + + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareHkdEntrust).Result() + if err != nil { + applogger.Error("%v ShareHkdTransactionCalculationEntrust.HGetAll:%v", common.ErrShareHkd, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareHkdTallyCache, 1) + var entrust share.ShareHkdTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareHkdTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareHkd, err) + continue + } + + // 股票实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareHkdPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareHkdTransactionCalculationEntrust.Get:%v---%v", common.ErrShareHkd, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + chg := GetShareChgHkd(flags.Hkd, entrust.Symbol) // 涨跌幅标识 + if share.CheckOrderHkdByChg(setting.MarketShareHkdEntrust, entrust, chg) { + //applogger.Warn("当前股票%v订单在挂单状态已达到涨跌幅上限.", entrust.Symbol) + continue + } + + wg.Add(1) + go func(value string) { + var resultMsg share.ShareHkdTallyCache + switch entrust.Order.DealType { + case flags.DealTypeLimited: // 限价挂单 + resultMsg = ShareHkdConcurrentComputingEntrustLimited(&entrust, newPrice, &wg) + case flags.DealTypeMarket: // 市价挂单(开盘即成交) + resultMsg = ShareHkdConcurrentComputingEntrustMarket(&entrust, newPrice, &wg) + } + msg <- resultMsg // 通知管道异步处理订单操作 + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收港股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到港股持仓信息:%v", resultMsg) + } + + // 开盘逻辑 + if err = ShareHkdLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareHkdTransactionCalculationEntrust.ShareHkdLiquidationEntrust:%v", common.ErrShareHkd, err) + continue + } + + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v ShareHkdTransactionCalculationEntrust.Marshal:%v", common.ErrShareHkd, err) + continue + } + + // TODO: 写入持仓消息队列 + //if err = uo.mqProducer.Entrust.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareHkdTransactionCalculationEntrust.EntrustPushNotice:%v", common.ErrShareHkd, err) + // continue + //} + + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareHkdPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("港股挂单并发计算执行完毕......") +} + +// ShareHkdConcurrentComputingEntrustLimited +// +// @Description: 港股挂单(限价|市价)缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareHkdTallyCache +func ShareHkdConcurrentComputingEntrustLimited(order *share.ShareHkdTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareHkdTallyCache { + var deleteCache bool + var dealPrice string + var limitPrice = decimal.RequireFromString(order.Order.LimitPrice) // 限价-价格 + var status = order.Status // 原始价格 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + // 限价买入逻辑判定 -> 挂单金额 > 当前价格 + if limitPrice.Cmp(newPrice) > 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + } + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + // 限价卖入逻辑判定 -> 挂单金额 < 当前价格 + if limitPrice.Cmp(newPrice) < 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareHkdEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareHkdConcurrentComputingEntrustLimited.HDel:%v", common.ErrShareHkd, err) + order.Status = status + } + } + + wg.Done() + return share.ShareHkdTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareHkdConcurrentComputingEntrustMarket +// +// @Description: 港股市价下单进入挂单队列(休市) +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareHkdTallyCache +func ShareHkdConcurrentComputingEntrustMarket(order *share.ShareHkdTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareHkdTallyCache { + var deleteCache bool + var dealPrice string + var marketPrice = decimal.RequireFromString(order.Order.MarketPrice) // 市价-价格 + var status = order.Status // 原始价格 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareHkdEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareHkdConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareHkd, err) + order.Status = status + } + } + + wg.Done() + return share.ShareHkdTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareBlockHkdConcurrentComputingEntrustMarket +// +// @Description: 大宗(港股)交易 +// @param order +// @param newPrice +// @param wg +// @return share.ShareHkdTallyCache +func ShareBlockHkdConcurrentComputingEntrustMarket(order *share.ShareHkdTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareHkdTallyCache { + var status = order.Status // 原始状态 + + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareBlkEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareBlockHkdConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareBlk, err) + order.Status = status + } + + wg.Done() + return share.ShareHkdTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: newPrice.String(), // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareHkdMqOpenBusiness +// +// @Description: TODO: 港股持仓消息队列 +// @param ctx +// @param uo +func ShareHkdMqOpenBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Entrust.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerEntrustMq.ShareHkdMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareHkdMqOpenBusiness.ShareIdnMq err....", common.ErrShareHkd) + continue + } + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareHkdTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareHkdMqOpenBusiness.Unmarshal:%v", common.ErrShareHkd, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareHkdLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareHkdMqOpenBusiness.ShareHkdLiquidationEntrust:%v", common.ErrShareHkd, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + applogger.Error("这里没有监控到持仓mq队列消息.........") + time.Sleep(2 * time.Second) + } + } +} + +// ShareHkdLiquidationEntrust +// +// @Description: 港股挂单-->开仓业务处理 +// @param ctx +// @param order +// @return error +func ShareHkdLiquidationEntrust(ctx context.Context, order *share.ShareHkdTallyCache) error { + // 1、开盘 + err := StockHkdOpenOrder(ctx, Msql, order.UserId, order.OrderId, order.OpenPrice, order.Order) + if err != nil { + applogger.Error("%v ShareHkdLiquidationEntrust.StockIdnOpenOrder:%v", common.ErrShareHkd, err) + return err + } + + // 大宗(港股)交易判定 + var entrustKey, adminKey string + if !CheckTypeStatus(order.Order.Type) { + entrustKey = setting.ShareHkdSubscribe + adminKey = setting.AdminShareHkdSubscribe + } else { + entrustKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // 2、更新用户订阅缓存列表订单状态 + updateKey := virtual.OrderIdListKey(entrustKey, order.UserId) + if err = UpdateShareHkdSubscribeHashStatusByOrderId(order.OrderId, updateKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareHkdLiquidationEntrust.Entrust.%v:%v", common.ErrShareHkd, entrustKey, err) + return err + } + + // 3、更新管理员订阅缓存列表订单状态 + if err = UpdateShareHkdSubscribeHashStatusByOrderId(order.OrderId, adminKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareHkdLiquidationEntrust.Entrust.%v:%v", common.ErrShareHkd, adminKey, err) + return err + } + + return nil +} + +// ShareHkdTransactionPosition +// +// @Description: 港股持仓订单 +// @param ctx +func ShareHkdTransactionPosition(ctx context.Context) { + for { + ShareHkdTransactionCalculationPosition(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareHkdTransactionCalculationPosition +// +// @Description: 港股持仓缓存队列计算 +// @param ctx +func ShareHkdTransactionCalculationPosition(ctx context.Context) { + var wg sync.WaitGroup + + // 判定是否交易 + if CheckGlobalTread(flags.HkdMarket) { + time.Sleep(5 * time.Second) + return + } + + // TODO: 获取IPO未支付订单缓存 + userIdMap, _ := GetBotUserArrears(ctx) + + // 获取持仓缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareHkdPosition).Result() + if err != nil { + applogger.Error("%v ShareHkdTransactionCalculationPosition.HGetAll:%v", common.ErrShareHkd, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareHkdTallyCache, 1) + var entrust share.ShareHkdTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareHkdTransactionCalculationPosition.Unmarshal:%v", common.ErrShareHkd, err) + continue + } + + // TODO: 判定是否未IPO未支付订单-不能平仓 + _, isOk := userIdMap[entrust.UserId] + if isOk { + continue + } + + // 处理时间 + if !CheckShareSystemTime(entrust.ClosingTime) { + applogger.Info("港股:%v,平仓时间:%v暂未到达...", entrust.Symbol, entrust.ClosingTime) + continue + } + + // TODO: 实时获取强平阈值 + //entrust.Order.System.StrongFlatRatio = GetForcedClosureValue(flags.Hkd, entrust.Symbol) + + // 印尼股实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareHkdPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareHkdTransactionCalculationPosition.Get:%v--%v", common.ErrShareHkd, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + chg := GetShareChgHkd(flags.Hkd, entrust.Symbol) + if share.CheckOrderHkdByChg(setting.MarketShareHkdEntrust, entrust, chg) { + //applogger.Warn("当前股票%v订单在挂单状态已达到涨跌幅上限.", entrust.Symbol) + continue + } + + // 判定配额强平 + checkFlattening := GetStrongFlatteningThreshold(entrust.UserId) + + wg.Add(1) + go func(value string) { + resultMsg := ShareHkdConcurrentComputingPosition(&entrust, newPrice, &wg, checkFlattening) + msg <- resultMsg + }(value) + + // 处理并发结果 + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Position: // 持仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到港股持仓信息:%v", resultMsg) + } + case flags.Close: // 平仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到港股平仓信息:%v", resultMsg) + } + + // TODO: 平仓操作(优化写入队列中等待平仓) + //var byteStr []byte + //byteStr, err = json.Marshal(resultMsg) + //if err != nil { + // applogger.Error("%v ShareHkdTransactionCalculationPosition.Marshal:%v", common.ErrShareHkd, err) + // continue + //} + //if err = uo.mqProducer.Position.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareHkdTransactionCalculationPosition.DealPublish:%v", common.ErrShareHkd, err) + // continue + //} + + if err = ShareHkdLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareHkdTransactionCalculationPosition.ShareHkdLiquidationPosition:%v", common.ErrShareHkd, err) + continue + } + } + } + } + + wg.Wait() + applogger.Info("港股持仓并发计算执行完毕......") +} + +// ShareHkdConcurrentComputingPosition +// +// @Description: 港股持仓缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareHkdTallyCache +func ShareHkdConcurrentComputingPosition(order *share.ShareHkdTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup, checkFlattening bool) share.ShareHkdTallyCache { + var deleteCache, checkBool bool + var dealPrice string + var sellShort decimal.Decimal + var openPrice = decimal.RequireFromString(order.OpenPrice) // 限价 + var orderNumber = decimal.RequireFromString(order.Order.OrderNumber) // 仓位 + + var pryNum decimal.Decimal + lenPryNum := len(utils.ReplaceStr(order.Order.PryNum)) == 0 + if lenPryNum || order.Order.PryNum == flags.SetZero || order.Order.System.UserStatus != flags.SetThree || !utils.IsNumberInt(order.Order.PryNum) { + pryNum = decimal.RequireFromString(flags.SetOne) + } else { + pryNum = decimal.RequireFromString(order.Order.PryNum) + } + + // 下单判定设置(false无设置|true止盈止损) + _, stopWinPrice, stopLossPrice, _ := StockHkdVoteStopType(order.Order) + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨(强平) + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,持仓开仓价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买涨:挂止损止盈,止盈价必须<当前价,止损价必须>当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + // 强行平仓(做多) + if !checkBool { + sellShort = newPrice.Sub(openPrice).Mul(orderNumber) + } + case flags.TradeTypeSell: // 买跌(存在强行平仓) + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价持仓买跌下单价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买跌:挂止损止盈,止盈价必须>当前价,止损价必须<当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + // 强行平仓(做空) + if !checkBool { + sellShort = openPrice.Sub(newPrice).Mul(orderNumber) + } + } + /* 强行平仓(做多|做空) + 1、做多:(最新成交价-开仓成交价)*仓位 + 2、做空:(开仓成交价-最新成交价)*仓位 + 3、当浮动盈亏 >= 保证金的70%订单强行平仓 + */ + if sellShort.IsNegative() && checkFlattening { + orderAmount := newPrice.Mul(decimal.RequireFromString(order.Order.OrderNumber)).Div(pryNum) // 保证金 = 当前价格 * 订单数量 / 杠杆 + floatPrice := orderAmount.Mul(decimal.RequireFromString(order.Order.System.StrongFlatRatio)) + if !flags.CheckSetting { + applogger.Debug("强平保证金:%v,强平浮动70:%v,强行平仓判定:%v", orderAmount, floatPrice, sellShort.Abs().Cmp(floatPrice)) + } + if sellShort.Abs().Cmp(floatPrice) >= 0 { + checkBool = true + // 设置价差 + difference := newPrice.Mul(utils.Difference()) // 设置价差 + switch order.Order.TradeType { + case flags.TradeTypeBuy: //买涨 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + case flags.TradeTypeSell: // 买跌 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + } + + if checkBool { + deleteCache = true + order.Status = flags.Close + } + + if deleteCache { + // 根据订单ID-删除持仓列表缓存订单 + if err := Reds.HDel(context.Background(), setting.MarketShareHkdPosition, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareHkdConcurrentComputingPosition.Position.HDel:%v", common.ErrShareHkd, err) + } + } + + wg.Done() + return share.ShareHkdTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + ClosingPrice: dealPrice, // 平仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareHkdMqClosingBusiness +// +// @Description: TODO: 处理港股平仓消息队列 +// @param ctx +// @param uo +func ShareHkdMqClosingBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Position.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerPositionMq.ShareHkdMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareHkdMqClosingBusiness.ShareHkdMq err....", common.ErrShareHkd) + continue + } + applogger.Info("接收到平仓信息:%v", string(message)) + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareHkdTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareHkdMqClosingBusiness.Unmarshal:%v", common.ErrShareHkd, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareHkdLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareHkdMqClosingBusiness.ShareHkdLiquidationPosition:%v", common.ErrShareHkd, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + time.Sleep(2 * time.Second) + } + } +} + +// ShareHkdLiquidationPosition +// +// @Description: 港股持仓-->平仓业务处理 +// @param ctx +// @param order +// @return error +func ShareHkdLiquidationPosition(ctx context.Context, order *share.ShareHkdTallyCache) error { + // 1、平仓操作 + err := StockHkdClosingOrder(ctx, Msql, order.OrderId, order.ClosingPrice, order.Order) + if err != nil { + applogger.Error("%v ShareHkdLiquidationPosition.StockIdnClosingOrder:%v", common.ErrShareHkd, err) + return err + } + + // 2、平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareHkdSubscribe, order.UserId) + if err = UpdateShareHkdSubscribeHashStatusByOrderId(order.OrderId, userSubKey, flags.Close, order.OpenPrice); err != nil { + applogger.Error("%v ShareHkdLiquidationPosition.Position.ShareHkdSubscribe:%v", common.ErrShareHkd, err) + return err + } + + // 3、平仓更新管理员订阅订单状态 + if err = UpdateShareHkdSubscribeHashStatusByOrderId(order.OrderId, setting.AdminShareHkdSubscribe, flags.Close, order.OpenPrice); err != nil { + applogger.Error("%v ShareHkdLiquidationPosition.Position.AdminShareHkdSubscribe:%v", common.ErrShareHkd, err) + return err + } + + return nil +} + +// StockHkdVoteStopType +// +// @Description: 港股判定取值止损止盈 +// @param order +// @return bool +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func StockHkdVoteStopType(order structure.ShareOrder) (bool, decimal.Decimal, decimal.Decimal, error) { + var checkBool bool + var stopWinPrice, stopLossPrice decimal.Decimal + switch order.StopType { + case flags.StopTypeNone: // 暂无设置止盈止损 + checkBool = false + case flags.StopTypeSet: // 设置止盈止损 + checkBool = true + stopWinPrice, _ = decimal.NewFromString(order.StopWinPrice) + stopLossPrice, _ = decimal.NewFromString(order.StopLossPrice) + default: + return checkBool, stopWinPrice, stopLossPrice, flags.ErrContractThirteen + } + + return checkBool, stopWinPrice, stopLossPrice, nil +} + +// GetShareHkdPrice +// +// @Description: 查询港股股票价格 +// @param symbol +// @return decimal.Decimal +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func GetShareHkdPrice(symbol string) (decimal.Decimal, error) { + var err error + var priceByte []byte + var newPrice decimal.Decimal + + key := publicData.SymbolCache(flags.Hkd, symbol, flags.TradeTypePrice) + priceByte, err = memory.GetShareHkdCache(key) + if err != nil { + return decimal.Decimal{}, err + } + + newPrice, err = decimal.NewFromString(string(priceByte)) + if err != nil { + return decimal.Decimal{}, err + } + + applogger.Info("shareHkdCode:%v,topIc:%v,shareHkdPrice:%v", symbol, key, newPrice) + + return newPrice, nil +} diff --git a/internal/data/subscribe_share_idn.go b/internal/data/subscribe_share_idn.go new file mode 100644 index 0000000..f0d6c50 --- /dev/null +++ b/internal/data/subscribe_share_idn.go @@ -0,0 +1,1247 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/mq/consumer" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/socket/shareData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "sync" + "time" +) + +/* +印尼股票行情订阅 +1、接收用户印尼股下单的交易对印尼股行情 +2、将订阅行情写入内存中用于并发计算 +3、挂单(市价|限价)缓存队列处理-开仓 +4、持仓缓存队列处理-平仓 +*/ + +// ShareIdnMessage +// @Description: +type ShareIdnMessage struct { + Symbol string `json:"symbol,omitempty"` // 交易所:股票代码 + StockCode string `json:"stock_code,omitempty"` // 股票代码 + StockName string `json:"stock_name,omitempty"` // 股票名,可能为空 + Price decimal.Decimal `json:"price,omitempty"` // 实时价格 + UpDownRate decimal.Decimal `json:"up_down_rate,omitempty"` // 涨跌% + UpDown decimal.Decimal `json:"up_down,omitempty"` // 涨跌额 + TradeV decimal.Decimal `json:"trade_v,omitempty"` // 技术评级指标值 + TradeK string `json:"trade_k,omitempty"` // 技术评级 + Vol int64 `json:"vol,omitempty"` // 成交量 + TurnoverPriceTotal decimal.Decimal `json:"turnover_price_total,omitempty"` // 成交量*价格 + PriceTotal string `json:"price_total,omitempty"` // 总市值 + PE string `json:"p_e,omitempty"` // pe + Eps string `json:"eps,omitempty"` // EPS + EmployeesNumber string `json:"employees_number,omitempty"` // 雇员 + Plate string `json:"plate,omitempty"` // 板块 + Desc string `json:"desc,omitempty"` // 描述 + PriceCode string `json:"price_code,omitempty"` // 价格类型 + Country string `json:"country,omitempty"` // 国家 + Ts int64 `json:"ts,omitempty"` // 时间 + Token string `json:"token,omitempty"` // Token 令牌 +} + +// ShareIdnSymbol +// @Description: +type ShareIdnSymbol struct { + IdnMap chan []byte // 订单交易对 -- 用户下单通知订阅 + IdnSetMap chan []byte // 订单交易对 -- 用户盘前|盘后行情订阅 + IdnMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 + IdnSetMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 +} + +// InitCacheSymbolShareIdn +// +// @Description: +// @param ctx +// @param uo +func InitCacheSymbolShareIdn(ctx context.Context, uo *Data) { + for { + idnList, err := GetBotStockIdnListByStockId(ctx, uo) + if err != nil { + return + } + + for _, value := range idnList { + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), setting.MarketShareIdn, value).Result() + if err != nil { + applogger.Error("%v InitCacheSymbolShareIdn.MarketShareMys.HExists:%v", common.ErrShareIdn, err) + continue + } + if !checkBool { + if err = uo.redisDB.HSet(context.Background(), setting.MarketShareIdn, value, value).Err(); err != nil { + applogger.Error("%v InitCacheSymbolShareIdn.MarketShareIdn.HSet:%v", common.ErrShareIdn, err) + continue + } + } + if !flags.CheckSetting { + applogger.Info("初始化印尼股票代码:%v", value) + } + } + + time.Sleep(10 * time.Second) + } +} + +// InitSubscribeShareIdn +// +// @Description: 印尼股订阅 +// @param ctx +// @param uo +// @param shareIdn +func InitSubscribeShareIdn(shareIdn *ShareIdnSymbol, check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkIdn + } else { + key = setting.MarketShareIdn + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareIdn.LoadLRangeList:%v", common.ErrShareIdn, err) + return + } + + for _, value := range listSpots { + // Handling duplicate subscriptions + _, ok := shareIdn.IdnMapSymbol.Load(value) + if ok { + continue + } + + shareIdn.IdnMap <- []byte(value) + } + + time.Sleep(10 * time.Second) + } +} + +// InitShareIdnCloseCachePrice +// +// @Description: +// @param shareIdn +// @param check +func InitShareIdnCloseCachePrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkIdn + } else { + key = setting.MarketShareIdn + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareIdn.LoadLRangeList:%v", common.ErrShareIdn, err) + return + } + + for _, value := range listSpots { + SubscribeIdnClosePrice(value) // 处理闭盘数据 + } + + time.Sleep(20 * time.Second) + } +} + +// InitShareIdnCloseNewPrice +// +// @Description: 同步实时行情 +// @param check +func InitShareIdnCloseNewPrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkIdn + } else { + key = setting.MarketShareIdn + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareIdnCloseNewPrice.LoadLRangeList:%v", common.ErrShareIdn, err) + time.Sleep(20 * time.Second) + continue + } + for _, value := range listSpots { + SubscribeIdnCloseNewPrice(value) + } + + time.Sleep(500 * time.Millisecond) + } +} + +// InitShareIdnPriceSetUp +// +// @Description: 同步插针行情 +// @param check +func InitShareIdnPriceSetUp(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkIdn + } else { + key = setting.MarketShareIdn + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareIdnPriceSetUp.LoadLRangeList:%v", common.ErrShareIdn, err) + time.Sleep(20 * time.Second) + continue + } + + for _, value := range listSpots { + idnKey := publicData.SymbolCache(flags.Idn, value, flags.TradeTypePrice) + idnSetCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareIdnMarketType, value) + vw, err := GetBeforeAndAfterSetPrice(idnSetCache) + if err != nil || len(vw) == 0 { + _ = memory.ShareIdnPriceSetUp.Delete(idnKey) + continue + } + if err = memory.ShareIdnPriceSetUp.Set(idnKey, []byte(vw)); err != nil { + applogger.Error("%v InitShareIdnPriceSetUp.ShareIdnPriceSetUp:%v", common.ErrShareIdn, err) + } + } + + time.Sleep(500 * time.Millisecond) + } +} + +// SubscribeIdnHSetCodeList +// +// @Description: 同步列表缓存 +// @param symbolStr +// @param check +func SubscribeIdnHSetCodeList(symbolStr string, check bool) { + var key string + if check { + key = setting.MarketShareBlkIdn + } else { + key = setting.MarketShareIdn + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + return + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeIdnHSetCodeList.%v.HSet:%v", common.ErrShareIdn, key, err) + return + } + } +} + +// SubscribeIdnCloseNewPrice +// +// @Description: 获取行情价 +// @param symbolStr +// @param check +func SubscribeIdnCloseNewPrice(symbolStr string) { + // 获取市场真实开闭盘时间 + timeValue, checkWeekday := MarketCheckOpenAndCloseTime(flags.ShareIdnMarketType) + // 判定是否盘中 + if utils.CheckInPlateTime(timeValue) && checkWeekday { + // 盘中实时价格 + realTimePrice, err := Reds.HGet(context.Background(), flags.ShareIndonesiaClosingNewPriceKey, symbolStr).Result() + if err != nil { + realTimePrice = decimal.Zero.String() + } + if realTimePrice != decimal.Zero.String() { + keys := publicData.SymbolCache(flags.Idn, symbolStr, flags.TradeTypePrice) + if err = memory.ShareIdnCache.Set(keys, []byte(realTimePrice)); err != nil { + applogger.Error("%v SubscribeIdnCloseNewPrice.ShareIdnCache:%v", common.ErrShareIdn, err) + } + } + } +} + +// SubscribeIdnClosePrice +// +// @Description: 获取闭盘价 +// @param symbolStr +func SubscribeIdnClosePrice(symbolStr string) { + var err error + var sub = decimal.Zero + var closeNewPrice, closingPrice, price string + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareIndonesiaClosingNewPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareIndonesiaClosingPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice = decimal.Zero.String() + } + } + + // 写入闭盘价格 + closingPrice, err = Reds.HGet(context.Background(), flags.ShareIndonesiaBeforeClose, symbolStr).Result() + if err != nil { + closingPrice = decimal.Zero.String() + } + + // 判定取值数据 + if closeNewPrice != decimal.Zero.String() { + price = closeNewPrice + } else { + price = closingPrice + } + closeKey := publicData.SymbolCache(flags.Idn, symbolStr, flags.TradeTypeClosePrice) + if err = memory.ShareIdnClosePrice.Set(closeKey, []byte(price)); err != nil { + applogger.Error("%v ShareIdnClosePrice.Set.price:%v", common.ErrShareIdn, err) + } + + // 写入涨跌幅价格判定缓存 + cn := closeNewPrice != decimal.Zero.String() + cp := closingPrice != decimal.Zero.String() + lcn := utils.IsNumber(closeNewPrice) + lcp := utils.IsNumber(closingPrice) + if cn && cp && lcn && lcp { + sub = decimal.RequireFromString(closingPrice).Sub(decimal.RequireFromString(closeNewPrice)) + } + chgKey := publicData.SymbolCache(flags.Idn, symbolStr, flags.TradeTypeChg) // 涨跌幅标识Key + if err = memory.ShareIdnChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v ShareIdnChgMark.Set.price:%v", common.ErrShareIdn, err) + } +} + +// OrderSubAdminShareIdnSubscribeBySum +// +// @Description: 持仓订单浮动盈亏计算 +// @param ctx +// @param uo +func OrderSubAdminShareIdnSubscribeBySum(uo *Data) { + for { + var topIc = setting.AdminShareIdnSubscribe + hashMap, err := uo.redisDB.HGetAll(context.Background(), topIc).Result() + if err != nil { + applogger.Error("OrderSubAdminShareIdnSubscribeBySum.HGetAll:%v", err) + time.Sleep(5 * time.Second) + continue + } + var hashList []share.ShareIdnTallyCache + for _, value := range hashMap { + var msg share.ShareIdnTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + switch msg.Status { + case flags.Entrust: // 挂单 + case flags.Position: // 持仓 + hashList = append(hashList, msg) + default: // 平仓|撤单 + err = uo.redisDB.HDel(context.Background(), topIc, msg.OrderId).Err() + if err != nil { + applogger.Error("OrderSubAdminShareIdnSubscribeBySum.HDel:%v", err) + continue + } + } + } + applogger.Info("印尼股数据量统计:%v", len(hashList)) + // 统计印尼股总持仓订单浮动盈亏 + priceSum := decimal.Zero + for _, value := range hashList { + orderModel := shareData.ShareIdnOrderProcessing(topIc, value) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch value.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 买跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + price := subPrice.Mul(decimal.RequireFromString(value.Order.OrderNumber)) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + + // 写入缓存 + if err = memory.ShareIdnFloating.Set(flags.FloatingIdn, []byte(priceSum.String())); err != nil { + applogger.Error("统计印尼股持仓订单浮动盈亏错误:%v", err) + time.Sleep(5 * time.Second) + continue + } + applogger.Info("统计印尼股持仓订单浮动盈亏:%v", priceSum) + + time.Sleep(1 * time.Second) + } +} + +// SubscribeShareIdn +// +// @Description: TODO: 印尼股订阅 +// @param ctx +// @param uo +// @param shareIdn +func SubscribeShareIdn(ctx context.Context, shareIdn *ShareIdnSymbol, check bool) { + for { + select { + case symbol, _ := <-shareIdn.IdnMap: + symbolStr := string(symbol) + topIc := fmt.Sprintf("%v.%v", symbolStr, flags.CountryIdn) + + // Handling duplicate subscriptions + _, ok := shareIdn.IdnMapSymbol.Load(symbolStr) + if ok { + time.Sleep(5 * time.Second) + continue + } + + // Transaction determination + var key string + if check { + key = setting.MarketShareBlkIdn // 大宗股交易 + } else { + key = setting.MarketShareIdn // 印尼股交易 + } + + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeShareIdn.MarketShareIdn.HSet:%v", common.ErrShareIdn, err) + time.Sleep(5 * time.Second) + continue + } + } + + // 处理订阅实时行情数据 + go func() { + symbolStrCache := symbolStr + pubSub := Reds.Subscribe(ctx, topIc) + defer pubSub.Close() + if _, err := pubSub.Receive(ctx); err != nil { + shareIdn.IdnMapSymbol.Delete(symbolStrCache) + return + } + ch := pubSub.Channel() + for { + select { + case msg, _ := <-ch: + var subMsg ShareIdnMessage + if err := json.Unmarshal([]byte(msg.Payload), &subMsg); err != nil { + applogger.Error("%v SubscribeShareIdn.Unmarshal:%v", common.ErrShareIdn, err) + time.Sleep(5 * time.Second) + continue + } + SubscribeIdnPrice(subMsg.Price.String(), symbolStr, flags.RealTime) + default: + Reds.Ping(ctx) // 如果没有消息,发送 PING 命令以维护连接 + time.Sleep(10 * time.Second) + } + } + }() + + // 监控盘前|盘后设置价格 + _, okc := shareIdn.IdnSetMapSymbol.Load(symbolStr) + if !okc { + go func() { + for { + keyCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareIdnMarketType, symbolStr) + vw, err := GetBeforeAndAfterSetPrice(keyCache) + if err != nil || len(vw) == 0 { + priceCache := publicData.SymbolCache(flags.Idn, symbolStr, flags.TradeTypePrice) + memory.ShareIdnPriceSetUp.Delete(priceCache) + time.Sleep(15 * time.Second) + continue + } + SubscribeIdnPrice(vw, symbolStr, flags.SetUp) + time.Sleep(10 * time.Second) + } + }() + // Write cache to determine whether to repeatedly open the protocol + shareIdn.IdnSetMapSymbol.Store(symbolStr, symbolStr) + } + + // Write in the map to determine whether to repeat subscription + shareIdn.IdnMapSymbol.Store(symbolStr, symbolStr) + } + } +} + +// SubscribeIdnPrice +// +// @Description: TODO: 订阅获取印尼股实时价格或者[盘前|盘后]设置价格 +// @param setPrice +// @param symbolStr +// @param check +func SubscribeIdnPrice(setPrice, symbolStr string, check int) { + var err error + var sub = decimal.Zero + + // 计算涨跌幅 + yClosingPrice, err := Reds.HGet(context.Background(), flags.ShareIndonesiaClosingPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice, err = Reds.HGet(context.Background(), flags.ShareIndonesiaClosingNewPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice = setPrice + } + } + + // 写入涨跌幅缓存数据 + yc := yClosingPrice != decimal.Zero.String() + sp := setPrice != decimal.Zero.String() + lyc := utils.IsNumber(yClosingPrice) + lsp := utils.IsNumber(setPrice) + if yc && sp && lyc && lsp { + sub = decimal.RequireFromString(setPrice).Sub(decimal.RequireFromString(yClosingPrice)) + } + chgKey := publicData.SymbolCache(flags.Idn, symbolStr, flags.TradeTypeChg) // 涨跌幅标识Key + if err = memory.ShareIdnChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v SubscribeShareIdn.ShareIdnChgMark.Set.price:%v", common.ErrShareIdn, err) + } + if !flags.CheckSetting { + applogger.Debug("涨跌幅交易对内存key:%v,涨跌幅数值:%v", symbolStr, sub) + } + + // 交易类型:0最新价,1买入,2卖出 + price := publicData.SymbolCache(flags.Idn, symbolStr, flags.TradeTypePrice) + switch check { + case flags.RealTime: // 实时价格(优先级高) + if err = memory.ShareIdnCache.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeShareIdn.ShareIdnCache.Set.price:%v", common.ErrShareIdn, err) + } + case flags.SetUp: // 设置[盘前|盘后]价格 + if err = memory.ShareIdnPriceSetUp.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeShareIdn.ShareIdnPriceSetUp:%v", common.ErrShareIdn, err) + } + } + if !flags.CheckSetting { + applogger.Debug("股票交易对内存Key:%v,最新价格:%v", price, setPrice) + } +} + +// SubscribeIdnSetForcedClosure +// +// @Description: TODO: 处理印尼股强平阈值 +// @param symbolStr +func SubscribeIdnSetForcedClosure(symbolStr string) { + flatRatio := GetCacheForcedClosure(flags.StockYNSystemSetUpKey, symbolStr) + chgKey := publicData.SymbolCache(flags.Idn, symbolStr, flags.TradeTypeForcedClosure) + if err := memory.ShareIdnForcedClosure.Set(chgKey, []byte(flatRatio.String())); err != nil { + applogger.Error("%v SubscribeIdnSetForcedClosure.StockYNSystemSetUpKey err:%v", common.ErrShareIdn, err) + return + } +} + +// ShareIdnTransactionEntrust +// +// @Description: 印尼股委托订单 +// @param ctx +func ShareIdnTransactionEntrust(ctx context.Context) { + for { + ShareIdnTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareIdnTransactionCalculationEntrust +// +// @Description: 印尼股挂单缓存队列计算 +// @param ctx +func ShareIdnTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 全局变量处理 + if CheckGlobalTread(flags.IdnMarket) { + time.Sleep(5 * time.Second) + return + } + + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareIdnEntrust).Result() + if err != nil { + applogger.Error("%v ShareIdnTransactionCalculationEntrust.HGetAll:%v", common.ErrShareIdn, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareIdnTallyCache, 1) + var entrust share.ShareIdnTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareIdnTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareIdn, err) + continue + } + + // 股票实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareIdnPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareIdnTransactionCalculationEntrust.Get:%v---%v", common.ErrShareIdn, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + chg := GetShareChgIdn(flags.Idn, entrust.Symbol) // 涨跌幅标识 + if share.CheckIdnOrderByChg(setting.MarketShareIdnEntrust, entrust, chg) { + //applogger.Warn("当前股票%v订单在挂单状态已达到涨跌幅上限.", entrust.Symbol) + continue + } + + wg.Add(1) + go func(value string) { + var resultMsg share.ShareIdnTallyCache + switch entrust.Order.DealType { + case flags.DealTypeLimited: // 限价挂单 + resultMsg = ShareIdnConcurrentComputingEntrustLimited(&entrust, newPrice, &wg) + case flags.DealTypeMarket: // 市价挂单(开盘即成交) + resultMsg = ShareIdnConcurrentComputingEntrustMarket(&entrust, newPrice, &wg) + } + msg <- resultMsg // 通知管道异步处理订单操作 + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收印尼股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到印尼股持仓信息:%v", resultMsg) + } + + // 开盘逻辑 + if err = ShareIdnLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareIdnTransactionCalculationEntrust.ShareUsLiquidationEntrust:%v", common.ErrShareIdn, err) + continue + } + + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v ShareIdnTransactionCalculationEntrust.Marshal:%v", common.ErrShareIdn, err) + continue + } + + // TODO: 写入持仓消息队列 + //if err = uo.mqProducer.Entrust.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareIdnTransactionCalculationEntrust.EntrustPushNotice:%v", common.ShareIdnError, err) + // continue + //} + + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareIdnPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("印尼股挂单并发计算执行完毕......") +} + +// ShareIdnConcurrentComputingEntrustLimited +// +// @Description: 印尼股挂单(限价|市价)缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareIdnTallyCache +func ShareIdnConcurrentComputingEntrustLimited(order *share.ShareIdnTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareIdnTallyCache { + var deleteCache bool + var dealPrice string + var limitPrice = decimal.RequireFromString(order.Order.LimitPrice) // 限价-价格 + var status = order.Status // 原始价格 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + // 限价买入逻辑判定 -> 挂单金额 > 当前价格 + if limitPrice.Cmp(newPrice) > 0 { + deleteCache = true + difference := utils.RandInt() // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + } + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + // 限价卖入逻辑判定 -> 挂单金额 < 当前价格 + if limitPrice.Cmp(newPrice) < 0 { + deleteCache = true + difference := utils.RandInt() // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareIdnEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareIdnConcurrentComputingEntrustLimited.HDel:%v", common.ErrShareIdn, err) + order.Status = status + } + } + + wg.Done() + return share.ShareIdnTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareIdnConcurrentComputingEntrustMarket +// +// @Description: 印尼股市价下单进入挂单队列(休市) +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareIdnTallyCache +func ShareIdnConcurrentComputingEntrustMarket(order *share.ShareIdnTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareIdnTallyCache { + var deleteCache bool + var dealPrice string + var marketPrice = decimal.RequireFromString(order.Order.MarketPrice) // 市价-价格 + var status = order.Status // 原始价格 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := utils.RandInt() // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := utils.RandInt() // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareIdnEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareIdnConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareIdn, err) + order.Status = status + } + } + + wg.Done() + return share.ShareIdnTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareBlockIdnConcurrentComputingEntrustMarket +// +// @Description: 大宗(印尼股)交易 +// @param order +// @param newPrice +// @param wg +// @return share.ShareIdnTallyCache +func ShareBlockIdnConcurrentComputingEntrustMarket(order *share.ShareIdnTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareIdnTallyCache { + var status = order.Status // 原始状态 + + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareBlkEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareBlockIdnConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareBlk, err) + order.Status = status + } + + wg.Done() + return share.ShareIdnTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: newPrice.String(), // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareIdnMqOpenBusiness +// +// @Description: TODO: 印尼股持仓消息队列 +// @param ctx +// @param uo +func ShareIdnMqOpenBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Entrust.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerEntrustMq.ShareIdnMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareIdnMqOpenBusiness.ShareIdnMq err....", common.ErrShareIdn) + continue + } + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareIdnTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareIdnMqOpenBusiness.Unmarshal:%v", common.ErrShareIdn, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareIdnLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareIdnMqOpenBusiness.ShareIdnLiquidationEntrust:%v", common.ErrShareIdn, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + applogger.Error("这里没有监控到持仓mq队列消息.........") + time.Sleep(2 * time.Second) + } + } +} + +// ShareIdnLiquidationEntrust +// +// @Description: 印尼股挂单-->开仓业务处理 +// @param ctx +// @param order +// @return error +func ShareIdnLiquidationEntrust(ctx context.Context, order *share.ShareIdnTallyCache) error { + // 1、开盘 + err := StockIdnOpenOrder(ctx, Msql, order.UserId, order.OrderId, order.OpenPrice, order.Order) + if err != nil { + applogger.Error("%v ShareIdnLiquidationEntrust.StockIdnOpenOrder:%v", common.ErrShareIdn, err) + return err + } + + // 大宗(印尼股)交易判定 + var entrustKey, adminKey string + if !CheckTypeStatus(order.Order.Type) { + entrustKey = setting.ShareIdnSubscribe + adminKey = setting.AdminShareIdnSubscribe + } else { + entrustKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // 2、更新用户订阅缓存列表订单状态 + updateKey := virtual.OrderIdListKey(entrustKey, order.UserId) + if err = UpdateShareIdnSubscribeHashStatusByOrderId(order.OrderId, updateKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareIdnLiquidationEntrust.Entrust.%v:%v", common.ErrShareIdn, entrustKey, err) + return err + } + + // 3、更新管理员订阅缓存列表订单状态 + if err = UpdateShareIdnSubscribeHashStatusByOrderId(order.OrderId, adminKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareIdnLiquidationEntrust.Entrust.%v:%v", common.ErrShareIdn, adminKey, err) + return err + } + + return nil +} + +// ShareIdnTransactionPosition +// +// @Description: 印尼股持仓订单 +// @param ctx +func ShareIdnTransactionPosition(ctx context.Context) { + for { + ShareIdnTransactionCalculationPosition(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareIdnTransactionCalculationPosition +// +// @Description: 印尼股持仓缓存队列计算 +// @param ctx +func ShareIdnTransactionCalculationPosition(ctx context.Context) { + var wg sync.WaitGroup + + // 判定是否交易 + if CheckGlobalTread(flags.IdnMarket) { + time.Sleep(5 * time.Second) + return + } + + // TODO: 获取IPO未支付订单缓存 + userIdMap, _ := GetBotUserArrears(ctx) + + // 获取持仓缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareIdnPosition).Result() + if err != nil { + applogger.Error("%v ShareIdnTransactionCalculationPosition.HGetAll:%v", common.ErrShareIdn, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareIdnTallyCache, 1) + var entrust share.ShareIdnTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareIdnTransactionCalculationPosition.Unmarshal:%v", common.ErrShareIdn, err) + continue + } + + // TODO: 判定是否未IPO未支付订单-不能平仓 + _, isOk := userIdMap[entrust.UserId] + if isOk { + continue + } + + // 处理时间 + if !CheckShareSystemTime(entrust.ClosingTime) { + applogger.Info("印尼股:%v,平仓时间:%v暂未到达...", entrust.Symbol, entrust.ClosingTime) + continue + } + + // TODO: 实时获取强平阈值 + //entrust.Order.System.StrongFlatRatio = GetForcedClosureValue(flags.Idn, entrust.Symbol) + + // 印尼股实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareIdnPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareIdnTransactionCalculationPosition.Get:%v--%v", common.ErrShareIdn, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + chg := GetShareChgIdn(flags.Idn, entrust.Symbol) // 涨跌幅标识 + if share.CheckIdnOrderByChg(setting.MarketShareIdnEntrust, entrust, chg) { + //applogger.Warn("当前股票%v订单在挂单状态已达到涨跌幅上限.", entrust.Symbol) + continue + } + + // 判定配额强平 + checkFlattening := GetStrongFlatteningThreshold(entrust.UserId) + + wg.Add(1) + go func(value string) { + resultMsg := ShareIdnConcurrentComputingPosition(&entrust, newPrice, &wg, checkFlattening) + msg <- resultMsg + }(value) + + // 处理并发结果 + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Position: // 持仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到印尼股持仓信息:%v", resultMsg) + } + case flags.Close: // 平仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到印尼股平仓信息:%v", resultMsg) + } + + // TODO: 平仓操作(优化写入队列中等待平仓) + //var byteStr []byte + //byteStr, err = json.Marshal(resultMsg) + //if err != nil { + // applogger.Error("%v ShareIdnTransactionCalculationPosition.Marshal:%v", common.ShareIdnError, err) + // continue + //} + //if err = uo.mqProducer.Position.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareIdnTransactionCalculationPosition.DealPublish:%v", common.ShareIdnError, err) + // continue + //} + + if err = ShareIdnLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareIdnTransactionCalculationPosition.ShareIdnLiquidationPosition:%v", common.ErrShareIdn, err) + continue + } + } + } + } + + wg.Wait() + applogger.Info("印尼股持仓并发计算执行完毕......") +} + +// ShareIdnConcurrentComputingPosition +// +// @Description: 印尼股持仓缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareIdnTallyCache +func ShareIdnConcurrentComputingPosition(order *share.ShareIdnTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup, checkFlattening bool) share.ShareIdnTallyCache { + var deleteCache, checkBool bool + var dealPrice string + var sellShort decimal.Decimal + var openPrice = decimal.RequireFromString(order.OpenPrice) // 限价 + var orderNumber = decimal.RequireFromString(order.Order.OrderNumber) // 仓位 + + var pryNum decimal.Decimal + lenPryNum := len(utils.ReplaceStr(order.Order.PryNum)) == 0 + if lenPryNum || order.Order.PryNum == flags.SetZero || order.Order.System.UserStatus != flags.SetThree || !utils.IsNumberInt(order.Order.PryNum) { + pryNum = decimal.RequireFromString(flags.SetOne) + } else { + pryNum = decimal.RequireFromString(order.Order.PryNum) + } + + // 下单判定设置(false无设置|true止盈止损) + _, stopWinPrice, stopLossPrice, _ := StockIdnVoteStopType(order.Order) + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨(强平) + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,持仓开仓价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买涨:挂止损止盈,止盈价必须<当前价,止损价必须>当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := utils.RandInt() // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := utils.RandInt() // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + // 强行平仓(做多) + if !checkBool { + sellShort = newPrice.Sub(openPrice).Mul(orderNumber) + } + case flags.TradeTypeSell: // 买跌(存在强行平仓) + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价持仓买跌下单价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买跌:挂止损止盈,止盈价必须>当前价,止损价必须<当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := utils.RandInt() // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := utils.RandInt() // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + // 强行平仓(做空) + if !checkBool { + sellShort = openPrice.Sub(newPrice).Mul(orderNumber) + } + } + /* 强行平仓(做多|做空) + 1、做多:(最新成交价-开仓成交价)*仓位 + 2、做空:(开仓成交价-最新成交价)*仓位 + 3、当浮动盈亏 >= 保证金的70%订单强行平仓 + */ + if sellShort.IsNegative() && checkFlattening { + orderAmount := newPrice.Mul(decimal.RequireFromString(order.Order.OrderNumber)).Div(pryNum) // 保证金 = 当前价格 * 订单数量 / 杠杆 + floatPrice := orderAmount.Mul(decimal.RequireFromString(order.Order.System.StrongFlatRatio)) + if !flags.CheckSetting { + applogger.Debug("强平保证金:%v,强平浮动70:%v,强行平仓判定:%v", orderAmount, floatPrice, sellShort.Abs().Cmp(floatPrice)) + } + if sellShort.Abs().Cmp(floatPrice) >= 0 { + checkBool = true + // 设置价差 + difference := utils.RandInt() + switch order.Order.TradeType { + case flags.TradeTypeBuy: //买涨 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + case flags.TradeTypeSell: // 买跌 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + } + + if checkBool { + deleteCache = true + order.Status = flags.Close + } + + if deleteCache { + // 根据订单ID-删除持仓列表缓存订单 + if err := Reds.HDel(context.Background(), setting.MarketShareIdnPosition, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareUsConcurrentComputingPosition.Position.HDel:%v", common.ErrShareIdn, err) + } + } + + wg.Done() + return share.ShareIdnTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + ClosingPrice: dealPrice, // 平仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareIdnMqClosingBusiness +// +// @Description: TODO: 处理印尼股平仓消息队列 +// @param ctx +// @param uo +func ShareIdnMqClosingBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Position.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerPositionMq.ShareIdnMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareIdnMqClosingBusiness.ShareIdnMq err....", common.ErrShareIdn) + continue + } + applogger.Info("接收到平仓信息:%v", string(message)) + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareIdnTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareIdnMqClosingBusiness.Unmarshal:%v", common.ErrShareIdn, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareIdnLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareIdnMqClosingBusiness.ShareIdnLiquidationPosition:%v", common.ErrShareIdn, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + time.Sleep(2 * time.Second) + } + } +} + +// ShareIdnLiquidationPosition +// +// @Description: 印尼股持仓-->平仓业务处理 +// @param ctx +// @param order +// @return error +func ShareIdnLiquidationPosition(ctx context.Context, order *share.ShareIdnTallyCache) error { + // 1、平仓操作 + err := StockIdnClosingOrder(ctx, Msql, order.OrderId, order.ClosingPrice, order.Order) + if err != nil { + applogger.Error("%v ShareIdnLiquidationPosition.StockIdnClosingOrder:%v", common.ErrShareIdn, err) + return err + } + + // 2、平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareIdnSubscribe, order.UserId) + if err = UpdateShareIdnSubscribeHashStatusByOrderId(order.OrderId, userSubKey, flags.Close, order.OpenPrice); err != nil { + applogger.Error("%v ShareIdnLiquidationPosition.Position.ShareIdnSubscribe:%v", common.ErrShareIdn, err) + return err + } + + // 3、平仓更新管理员订阅订单状态 + if err = UpdateShareIdnSubscribeHashStatusByOrderId(order.OrderId, setting.AdminShareIdnSubscribe, flags.Close, order.OpenPrice); err != nil { + applogger.Error("%v ShareIdnLiquidationPosition.Position.AdminShareIdnSubscribe:%v", common.ErrShareIdn, err) + return err + } + + return nil +} + +// StockIdnVoteStopType +// +// @Description: 印尼股判定取值止损止盈 +// @param order +// @return bool +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func StockIdnVoteStopType(order structure.ShareOrder) (bool, decimal.Decimal, decimal.Decimal, error) { + var checkBool bool + var stopWinPrice, stopLossPrice decimal.Decimal + switch order.StopType { + case flags.StopTypeNone: // 暂无设置止盈止损 + checkBool = false + case flags.StopTypeSet: // 设置止盈止损 + checkBool = true + stopWinPrice, _ = decimal.NewFromString(order.StopWinPrice) + stopLossPrice, _ = decimal.NewFromString(order.StopLossPrice) + default: + return checkBool, stopWinPrice, stopLossPrice, flags.ErrContractThirteen + } + + return checkBool, stopWinPrice, stopLossPrice, nil +} + +// GetShareIdnPrice +// +// @Description: 查询印尼股股票价格 +// @param symbol +// @return decimal.Decimal +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func GetShareIdnPrice(symbol string) (decimal.Decimal, error) { + var err error + var priceByte []byte + var newPrice decimal.Decimal + + key := publicData.SymbolCache(flags.Idn, symbol, flags.TradeTypePrice) + priceByte, err = memory.GetShareIdnCache(key) + if err != nil { + return decimal.Decimal{}, err + } + + newPrice, err = decimal.NewFromString(string(priceByte)) + if err != nil { + return decimal.Decimal{}, err + } + + applogger.Info("shareIdnCode:%v,topIc:%v,shareIdnPrice:%v", symbol, key, newPrice) + + return newPrice, nil +} diff --git a/internal/data/subscribe_share_inr.go b/internal/data/subscribe_share_inr.go new file mode 100644 index 0000000..1a7f60f --- /dev/null +++ b/internal/data/subscribe_share_inr.go @@ -0,0 +1,1248 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/mq/consumer" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/socket/shareData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "sync" + "time" +) + +/* +印度股行情订阅 +1、接收用户印度股下单的交易对印度股行情 +2、将订阅行情写入内存中用于并发计算 +3、挂单(市价|限价)缓存队列处理-开仓 +4、持仓缓存队列处理-平仓 +*/ + +// ShareInrMessage +// @Description: +type ShareInrMessage struct { + Symbol string `json:"symbol,omitempty"` // 交易所:股票代码 + StockCode string `json:"stock_code,omitempty"` // 股票代码 + StockName string `json:"stock_name,omitempty"` // 股票名,可能为空 + Price decimal.Decimal `json:"price,omitempty"` // 实时价格 + UpDownRate decimal.Decimal `json:"up_down_rate,omitempty"` // 涨跌% + UpDown decimal.Decimal `json:"up_down,omitempty"` // 涨跌额 + TradeV decimal.Decimal `json:"trade_v,omitempty"` // 技术评级指标值 + TradeK string `json:"trade_k,omitempty"` // 技术评级 + Vol int64 `json:"vol,omitempty"` // 成交量 + TurnoverPriceTotal decimal.Decimal `json:"turnover_price_total,omitempty"` // 成交量*价格 + PriceTotal string `json:"price_total,omitempty"` // 总市值 + PE string `json:"p_e,omitempty"` // pe + Eps string `json:"eps,omitempty"` // EPS + EmployeesNumber string `json:"employees_number,omitempty"` // 雇员 + Plate string `json:"plate,omitempty"` // 板块 + Desc string `json:"desc,omitempty"` // 描述 + PriceCode string `json:"price_code,omitempty"` // 价格类型 + Country string `json:"country,omitempty"` // 国家 + Ts int64 `json:"ts,omitempty"` // 时间 + Token string `json:"token,omitempty"` // Token 令牌 +} + +// ShareInrSymbol +// @Description: +type ShareInrSymbol struct { + InrMap chan []byte // 订单交易对 -- 用户下单通知订阅 + InrSetMap chan []byte // 订单交易对 -- 用户盘前|盘后行情订阅 + InrMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 + InrSetMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 +} + +// InitCacheSymbolShareInr +// +// @Description: +// @param ctx +// @param uo +func InitCacheSymbolShareInr(ctx context.Context, uo *Data) { + for { + thaList, err := GetBotStockInListByStockId(ctx, uo) + if err != nil { + return + } + + for _, value := range thaList { + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := uo.redisDB.HExists(context.Background(), setting.MarketShareInr, value).Result() + if err != nil { + applogger.Error("%v InitCacheSymbolShareInr.MarketShareInr.HExists:%v", common.ErrShareInr, err) + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err := uo.redisDB.HSet(context.Background(), setting.MarketShareInr, value, value).Err(); err != nil { + applogger.Error("%v InitCacheSymbolShareInr.MarketShareInr.HSet:%v", common.ErrShareInr, err) + time.Sleep(5 * time.Second) + continue + } + } + if !flags.CheckSetting { + applogger.Info("初始化印度股股票代码:%v", value) + } + } + + time.Sleep(10 * time.Second) + } +} + +// InitSubscribeShareInr +// +// @Description: 状态机加载订阅 +// @param ctx +// @param uo +// @param shareTha +func InitSubscribeShareInr(shareInr *ShareInrSymbol, check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkInr + } else { + key = setting.MarketShareInr + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareInr.LoadLRangeList:%v", common.ErrShareInr, err) + return + } + + for _, value := range listSpots { + // Handling duplicate subscriptions + _, ok := shareInr.InrMapSymbol.Load(value) + if ok { + continue + } + + shareInr.InrMap <- []byte(value) + } + + time.Sleep(10 * time.Second) + } +} + +// InitShareInrCloseCachePrice +// +// @Description: +// @param shareInr +// @param check +func InitShareInrCloseCachePrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkInr + } else { + key = setting.MarketShareInr + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareInr.LoadLRangeList:%v", common.ErrShareInr, err) + return + } + + for _, value := range listSpots { + SubscribeInrClosePrice(value) // 处理闭盘数据 + } + + time.Sleep(20 * time.Second) + } +} + +// InitShareInrCloseNewPrice +// +// @Description: 同步实时行情 +// @param check +func InitShareInrCloseNewPrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkInr + } else { + key = setting.MarketShareInr + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareInrCloseNewPrice.LoadLRangeList:%v", common.ErrShareInr, err) + time.Sleep(20 * time.Second) + continue + } + + for _, value := range listSpots { + SubscribeInrCloseNewPrice(value) + } + + time.Sleep(500 * time.Millisecond) + } +} + +// InitShareInrPriceSetUp +// +// @Description: 同步插针行情 +// @param check +func InitShareInrPriceSetUp(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkInr + } else { + key = setting.MarketShareInr + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareInrPriceSetUp.LoadLRangeList:%v", common.ErrShareInr, err) + time.Sleep(20 * time.Second) + continue + } + + for _, value := range listSpots { + inrKey := publicData.SymbolCache(flags.Inr, value, flags.TradeTypePrice) + inrSetCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareInrMarketType, value) + vw, err := GetBeforeAndAfterSetPrice(inrSetCache) + if err != nil || len(vw) == 0 { + _ = memory.ShareInrPriceSetUp.Delete(inrKey) + continue + } + if err = memory.ShareInrPriceSetUp.Set(inrKey, []byte(vw)); err != nil { + applogger.Error("%v InitShareInrPriceSetUp.ShareInrPriceSetUp:%v", common.ErrShareInr, err) + } + } + + time.Sleep(500 * time.Millisecond) + } +} + +// SubscribeInrHSetCodeList +// +// @Description: 同步列表缓存 +// @param symbolStr +// @param check +func SubscribeInrHSetCodeList(symbolStr string, check bool) { + var key string + if check { + key = setting.MarketShareBlkInr + } else { + key = setting.MarketShareInr + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + return + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeInrHSetCodeList.%v.HSet:%v", common.ErrShareInr, key, err) + return + } + } +} + +// SubscribeInrCloseNewPrice +// +// @Description: 获取行情价 +// @param symbolStr +// @param check +func SubscribeInrCloseNewPrice(symbolStr string) { + // 获取市场真实开闭盘时间 + timeValue, checkWeekday := MarketCheckOpenAndCloseTime(flags.ShareInrMarketType) + // 判定是否盘中 + if utils.CheckInPlateTime(timeValue) && checkWeekday { + // 盘中实时价格 + realTimePrice, err := Reds.HGet(context.Background(), flags.ShareIndiaClosingNewPriceKey, symbolStr).Result() + if err != nil { + realTimePrice = decimal.Zero.String() + } + if realTimePrice != decimal.Zero.String() { + keys := publicData.SymbolCache(flags.Inr, symbolStr, flags.TradeTypePrice) + if err = memory.ShareInrCache.Set(keys, []byte(realTimePrice)); err != nil { + applogger.Error("%v SubscribeInrCloseNewPrice.ShareInrCache:%v", common.ErrShareInr, err) + } + } + } +} + +// SubscribeInrClosePrice +// +// @Description: 获取闭盘价 +// @param symbolStr +func SubscribeInrClosePrice(symbolStr string) { + var err error + var sub = decimal.Zero + var closeNewPrice, closingPrice, price string + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareIndiaClosingNewPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareIndiaClosingPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice = decimal.Zero.String() + } + } + + // 写入闭盘价格 + closingPrice, err = Reds.HGet(context.Background(), flags.ShareIndiaBeforeClose, symbolStr).Result() + if err != nil { + closingPrice = decimal.Zero.String() + } + + // 判定取值数据 + if closeNewPrice != decimal.Zero.String() { + price = closeNewPrice + } else { + price = closingPrice + } + closeKey := publicData.SymbolCache(flags.Inr, symbolStr, flags.TradeTypeClosePrice) + if err = memory.ShareInrClosePrice.Set(closeKey, []byte(price)); err != nil { + applogger.Error("%v SubscribeInrClosePrice.Set.price:%v", common.ErrShareInr, err) + } + + // 写入涨跌幅价格判定缓存 + cn := closeNewPrice != decimal.Zero.String() + cp := closingPrice != decimal.Zero.String() + lcn := utils.IsNumber(closeNewPrice) + lcp := utils.IsNumber(closingPrice) + if cn && cp && lcn && lcp { + sub = decimal.RequireFromString(closingPrice).Sub(decimal.RequireFromString(closeNewPrice)) + } + chgKey := publicData.SymbolCache(flags.Inr, symbolStr, flags.TradeTypeChg) // 涨跌幅标识Key + if err = memory.ShareInrChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v SubscribeInrClosePrice.Set.price:%v", common.ErrShareInr, err) + } +} + +// OrderSubAdminShareInrSubscribeBySum +// +// @Description: 持仓订单浮动盈亏计算 +// @param ctx +// @param uo +func OrderSubAdminShareInrSubscribeBySum(uo *Data) { + for { + var topIc = setting.AdminShareInrSubscribe + hashMap, err := uo.redisDB.HGetAll(context.Background(), topIc).Result() + if err != nil { + applogger.Error("OrderSubAdminShareInrSubscribeBySum.HGetAll:%v", err) + time.Sleep(5 * time.Second) + continue + } + var hashList []share.ShareInrTallyCache + for _, value := range hashMap { + var msg share.ShareInrTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + switch msg.Status { + case flags.Entrust: // 挂单 + case flags.Position: // 持仓 + hashList = append(hashList, msg) + default: // 平仓|撤单 + err = uo.redisDB.HDel(context.Background(), topIc, msg.OrderId).Err() + if err != nil { + applogger.Error("OrderSubAdminShareInrSubscribeBySum.HDel:%v", err) + continue + } + } + } + applogger.Info("印度股数据量统计:%v", len(hashList)) + // 统计印度股总持仓订单浮动盈亏 + priceSum := decimal.Zero + for _, value := range hashList { + orderModel := shareData.ShareInrOrderProcessing(topIc, value) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch orderModel.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + price := subPrice.Mul(decimal.RequireFromString(value.Order.OrderNumber)) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + // 写入缓存 + if err = memory.ShareInrFloating.Set(flags.FloatingInr, []byte(priceSum.String())); err != nil { + applogger.Error("统计印度股持仓订单浮动盈亏错误:%v", err) + time.Sleep(5 * time.Second) + continue + } + applogger.Info("统计印度股持仓订单浮动盈亏:%v", priceSum) + + time.Sleep(1 * time.Second) + } +} + +// SubscribeShareInr +// @Description: TODO: 印度股订阅 +// @param ctx +// @param uo +// @param shareIdn +func SubscribeShareInr(ctx context.Context, shareInr *ShareInrSymbol, check bool) { + for { + select { + case symbol, _ := <-shareInr.InrMap: + symbolStr := string(symbol) + topIc := fmt.Sprintf("%v.%v", symbolStr, flags.CountryInr) + // Handling duplicate subscriptions + _, ok := shareInr.InrMapSymbol.Load(symbolStr) + if ok { + time.Sleep(5 * time.Second) + continue + } + // Transaction determination + var key string + if check { + key = setting.MarketShareBlkInr // 大宗股交易 + } else { + key = setting.MarketShareInr // 印度股交易 + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeShareInr.%v.HSet:%v", common.ErrShareInr, key, err) + time.Sleep(5 * time.Second) + continue + } + } + + // 处理订阅实时行情数据 + go func() { + symbolStrCache := symbolStr + pubSub := Reds.Subscribe(ctx, topIc) + defer pubSub.Close() + if _, err := pubSub.Receive(ctx); err != nil { + shareInr.InrMapSymbol.Delete(symbolStrCache) + return + } + ch := pubSub.Channel() + for { + select { + case msg, _ := <-ch: + var subMsg ShareInrMessage + if err := json.Unmarshal([]byte(msg.Payload), &subMsg); err != nil { + applogger.Error("%v SubscribeShareInr.Unmarshal:%v", common.ErrShareInr, err) + time.Sleep(5 * time.Second) + return + } + SubscribeInrPrice(subMsg.Price.String(), symbolStr, flags.RealTime) + default: + Reds.Ping(ctx) // 如果没有消息,发送 PING 命令以维护连接 + time.Sleep(10 * time.Second) + } + } + }() + + // 盘前|盘后价格设置 + _, okc := shareInr.InrSetMapSymbol.Load(symbolStr) + if !okc { + go func() { + for { + keyCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareInrMarketType, symbolStr) + vw, err := GetBeforeAndAfterSetPrice(keyCache) + if err != nil || len(vw) == 0 { + priceCache := publicData.SymbolCache(flags.Inr, symbolStr, flags.TradeTypePrice) + memory.ShareInrPriceSetUp.Delete(priceCache) + time.Sleep(15 * time.Second) + continue + } + SubscribeInrPrice(vw, symbolStr, flags.SetUp) + time.Sleep(10 * time.Second) + } + }() + // Write cache to determine whether to repeatedly open the protocol + shareInr.InrSetMapSymbol.Store(symbolStr, symbolStr) + } + + // Write in the map to determine whether to repeat subscription + shareInr.InrMapSymbol.Store(symbolStr, symbolStr) + } + } +} + +// SubscribeInrPrice +// +// @Description: TODO: 订阅获取印度股实时价格或者[盘前|盘后]设置价格 +// @param setPrice +// @param symbolStr +// @param check +func SubscribeInrPrice(setPrice, symbolStr string, check int) { + var err error + var sub = decimal.Zero + + // 计算涨跌幅 + yClosingPrice, err := Reds.HGet(context.Background(), flags.ShareIndiaClosingPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice, err = Reds.HGet(context.Background(), flags.ShareIndiaClosingNewPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice = setPrice + } + } + + // 写入涨跌幅缓存数据 + yc := yClosingPrice != decimal.Zero.String() + sp := setPrice != decimal.Zero.String() + lyc := utils.IsNumber(yClosingPrice) + lsp := utils.IsNumber(setPrice) + if yc && sp && lyc && lsp { + sub = decimal.RequireFromString(setPrice).Sub(decimal.RequireFromString(yClosingPrice)) + } + chgKey := publicData.SymbolCache(flags.Inr, symbolStr, flags.TradeTypeChg) // 涨跌幅标识Key + if err = memory.ShareInrChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v SubscribeInrPrice.ShareIdnChgMark.Set.price:%v", common.ErrShareInr, err) + } + if !flags.CheckSetting { + applogger.Debug("涨跌幅交易对内存key:%v,涨跌幅数值:%v", symbolStr, sub) + } + + // 交易类型:0最新价,1买入,2卖出 + price := publicData.SymbolCache(flags.Inr, symbolStr, flags.TradeTypePrice) + switch check { + case flags.RealTime: // 实时价格(优先级高) + if err = memory.ShareInrCache.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeInrPrice.ShareInrCache.Set.price:%v", common.ErrShareInr, err) + } + case flags.SetUp: // 设置[盘前|盘后]价格 + if err = memory.ShareInrPriceSetUp.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeInrPrice.ShareInrPriceSetUp:%v", common.ErrShareInr, err) + } + } + if !flags.CheckSetting { + applogger.Debug("股票交易对内存Key:%v,最新价格:%v", price, setPrice) + } +} + +// SubscribeInrSetForcedClosure +// +// @Description: TODO: 处理印度股强平阈值 +// @param symbolStr +func SubscribeInrSetForcedClosure(symbolStr string) { + flatRatio := GetCacheForcedClosure(flags.StockYDSystemSetUpKey, symbolStr) + chgKey := publicData.SymbolCache(flags.Inr, symbolStr, flags.TradeTypeForcedClosure) + if err := memory.ShareInrForcedClosure.Set(chgKey, []byte(flatRatio.String())); err != nil { + applogger.Error("%v SubscribeInrSetForcedClosure.StockYDSystemSetUpKey err:%v", common.ErrShareInr, err) + return + } +} + +// ShareInrTransactionEntrust +// +// @Description: 印度股委托订单 +// @param ctx +func ShareInrTransactionEntrust(ctx context.Context) { + for { + ShareInrTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareInrTransactionCalculationEntrust +// +// @Description: 印度股挂单缓存队列计算 +// @param ctx +// @param uo +func ShareInrTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 全局变量处理 + if CheckGlobalTread(flags.InrMarket) { + time.Sleep(5 * time.Second) + return + } + + // 获取印度股挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareInrEntrust).Result() + if err != nil { + applogger.Error("%v ShareInrTransactionCalculationEntrust.HGetAll:%v", common.ErrShareInr, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareInrTallyCache, 1) + var entrust share.ShareInrTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareInrTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareInr, err) + continue + } + + // 股票实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareInrPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareInrTransactionCalculationEntrust.Get:%v---%v", common.ErrShareInr, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + chg := GetShareChgInr(flags.Inr, entrust.Symbol) // 涨跌幅标识 + if share.CheckInrOrderByChg(setting.MarketShareInrEntrust, entrust, chg) { + //applogger.Warn("当前股票%v订单在挂单状态已达到涨跌幅上限.", entrust.Symbol) + continue + } + + wg.Add(1) + go func(value string) { + var resultMsg share.ShareInrTallyCache + switch entrust.Order.DealType { + case flags.DealTypeLimited: // 限价挂单 + resultMsg = ShareInrConcurrentComputingEntrustLimited(&entrust, newPrice, &wg) + case flags.DealTypeMarket: // 市价挂单(开盘即成交) + resultMsg = ShareInrConcurrentComputingEntrustMarket(&entrust, newPrice, &wg) + } + msg <- resultMsg // 通知管道异步处理订单操作 + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收印度股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到印度股持仓信息:%v", resultMsg) + } + + // 开盘逻辑 + if err = ShareInrLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Warn("%v ShareInrTransactionCalculationEntrust.ShareInrLiquidationEntrust:%v", common.ErrShareInr, err) + continue + } + + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v ShareInrTransactionCalculationEntrust.Marshal:%v", common.ErrShareInr, err) + continue + } + + // TODO: 写入持仓消息队列 + //if err = uo.mqProducer.Entrust.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareInrTransactionCalculationEntrust.EntrustPushNotice:%v", common.ShareInrError, err) + // continue + //} + + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareInrPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("印度股挂单并发计算执行完毕......") +} + +// ShareInrConcurrentComputingEntrustLimited +// +// @Description: 印度股挂单(限价|市价)缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareInrTallyCache +func ShareInrConcurrentComputingEntrustLimited(order *share.ShareInrTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareInrTallyCache { + var deleteCache bool + var dealPrice string + var limitPrice = decimal.RequireFromString(order.Order.LimitPrice) // 限价-价格 + var status = order.Status // 原始价格 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价买入逻辑判定 -> 挂单金额 > 当前价格 + if limitPrice.Cmp(newPrice) > 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + } + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价卖入逻辑判定 -> 挂单金额 < 当前价格 + if limitPrice.Cmp(newPrice) < 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareInrEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareInrConcurrentComputingEntrustLimited.HDel:%v", common.ErrShareInr, err) + order.Status = status + } + } + + wg.Done() + return share.ShareInrTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareInrConcurrentComputingEntrustMarket +// +// @Description: 印度股市价下单进入挂单队列(休市) +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareInrTallyCache +func ShareInrConcurrentComputingEntrustMarket(order *share.ShareInrTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareInrTallyCache { + var deleteCache bool + var dealPrice string + var marketPrice = decimal.RequireFromString(order.Order.MarketPrice) // 市价-价格 + var status = order.Status // 原始价格 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareInrEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareInrConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareInr, err) + order.Status = status + } + } + + wg.Done() + return share.ShareInrTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareBlockInrConcurrentComputingEntrustMarket +// +// @Description: 大宗(印尼股)交易 +// @param order +// @param newPrice +// @param wg +// @return share.ShareInrTallyCache +func ShareBlockInrConcurrentComputingEntrustMarket(order *share.ShareInrTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareInrTallyCache { + var status = order.Status // 原始状态 + + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareBlkEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareBlockInrConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareBlk, err) + order.Status = status + } + + wg.Done() + return share.ShareInrTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: newPrice.String(), // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareInrMqOpenBusiness +// +// @Description: TODO: 印度股持仓消息队列 +// @param ctx +// @param uo +func ShareInrMqOpenBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Entrust.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerEntrustMq.ShareInrMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareInrMqOpenBusiness.ShareInrMq err....", common.ErrShareInr) + continue + } + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareInrTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareInrMqOpenBusiness.Unmarshal:%v", common.ErrShareInr, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareInrLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareInrMqOpenBusiness.ShareInrLiquidationEntrust:%v", common.ErrShareInr, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + applogger.Error("这里没有监控到持仓mq队列消息.........") + time.Sleep(2 * time.Second) + } + } +} + +// ShareInrLiquidationEntrust +// +// @Description: 印度股挂单-->开仓业务处理 +// @param ctx +// @param order +// @return error +func ShareInrLiquidationEntrust(ctx context.Context, order *share.ShareInrTallyCache) error { + // 1、开盘 + err := StockInrOpenOrder(ctx, Msql, order.UserId, order.OrderId, order.OpenPrice, order.Order) + if err != nil { + applogger.Error("%v ShareInrLiquidationEntrust.StockInrOpenOrder:%v", common.ErrShareInr, err) + return err + } + + // 大宗(印度股)交易判定 + var entrustKey, adminKey string + if !CheckTypeStatus(order.Order.Type) { + entrustKey = setting.ShareInrSubscribe + adminKey = setting.AdminShareInrSubscribe + } else { + entrustKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // 2、更新用户订阅缓存列表订单状态 + updateKey := virtual.OrderIdListKey(entrustKey, order.UserId) + if err = UpdateShareInrSubscribeHashStatusByOrderId(order.OrderId, updateKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareInrLiquidationEntrust.Entrust.%v:%v", common.ErrShareInr, entrustKey, err) + return err + } + + // 3、更新管理员订阅缓存列表订单状态 + if err = UpdateShareInrSubscribeHashStatusByOrderId(order.OrderId, adminKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareInrLiquidationEntrust.Entrust.%v:%v", common.ErrShareInr, adminKey, err) + return err + } + + return nil +} + +// ShareInrTransactionPosition +// +// @Description: 印度股持仓订单 +// @param ctx +func ShareInrTransactionPosition(ctx context.Context) { + for { + ShareInrTransactionCalculationPosition(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareInrTransactionCalculationPosition +// +// @Description: 印尼股持仓缓存队列计算 +// @param ctx +func ShareInrTransactionCalculationPosition(ctx context.Context) { + var wg sync.WaitGroup + + // 判定是否交易 + if CheckGlobalTread(flags.InrMarket) { + time.Sleep(5 * time.Second) + return + } + + // TODO: 获取IPO未支付订单缓存 + userIdMap, _ := GetBotUserArrears(ctx) + + // 获取持仓缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareInrPosition).Result() + if err != nil { + applogger.Error("%v ShareInrTransactionCalculationPosition.HGetAll:%v", common.ErrShareInr, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareInrTallyCache, 1) + var entrust share.ShareInrTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareInrTransactionCalculationPosition.Unmarshal:%v", common.ErrShareInr, err) + continue + } + + // TODO: 判定是否未IPO未支付订单-不能平仓 + _, isOk := userIdMap[entrust.UserId] + if isOk { + continue + } + + // 处理时间 + if !CheckShareSystemTime(entrust.ClosingTime) { + applogger.Info("印度股:%v,平仓时间:%v暂未到达...", entrust.Symbol, entrust.ClosingTime) + continue + } + + // TODO: 实时获取强平阈值 + //entrust.Order.System.StrongFlatRatio = GetForcedClosureValue(flags.Inr, entrust.Symbol) + + // 实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareInrPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareInrTransactionCalculationPosition.Get:%v--%v", common.ErrShareInr, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + chg := GetShareChgInr(flags.Inr, entrust.Symbol) // 涨跌幅标识 + if share.CheckInrOrderByChg(setting.MarketShareInrEntrust, entrust, chg) { + //applogger.Warn("当前股票%v订单在挂单状态已达到涨跌幅上限.", entrust.Symbol) + continue + } + + // 判定配额强平 + checkFlattening := GetStrongFlatteningThreshold(entrust.UserId) + + wg.Add(1) + go func(value string) { + resultMsg := ShareInrConcurrentComputingPosition(&entrust, newPrice, &wg, checkFlattening) + msg <- resultMsg + }(value) + + // 处理并发结果 + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Position: // 持仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到印度股持仓信息:%v", resultMsg) + } + case flags.Close: // 平仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到印度股平仓信息:%v", resultMsg) + } + + // TODO: 平仓操作(优化写入队列中等待平仓) + //var byteStr []byte + //byteStr, err = json.Marshal(resultMsg) + //if err != nil { + // applogger.Error("%v ShareInrTransactionCalculationPosition.Marshal:%v", common.ShareInrError, err) + // continue + //} + //if err = uo.mqProducer.Position.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareInrTransactionCalculationPosition.DealPublish:%v", common.ShareInrError, err) + // continue + //} + + if err = ShareInrLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareInrTransactionCalculationPosition.ShareInrLiquidationPosition:%v", common.ErrShareInr, err) + continue + } + } + } + } + + wg.Wait() + applogger.Info("印度股持仓并发计算执行完毕......") +} + +// ShareInrConcurrentComputingPosition +// +// @Description: 印度股持仓缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareInrTallyCache +func ShareInrConcurrentComputingPosition(order *share.ShareInrTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup, checkFlattening bool) share.ShareInrTallyCache { + var deleteCache, checkBool bool + var dealPrice string + var sellShort decimal.Decimal + var openPrice = decimal.RequireFromString(order.OpenPrice) // 限价 + var orderNumber = decimal.RequireFromString(order.Order.OrderNumber) // 仓位 + + var pryNum decimal.Decimal + lenPryNum := len(utils.ReplaceStr(order.Order.PryNum)) == 0 + if lenPryNum || order.Order.PryNum == flags.SetZero || order.Order.System.UserStatus != flags.SetThree || !utils.IsNumberInt(order.Order.PryNum) { + pryNum = decimal.RequireFromString(flags.SetOne) + } else { + pryNum = decimal.RequireFromString(order.Order.PryNum) + } + + // 下单判定设置(false无设置|true止盈止损) + _, stopWinPrice, stopLossPrice, _ := StockInrVoteStopType(order.Order) + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨(强平) + if !flags.CheckSetting { + applogger.Info("用户ID:%v,持仓开仓价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买涨:挂止损止盈,止盈价必须<当前价,止损价必须>当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + // 强行平仓(做多) + if !checkBool { + sellShort = newPrice.Sub(openPrice).Mul(orderNumber) + } + case flags.TradeTypeSell: // 买跌(存在强行平仓) + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价持仓买跌下单价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买跌:挂止损止盈,止盈价必须>当前价,止损价必须<当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + // 强行平仓(做空) + if !checkBool { + sellShort = openPrice.Sub(newPrice).Mul(orderNumber) + } + } + /* 强行平仓(做多|做空) + 1、做多:(最新成交价-开仓成交价)*仓位 + 2、做空:(开仓成交价-最新成交价)*仓位 + 3、当浮动盈亏 >= 保证金的70%订单强行平仓 + */ + if sellShort.IsNegative() && checkFlattening { + orderAmount := newPrice.Mul(decimal.RequireFromString(order.Order.OrderNumber)).Div(pryNum) // 订单金额 = 当前价格 * 订单数量 / 杠杆 + floatPrice := orderAmount.Mul(decimal.RequireFromString(order.Order.System.StrongFlatRatio)) + if !flags.CheckSetting { + applogger.Debug("强平保证金:%v,强平浮动70:%v,强行平仓判定:%v", orderAmount, floatPrice, sellShort.Abs().Cmp(floatPrice)) + } + + if sellShort.Abs().Cmp(floatPrice) >= 0 { + checkBool = true + // 设置价差 + difference := newPrice.Mul(utils.Difference()) // 设置价差 + switch order.Order.TradeType { + case flags.TradeTypeBuy: //买涨 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + case flags.TradeTypeSell: // 买跌 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + } + // 交易状态判定 + if checkBool { + deleteCache = true + order.Status = flags.Close + } + if deleteCache { + // 根据订单ID-删除持仓列表缓存订单 + if err := Reds.HDel(context.Background(), setting.MarketShareInrPosition, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareInrConcurrentComputingPosition.Position.HDel:%v", common.ErrShareInr, err) + } + } + + wg.Done() + return share.ShareInrTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + ClosingPrice: dealPrice, // 平仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareInrMqClosingBusiness +// +// @Description: TODO: 处理印度股平仓消息队列 +// @param ctx +// @param uo +func ShareInrMqClosingBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Position.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerPositionMq.ShareInrMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareInrMqClosingBusiness.ShareInrMq err....", common.ErrShareInr) + continue + } + applogger.Info("接收到平仓信息:%v", string(message)) + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareInrTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareInrMqClosingBusiness.Unmarshal:%v", common.ErrShareInr, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareInrLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareInrMqClosingBusiness.ShareInrLiquidationPosition:%v", common.ErrShareInr, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + time.Sleep(2 * time.Second) + } + } +} + +// ShareInrLiquidationPosition +// +// @Description: 印度股持仓-->平仓业务处理 +// @param ctx +// @param order +// @return error +func ShareInrLiquidationPosition(ctx context.Context, order *share.ShareInrTallyCache) error { + // 1、平仓操作 + err := StockInrClosingOrder(ctx, Msql, order.OrderId, order.ClosingPrice, order.Order) + if err != nil { + applogger.Error("%v ShareInrLiquidationPosition.StockIdnClosingOrder:%v", common.ErrShareInr, err) + return err + } + + // 2、平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareInrSubscribe, order.UserId) + if err = UpdateShareInrSubscribeHashStatusByOrderId(order.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v ShareInrLiquidationPosition.Position.ShareInrSubscribe:%v", common.ErrShareInr, err) + return err + } + + // 3、平仓更新管理员订阅订单状态 + if err = UpdateShareInrSubscribeHashStatusByOrderId(order.OrderId, setting.AdminShareInrSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v ShareInrLiquidationPosition.Position.AdminShareInrSubscribe:%v", common.ErrShareInr, err) + return err + } + + return nil +} + +// StockInrVoteStopType +// +// @Description: 印度股判定取值止损止盈 +// @param order +// @return bool +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func StockInrVoteStopType(order structure.ShareOrder) (bool, decimal.Decimal, decimal.Decimal, error) { + var checkBool bool + var stopWinPrice, stopLossPrice decimal.Decimal + switch order.StopType { + case flags.StopTypeNone: // 暂无设置止盈止损 + checkBool = false + case flags.StopTypeSet: // 设置止盈止损 + checkBool = true + stopWinPrice, _ = decimal.NewFromString(order.StopWinPrice) + stopLossPrice, _ = decimal.NewFromString(order.StopLossPrice) + default: + return checkBool, stopWinPrice, stopLossPrice, flags.ErrContractThirteen + } + + return checkBool, stopWinPrice, stopLossPrice, nil +} + +// GetShareInrPrice +// +// @Description: 查询印度股股票价格 +// @param symbol +// @return decimal.Decimal +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func GetShareInrPrice(symbol string) (decimal.Decimal, error) { + var err error + var priceByte []byte + var newPrice decimal.Decimal + + key := publicData.SymbolCache(flags.Inr, symbol, flags.TradeTypePrice) + priceByte, err = memory.GetShareInrCache(key) + if err != nil { + return decimal.Decimal{}, err + } + + newPrice, err = decimal.NewFromString(string(priceByte)) + if err != nil { + return decimal.Decimal{}, err + } + + applogger.Info("shareInrCode:%v,topIc:%v,shareInrPrice:%v", symbol, key, newPrice) + + return newPrice, nil +} diff --git a/internal/data/subscribe_share_jpy.go b/internal/data/subscribe_share_jpy.go new file mode 100644 index 0000000..74a475a --- /dev/null +++ b/internal/data/subscribe_share_jpy.go @@ -0,0 +1,1250 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/mq/consumer" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/socket/shareData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "sync" + "time" +) + +/* +日本股行情订阅 +1、接收用户日本股下单的交易对日本股行情 +2、将订阅行情写入内存中用于并发计算 +3、挂单(市价|限价)缓存队列处理-开仓 +4、持仓缓存队列处理-平仓 +*/ + +// ShareJpyMessage +// @Description: +type ShareJpyMessage struct { + Symbol string `json:"symbol,omitempty"` // 交易所:股票代码 + StockCode string `json:"stock_code,omitempty"` // 股票代码 + StockName string `json:"stock_name,omitempty"` // 股票名,可能为空 + Price decimal.Decimal `json:"price,omitempty"` // 实时价格 + UpDownRate decimal.Decimal `json:"up_down_rate,omitempty"` // 涨跌% + UpDown decimal.Decimal `json:"up_down,omitempty"` // 涨跌额 + TradeV decimal.Decimal `json:"trade_v,omitempty"` // 技术评级指标值 + TradeK string `json:"trade_k,omitempty"` // 技术评级 + Vol int64 `json:"vol,omitempty"` // 成交量 + TurnoverPriceTotal decimal.Decimal `json:"turnover_price_total,omitempty"` // 成交量*价格 + PriceTotal string `json:"price_total,omitempty"` // 总市值 + PE string `json:"p_e,omitempty"` // pe + Eps string `json:"eps,omitempty"` // EPS + EmployeesNumber string `json:"employees_number,omitempty"` // 雇员 + Plate string `json:"plate,omitempty"` // 板块 + Desc string `json:"desc,omitempty"` // 描述 + PriceCode string `json:"price_code,omitempty"` // 价格类型 + Country string `json:"country,omitempty"` // 国家 + Ts int64 `json:"ts,omitempty"` // 时间 + Token string `json:"token,omitempty"` // Token 令牌 +} + +// ShareEurSymbol +// @Description: +type ShareJpySymbol struct { + JpyMap chan []byte // 订单交易对 -- 用户下单通知订阅 + JpySetMap chan []byte // 订单交易对 -- 用户盘前|盘后行情订阅 + JpyMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 + JpySetMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 +} + +// InitCacheSymbolShareJpy +// +// @Description: +// @param ctx +// @param uo +func InitCacheSymbolShareJpy(ctx context.Context, uo *Data) { + for { + thaList, err := GetBotStockJpyListByStockId(ctx, uo) + if err != nil { + return + } + + for _, value := range thaList { + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := uo.redisDB.HExists(context.Background(), setting.MarketShareJpy, value).Result() + if err != nil { + applogger.Error("%v InitCacheSymbolShareJpy.MarketShareEur.HExists:%v", common.ErrShareJpy, err) + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err = uo.redisDB.HSet(context.Background(), setting.MarketShareJpy, value, value).Err(); err != nil { + applogger.Error("%v InitCacheSymbolShareJpy.MarketShareEur.HSet:%v", common.ErrShareJpy, err) + time.Sleep(5 * time.Second) + continue + } + } + if !flags.CheckSetting { + applogger.Info("初始化日股票代码:%v", value) + } + } + + time.Sleep(10 * time.Second) + } +} + +// InitSubscribeShareJpy +// +// @Description: 状态机加载订阅 +// @param ctx +// @param uo +// @param shareTha +func InitSubscribeShareJpy(shareJpy *ShareJpySymbol, check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkJpy + } else { + key = setting.MarketShareJpy + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareEur.LoadLRangeList:%v", common.ErrShareJpy, err) + return + } + + for _, value := range listSpots { + // Handling duplicate subscriptions + _, ok := shareJpy.JpyMapSymbol.Load(value) + if ok { + continue + } + + shareJpy.JpyMap <- []byte(value) + } + + time.Sleep(10 * time.Second) + } +} + +// InitShareJpyCloseCachePrice +// +// @Description: +// @param shareSgd +// @param check +func InitShareJpyCloseCachePrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkJpy + } else { + key = setting.MarketShareJpy + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareJpyCloseCachePrice.LoadLRangeList:%v", common.ErrShareJpy, err) + return + } + + for _, value := range listSpots { + SubscribeJpyClosePrice(value) // 处理闭盘取价 + } + + time.Sleep(20 * time.Second) + } +} + +// InitShareJpyCloseNewPrice +// +// @Description: 同步实时行情 +// @param check +func InitShareJpyCloseNewPrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkJpy + } else { + key = setting.MarketShareJpy + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareJpyCloseNewPrice.LoadLRangeList:%v", common.ErrShareJpy, err) + time.Sleep(20 * time.Second) + continue + } + for _, value := range listSpots { + SubscribeJpyCloseNewPrice(value) + } + + time.Sleep(500 * time.Millisecond) + } +} + +// InitShareJpyPriceSetUp +// +// @Description: 同步插针价 +// @param check +func InitShareJpyPriceSetUp(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkJpy + } else { + key = setting.MarketShareJpy + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareJpyPriceSetUp.LoadLRangeList:%v", common.ErrShareJpy, err) + time.Sleep(20 * time.Second) + continue + } + + for _, value := range listSpots { + furKey := publicData.SymbolCache(flags.Jpy, value, flags.TradeTypePrice) + furSetCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareJpyMarketType, value) + vw, err := GetBeforeAndAfterSetPrice(furSetCache) + if err != nil || len(vw) == 0 { + _ = memory.ShareJpyPriceSetUp.Delete(furKey) + continue + } + if err = memory.ShareJpyPriceSetUp.Set(furKey, []byte(vw)); err != nil { + applogger.Error("%v InitShareJpyPriceSetUp.ShareJpyPriceSetUp:%v", common.ErrShareJpy, err) + } + } + + time.Sleep(500 * time.Millisecond) + } +} + +// SubscribeJpyHSetCodeList +// +// @Description: 同步列表缓存 +// @param symbolStr +// @param check +func SubscribeJpyHSetCodeList(symbolStr string, check bool) { + var key string + if check { + key = setting.MarketShareBlkJpy + } else { + key = setting.MarketShareJpy + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + return + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeJpyHSetCodeList.%v.HSet:%v", common.ErrShareJpy, key, err) + return + } + } +} + +// SubscribeJpyCloseNewPrice +// +// @Description: 获取行情价 +// @param symbolStr +// @param check +func SubscribeJpyCloseNewPrice(symbolStr string) { + // 获取市场真实开闭盘时间 + timeValue, checkWeekday := MarketCheckOpenAndCloseTime(flags.ShareJpyMarketType) + // 判定是否盘中 + if utils.CheckInPlateTime(timeValue) && checkWeekday { + // 盘中实时价格 + realTimePrice, err := Reds.HGet(context.Background(), flags.ShareJapanClosingNewPriceKey, symbolStr).Result() + if err != nil { + realTimePrice = decimal.Zero.String() + } + if realTimePrice != decimal.Zero.String() { + keys := publicData.SymbolCache(flags.Jpy, symbolStr, flags.TradeTypePrice) + if err = memory.ShareJpyCache.Set(keys, []byte(realTimePrice)); err != nil { + applogger.Error("%v SubscribeJpyCloseNewPrice.ShareJpyCache:%v", common.ErrShareJpy, err) + } + } + } +} + +// SubscribeJpyClosePrice +// +// @Description: 获取闭盘价 +// @param symbolStr +func SubscribeJpyClosePrice(symbolStr string) { + var err error + var sub = decimal.Zero + var closeNewPrice, closingPrice, price string + + // 闭盘价格 + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareJapanClosingNewPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareJapanClosingPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice = decimal.Zero.String() + } + } + + // 市价(实时价格) + closingPrice, err = Reds.HGet(context.Background(), flags.ShareJapanBeforeClose, symbolStr).Result() + if err != nil { + closingPrice = decimal.Zero.String() + } + + // 判定取值数据 + if closeNewPrice != decimal.Zero.String() { + price = closeNewPrice + } else { + price = closingPrice + } + closeKey := publicData.SymbolCache(flags.Jpy, symbolStr, flags.TradeTypeClosePrice) + if err = memory.ShareJpyClosePrice.Set(closeKey, []byte(price)); err != nil { + applogger.Error("%v SubscribeJpyClosePrice.Set.price:%v", common.ErrShareJpy, err) + } + + // 写入涨跌幅价格判定缓存(计算涨跌幅 = 最新价格 - 闭盘价格(昨天关闭价格或者上次毕盘价格)) + cn := closeNewPrice != decimal.Zero.String() + cp := closingPrice != decimal.Zero.String() + lcn := utils.IsNumber(closeNewPrice) + lcp := utils.IsNumber(closingPrice) + if cn && cp && lcn && lcp { + sub = decimal.RequireFromString(closingPrice).Sub(decimal.RequireFromString(closeNewPrice)) + } + chgKey := publicData.SymbolCache(flags.Jpy, symbolStr, flags.TradeTypeChg) // 涨跌幅标识Key + if err = memory.ShareJpyChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v SubscribeJpyClosePrice.Set.price:%v", common.ErrShareJpy, err) + } +} + +// OrderSubAdminShareJpySubscribeBySum +// +// @Description: 持仓订单浮动盈亏计算 +// @param ctx +// @param uo +func OrderSubAdminShareJpySubscribeBySum(uo *Data) { + for { + var topIc = setting.AdminShareJpySubscribe + hashMap, err := uo.redisDB.HGetAll(context.Background(), topIc).Result() + if err != nil { + applogger.Error("OrderSubAdminShareJpySubscribeBySum.HGetAll:%v", err) + time.Sleep(5 * time.Second) + continue + } + var hashList []share.ShareJpyTallyCache + for _, value := range hashMap { + var msg share.ShareJpyTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + switch msg.Status { + case flags.Entrust: // 挂单 + case flags.Position: // 持仓 + hashList = append(hashList, msg) + default: // 平仓|撤单 + err = uo.redisDB.HDel(context.Background(), topIc, msg.OrderId).Err() + if err != nil { + applogger.Error("OrderSubAdminShareJpySubscribeBySum.HDel:%v", err) + continue + } + } + } + applogger.Info("日股数据量统计:%v", len(hashList)) + // 统计德股总持仓订单浮动盈亏 + priceSum := decimal.Zero + for _, value := range hashList { + orderModel := shareData.ShareJpyOrderProcessing(topIc, value) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch value.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + price := subPrice.Mul(decimal.RequireFromString(value.Order.OrderNumber)) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + + // 写入缓存 + if err = memory.ShareJpyFloating.Set(flags.FloatingJpy, []byte(priceSum.String())); err != nil { + applogger.Error("统计日股持仓订单浮动盈亏错误:%v", err) + time.Sleep(5 * time.Second) + continue + } + applogger.Info("统计的日股持仓订单浮动盈亏:%v", priceSum) + + time.Sleep(1 * time.Second) + } +} + +// SubscribeShareJpy +// +// @Description: TODO: 订阅 +// @param ctx +// @param uo +// @param shareJpy +func SubscribeShareJpy(ctx context.Context, shareJpy *ShareJpySymbol, check bool) { + for { + select { + case symbol, _ := <-shareJpy.JpyMap: + symbolStr := string(symbol) + topIc := fmt.Sprintf("%v.%v", symbolStr, flags.CountryJpy) + // Handling duplicate subscriptions + _, ok := shareJpy.JpyMapSymbol.Load(symbolStr) + if ok { + time.Sleep(5 * time.Second) + continue + } + // Transaction determination + var key string + if check { + key = setting.MarketShareBlkJpy // 大宗股交易 + } else { + key = setting.MarketShareJpy // 日股交易 + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeShareJpy.%v.HSet:%v", common.ErrShareJpy, key, err) + time.Sleep(5 * time.Second) + continue + } + } + + // 处理订阅实时行情数据 + go func() { + symbolStrCache := symbolStr + pubSub := Reds.Subscribe(ctx, topIc) + defer pubSub.Close() + if _, err := pubSub.Receive(ctx); err != nil { + shareJpy.JpyMapSymbol.Delete(symbolStrCache) + return + } + ch := pubSub.Channel() + for { + select { + case msg, _ := <-ch: + var subMsg ShareJpyMessage + if err := json.Unmarshal([]byte(msg.Payload), &subMsg); err != nil { + applogger.Error("%v SubscribeShareJpy.Unmarshal:%v", common.ErrShareJpy, err) + time.Sleep(5 * time.Second) + continue + } + SubscribeJpyPrice(subMsg.Price.String(), symbolStr, flags.RealTime) + default: + Reds.Ping(ctx) // 如果没有消息,发送 PING 命令以维护连接 + time.Sleep(10 * time.Second) + } + } + }() + + // 监控盘前|盘后设置价格 + _, okc := shareJpy.JpySetMapSymbol.Load(symbolStr) + if !okc { + go func() { + for { + keyCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareJpyMarketType, symbolStr) + vw, err := GetBeforeAndAfterSetPrice(keyCache) + if err != nil || len(vw) == 0 { + priceCache := publicData.SymbolCache(flags.Jpy, symbolStr, flags.TradeTypePrice) + memory.ShareJpyPriceSetUp.Delete(priceCache) + time.Sleep(15 * time.Second) + continue + } + SubscribeJpyPrice(vw, symbolStr, flags.SetUp) + time.Sleep(10 * time.Second) + } + }() + // Write cache to determine whether to repeatedly open the protocol + shareJpy.JpySetMapSymbol.Store(symbolStr, symbolStr) + } + + // Write in the map to determine whether to repeat subscription + shareJpy.JpyMapSymbol.Store(symbolStr, symbolStr) + } + } +} + +// SubscribeJpyPrice +// +// @Description: TODO: 订阅获取日股实时价格或者[盘前|盘后]设置价格 +// @param setPrice +// @param symbolStr +// @param check +func SubscribeJpyPrice(setPrice, symbolStr string, check int) { + var err error + var sub = decimal.Zero + + // 计算涨跌幅 + yClosingPrice, err := Reds.HGet(context.Background(), flags.ShareJapanClosingPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice, err = Reds.HGet(context.Background(), flags.ShareJapanClosingNewPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice = setPrice + sub = decimal.Zero + } + } + + // 写入涨跌幅缓存数据 + yc := yClosingPrice != decimal.Zero.String() + sp := setPrice != decimal.Zero.String() + lyc := utils.IsNumber(yClosingPrice) + lsp := utils.IsNumber(setPrice) + if yc && sp && lyc && lsp { + sub = decimal.RequireFromString(setPrice).Sub(decimal.RequireFromString(yClosingPrice)) + } + chgKey := publicData.SymbolCache(flags.Jpy, symbolStr, flags.TradeTypeChg) + if err = memory.ShareJpyChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v SubscribeJpyPrice.ShareEurChgMark.Set.price:%v", common.ErrShareJpy, err) + } + if !flags.CheckSetting { + applogger.Debug("涨跌幅交易对内存key:%v,涨跌幅数值:%v", symbolStr, sub) + } + + // 交易类型:0最新价,1买入,2卖出 + price := publicData.SymbolCache(flags.Jpy, symbolStr, flags.TradeTypePrice) + switch check { + case flags.RealTime: // 实时价格(优先级高) + if err = memory.ShareJpyCache.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeJpyPrice.ShareEurCache.Set.price:%v", common.ErrShareJpy, err) + } + case flags.SetUp: // 设置[盘前|盘后]价格 + if err = memory.ShareJpyPriceSetUp.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeJpyPrice.ShareEurPriceSetUp:%v", common.ErrShareJpy, err) + } + } + if !flags.CheckSetting { + applogger.Debug("股票交易对内存Key:%v,最新价格:%v", price, setPrice) + } +} + +// SubscribeJpySetForcedClosure +// +// @Description: TODO: 处理日股强平阈值 +// @param symbolStr +func SubscribeJpySetForcedClosure(symbolStr string) { + flatRatio := GetCacheForcedClosure(flags.StockFURSystemSetUpKey, symbolStr) + chgKey := publicData.SymbolCache(flags.Jpy, symbolStr, flags.TradeTypeForcedClosure) + if err := memory.ShareJpyForcedClosure.Set(chgKey, []byte(flatRatio.String())); err != nil { + applogger.Error("%v SubscribeJpySetForcedClosure.ShareJpyForcedClosure err:%v", common.ErrShareJpy, err) + return + } +} + +// ShareJpyTransactionCalculationEntrust +// +// @Description: 日股委托订单 +// @param ctx +func ShareJpyTransactionEntrust(ctx context.Context) { + for { + ShareJpyTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareJpyTransactionCalculationEntrust +// +// @Description: 日股挂单缓存队列计算 +// @param ctx +func ShareJpyTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 全局变量处理 + if CheckGlobalTread(flags.JpyMarket) { + time.Sleep(5 * time.Second) + return + } + + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareJpyEntrust).Result() + if err != nil { + applogger.Error("%v ShareJpyTransactionCalculationEntrust.HGetAll:%v", common.ErrShareJpy, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareJpyTallyCache, 1) + var entrust share.ShareJpyTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareJpyTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareJpy, err) + continue + } + + // 股票实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareJpyPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareEurTransactionCalculationEntrust.GetShareJpyPrice:%v---%v", common.ErrShareJpy, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + //chg := GetShareChgJpy(flags.Jpy, entrust.Symbol) // 涨跌幅标识 + //if share.CheckOrderJpyByChg(setting.MarketShareJpyEntrust, entrust, chg) { + // continue + //} + + wg.Add(1) + go func(value string) { + var resultMsg share.ShareJpyTallyCache + switch entrust.Order.DealType { + case flags.DealTypeLimited: // 限价挂单 + resultMsg = ShareJpyConcurrentComputingEntrustLimited(&entrust, newPrice, &wg) + case flags.DealTypeMarket: // 市价挂单(开盘即成交) + resultMsg = ShareJpyConcurrentComputingEntrustMarket(&entrust, newPrice, &wg) + } + msg <- resultMsg // 通知管道异步处理订单操作 + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收日股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到日股持仓信息:%v", resultMsg) + } + + // 开盘逻辑 + if err = ShareJpyLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Warn("%v ShareJpyTransactionCalculationEntrust.ShareJpyLiquidationEntrust:%v", common.ErrShareJpy, err) + continue + } + + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Warn("%v ShareJpyTransactionCalculationEntrust.Marshal:%v", common.ErrShareJpy, err) + continue + } + + // TODO: 写入持仓消息队列 + //if err = uo.mqProducer.Entrust.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareJpyTransactionCalculationEntrust.PushNotice:%v", common.ErrShareJpy, err) + // continue + //} + + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareJpyPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("日股挂单并发计算执行完毕......") +} + +// ShareJpyConcurrentComputingEntrustLimited +// +// @Description: 日股挂单(限价|市价)缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareJpyTallyCache +func ShareJpyConcurrentComputingEntrustLimited(order *share.ShareJpyTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareJpyTallyCache { + var deleteCache bool + var dealPrice string + var limitPrice = decimal.RequireFromString(order.Order.LimitPrice) // 限价-价格 + var status = order.Status // 原始价格 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价买入逻辑判定 -> 挂单金额 > 当前价格 + if limitPrice.Cmp(newPrice) > 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + } + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价卖入逻辑判定 -> 挂单金额 < 当前价格 + if limitPrice.Cmp(newPrice) < 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareJpyEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareJpyConcurrentComputingEntrustLimited.MarketShareJpyEntrust.HDel:%v", common.ErrShareJpy, err) + order.Status = status + } + } + + wg.Done() + return share.ShareJpyTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareJpyConcurrentComputingEntrustMarket +// +// @Description: 日股市价下单进入挂单队列(休市) +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareJpyTallyCache +func ShareJpyConcurrentComputingEntrustMarket(order *share.ShareJpyTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareJpyTallyCache { + var deleteCache bool + var dealPrice string + var marketPrice = decimal.RequireFromString(order.Order.MarketPrice) // 市价-价格 + var status = order.Status // 原始价格记录 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareJpyEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareJpyConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareJpy, err) + order.Status = status + } + } + + wg.Done() + return share.ShareJpyTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareBlockJpyConcurrentComputingEntrustMarket +// +// @Description: 大宗(日股)交易 +// @param order +// @param newPrice +// @param wg +// @return share.ShareJpyTallyCache +func ShareBlockJpyConcurrentComputingEntrustMarket(order *share.ShareJpyTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareJpyTallyCache { + var status = order.Status // 原始状态 + + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareBlkEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareBlockJpyConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareBlk, err) + order.Status = status + } + + wg.Done() + return share.ShareJpyTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: newPrice.String(), // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareJpyMqOpenBusiness +// +// @Description: TODO: 日股持仓消息队列 +// @param ctx +// @param uo +func ShareJpyMqOpenBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Entrust.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerEntrustMq.ShareJpyMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareJpyMqOpenBusiness.ShareJpyMq err....", common.ErrShareJpy) + continue + } + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareJpyTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareJpyMqOpenBusiness.Unmarshal:%v", common.ErrShareJpy, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareJpyLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareJpyMqOpenBusiness.ShareJpyLiquidationEntrust:%v", common.ErrShareJpy, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + applogger.Info("这里没有监控到持仓mq队列消息.........") + time.Sleep(2 * time.Second) + } + } +} + +// ShareJpyLiquidationEntrust +// +// @Description: 日股挂单-->开仓业务处理 +// @param ctx +// @param order +// @return error +func ShareJpyLiquidationEntrust(ctx context.Context, order *share.ShareJpyTallyCache) error { + // 1、开盘 + err := StockJpyOpenOrder(ctx, Msql, order.UserId, order.OrderId, order.OpenPrice, order.Order) + if err != nil { + applogger.Error("%v ShareJpyLiquidationEntrust.StockJpyOpenOrder:%v", common.ErrShareJpy, err) + return err + } + + // 大宗(新加坡股)交易判定 + var entrustKey, adminKey string + if !CheckTypeStatus(order.Order.Type) { + entrustKey = setting.ShareJpySubscribe + adminKey = setting.AdminShareJpySubscribe + } else { + entrustKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // 2、更新用户订阅缓存列表订单状态 + updateKey := virtual.OrderIdListKey(entrustKey, order.UserId) + if err = UpdateShareJpySubscribeHashStatusByOrderId(order.OrderId, updateKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareJpyLiquidationEntrust.Entrust.%v:%v", common.ErrShareJpy, entrustKey, err) + return err + } + + // 3、更新管理员订阅缓存列表订单状态 + if err = UpdateShareJpySubscribeHashStatusByOrderId(order.OrderId, adminKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareJpyLiquidationEntrust.Entrust.%v:%v", common.ErrShareJpy, adminKey, err) + return err + } + + return nil +} + +// ShareJpyTransactionPosition +// +// @Description: 日股持仓订单 +// @param ctx +func ShareJpyTransactionPosition(ctx context.Context) { + for { + ShareJpyTransactionCalculationPosition(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareJpyTransactionCalculationPosition +// +// @Description: 日股持仓缓存队列计算 +// @param ctx +func ShareJpyTransactionCalculationPosition(ctx context.Context) { + var wg sync.WaitGroup + + // 判定是否交易 + if CheckGlobalTread(flags.JpyMarket) { + time.Sleep(5 * time.Second) + return + } + + // TODO: 获取IPO未支付订单缓存 + userIdMap, _ := GetBotUserArrears(ctx) + + // 获取持仓缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareJpyPosition).Result() + if err != nil { + applogger.Error("%v ShareJpyTransactionCalculationPosition.HGetAll:%v", common.ErrShareJpy, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareJpyTallyCache, 1) + var entrust share.ShareJpyTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareJpyTransactionCalculationPosition.Unmarshal:%v", common.ErrShareJpy, err) + continue + } + + // TODO: 判定是否未IPO未支付订单-不能平仓 + _, isOk := userIdMap[entrust.UserId] + if isOk { + continue + } + + // 处理时间 + if !CheckShareSystemTime(entrust.ClosingTime) { + applogger.Debug("日股:%v,平仓时间:%v暂未到达...", entrust.Symbol, entrust.ClosingTime) + continue + } + + // TODO: 实时获取强平阈值 + //entrust.Order.System.StrongFlatRatio = GetForcedClosureValue(flags.Sgd, entrust.Symbol) + + // 股票实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareJpyPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareJpyTransactionCalculationPosition.GetShareJpyPrice:%v--%v", common.ErrShareJpy, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + //chg := GetShareChgJpy(flags.Jpy, entrust.Symbol) // 涨跌幅标识 + //if share.CheckOrderJpyByChg(setting.MarketShareJpyEntrust, entrust, chg) { + // continue + //} + + // 判定配额强平 + checkFlattening := GetStrongFlatteningThreshold(entrust.UserId) + + wg.Add(1) + go func(value string) { + resultMsg := ShareJpyConcurrentComputingPosition(&entrust, newPrice, &wg, checkFlattening) + msg <- resultMsg + }(value) + + // 处理并发结果 + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Position: // 持仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到日股持仓信息:%v", resultMsg) + } + case flags.Close: // 平仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到日股平仓信息:%v", resultMsg) + } + + // TODO: 平仓操作(优化写入队列中等待平仓) + //var byteStr []byte + //byteStr, err = json.Marshal(resultMsg) + //if err != nil { + // applogger.Error("%v ShareJpyTransactionCalculationPosition.Marshal:%v", common.ErrShareJpy, err) + // continue + //} + //if err = uo.mqProducer.Position.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareJpyTransactionCalculationPosition.PushNotice:%v", common.ErrShareJpy, err) + // continue + //} + + // 平仓操作 + if err = ShareJpyLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareJpyTransactionCalculationPosition.ShareJpyLiquidationPosition:%v", common.ErrShareJpy, err) + continue + } + } + } + } + + wg.Wait() + applogger.Info("日股持仓并发计算执行完毕......") +} + +// ShareJpyConcurrentComputingPosition +// +// @Description: 日股持仓缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareJpyTallyCache +func ShareJpyConcurrentComputingPosition(order *share.ShareJpyTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup, checkFlattening bool) share.ShareJpyTallyCache { + var deleteCache, checkBool bool + var dealPrice string + var sellShort decimal.Decimal + var openPrice = decimal.RequireFromString(order.OpenPrice) // 限价 + var orderNumber = decimal.RequireFromString(order.Order.OrderNumber) // 仓位 + + var pryNum decimal.Decimal + lenPryNum := len(utils.ReplaceStr(order.Order.PryNum)) == 0 + if lenPryNum || order.Order.PryNum == flags.SetZero || order.Order.System.UserStatus != flags.SetThree || !utils.IsNumberInt(order.Order.PryNum) { + pryNum = decimal.RequireFromString(flags.SetOne) + } else { + pryNum = decimal.RequireFromString(order.Order.PryNum) + } + + // 下单判定设置(false无设置|true止盈止损) + _, stopWinPrice, stopLossPrice, _ := StockEurVoteStopType(order.Order) + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨(强平) + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,持仓开仓价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买涨:挂止损止盈,止盈价必须<当前价,止损价必须>当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + // 强行平仓(做多) + if !checkBool { + sellShort = newPrice.Sub(openPrice).Mul(orderNumber) + } + case flags.TradeTypeSell: // 买跌(存在强行平仓) + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价持仓买跌下单价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买跌:挂止损止盈,止盈价必须>当前价,止损价必须<当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + // 强行平仓(做空) + if !checkBool { + sellShort = openPrice.Sub(newPrice).Mul(orderNumber) + } + } + /* 强行平仓(做多|做空) + 1、做多:(最新成交价-开仓成交价)*仓位 + 2、做空:(开仓成交价-最新成交价)*仓位 + 3、当浮动盈亏 >= 保证金的70%订单强行平仓 + */ + if sellShort.IsNegative() && checkFlattening { + orderAmount := newPrice.Mul(decimal.RequireFromString(order.Order.OrderNumber)).Div(pryNum) // 订单金额 = 当前价格 * 订单数量 / 杠杆 + floatPrice := orderAmount.Mul(decimal.RequireFromString(order.Order.System.StrongFlatRatio)) + if !flags.CheckSetting { + applogger.Debug("强平保证金:%v,强平浮动70:%v,强行平仓判定:%v", orderAmount, floatPrice, sellShort.Abs().Cmp(floatPrice)) + } + + if sellShort.Abs().Cmp(floatPrice) >= 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + switch order.Order.TradeType { + case flags.TradeTypeBuy: //买涨 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + case flags.TradeTypeSell: // 买跌 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + } + + if checkBool { + deleteCache = true + order.Status = flags.Close + } + + if deleteCache { + // 根据订单ID-删除持仓列表缓存订单 + if err := Reds.HDel(context.Background(), setting.MarketShareJpyPosition, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareJpyConcurrentComputingPosition.Position.HDel:%v", common.ErrShareJpy, err) + } + } + + wg.Done() + return share.ShareJpyTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + ClosingPrice: dealPrice, // 平仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareJpyMqClosingBusiness +// +// @Description: TODO: 处理日股平仓消息队列 +// @param ctx +// @param uo +func ShareJpyMqClosingBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Position.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerPositionMq.ShareJpyMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareJpyMqClosingBusiness.ShareJpyMq err....", common.ErrShareJpy) + continue + } + applogger.Info("接收到平仓信息:%v", string(message)) + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareJpyTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareJpyMqClosingBusiness.Unmarshal:%v", common.ErrShareJpy, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareJpyLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareJpyMqClosingBusiness.ShareJpyLiquidationPosition:%v", common.ErrShareJpy, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + time.Sleep(2 * time.Second) + } + } +} + +// ShareJpyLiquidationPosition +// +// @Description: 日股持仓-->平仓业务处理 +// @param ctx +// @param order +// @return error +func ShareJpyLiquidationPosition(ctx context.Context, order *share.ShareJpyTallyCache) error { + // 1、平仓操作 + err := StockJpyClosingOrder(ctx, Msql, order.OrderId, order.ClosingPrice, order.Order) + if err != nil { + applogger.Error("%v ShareEurLiquidationPosition.StockJpyClosingOrder:%v", common.ErrShareJpy, err) + return err + } + + // 2、平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareJpySubscribe, order.UserId) + if err = UpdateShareJpySubscribeHashStatusByOrderId(order.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v ShareJpyLiquidationPosition.Position.ShareJpySubscribe:%v", common.ErrShareJpy, err) + return err + } + + // 3、平仓更新管理员订阅订单状态 + if err = UpdateShareJpySubscribeHashStatusByOrderId(order.OrderId, setting.AdminShareJpySubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v ShareJpyLiquidationPosition.Position.AdminShareJpySubscribe:%v", common.ErrShareJpy, err) + return err + } + + return nil +} + +// StockJpyVoteStopType +// +// @Description: 日股判定取值止损止盈 +// @param order +// @return bool +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func StockJpyVoteStopType(order structure.ShareOrder) (bool, decimal.Decimal, decimal.Decimal, error) { + var checkBool bool + var stopWinPrice, stopLossPrice decimal.Decimal + switch order.StopType { + case flags.StopTypeNone: // 暂无设置止盈止损 + checkBool = false + case flags.StopTypeSet: // 设置止盈止损 + checkBool = true + stopWinPrice, _ = decimal.NewFromString(order.StopWinPrice) + stopLossPrice, _ = decimal.NewFromString(order.StopLossPrice) + default: + return checkBool, stopWinPrice, stopLossPrice, flags.ErrContractThirteen + } + + return checkBool, stopWinPrice, stopLossPrice, nil +} + +// GetShareJpyPrice +// +// @Description: 日股票价格 +// @param symbol +// @return decimal.Decimal +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func GetShareJpyPrice(symbol string) (decimal.Decimal, error) { + var err error + var priceByte []byte + var newPrice decimal.Decimal + + key := publicData.SymbolCache(flags.Jpy, symbol, flags.TradeTypePrice) + priceByte, err = memory.GetShareJpyCache(key) + if err != nil { + return decimal.Decimal{}, err + } + + newPrice, err = decimal.NewFromString(string(priceByte)) + if err != nil { + return decimal.Decimal{}, err + } + + applogger.Info("GetShareJpyPrice:%v,topIc:%v,shareJpyPrice:%v", symbol, key, newPrice) + + return newPrice, nil +} diff --git a/internal/data/subscribe_share_mys.go b/internal/data/subscribe_share_mys.go new file mode 100644 index 0000000..7ddad06 --- /dev/null +++ b/internal/data/subscribe_share_mys.go @@ -0,0 +1,1246 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/mq/consumer" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/socket/shareData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "sync" + "time" +) + +/* +马股行情订阅 +1、接收用户马股下单的交易对马股行情 +2、将订阅行情写入内存中用于并发计算 +3、挂单(市价|限价)缓存队列处理-开仓 +4、持仓缓存队列处理-平仓 +*/ + +// ShareMysMessage +// @Description: +type ShareMysMessage struct { + Symbol string `json:"symbol,omitempty"` // 交易所:股票代码 + StockCode string `json:"stock_code,omitempty"` // 股票代码 + StockName string `json:"stock_name,omitempty"` // 股票名,可能为空 + Price decimal.Decimal `json:"price,omitempty"` // 实时价格 + UpDownRate decimal.Decimal `json:"up_down_rate,omitempty"` // 涨跌% + UpDown decimal.Decimal `json:"up_down,omitempty"` // 涨跌额 + TradeV decimal.Decimal `json:"trade_v,omitempty"` // 技术评级指标值 + TradeK string `json:"trade_k,omitempty"` // 技术评级 + Vol int64 `json:"vol,omitempty"` // 成交量 + TurnoverPriceTotal decimal.Decimal `json:"turnover_price_total,omitempty"` // 成交量*价格 + PriceTotal string `json:"price_total,omitempty"` // 总市值 + PE string `json:"p_e,omitempty"` // pe + Eps string `json:"eps,omitempty"` // EPS + EmployeesNumber string `json:"employees_number,omitempty"` // 雇员 + Plate string `json:"plate,omitempty"` // 板块 + Desc string `json:"desc,omitempty"` // 描述 + PriceCode string `json:"price_code,omitempty"` // 价格类型 + Country string `json:"country,omitempty"` // 国家 + Ts int64 `json:"ts,omitempty"` // 时间 + Token string `json:"token,omitempty"` // Token 令牌 +} + +// ShareMysSymbol +// @Description: +type ShareMysSymbol struct { + MysMap chan []byte // 订单交易对 -- 用户下单通知订阅 + MysSetMap chan []byte // 订单交易对 -- 用户盘前|盘后行情订阅 + MysMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 + MysSetMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 +} + +// InitCacheSymbolShareMys +// +// @Description: +// @param ctx +// @param uo +func InitCacheSymbolShareMys(ctx context.Context, uo *Data) { + for { + mysList, err := GetBotStockMysListByStockId(ctx, uo) + if err != nil { + return + } + + for _, value := range mysList { + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := uo.redisDB.HExists(context.Background(), setting.MarketShareMys, value).Result() + if err != nil { + applogger.Error("%v SubscribeShareMys.MarketShareMys.HExists:%v", common.ErrShareMys, err) + continue + } + if !checkBool { + if err := uo.redisDB.HSet(context.Background(), setting.MarketShareMys, value, value).Err(); err != nil { + applogger.Error("%v SubscribeShareMys.MarketShareMys.HSet:%v", common.ErrShareMys, err) + continue + } + } + if !flags.CheckSetting { + applogger.Info("初始化马股股票代码:%v", value) + } + } + + time.Sleep(10 * time.Second) + } +} + +// InitSubscribeShareMys +// +// @Description: 状态机加载订阅 +// @param ctx +// @param uo +// @param shareMys +func InitSubscribeShareMys(shareMys *ShareMysSymbol, check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkMys + } else { + key = setting.MarketShareMys + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareMys.LoadLRangeList:%v", common.ErrShareMys, err) + return + } + + for _, value := range listSpots { + // Handling duplicate subscriptions + _, ok := shareMys.MysMapSymbol.Load(value) + if ok { + continue + } + + shareMys.MysMap <- []byte(value) + } + + time.Sleep(10 * time.Second) + } +} + +// InitShareMysCloseCachePrice +// +// @Description: +// @param shareMys +// @param check +func InitShareMysCloseCachePrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkMys + } else { + key = setting.MarketShareMys + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareMys.LoadLRangeList:%v", common.ErrShareMys, err) + return + } + + for _, value := range listSpots { + SubscribeMysClosePrice(value) // 处理闭盘价格取值 + } + + time.Sleep(10 * time.Second) + } +} + +// InitShareMysCloseNewPrice +// +// @Description: 同步实时行情 +// @param check +func InitShareMysCloseNewPrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkMys + } else { + key = setting.MarketShareMys + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareMysCloseNewPrice.LoadLRangeList:%v", common.ErrShareMys, err) + time.Sleep(20 * time.Second) + continue + } + for _, value := range listSpots { + SubscribeMysCloseNewPrice(value) + } + + time.Sleep(500 * time.Millisecond) + } +} + +// InitShareMysPriceSetUp +// +// @Description: 同步插针行情 +// @param check +func InitShareMysPriceSetUp(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkMys + } else { + key = setting.MarketShareMys + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareMysPriceSetUp.LoadLRangeList:%v", common.ErrShareMys, err) + time.Sleep(20 * time.Second) + continue + } + + for _, value := range listSpots { + mysKey := publicData.SymbolCache(flags.Mys, value, flags.TradeTypePrice) + mysSetCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareMysMarketType, value) + vw, err := GetBeforeAndAfterSetPrice(mysSetCache) + if err != nil || len(vw) == 0 { + _ = memory.ShareMysPriceSetUp.Delete(mysKey) + continue + } + if err = memory.ShareMysPriceSetUp.Set(mysKey, []byte(vw)); err != nil { + applogger.Error("%v InitShareMysPriceSetUp.ShareMysPriceSetUp:%v", common.ErrShareMys, err) + } + } + + time.Sleep(500 * time.Millisecond) + } +} + +// SubscribeMysHSetCodeList +// +// @Description: 同步列表缓存 +// @param symbolStr +// @param check +func SubscribeMysHSetCodeList(symbolStr string, check bool) { + var key string + if check { + key = setting.MarketShareBlkMys + } else { + key = setting.MarketShareMys + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + return + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeMysHSetCodeList.%v.HSet:%v", common.ErrShareMys, key, err) + return + } + } +} + +// SubscribeMysCloseNewPrice +// +// @Description: 获取行情价 +// @param symbolStr +func SubscribeMysCloseNewPrice(symbolStr string) { + // 获取市场真实开闭盘时间 + timeValue, checkWeekday := MarketCheckOpenAndCloseTime(flags.ShareMysMarketType) + // 判定是否盘中 + if utils.CheckInPlateTime(timeValue) && checkWeekday { + // 盘中实时价格 + realTimePrice, err := Reds.HGet(context.Background(), flags.ShareMalaysiaClosingNewPriceKey, symbolStr).Result() + if err != nil { + realTimePrice = decimal.Zero.String() + } + if realTimePrice != decimal.Zero.String() { + keys := publicData.SymbolCache(flags.Mys, symbolStr, flags.TradeTypePrice) + if err = memory.ShareMysCache.Set(keys, []byte(realTimePrice)); err != nil { + applogger.Error("%v SubscribeMysCloseNewPrice.ShareMysCache:%v", common.ErrShareMys, err) + } + } + } +} + +// SubscribeMysClosePrice +// +// @Description: 获取闭盘价 +// @param symbolStr +func SubscribeMysClosePrice(symbolStr string) { + var err error + var sub = decimal.Zero + var closeNewPrice, closingPrice, price string + + // 闭盘价格 + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareMalaysiaClosingNewPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareMalaysiaClosingPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice = decimal.Zero.String() + } + } + + // 市价(实时价格) + closingPrice, err = Reds.HGet(context.Background(), flags.ShareMalaysiaBeforeClose, symbolStr).Result() + if err != nil { + closingPrice = decimal.Zero.String() + } + + // 判定取值数据 + if closeNewPrice != decimal.Zero.String() { + price = closeNewPrice + } else { + price = closingPrice + } + closeKey := publicData.SymbolCache(flags.Mys, symbolStr, flags.TradeTypeClosePrice) + if err = memory.ShareMysClosePrice.Set(closeKey, []byte(price)); err != nil { + applogger.Error("%v ShareMysClosePrice.Set.price:%v", common.ErrShareMys, err) + } + + // 写入涨跌幅价格判定缓存 + cn := closeNewPrice != decimal.Zero.String() + cp := closingPrice != decimal.Zero.String() + lcn := utils.IsNumber(closeNewPrice) + lcp := utils.IsNumber(closingPrice) + if cn && cp && lcn && lcp { + sub = decimal.RequireFromString(closingPrice).Sub(decimal.RequireFromString(closeNewPrice)) + } + chgKey := publicData.SymbolCache(flags.Mys, symbolStr, flags.TradeTypeChg) // 涨跌幅标识Key + if err = memory.ShareMysChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v ShareMysChgMark.Set.price:%v", common.ErrShareMys, err) + } +} + +// OrderSubAdminShareMysSubscribeBySum +// +// @Description: 持仓订单浮动盈亏计算 +// @param ctx +// @param uo +func OrderSubAdminShareMysSubscribeBySum(uo *Data) { + for { + var topIc = setting.AdminShareMysSubscribe + hashMap, err := uo.redisDB.HGetAll(context.Background(), topIc).Result() + if err != nil { + applogger.Error("OrderSubAdminShareMysSubscribeBySum.HGetAll:%v", err) + time.Sleep(5 * time.Second) + continue + } + var hashList []share.ShareMysTallyCache + for _, value := range hashMap { + var msg share.ShareMysTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + switch msg.Status { + case flags.Entrust: // 挂单 + case flags.Position: // 持仓 + hashList = append(hashList, msg) + default: // 平仓|撤单 + err = uo.redisDB.HDel(context.Background(), topIc, msg.OrderId).Err() + if err != nil { + applogger.Error("AdminContractSubscribe.HDel:%v", err) + continue + } + } + } + applogger.Info("马股数据量统计:%v", len(hashList)) + + // 统计马股总持仓订单浮动盈亏 + priceSum := decimal.Zero + for _, value := range hashList { + orderModel := shareData.ShareMysOrderProcessing(topIc, value) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch value.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + price := subPrice.Mul(decimal.RequireFromString(value.Order.OrderNumber)) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + + // 写入缓存 + if err = memory.ShareMysFloating.Set(flags.FloatingMys, []byte(priceSum.String())); err != nil { + applogger.Error("统计马股持仓订单浮动盈亏错误:%v", err) + time.Sleep(5 * time.Second) + continue + } + applogger.Info("统计马股持仓订单浮动盈亏:%v", priceSum) + + time.Sleep(1 * time.Second) + } +} + +// SubscribeShareMys +// +// @Description: TODO: 马股订阅 +// @param ctx +// @param uo +// @param shareMys +func SubscribeShareMys(ctx context.Context, shareMys *ShareMysSymbol, check bool) { + for { + select { + case symbol, _ := <-shareMys.MysMap: + symbolStr := string(symbol) + topIc := fmt.Sprintf("%v.%v", symbolStr, flags.CountryMys) + // Handling duplicate subscriptions + _, ok := shareMys.MysMapSymbol.Load(symbolStr) + if ok { + time.Sleep(5 * time.Second) + continue + } + // Transaction determination + var key string + if check { + key = setting.MarketShareBlkMys // 大宗股交易 + } else { + key = setting.MarketShareMys // 马股交易 + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeShareMys.%v.HSet:%v", common.ErrShareMys, key, err) + time.Sleep(5 * time.Second) + continue + } + } + + // 处理订阅实时行情数据 + go func() { + symbolStrCache := symbolStr + pubSub := Reds.Subscribe(ctx, topIc) + defer pubSub.Close() + if _, err := pubSub.Receive(ctx); err != nil { + shareMys.MysMapSymbol.Delete(symbolStrCache) + return + } + ch := pubSub.Channel() + for { + select { + case msg, _ := <-ch: + var subMsg ShareMysMessage + if err := json.Unmarshal([]byte(msg.Payload), &subMsg); err != nil { + applogger.Error("%v SubscribeShareMys.Unmarshal:%v", common.ErrShareMys, err) + time.Sleep(5 * time.Second) + continue + } + SubscribeMysPrice(subMsg.Price.String(), symbolStr, flags.RealTime) + default: + Reds.Ping(ctx) // 如果没有消息,发送 PING 命令以维护连接 + time.Sleep(10 * time.Second) + } + } + }() + + // 盘前|盘后价格设置 + _, okc := shareMys.MysSetMapSymbol.Load(symbolStr) + if !okc { + go func() { + for { + keyCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareMysMarketType, symbolStr) + vw, err := GetBeforeAndAfterSetPrice(keyCache) + if err != nil || len(vw) == 0 { + priceCache := publicData.SymbolCache(flags.Mys, symbolStr, flags.TradeTypePrice) + memory.ShareMysPriceSetUp.Delete(priceCache) + time.Sleep(15 * time.Second) + continue + } + SubscribeMysPrice(vw, symbolStr, flags.SetUp) + time.Sleep(10 * time.Second) + } + }() + // Write cache to determine whether to repeatedly open the protocol + shareMys.MysSetMapSymbol.Store(symbolStr, symbolStr) + } + + // Write in the map to determine whether to repeat subscription + shareMys.MysMapSymbol.Store(symbolStr, symbolStr) + } + } +} + +// SubscribeMysPrice +// +// @Description: TODO: 订阅获取马股股实时价格或者[盘前|盘后]设置价格 +// @param setPrice +// @param symbolStr +// @param check +func SubscribeMysPrice(setPrice, symbolStr string, check int) { + var err error + var sub = decimal.Zero + + // 计算涨跌幅 + yClosingPrice, err := Reds.HGet(context.Background(), flags.ShareMalaysiaClosingPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice, err = Reds.HGet(context.Background(), flags.ShareMalaysiaClosingNewPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice = setPrice + } + } + + // 写入涨跌幅缓存数据 + yc := yClosingPrice != decimal.Zero.String() + sp := setPrice != decimal.Zero.String() + lyc := utils.IsNumber(yClosingPrice) + lsp := utils.IsNumber(setPrice) + if yc && sp && lyc && lsp { + sub = decimal.RequireFromString(setPrice).Sub(decimal.RequireFromString(yClosingPrice)) + } + chgKey := publicData.SymbolCache(flags.Mys, symbolStr, flags.TradeTypeChg) // 涨跌幅标识Key + if err = memory.ShareMysChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v SubscribeShareMys.ShareMysChgMark.Set.price:%v", common.ErrShareMys, err) + } + if !flags.CheckSetting { + applogger.Debug("涨跌幅交易对内存key:%v,涨跌幅数值:%v", symbolStr, sub) + } + + // 交易类型:0最新价,1买入,2卖出 + price := publicData.SymbolCache(flags.Mys, symbolStr, flags.TradeTypePrice) + switch check { + case flags.RealTime: // 实时价格(优先级高) + if err = memory.ShareMysCache.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeShareMys.ShareMysCache.Set.price:%v", common.ErrShareMys, err) + } + case flags.SetUp: // 设置[盘前|盘后]价格 + if err = memory.ShareMysPriceSetUp.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeShareMys.ShareMysPriceSetUp:%v", common.ErrShareMys, err) + } + } + if !flags.CheckSetting { + applogger.Debug("股票交易对内存Key:%v,最新价格:%v", price, setPrice) + } +} + +// SubscribeMysSetForcedClosure +// +// @Description: TODO: 处理马股强平阈值 +// @param symbolStr +func SubscribeMysSetForcedClosure(symbolStr string) { + flatRatio := GetCacheForcedClosure(flags.StockMGSystemSetUpKey, symbolStr) + chgKey := publicData.SymbolCache(flags.Mys, symbolStr, flags.TradeTypeForcedClosure) + if err := memory.ShareMysForcedClosure.Set(chgKey, []byte(flatRatio.String())); err != nil { + applogger.Error("%v SubscribeMysSetForcedClosure.StockMGSystemSetUpKey err:%v", common.ErrShareMys, err) + return + } +} + +// ShareMysTransactionEntrust +// +// @Description: 马股委托订单 +// @param ctx +func ShareMysTransactionEntrust(ctx context.Context) { + for { + ShareMysTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareMysTransactionCalculationEntrust +// +// @Description: 马股挂单缓存队列计算 +// @param ctx +func ShareMysTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 全局变量处理 + if CheckGlobalTread(flags.MysMarket) { + time.Sleep(5 * time.Second) + return + } + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareMysEntrust).Result() + if err != nil { + applogger.Error("%v ShareMysTransactionCalculationEntrust.HGetAll:%v", common.ErrShareMys, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareMysTallyCache, 1) + var entrust share.ShareMysTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareMysTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareMys, err) + continue + } + + // 股票实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareMysPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareMysTransactionCalculationEntrust.GetShareMysPrice:%v---%v", common.ErrShareMys, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + chg := GetShareChgMys(flags.MysMarket, entrust.Symbol) // 涨跌幅标识 + if share.CheckOrderMysByChg(setting.MarketShareMysEntrust, entrust, chg) { + //applogger.Warn("当前股票%v订单在挂单状态已达到涨跌幅上限.", entrust.Symbol) + continue + } + + wg.Add(1) + go func(value string) { + var resultMsg share.ShareMysTallyCache + switch entrust.Order.DealType { + case flags.DealTypeLimited: // 限价挂单 + resultMsg = ShareMysConcurrentComputingEntrustLimited(&entrust, newPrice, &wg) + case flags.DealTypeMarket: // 市价挂单(开盘即成交) + resultMsg = ShareMysConcurrentComputingEntrustMarket(&entrust, newPrice, &wg) + } + msg <- resultMsg // 通知管道异步处理订单操作 + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收马股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到马股持仓信息:%v", resultMsg) + } + + // 开盘逻辑 + if err = ShareMysLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareMysTransactionCalculationEntrust.ShareMysLiquidationEntrust:%v", common.ErrShareMys, err) + continue + } + + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v ShareMysTransactionCalculationEntrust.Marshal:%v", common.ErrShareMys, err) + continue + } + + // TODO: 写入持仓消息队列 + //if err = uo.mqProducer.Entrust.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareMysTransactionCalculationEntrust.PushNotice:%v", common.ShareMysError, err) + // continue + //} + + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareMysPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("马股挂单并发计算执行完毕......") +} + +// ShareMysConcurrentComputingEntrustLimited +// +// @Description: +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareMysTallyCache +func ShareMysConcurrentComputingEntrustLimited(order *share.ShareMysTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareMysTallyCache { + var deleteCache bool + var dealPrice string + var limitPrice = decimal.RequireFromString(order.Order.LimitPrice) // 限价-价格 + var status = order.Status // 原始价格 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价买入逻辑判定 -> 挂单金额 > 当前价格 + if limitPrice.Cmp(newPrice) > 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + } + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价卖入逻辑判定 -> 挂单金额 < 当前价格 + if limitPrice.Cmp(newPrice) < 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareMysEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareMysConcurrentComputingEntrustLimited.MarketShareMysEntrust.HDel:%v", common.ErrShareMys, err) + order.Status = status + } + } + + wg.Done() + return share.ShareMysTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareMysConcurrentComputingEntrustMarket +// +// @Description: 马股市价下单进入挂单队列(休市) +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareMysTallyCache +func ShareMysConcurrentComputingEntrustMarket(order *share.ShareMysTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareMysTallyCache { + var deleteCache bool + var dealPrice string + var marketPrice = decimal.RequireFromString(order.Order.MarketPrice) // 市价-价格 + var status = order.Status // 原始价格 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareMysEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareUsConcurrentComputingEntrustMarket.MarketShareMysEntrust.HDel:%v", common.ErrShareMys, err) + order.Status = status + } + } + + wg.Done() + return share.ShareMysTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareBlockMysConcurrentComputingEntrustMarket +// +// @Description: 大宗(马股)交易 +// @param order +// @param newPrice +// @param wg +// @return share.ShareMysTallyCache +func ShareBlockMysConcurrentComputingEntrustMarket(order *share.ShareMysTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareMysTallyCache { + var status = order.Status // 原始状态 + + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareBlkEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareBlockMysConcurrentComputingEntrustMarket.MarketShareBlkEntrust.HDel:%v", common.ErrShareBlk, err) + order.Status = status + } + + wg.Done() + return share.ShareMysTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: newPrice.String(), // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareMysMqOpenBusiness +// +// @Description: TODO: 马股持仓消息队列 +// @param ctx +// @param uo +func ShareMysMqOpenBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Entrust.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerEntrustMq.ShareMysMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareMysMqOpenBusiness.ShareMysMq err....", common.ErrShareMys) + continue + } + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareMysTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareMysMqOpenBusiness.Unmarshal:%v", common.ErrShareMys, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareMysLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareMysMqOpenBusiness.ShareMysLiquidationEntrust:%v", common.ErrShareMys, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + applogger.Info("这里没有监控到持仓mq队列消息.........") + time.Sleep(2 * time.Second) + } + } +} + +// ShareMysLiquidationEntrust +// +// @Description: 马股挂单-->开仓业务处理 +// @param ctx +// @param order +// @return error +func ShareMysLiquidationEntrust(ctx context.Context, order *share.ShareMysTallyCache) error { + // 1、开盘 + err := StockMysOpenOrder(ctx, Msql, order.UserId, order.OrderId, order.OpenPrice, order.Order) + if err != nil { + applogger.Error("%v ShareMysLiquidationEntrust.StockMysOpenOrder:%v", common.ErrShareMys, err) + return err + } + + // 大宗(马股)交易判定 + var entrustKey, adminKey string + if !CheckTypeStatus(order.Order.Type) { + entrustKey = setting.ShareMysSubscribe + adminKey = setting.AdminShareMysSubscribe + } else { + entrustKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // 2、更新用户订阅缓存列表订单状态 + updateKey := virtual.OrderIdListKey(entrustKey, order.UserId) + if err = UpdateShareMysSubscribeHashStatusByOrderId(order.OrderId, updateKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareMysLiquidationEntrust.%v:%v", common.ErrShareMys, entrustKey, err) + return err + } + + // 3、更新管理员订阅缓存列表订单状态 + if err = UpdateShareMysSubscribeHashStatusByOrderId(order.OrderId, adminKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareMysLiquidationEntrust.Entrust.%v:%v", common.ErrShareMys, adminKey, err) + return err + } + + return nil +} + +// ShareMysTransactionPosition +// +// @Description: 马股持仓订单 +// @param ctx +func ShareMysTransactionPosition(ctx context.Context) { + for { + ShareMysTransactionCalculationPosition(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareMysTransactionCalculationPosition +// +// @Description: 马股持仓缓存队列计算 +// @param ctx +func ShareMysTransactionCalculationPosition(ctx context.Context) { + var wg sync.WaitGroup + + // 判定是否交易 + if CheckGlobalTread(flags.MysMarket) { + time.Sleep(5 * time.Second) + return + } + + // TODO: 获取IPO未支付订单缓存 + userIdMap, _ := GetBotUserArrears(ctx) + + // 获取持仓缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareMysPosition).Result() + if err != nil { + applogger.Error("%v ShareMysTransactionCalculationPosition.HGetAll:%v", common.ErrShareMys, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareMysTallyCache, 1) + var entrust share.ShareMysTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareMysTransactionCalculationPosition.Unmarshal:%v", common.ErrShareMys, err) + continue + } + + // TODO: 判定是否未IPO未支付订单-不能平仓 + _, isOk := userIdMap[entrust.UserId] + if isOk { + continue + } + + // 处理时间 + if !CheckShareSystemTime(entrust.ClosingTime) { + applogger.Warn("马股:%v,平仓时间:%v暂未到达...", entrust.Symbol, entrust.ClosingTime) + continue + } + + // TODO: 实时获取强平阈值 + //entrust.Order.System.StrongFlatRatio = GetForcedClosureValue(flags.Mys, entrust.Symbol) + + // 股票实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareMysPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareMysTransactionCalculationPosition.Get:%v--%v", common.ErrShareMys, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + chg := GetShareChgMys(flags.Mys, entrust.Symbol) // 涨跌幅标识 + if share.CheckOrderMysByChg(setting.MarketShareMysEntrust, entrust, chg) { + //applogger.Warn("当前股票%v订单在挂单状态已达到涨跌幅上限.", entrust.Symbol) + continue + } + + // 判定配额强平 + checkFlattening := GetStrongFlatteningThreshold(entrust.UserId) + + wg.Add(1) + go func(value string) { + resultMsg := ShareMysConcurrentComputingPosition(&entrust, newPrice, &wg, checkFlattening) + msg <- resultMsg + }(value) + + // 处理并发结果 + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Position: // 持仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到马股持仓信息:%v", resultMsg) + } + case flags.Close: // 平仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到马股平仓信息:%v", resultMsg) + } + + // TODO: 平仓操作(优化写入队列中等待平仓) + //var byteStr []byte + //byteStr, err = json.Marshal(resultMsg) + //if err != nil { + // applogger.Error("%v ShareMysTransactionCalculationPosition.Marshal:%v", common.ShareMysError, err) + // continue + //} + //if err = uo.mqProducer.Position.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareMysTransactionCalculationPosition.PushNotice:%v", common.ShareMysError, err) + // continue + //} + + if err = ShareMysLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareMysTransactionCalculationPosition.ShareMysLiquidationPosition:%v", common.ErrShareMys, err) + continue + } + } + } + } + + wg.Wait() + applogger.Info("马股持仓并发计算执行完毕......") +} + +// ShareMysConcurrentComputingPosition +// +// @Description: 马股持仓缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareMysTallyCache +func ShareMysConcurrentComputingPosition(order *share.ShareMysTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup, checkFlattening bool) share.ShareMysTallyCache { + var deleteCache, checkBool bool + var dealPrice string + var sellShort decimal.Decimal + var openPrice = decimal.RequireFromString(order.OpenPrice) // 限价 + var orderNumber = decimal.RequireFromString(order.Order.OrderNumber) // 仓位 + + var pryNum decimal.Decimal + lenPryNum := len(utils.ReplaceStr(order.Order.PryNum)) == 0 + if lenPryNum || order.Order.PryNum == flags.SetZero || order.Order.System.UserStatus != flags.SetThree || !utils.IsNumberInt(order.Order.PryNum) { + pryNum = decimal.RequireFromString(flags.SetOne) + } else { + pryNum = decimal.RequireFromString(order.Order.PryNum) + } + + // 下单判定设置(false无设置|true止盈止损) + _, stopWinPrice, stopLossPrice, _ := StockMysVoteStopType(order.Order) + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨(强平) + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,持仓开仓价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买涨:挂止损止盈,止盈价必须<当前价,止损价必须>当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + // 强行平仓(做多) + if !checkBool { + sellShort = newPrice.Sub(openPrice).Mul(orderNumber) + } + case flags.TradeTypeSell: // 买跌(存在强行平仓) + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价持仓买跌下单价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买跌:挂止损止盈,止盈价必须>当前价,止损价必须<当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + // 强行平仓(做空) + if !checkBool { + sellShort = openPrice.Sub(newPrice).Mul(orderNumber) + } + } + /* 强行平仓(做多|做空) + 1、做多:(最新成交价-开仓成交价)*仓位 + 2、做空:(开仓成交价-最新成交价)*仓位 + 3、当浮动盈亏 >= 保证金的70%订单强行平仓 + */ + if sellShort.IsNegative() && checkFlattening { + orderAmount := newPrice.Mul(decimal.RequireFromString(order.Order.OrderNumber)).Div(pryNum) // 保证金 = 当前价格 * 订单数量 / 杠杆 + floatPrice := orderAmount.Mul(decimal.RequireFromString(order.Order.System.StrongFlatRatio)) + if !flags.CheckSetting { + applogger.Debug("强平保证金:%v,强平浮动70:%v,强行平仓判定:%v", orderAmount, floatPrice, sellShort.Abs().Cmp(floatPrice)) + } + + if sellShort.Abs().Cmp(floatPrice) >= 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + switch order.Order.TradeType { + case flags.TradeTypeBuy: //买涨 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + case flags.TradeTypeSell: // 买跌 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + } + // 判定交易状态 + if checkBool { + deleteCache = true + order.Status = flags.Close + } + if deleteCache { + // 根据订单ID-删除持仓列表缓存订单 + if err := Reds.HDel(context.Background(), setting.MarketShareMysPosition, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareMysConcurrentComputingPosition.MarketShareMysPosition.HDel:%v", common.ErrShareMys, err) + } + } + + wg.Done() + return share.ShareMysTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + ClosingPrice: dealPrice, // 平仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareMysMqClosingBusiness +// +// @Description: TODO: 处理马股平仓消息队列 +// @param ctx +// @param uo +func ShareMysMqClosingBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Position.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerPositionMq.ShareMysMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareMysMqClosingBusiness.ShareMysMq err....", common.ErrShareMys) + continue + } + applogger.Info("接收到平仓信息:%v", string(message)) + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareMysTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareMysMqClosingBusiness.Unmarshal:%v", common.ErrShareMys, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareMysLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareMysMqClosingBusiness.ShareMysLiquidationPosition:%v", common.ErrShareMys, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + time.Sleep(2 * time.Second) + } + } +} + +// ShareMysLiquidationPosition +// +// @Description: 马股持仓-->平仓业务处理 +// @param ctx +// @param order +// @return error +func ShareMysLiquidationPosition(ctx context.Context, order *share.ShareMysTallyCache) error { + // 1、平仓操作 + err := StockMysClosingOrder(ctx, Msql, order.OrderId, order.ClosingPrice, order.Order) + if err != nil { + applogger.Error("%v ShareMysLiquidationPosition.StockMysClosingOrder:%v", common.ErrShareMys, err) + return err + } + + // 2、平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareMysSubscribe, order.UserId) + if err = UpdateShareMysSubscribeHashStatusByOrderId(order.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v ShareMysLiquidationPosition.Position.ShareMysSubscribe:%v", common.ErrShareMys, err) + return err + } + + // 3、平仓更新管理员订阅订单状态 + if err = UpdateShareMysSubscribeHashStatusByOrderId(order.OrderId, setting.AdminShareMysSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v ShareMysLiquidationPosition.Position.AdminShareMysSubscribe:%v", common.ErrShareMys, err) + return err + } + + return nil +} + +// StockMysVoteStopType +// +// @Description: 马股判定取值止损止盈 +// @param order +// @return bool +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func StockMysVoteStopType(order structure.ShareOrder) (bool, decimal.Decimal, decimal.Decimal, error) { + var checkBool bool + var stopWinPrice, stopLossPrice decimal.Decimal + switch order.StopType { + case flags.StopTypeNone: // 暂无设置止盈止损 + checkBool = false + case flags.StopTypeSet: // 设置止盈止损 + checkBool = true + stopWinPrice, _ = decimal.NewFromString(order.StopWinPrice) + stopLossPrice, _ = decimal.NewFromString(order.StopLossPrice) + default: + return checkBool, stopWinPrice, stopLossPrice, flags.ErrContractThirteen + } + + return checkBool, stopWinPrice, stopLossPrice, nil +} + +// GetShareMysPrice +// +// @Description: 查询马股股票价格 +// @param symbol +// @return decimal.Decimal +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func GetShareMysPrice(symbol string) (decimal.Decimal, error) { + var err error + var priceByte []byte + var newPrice decimal.Decimal + + key := publicData.SymbolCache(flags.Mys, symbol, flags.TradeTypePrice) + priceByte, err = memory.GetShareMysCache(key) + if err != nil { + return decimal.Decimal{}, err + } + + newPrice, err = decimal.NewFromString(string(priceByte)) + if err != nil { + return decimal.Decimal{}, err + } + + applogger.Info("shareMysCode:%v,topIc:%v,shareMysPrice:%v", symbol, key, newPrice) + + return newPrice, nil +} diff --git a/internal/data/subscribe_share_sgd.go b/internal/data/subscribe_share_sgd.go new file mode 100644 index 0000000..c04fcf3 --- /dev/null +++ b/internal/data/subscribe_share_sgd.go @@ -0,0 +1,1249 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/mq/consumer" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/socket/shareData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "sync" + "time" +) + +/* +新加坡股行情订阅 +1、接收用户新加坡股下单的交易对新加坡股行情 +2、将订阅行情写入内存中用于并发计算 +3、挂单(市价|限价)缓存队列处理-开仓 +4、持仓缓存队列处理-平仓 +*/ + +// ShareSgdMessage +// @Description: +type ShareSgdMessage struct { + Symbol string `json:"symbol,omitempty"` // 交易所:股票代码 + StockCode string `json:"stock_code,omitempty"` // 股票代码 + StockName string `json:"stock_name,omitempty"` // 股票名,可能为空 + Price decimal.Decimal `json:"price,omitempty"` // 实时价格 + UpDownRate decimal.Decimal `json:"up_down_rate,omitempty"` // 涨跌% + UpDown decimal.Decimal `json:"up_down,omitempty"` // 涨跌额 + TradeV decimal.Decimal `json:"trade_v,omitempty"` // 技术评级指标值 + TradeK string `json:"trade_k,omitempty"` // 技术评级 + Vol int64 `json:"vol,omitempty"` // 成交量 + TurnoverPriceTotal decimal.Decimal `json:"turnover_price_total,omitempty"` // 成交量*价格 + PriceTotal string `json:"price_total,omitempty"` // 总市值 + PE string `json:"p_e,omitempty"` // pe + Eps string `json:"eps,omitempty"` // EPS + EmployeesNumber string `json:"employees_number,omitempty"` // 雇员 + Plate string `json:"plate,omitempty"` // 板块 + Desc string `json:"desc,omitempty"` // 描述 + PriceCode string `json:"price_code,omitempty"` // 价格类型 + Country string `json:"country,omitempty"` // 国家 + Ts int64 `json:"ts,omitempty"` // 时间 + Token string `json:"token,omitempty"` // Token 令牌 +} + +// ShareSgdSymbol +// @Description: +type ShareSgdSymbol struct { + SgdMap chan []byte // 订单交易对 -- 用户下单通知订阅 + SgdSetMap chan []byte // 订单交易对 -- 用户盘前|盘后行情订阅 + SgdMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 + SgdSetMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 +} + +// InitCacheSymbolShareSgd +// +// @Description: +// @param ctx +// @param uo +func InitCacheSymbolShareSgd(ctx context.Context, uo *Data) { + for { + SgdList, err := GetBotStockSgdListByStockId(ctx, uo) + if err != nil { + return + } + + for _, value := range SgdList { + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := uo.redisDB.HExists(context.Background(), setting.MarketShareSgd, value).Result() + if err != nil { + applogger.Error("%v InitCacheSymbolShareSgd.MarketShareSgd.HExists:%v", common.ErrShareSgd, err) + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err = uo.redisDB.HSet(context.Background(), setting.MarketShareSgd, value, value).Err(); err != nil { + applogger.Error("%v InitCacheSymbolShareSgd.MarketShareSgd.HSet:%v", common.ErrShareSgd, err) + time.Sleep(5 * time.Second) + continue + } + } + if !flags.CheckSetting { + applogger.Info("初始化新加坡股票代码:%v", value) + } + } + + time.Sleep(10 * time.Second) + } +} + +// InitSubscribeShareSgd +// +// @Description: 状态机加载订阅 +// @param ctx +// @param uo +// @param shareSgd +func InitSubscribeShareSgd(shareSgd *ShareSgdSymbol, check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkSgd + } else { + key = setting.MarketShareSgd + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareSgd.LoadLRangeList:%v", common.ErrShareSgd, err) + return + } + + for _, value := range listSpots { + // Handling duplicate subscriptions + _, ok := shareSgd.SgdMapSymbol.Load(value) + if ok { + continue + } + + shareSgd.SgdMap <- []byte(value) + } + + time.Sleep(10 * time.Second) + } +} + +// InitShareSgdCloseCachePrice +// +// @Description: +// @param shareSgd +// @param check +func InitShareSgdCloseCachePrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkSgd + } else { + key = setting.MarketShareSgd + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareSgd.LoadLRangeList:%v", common.ErrShareSgd, err) + return + } + + for _, value := range listSpots { + SubscribeSgdClosePrice(value) // 处理闭盘取价 + } + + time.Sleep(20 * time.Second) + } +} + +// InitShareSgdCloseNewPrice +// +// @Description: 同步实时行情 +// @param check +func InitShareSgdCloseNewPrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkSgd + } else { + key = setting.MarketShareSgd + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareSgdCloseNewPrice.LoadLRangeList:%v", common.ErrShareSgd, err) + return + } + for _, value := range listSpots { + SubscribeSgdCloseNewPrice(value) + } + + time.Sleep(500 * time.Millisecond) + } +} + +// InitShareSgdPriceSetUp +// +// @Description: 同步插针行情 +// @param check +func InitShareSgdPriceSetUp(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkSgd + } else { + key = setting.MarketShareSgd + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareSgdPriceSetUp.LoadLRangeList:%v", common.ErrShareSgd, err) + time.Sleep(20 * time.Second) + continue + } + + for _, value := range listSpots { + sgdKey := publicData.SymbolCache(flags.Sgd, value, flags.TradeTypePrice) + sgdSetCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareSgdMarketType, value) + vw, err := GetBeforeAndAfterSetPrice(sgdSetCache) + if err != nil || len(vw) == 0 { + _ = memory.ShareSgdPriceSetUp.Delete(sgdKey) + continue + } + if err = memory.ShareSgdPriceSetUp.Set(sgdKey, []byte(vw)); err != nil { + applogger.Error("%v InitShareSgdPriceSetUp.ShareSgdPriceSetUp:%v", common.ErrShareSgd, err) + } + } + + time.Sleep(500 * time.Millisecond) + } +} + +// SubscribeSgdHSetCodeList +// +// @Description: 同步列表缓存 +// @param symbolStr +// @param check +func SubscribeSgdHSetCodeList(symbolStr string, check bool) { + var key string + if check { + key = setting.MarketShareBlkSgd + } else { + key = setting.MarketShareSgd + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + return + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeSgbHSetCodeList.%v.HSet:%v", common.ErrShareSgd, key, err) + return + } + } +} + +// SubscribeSgdCloseNewPrice +// +// @Description: 获取行情价 +// @param symbolStr +func SubscribeSgdCloseNewPrice(symbolStr string) { + // 获取市场真实开闭盘时间 + timeValue, checkWeekday := MarketCheckOpenAndCloseTime(flags.ShareSgdMarketType) + // 判定是否盘中 + if utils.CheckInPlateTime(timeValue) && checkWeekday { + // 盘中实时价格 + realTimePrice, err := Reds.HGet(context.Background(), flags.ShareSingaporeClosingNewPriceKey, symbolStr).Result() + if err != nil { + realTimePrice = decimal.Zero.String() + } + if realTimePrice != decimal.Zero.String() { + keys := publicData.SymbolCache(flags.Sgd, symbolStr, flags.TradeTypePrice) + if err = memory.ShareSgdCache.Set(keys, []byte(realTimePrice)); err != nil { + applogger.Error("%v SubscribeSgbCloseNewPrice.ShareSgdCache:%v", common.ErrShareSgd, err) + } + } + } +} + +// SubscribeSgdClosePrice +// +// @Description: 获取闭盘价 +// @param symbolStr +func SubscribeSgdClosePrice(symbolStr string) { + var err error + var sub = decimal.Zero + var closeNewPrice, closingPrice, price string + + // 闭盘价格 + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareSingaporeClosingNewPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareSingaporeClosingPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice = decimal.Zero.String() + } + } + + // 市价(实时价格) + closingPrice, err = Reds.HGet(context.Background(), flags.ShareSingaporeBeforeClose, symbolStr).Result() + if err != nil { + closingPrice = decimal.Zero.String() + } + + // 判定取值数据 + if closeNewPrice != decimal.Zero.String() { + price = closeNewPrice + } else { + price = closingPrice + } + closeKey := publicData.SymbolCache(flags.Sgd, symbolStr, flags.TradeTypeClosePrice) + if err = memory.ShareSgdClosePrice.Set(closeKey, []byte(price)); err != nil { + applogger.Error("%v ShareSgdClosePrice.Set.price:%v", common.ErrShareSgd, err) + } + + // 写入涨跌幅价格判定缓存(计算涨跌幅 = 最新价格 - 闭盘价格(昨天关闭价格或者上次毕盘价格)) + cn := closeNewPrice != decimal.Zero.String() + cp := closingPrice != decimal.Zero.String() + lcn := utils.IsNumber(closeNewPrice) + lcp := utils.IsNumber(closingPrice) + if cn && cp && lcn && lcp { + sub = decimal.RequireFromString(closingPrice).Sub(decimal.RequireFromString(closeNewPrice)) + } + chgKey := publicData.SymbolCache(flags.Sgd, symbolStr, flags.TradeTypeChg) // 涨跌幅标识Key + if err = memory.ShareSgdChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v ShareSgdChgMark.Set.price:%v", common.ErrShareSgd, err) + } +} + +// OrderSubAdminShareSgdSubscribeBySum +// +// @Description: 持仓订单浮动盈亏计算 +// @param ctx +// @param uo +func OrderSubAdminShareSgdSubscribeBySum(uo *Data) { + for { + var topIc = setting.AdminShareSgdSubscribe + hashMap, err := uo.redisDB.HGetAll(context.Background(), topIc).Result() + if err != nil { + applogger.Error("OrderSubAdminShareSgdSubscribeBySum.HGetAll:%v", err) + time.Sleep(5 * time.Second) + continue + } + var hashList []share.ShareSgdTallyCache + for _, value := range hashMap { + var msg share.ShareSgdTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + switch msg.Status { + case flags.Entrust: // 挂单 + case flags.Position: // 持仓 + hashList = append(hashList, msg) + default: // 平仓|撤单 + err = uo.redisDB.HDel(context.Background(), topIc, msg.OrderId).Err() + if err != nil { + applogger.Error("OrderSubAdminShareSgdSubscribeBySum.HDel:%v", err) + continue + } + } + } + applogger.Info("新加坡股数据量统计:%v", len(hashList)) + // 统计泰股总持仓订单浮动盈亏 + priceSum := decimal.Zero + for _, value := range hashList { + orderModel := shareData.ShareSgdOrderProcessing(topIc, value) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch value.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + price := subPrice.Mul(decimal.RequireFromString(value.Order.OrderNumber)) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + + // 写入缓存 + if err = memory.ShareSgdFloating.Set(flags.FloatingSgd, []byte(priceSum.String())); err != nil { + applogger.Error("统计新加坡股持仓订单浮动盈亏错误:%v", err) + time.Sleep(5 * time.Second) + continue + } + applogger.Info("统计新加坡股持仓订单浮动盈亏:%v", priceSum) + + time.Sleep(1 * time.Second) + } +} + +// SubscribeShareSgd +// +// @Description: TODO: 新加坡订阅 +// @param ctx +// @param uo +// @param shareSgd +func SubscribeShareSgd(ctx context.Context, shareSgd *ShareSgdSymbol, check bool) { + for { + select { + case symbol, _ := <-shareSgd.SgdMap: + symbolStr := string(symbol) + topIc := fmt.Sprintf("%v.%v", symbolStr, flags.CountrySgd) + // Handling duplicate subscriptions + _, ok := shareSgd.SgdMapSymbol.Load(symbolStr) + if ok { + time.Sleep(5 * time.Second) + continue + } + // Transaction determination + var key string + if check { + key = setting.MarketShareBlkSgd // 大宗股交易 + } else { + key = setting.MarketShareSgd // 新加坡股交易 + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeShareSgd.%v.HSet:%v", common.ErrShareSgd, key, err) + time.Sleep(5 * time.Second) + continue + } + } + + // 处理订阅实时行情数据 + go func() { + symbolStrCache := symbolStr + pubSub := Reds.Subscribe(ctx, topIc) + defer pubSub.Close() + if _, err := pubSub.Receive(ctx); err != nil { + shareSgd.SgdMapSymbol.Delete(symbolStrCache) + return + } + ch := pubSub.Channel() + for { + select { + case msg, _ := <-ch: + var subMsg ShareSgdMessage + if err := json.Unmarshal([]byte(msg.Payload), &subMsg); err != nil { + applogger.Error("%v SubscribeShareSgd.Unmarshal:%v", common.ErrShareSgd, err) + time.Sleep(5 * time.Second) + continue + } + SubscribeSgdPrice(subMsg.Price.String(), symbolStr, flags.RealTime) + default: + Reds.Ping(ctx) // 如果没有消息,发送 PING 命令以维护连接 + time.Sleep(10 * time.Second) + } + } + }() + + // 盘前|盘后价格设置 + _, okc := shareSgd.SgdSetMapSymbol.Load(symbolStr) + if !okc { + go func() { + for { + keyCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareSgdMarketType, symbolStr) + vw, err := GetBeforeAndAfterSetPrice(keyCache) + if err != nil || len(vw) == 0 { + priceCache := publicData.SymbolCache(flags.Sgd, symbolStr, flags.TradeTypePrice) + memory.ShareSgdPriceSetUp.Delete(priceCache) + time.Sleep(15 * time.Second) + continue + } + SubscribeSgdPrice(vw, symbolStr, flags.SetUp) + time.Sleep(10 * time.Second) + } + }() + // Write cache to determine whether to repeatedly open the protocol + shareSgd.SgdSetMapSymbol.Store(symbolStr, symbolStr) + } + + // Write in the map to determine whether to repeat subscription + shareSgd.SgdMapSymbol.Store(symbolStr, symbolStr) + } + } +} + +// SubscribeSgdPrice +// +// @Description: TODO: 订阅获取新加坡股股实时价格或者[盘前|盘后]设置价格 +// @param setPrice +// @param symbolStr +// @param check +func SubscribeSgdPrice(setPrice, symbolStr string, check int) { + var err error + var sub = decimal.Zero + + // 计算涨跌幅 + yClosingPrice, err := Reds.HGet(context.Background(), flags.ShareSingaporeClosingPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice, err = Reds.HGet(context.Background(), flags.ShareSingaporeClosingNewPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice = setPrice + sub = decimal.Zero + } + } + + // 写入涨跌幅缓存数据 + yc := yClosingPrice != decimal.Zero.String() + sp := setPrice != decimal.Zero.String() + lyc := utils.IsNumber(yClosingPrice) + lsp := utils.IsNumber(setPrice) + if yc && sp && lyc && lsp { + sub = decimal.RequireFromString(setPrice).Sub(decimal.RequireFromString(yClosingPrice)) + } + chgKey := publicData.SymbolCache(flags.Sgd, symbolStr, flags.TradeTypeChg) + if err = memory.ShareSgdChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v SubscribeSgdPrice.ShareSgdChgMark.Set.price:%v", common.ErrShareSgd, err) + } + if !flags.CheckSetting { + applogger.Debug("涨跌幅交易对内存key:%v,涨跌幅数值:%v", symbolStr, sub) + } + + // 交易类型:0最新价,1买入,2卖出 + price := publicData.SymbolCache(flags.Sgd, symbolStr, flags.TradeTypePrice) + switch check { + case flags.RealTime: // 实时价格(优先级高) + if err = memory.ShareSgdCache.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeSgdPrice.ShareSgdCache.Set.price:%v", common.ErrShareSgd, err) + } + case flags.SetUp: // 设置[盘前|盘后]价格 + if err = memory.ShareSgdPriceSetUp.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeSgdPrice.ShareSgdPriceSetUp:%v", common.ErrShareSgd, err) + } + } + if !flags.CheckSetting { + applogger.Debug("股票交易对内存Key:%v,最新价格:%v", price, setPrice) + } +} + +// SubscribeSgdSetForcedClosure +// +// @Description: TODO: 处理新加坡股强平阈值 +// @param symbolStr +func SubscribeSgdSetForcedClosure(symbolStr string) { + flatRatio := GetCacheForcedClosure(flags.StockSGDSystemSetUpKey, symbolStr) + chgKey := publicData.SymbolCache(flags.Sgd, symbolStr, flags.TradeTypeForcedClosure) + if err := memory.ShareSgdForcedClosure.Set(chgKey, []byte(flatRatio.String())); err != nil { + applogger.Error("%v SubscribeSgdSetForcedClosure.ShareSgdForcedClosure err:%v", common.ErrShareSgd, err) + return + } +} + +// ShareSgdTransactionEntrust +// +// @Description: 新加坡股委托订单 +// @param ctx +func ShareSgdTransactionEntrust(ctx context.Context) { + for { + ShareSgdTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareSgdTransactionCalculationEntrust +// +// @Description: 新加坡股挂单缓存队列计算 +// @param ctx +func ShareSgdTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 全局变量处理 + if CheckGlobalTread(flags.SgdMarket) { + time.Sleep(5 * time.Second) + return + } + + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareSgdEntrust).Result() + if err != nil { + applogger.Error("%v ShareSgdTransactionCalculationEntrust.HGetAll:%v", common.ErrShareSgd, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareSgdTallyCache, 1) + var entrust share.ShareSgdTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareSgdTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareSgd, err) + continue + } + + // 股票实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareSgdPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareSgdTransactionCalculationEntrust.GetShareSgdPrice:%v---%v", common.ErrShareSgd, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + chg := GetShareChgSgd(flags.Sgd, entrust.Symbol) // 涨跌幅标识 + if share.CheckOrderSgdByChg(setting.MarketShareSgdEntrust, entrust, chg) { + //applogger.Warn("当前股票%v订单在挂单状态已达到涨跌幅上限.", entrust.Symbol) + continue + } + + wg.Add(1) + go func(value string) { + var resultMsg share.ShareSgdTallyCache + switch entrust.Order.DealType { + case flags.DealTypeLimited: // 限价挂单 + resultMsg = ShareSgdConcurrentComputingEntrustLimited(&entrust, newPrice, &wg) + case flags.DealTypeMarket: // 市价挂单(开盘即成交) + resultMsg = ShareSgdConcurrentComputingEntrustMarket(&entrust, newPrice, &wg) + } + msg <- resultMsg // 通知管道异步处理订单操作 + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收新加坡股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到新加坡股持仓信息:%v", resultMsg) + } + + // 开盘逻辑 + if err = ShareSgdLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Warn("%v ShareSgdTransactionCalculationEntrust.ShareSgdLiquidationEntrust:%v", common.ErrShareSgd, err) + continue + } + + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Warn("%v ShareSgdTransactionCalculationEntrust.Marshal:%v", common.ErrShareSgd, err) + continue + } + + // TODO: 写入持仓消息队列 + //if err = uo.mqProducer.Entrust.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareSgdTransactionCalculationEntrust.PushNotice:%v", common.ShareSgdError, err) + // continue + //} + + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareSgdPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("新加坡股挂单并发计算执行完毕......") +} + +// ShareSgdConcurrentComputingEntrustLimited +// +// @Description: 新加坡股挂单(限价|市价)缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareSgdTallyCache +func ShareSgdConcurrentComputingEntrustLimited(order *share.ShareSgdTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareSgdTallyCache { + var deleteCache bool + var dealPrice string + var limitPrice = decimal.RequireFromString(order.Order.LimitPrice) // 限价-价格 + var status = order.Status // 原始价格 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价买入逻辑判定 -> 挂单金额 > 当前价格 + if limitPrice.Cmp(newPrice) > 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + } + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价卖入逻辑判定 -> 挂单金额 < 当前价格 + if limitPrice.Cmp(newPrice) < 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareSgdEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareSgdConcurrentComputingEntrustLimited.MarketShareSgdEntrust.HDel:%v", common.ErrShareSgd, err) + order.Status = status + } + } + + wg.Done() + return share.ShareSgdTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareSgdConcurrentComputingEntrustMarket +// +// @Description: 新加坡股市价下单进入挂单队列(休市) +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareSgdTallyCache +func ShareSgdConcurrentComputingEntrustMarket(order *share.ShareSgdTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareSgdTallyCache { + var deleteCache bool + var dealPrice string + var marketPrice = decimal.RequireFromString(order.Order.MarketPrice) // 市价-价格 + var status = order.Status // 原始价格记录 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareSgdEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareSgdConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareSgd, err) + order.Status = status + } + } + + wg.Done() + return share.ShareSgdTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareBlockSgdConcurrentComputingEntrustMarket +// +// @Description: 大宗(新加坡股)交易 +// @param order +// @param newPrice +// @param wg +// @return share.ShareSgdTallyCache +func ShareBlockSgdConcurrentComputingEntrustMarket(order *share.ShareSgdTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareSgdTallyCache { + var status = order.Status // 原始状态 + + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareBlkEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareBlockSgdConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareBlk, err) + order.Status = status + } + + wg.Done() + return share.ShareSgdTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: newPrice.String(), // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareSgdMqOpenBusiness +// +// @Description: TODO: 新加坡股持仓消息队列 +// @param ctx +// @param uo +func ShareSgdMqOpenBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Entrust.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerEntrustMq.ShareSgdMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareSgdMqOpenBusiness.ShareSgdMq err....", common.ErrShareSgd) + continue + } + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareSgdTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareSgdMqOpenBusiness.Unmarshal:%v", common.ErrShareSgd, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareSgdLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareSgdMqOpenBusiness.ShareSgdLiquidationEntrust:%v", common.ErrShareSgd, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + applogger.Info("这里没有监控到持仓mq队列消息.........") + time.Sleep(2 * time.Second) + } + } +} + +// ShareSgdLiquidationEntrust +// +// @Description: 新加坡股挂单-->开仓业务处理 +// @param ctx +// @param order +// @return error +func ShareSgdLiquidationEntrust(ctx context.Context, order *share.ShareSgdTallyCache) error { + // 1、开盘 + err := StockSgdOpenOrder(ctx, Msql, order.UserId, order.OrderId, order.OpenPrice, order.Order) + if err != nil { + applogger.Error("%v ShareSgdLiquidationEntrust.StockSgdOpenOrder:%v", common.ErrShareSgd, err) + return err + } + + // 大宗(新加坡股)交易判定 + var entrustKey, adminKey string + if !CheckTypeStatus(order.Order.Type) { + entrustKey = setting.ShareSgdSubscribe + adminKey = setting.AdminShareSgdSubscribe + } else { + entrustKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // 2、更新用户订阅缓存列表订单状态 + updateKey := virtual.OrderIdListKey(entrustKey, order.UserId) + if err = UpdateShareSgdSubscribeHashStatusByOrderId(order.OrderId, updateKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareSgdLiquidationEntrust.Entrust.%v:%v", common.ErrShareSgd, entrustKey, err) + return err + } + + // 3、更新管理员订阅缓存列表订单状态 + if err = UpdateShareSgdSubscribeHashStatusByOrderId(order.OrderId, adminKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareSgdLiquidationEntrust.Entrust.%v:%v", common.ErrShareSgd, adminKey, err) + return err + } + + return nil +} + +// ShareSgdTransactionPosition +// +// @Description: 新加坡股持仓订单 +// @param ctx +func ShareSgdTransactionPosition(ctx context.Context) { + for { + ShareSgdTransactionCalculationPosition(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareSgdTransactionCalculationPosition +// +// @Description: 新加坡股持仓缓存队列计算 +// @param ctx +func ShareSgdTransactionCalculationPosition(ctx context.Context) { + var wg sync.WaitGroup + + // 判定是否交易 + if CheckGlobalTread(flags.SgdMarket) { + time.Sleep(5 * time.Second) + return + } + + // TODO: 获取IPO未支付订单缓存 + userIdMap, _ := GetBotUserArrears(ctx) + + // 获取持仓缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareSgdPosition).Result() + if err != nil { + applogger.Error("%v ShareSgdTransactionCalculationPosition.HGetAll:%v", common.ErrShareSgd, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareSgdTallyCache, 1) + var entrust share.ShareSgdTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareSgdTransactionCalculationPosition.Unmarshal:%v", common.ErrShareSgd, err) + continue + } + + // TODO: 判定是否未IPO未支付订单-不能平仓 + _, isOk := userIdMap[entrust.UserId] + if isOk { + continue + } + + // 处理时间 + if !CheckShareSystemTime(entrust.ClosingTime) { + applogger.Debug("新加坡股:%v,平仓时间:%v暂未到达...", entrust.Symbol, entrust.ClosingTime) + continue + } + + // TODO: 实时获取强平阈值 + //entrust.Order.System.StrongFlatRatio = GetForcedClosureValue(flags.Sgd, entrust.Symbol) + + // 股票实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareSgdPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareSgdTransactionCalculationPosition.GetShareSgdPrice:%v--%v", common.ErrShareSgd, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + chg := GetShareChgSgd(flags.Sgd, entrust.Symbol) // 涨跌幅标识 + if share.CheckOrderSgdByChg(setting.MarketShareSgdEntrust, entrust, chg) { + continue + } + + // 判定配额强平 + checkFlattening := GetStrongFlatteningThreshold(entrust.UserId) + + wg.Add(1) + go func(value string) { + resultMsg := ShareSgdConcurrentComputingPosition(&entrust, newPrice, &wg, checkFlattening) + msg <- resultMsg + }(value) + + // 处理并发结果 + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Position: // 持仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到新加坡股持仓信息:%v", resultMsg) + } + case flags.Close: // 平仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到新加坡股平仓信息:%v", resultMsg) + } + + // TODO: 平仓操作(优化写入队列中等待平仓) + //var byteStr []byte + //byteStr, err = json.Marshal(resultMsg) + //if err != nil { + // applogger.Error("%v ShareSgdTransactionCalculationPosition.Marshal:%v", common.ShareSgdError, err) + // continue + //} + //if err = uo.mqProducer.Position.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareSgdTransactionCalculationPosition.PushNotice:%v", common.ShareSgdError, err) + // continue + //} + + // 平仓操作 + if err = ShareSgdLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareSgdTransactionCalculationPosition.ShareSgdLiquidationPosition:%v", common.ErrShareSgd, err) + continue + } + } + } + } + + wg.Wait() + applogger.Info("新加坡股持仓并发计算执行完毕......") +} + +// ShareSgdConcurrentComputingPosition +// +// @Description: 新加坡股持仓缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareSgdTallyCache +func ShareSgdConcurrentComputingPosition(order *share.ShareSgdTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup, checkFlattening bool) share.ShareSgdTallyCache { + var deleteCache, checkBool bool + var dealPrice string + var sellShort decimal.Decimal + var openPrice = decimal.RequireFromString(order.OpenPrice) // 限价 + var orderNumber = decimal.RequireFromString(order.Order.OrderNumber) // 仓位 + + var pryNum decimal.Decimal + lenPryNum := len(utils.ReplaceStr(order.Order.PryNum)) == 0 + if lenPryNum || order.Order.PryNum == flags.SetZero || order.Order.System.UserStatus != flags.SetThree || !utils.IsNumberInt(order.Order.PryNum) { + pryNum = decimal.RequireFromString(flags.SetOne) + } else { + pryNum = decimal.RequireFromString(order.Order.PryNum) + } + + // 下单判定设置(false无设置|true止盈止损) + _, stopWinPrice, stopLossPrice, _ := StockSgdVoteStopType(order.Order) + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨(强平) + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,持仓开仓价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买涨:挂止损止盈,止盈价必须<当前价,止损价必须>当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + // 强行平仓(做多) + if !checkBool { + sellShort = newPrice.Sub(openPrice).Mul(orderNumber) + } + case flags.TradeTypeSell: // 买跌(存在强行平仓) + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价持仓买跌下单价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买跌:挂止损止盈,止盈价必须>当前价,止损价必须<当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + // 强行平仓(做空) + if !checkBool { + sellShort = openPrice.Sub(newPrice).Mul(orderNumber) + } + } + /* 强行平仓(做多|做空) + 1、做多:(最新成交价-开仓成交价)*仓位 + 2、做空:(开仓成交价-最新成交价)*仓位 + 3、当浮动盈亏 >= 保证金的70%订单强行平仓 + */ + if sellShort.IsNegative() && checkFlattening { + orderAmount := newPrice.Mul(decimal.RequireFromString(order.Order.OrderNumber)).Div(pryNum) // 订单金额 = 当前价格 * 订单数量 / 杠杆 + floatPrice := orderAmount.Mul(decimal.RequireFromString(order.Order.System.StrongFlatRatio)) + if !flags.CheckSetting { + applogger.Debug("强平保证金:%v,强平浮动70:%v,强行平仓判定:%v", orderAmount, floatPrice, sellShort.Abs().Cmp(floatPrice)) + } + + if sellShort.Abs().Cmp(floatPrice) >= 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + switch order.Order.TradeType { + case flags.TradeTypeBuy: //买涨 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + case flags.TradeTypeSell: // 买跌 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + } + + if checkBool { + deleteCache = true + order.Status = flags.Close + } + + if deleteCache { + // 根据订单ID-删除持仓列表缓存订单 + if err := Reds.HDel(context.Background(), setting.MarketShareSgdPosition, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareSgdConcurrentComputingPosition.Position.HDel:%v", common.ErrShareSgd, err) + } + } + + wg.Done() + return share.ShareSgdTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + ClosingPrice: dealPrice, // 平仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareSgdMqClosingBusiness +// +// @Description: TODO: 处理新加坡股平仓消息队列 +// @param ctx +// @param uo +func ShareSgdMqClosingBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Position.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerPositionMq.ShareSgdMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareSgdMqClosingBusiness.ShareSgdMq err....", common.ErrShareSgd) + continue + } + applogger.Info("接收到平仓信息:%v", string(message)) + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareSgdTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareSgdMqClosingBusiness.Unmarshal:%v", common.ErrShareSgd, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareSgdLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareSgdMqClosingBusiness.ShareSgdLiquidationPosition:%v", common.ErrShareSgd, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + time.Sleep(2 * time.Second) + } + } +} + +// ShareSgdLiquidationPosition +// +// @Description: 新加坡股持仓-->平仓业务处理 +// @param ctx +// @param order +// @return error +func ShareSgdLiquidationPosition(ctx context.Context, order *share.ShareSgdTallyCache) error { + // 1、平仓操作 + err := StockSgdClosingOrder(ctx, Msql, order.OrderId, order.ClosingPrice, order.Order) + if err != nil { + applogger.Error("%v ShareSgdLiquidationPosition.StockSgdClosingOrder:%v", common.ErrShareSgd, err) + return err + } + + // 2、平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareSgdSubscribe, order.UserId) + if err = UpdateShareSgdSubscribeHashStatusByOrderId(order.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v ShareSgdLiquidationPosition.Position.ShareSgdSubscribe:%v", common.ErrShareSgd, err) + return err + } + + // 3、平仓更新管理员订阅订单状态 + if err = UpdateShareSgdSubscribeHashStatusByOrderId(order.OrderId, setting.AdminShareSgdSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v ShareSgdLiquidationPosition.Position.AdminShareSgdSubscribe:%v", common.ErrShareSgd, err) + return err + } + + return nil +} + +// StockSgdVoteStopType +// +// @Description: 新加坡股判定取值止损止盈 +// @param order +// @return bool +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func StockSgdVoteStopType(order structure.ShareOrder) (bool, decimal.Decimal, decimal.Decimal, error) { + var checkBool bool + var stopWinPrice, stopLossPrice decimal.Decimal + switch order.StopType { + case flags.StopTypeNone: // 暂无设置止盈止损 + checkBool = false + case flags.StopTypeSet: // 设置止盈止损 + checkBool = true + stopWinPrice, _ = decimal.NewFromString(order.StopWinPrice) + stopLossPrice, _ = decimal.NewFromString(order.StopLossPrice) + default: + return checkBool, stopWinPrice, stopLossPrice, flags.ErrContractThirteen + } + + return checkBool, stopWinPrice, stopLossPrice, nil +} + +// GetShareSgdPrice +// +// @Description: 新加坡股股票价格 +// @param symbol +// @return decimal.Decimal +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func GetShareSgdPrice(symbol string) (decimal.Decimal, error) { + var err error + var priceByte []byte + var newPrice decimal.Decimal + + key := publicData.SymbolCache(flags.Sgd, symbol, flags.TradeTypePrice) + priceByte, err = memory.GetShareSgdCache(key) + if err != nil { + return decimal.Decimal{}, err + } + + newPrice, err = decimal.NewFromString(string(priceByte)) + if err != nil { + return decimal.Decimal{}, err + } + + applogger.Info("shareSgdCode:%v,topIc:%v,shareSgdPrice:%v", symbol, key, newPrice) + + return newPrice, nil +} diff --git a/internal/data/subscribe_share_tha.go b/internal/data/subscribe_share_tha.go new file mode 100644 index 0000000..2f376a5 --- /dev/null +++ b/internal/data/subscribe_share_tha.go @@ -0,0 +1,1249 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/mq/consumer" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/socket/shareData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "sync" + "time" +) + +/* +泰股行情订阅 +1、接收用户泰股下单的交易对泰股行情 +2、将订阅行情写入内存中用于并发计算 +3、挂单(市价|限价)缓存队列处理-开仓 +4、持仓缓存队列处理-平仓 +*/ + +// ShareThaMessage +// @Description: +type ShareThaMessage struct { + Symbol string `json:"symbol,omitempty"` // 交易所:股票代码 + StockCode string `json:"stock_code,omitempty"` // 股票代码 + StockName string `json:"stock_name,omitempty"` // 股票名,可能为空 + Price decimal.Decimal `json:"price,omitempty"` // 实时价格 + UpDownRate decimal.Decimal `json:"up_down_rate,omitempty"` // 涨跌% + UpDown decimal.Decimal `json:"up_down,omitempty"` // 涨跌额 + TradeV decimal.Decimal `json:"trade_v,omitempty"` // 技术评级指标值 + TradeK string `json:"trade_k,omitempty"` // 技术评级 + Vol int64 `json:"vol,omitempty"` // 成交量 + TurnoverPriceTotal decimal.Decimal `json:"turnover_price_total,omitempty"` // 成交量*价格 + PriceTotal string `json:"price_total,omitempty"` // 总市值 + PE string `json:"p_e,omitempty"` // pe + Eps string `json:"eps,omitempty"` // EPS + EmployeesNumber string `json:"employees_number,omitempty"` // 雇员 + Plate string `json:"plate,omitempty"` // 板块 + Desc string `json:"desc,omitempty"` // 描述 + PriceCode string `json:"price_code,omitempty"` // 价格类型 + Country string `json:"country,omitempty"` // 国家 + Ts int64 `json:"ts,omitempty"` // 时间 + Token string `json:"token,omitempty"` // Token 令牌 +} + +// ShareThaSymbol +// @Description: +type ShareThaSymbol struct { + ThaMap chan []byte // 订单交易对 -- 用户下单通知订阅 + ThaSetMap chan []byte // 订单交易对 -- 用户盘前|盘后行情订阅 + ThaMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 + ThaSetMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 +} + +// InitCacheSymbolShareTha +// +// @Description: +// @param ctx +// @param uo +func InitCacheSymbolShareTha(ctx context.Context, uo *Data) { + for { + thaList, err := GetBotStockThaListByStockId(ctx, uo) + if err != nil { + return + } + + for _, value := range thaList { + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := uo.redisDB.HExists(context.Background(), setting.MarketShareTha, value).Result() + if err != nil { + applogger.Error("%v InitCacheSymbolShareTha.MarketShareTha.HExists:%v", common.ErrShareTha, err) + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err = uo.redisDB.HSet(context.Background(), setting.MarketShareTha, value, value).Err(); err != nil { + applogger.Error("%v InitCacheSymbolShareTha.MarketShareTha.HSet:%v", common.ErrShareTha, err) + time.Sleep(5 * time.Second) + continue + } + } + if !flags.CheckSetting { + applogger.Info("初始化泰股股票代码:%v", value) + } + } + + time.Sleep(10 * time.Second) + } +} + +// InitSubscribeShareTha +// +// @Description: 状态机加载订阅 +// @param ctx +// @param uo +// @param shareTha +func InitSubscribeShareTha(shareTha *ShareThaSymbol, check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkTha + } else { + key = setting.MarketShareTha + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareTha.LoadLRangeList:%v", common.ErrShareTha, err) + return + } + + for _, value := range listSpots { + // Handling duplicate subscriptions + _, ok := shareTha.ThaMapSymbol.Load(value) + if ok { + continue + } + + shareTha.ThaMap <- []byte(value) + } + + time.Sleep(10 * time.Second) + } +} + +// InitShareThaCloseCachePrice +// +// @Description: +// @param shareTha +// @param check +func InitShareThaCloseCachePrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkTha + } else { + key = setting.MarketShareTha + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareTha.LoadLRangeList:%v", common.ErrShareTha, err) + return + } + + for _, value := range listSpots { + SubscribeThaClosePrice(value) // 处理闭盘取价 + } + + time.Sleep(20 * time.Second) + } +} + +// InitShareThaCloseNewPrice +// +// @Description: 同步实时行情 +// @param check +func InitShareThaCloseNewPrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkTha + } else { + key = setting.MarketShareTha + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareThaCloseNewPrice.LoadLRangeList:%v", common.ErrShareTha, err) + time.Sleep(20 * time.Second) + continue + } + for _, value := range listSpots { + SubscribeThaCloseNewPrice(value) + } + + time.Sleep(500 * time.Millisecond) + } +} + +// InitShareThaPriceSetUp +// +// @Description: 同步插针行情 +// @param check +func InitShareThaPriceSetUp(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkTha + } else { + key = setting.MarketShareTha + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareThaPriceSetUp.LoadLRangeList:%v", common.ErrShareTha, err) + time.Sleep(20 * time.Second) + continue + } + + for _, value := range listSpots { + thaKey := publicData.SymbolCache(flags.Tha, value, flags.TradeTypePrice) + thaSetCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareThaMarketType, value) + vw, err := GetBeforeAndAfterSetPrice(thaSetCache) + if err != nil || len(vw) == 0 { + _ = memory.ShareThaPriceSetUp.Delete(thaKey) + continue + } + if err = memory.ShareThaPriceSetUp.Set(thaKey, []byte(vw)); err != nil { + applogger.Error("%v InitShareThaPriceSetUp.ShareThaPriceSetUp:%v", common.ErrShareTha, err) + } + } + + time.Sleep(500 * time.Millisecond) + } +} + +// SubscribeThaHSetCodeList +// +// @Description: 同步列表缓存 +// @param symbolStr +// @param check +func SubscribeThaHSetCodeList(symbolStr string, check bool) { + var key string + if check { + key = setting.MarketShareBlkTha + } else { + key = setting.MarketShareTha + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + return + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeThaHSetCodeList.%v.HSet:%v", common.ErrShareTha, key, err) + return + } + } +} + +// SubscribeThaCloseNewPrice +// +// @Description: 获取行情价 +// @param symbolStr +func SubscribeThaCloseNewPrice(symbolStr string) { + // 获取市场真实开闭盘时间 + timeValue, checkWeekday := MarketCheckOpenAndCloseTime(flags.ShareThaMarketType) + // 判定是否盘中 + if utils.CheckInPlateTime(timeValue) && checkWeekday { + // 盘中实时价格 + realTimePrice, err := Reds.HGet(context.Background(), flags.ShareThailandClosingNewPriceKey, symbolStr).Result() + if err != nil { + realTimePrice = decimal.Zero.String() + } + if realTimePrice != decimal.Zero.String() { + keys := publicData.SymbolCache(flags.Tha, symbolStr, flags.TradeTypePrice) + if err = memory.ShareThaCache.Set(keys, []byte(realTimePrice)); err != nil { + applogger.Error("%v SubscribeThaCloseNewPrice.ShareGbxCache:%v", common.ErrShareTha, err) + } + } + } +} + +// SubscribeThaClosePrice +// +// @Description: 获取闭盘价 +// @param symbolStr +func SubscribeThaClosePrice(symbolStr string) { + var err error + var sub = decimal.Zero + var closeNewPrice, closingPrice, price string + + // 闭盘价格 + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareThailandClosingNewPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareThailandClosingPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice = decimal.Zero.String() + } + } + + // 市价(实时价格) + closingPrice, err = Reds.HGet(context.Background(), flags.ShareThailandBeforeClose, symbolStr).Result() + if err != nil { + closingPrice = decimal.Zero.String() + } + + // 判定取值数据 + if closeNewPrice != decimal.Zero.String() { + price = closeNewPrice + } else { + price = closingPrice + } + closeKey := publicData.SymbolCache(flags.Tha, symbolStr, flags.TradeTypeClosePrice) + if err = memory.ShareThaClosePrice.Set(closeKey, []byte(price)); err != nil { + applogger.Error("%v ShareThaClosePrice.Set.price:%v", common.ErrShareTha, err) + } + + // 写入涨跌幅价格判定缓存(计算涨跌幅 = 最新价格 - 闭盘价格(昨天关闭价格或者上次毕盘价格)) + cn := closeNewPrice != decimal.Zero.String() + cp := closingPrice != decimal.Zero.String() + lcn := utils.IsNumber(closeNewPrice) + lcp := utils.IsNumber(closingPrice) + if cn && cp && lcn && lcp { + sub = decimal.RequireFromString(closingPrice).Sub(decimal.RequireFromString(closeNewPrice)) + } + chgKey := publicData.SymbolCache(flags.Tha, symbolStr, flags.TradeTypeChg) // 涨跌幅标识Key + if err = memory.ShareThaChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v ShareThaChgMark.Set.price:%v", common.ErrShareTha, err) + } +} + +// OrderSubAdminShareThaSubscribeBySum +// +// @Description: 持仓订单浮动盈亏计算 +// @param ctx +// @param uo +func OrderSubAdminShareThaSubscribeBySum(uo *Data) { + for { + var topIc = setting.AdminShareThaSubscribe + hashMap, err := uo.redisDB.HGetAll(context.Background(), topIc).Result() + if err != nil { + applogger.Error("OrderSubAdminShareThaSubscribeBySum.HGetAll:%v", err) + time.Sleep(5 * time.Second) + continue + } + var hashList []share.ShareThaTallyCache + for _, value := range hashMap { + var msg share.ShareThaTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + switch msg.Status { + case flags.Entrust: // 挂单 + case flags.Position: // 持仓 + hashList = append(hashList, msg) + default: // 平仓|撤单 + err = uo.redisDB.HDel(context.Background(), topIc, msg.OrderId).Err() + if err != nil { + applogger.Error("OrderSubAdminShareThaSubscribeBySum.HDel:%v", err) + continue + } + } + } + applogger.Info("泰股数据量统计:%v", len(hashList)) + + // 统计泰股总持仓订单浮动盈亏 + priceSum := decimal.Zero + for _, value := range hashList { + orderModel := shareData.ShareThaOrderProcessing(topIc, value) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch value.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + price := subPrice.Mul(decimal.RequireFromString(value.Order.OrderNumber)) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + + // 写入缓存 + if err = memory.ShareThaFloating.Set(flags.FloatingTha, []byte(priceSum.String())); err != nil { + applogger.Error("统计泰股持仓订单浮动盈亏错误:%v", err) + time.Sleep(5 * time.Second) + continue + } + applogger.Info("统计泰股持仓订单浮动盈亏:%v", priceSum) + + time.Sleep(1 * time.Second) + } +} + +// SubscribeShareTha +// +// @Description: TODO: 泰股订阅 +// @param ctx +// @param uo +// @param shareTha +func SubscribeShareTha(ctx context.Context, shareTha *ShareThaSymbol, check bool) { + for { + select { + case symbol, _ := <-shareTha.ThaMap: + symbolStr := string(symbol) + topIc := fmt.Sprintf("%v.%v", symbolStr, flags.CountryTha) + // Handling duplicate subscriptions + _, ok := shareTha.ThaMapSymbol.Load(symbolStr) + if ok { + time.Sleep(5 * time.Second) + continue + } + // Transaction determination + var key string + if check { + key = setting.MarketShareBlkTha // 大宗股交易 + } else { + key = setting.MarketShareTha // 泰股交易 + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeShareTha.%v.HSet:%v", common.ErrShareTha, key, err) + time.Sleep(5 * time.Second) + continue + } + } + + // 处理订阅实时行情数据 + go func() { + symbolStrCache := symbolStr + pubSub := Reds.Subscribe(ctx, topIc) + defer pubSub.Close() + if _, err := pubSub.Receive(ctx); err != nil { + shareTha.ThaMapSymbol.Delete(symbolStrCache) + return + } + ch := pubSub.Channel() + for { + select { + case msg, _ := <-ch: + var subMsg ShareThaMessage + if err := json.Unmarshal([]byte(msg.Payload), &subMsg); err != nil { + applogger.Error("%v SubscribeShareTha.Unmarshal:%v", common.ErrShareTha, err) + time.Sleep(5 * time.Second) + continue + } + SubscribeThaPrice(subMsg.Price.String(), symbolStr, flags.RealTime) + default: + Reds.Ping(ctx) // 如果没有消息,发送 PING 命令以维护连接 + time.Sleep(10 * time.Second) + } + } + }() + + // 监控盘前|盘后设置价格 + _, okc := shareTha.ThaSetMapSymbol.Load(symbolStr) + if !okc { + go func() { + for { + keyCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareThaMarketType, symbolStr) + vw, err := GetBeforeAndAfterSetPrice(keyCache) + if err != nil || len(vw) == 0 { + priceCache := publicData.SymbolCache(flags.Tha, symbolStr, flags.TradeTypePrice) + memory.ShareThaPriceSetUp.Delete(priceCache) + time.Sleep(15 * time.Second) + continue + } + SubscribeThaPrice(vw, symbolStr, flags.SetUp) + time.Sleep(10 * time.Second) + } + }() + // Write cache to determine whether to repeatedly open the protocol + shareTha.ThaSetMapSymbol.Store(symbolStr, symbolStr) + } + + // Write in the map to determine whether to repeat subscription + shareTha.ThaMapSymbol.Store(symbolStr, symbolStr) + } + } +} + +// SubscribeThaPrice +// +// @Description: TODO: 订阅获取泰股股实时价格或者[盘前|盘后]设置价格 +// @param setPrice +// @param symbolStr +// @param check +func SubscribeThaPrice(setPrice, symbolStr string, check int) { + var err error + var sub = decimal.Zero + + // 计算涨跌幅 + yClosingPrice, err := Reds.HGet(context.Background(), flags.ShareThailandClosingPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice, err = Reds.HGet(context.Background(), flags.ShareThailandClosingNewPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice = setPrice + sub = decimal.Zero + } + } + + // 写入涨跌幅缓存数据 + yc := yClosingPrice != decimal.Zero.String() + sp := setPrice != decimal.Zero.String() + lyc := utils.IsNumber(yClosingPrice) + lsp := utils.IsNumber(setPrice) + if yc && sp && lyc && lsp { + sub = decimal.RequireFromString(setPrice).Sub(decimal.RequireFromString(yClosingPrice)) + } + chgKey := publicData.SymbolCache(flags.Tha, symbolStr, flags.TradeTypeChg) + if err = memory.ShareThaChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v SubscribeShareTha.ShareThaChgMark.Set.price:%v", common.ErrShareTha, err) + } + if !flags.CheckSetting { + applogger.Debug("涨跌幅交易对内存key:%v,涨跌幅数值:%v", symbolStr, sub) + } + + // 交易类型:0最新价,1买入,2卖出 + price := publicData.SymbolCache(flags.Tha, symbolStr, flags.TradeTypePrice) + switch check { + case flags.RealTime: // 实时价格(优先级高) + if err = memory.ShareThaCache.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeShareTha.ShareThaCache.Set.price:%v", common.ErrShareTha, err) + } + case flags.SetUp: // 设置[盘前|盘后]价格 + if err = memory.ShareThaPriceSetUp.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeShareTha.ShareThaPriceSetUp:%v", common.ErrShareTha, err) + } + } + if !flags.CheckSetting { + applogger.Debug("股票交易对内存Key:%v,最新价格:%v", price, setPrice) + } +} + +// SubscribeThaSetForcedClosure +// +// @Description: TODO: 处理泰股强平阈值 +// @param symbolStr +func SubscribeThaSetForcedClosure(symbolStr string) { + flatRatio := GetCacheForcedClosure(flags.StockTGSystemSetUpKey, symbolStr) + chgKey := publicData.SymbolCache(flags.Tha, symbolStr, flags.TradeTypeForcedClosure) + if err := memory.ShareThaForcedClosure.Set(chgKey, []byte(flatRatio.String())); err != nil { + applogger.Error("%v SubscribeThaSetForcedClosure.StockTGSystemSetUpKey err:%v", common.ErrShareTha, err) + return + } +} + +// ShareThaTransactionEntrust +// +// @Description: 泰股委托订单 +// @param ctx +func ShareThaTransactionEntrust(ctx context.Context) { + for { + ShareThaTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareThaTransactionCalculationEntrust +// +// @Description: 泰股挂单缓存队列计算 +// @param ctx +func ShareThaTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 全局变量处理 + if CheckGlobalTread(flags.ThaMarket) { + time.Sleep(5 * time.Second) + return + } + + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareThaEntrust).Result() + if err != nil { + applogger.Error("%v ShareThaTransactionCalculationEntrust.HGetAll:%v", common.ErrShareTha, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareThaTallyCache, 1) + var entrust share.ShareThaTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareThaTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareTha, err) + continue + } + + // 股票实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareThaPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareThaTransactionCalculationEntrust.GetShareThaPrice:%v---%v", common.ErrShareTha, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + chg := GetShareChgTha(flags.Tha, entrust.Symbol) // 涨跌幅标识 + if share.CheckOrderThaByChg(setting.MarketShareThaEntrust, entrust, chg) { + //applogger.Warn("当前股票%v订单在挂单状态已达到涨跌幅上限.", entrust.Symbol) + continue + } + + wg.Add(1) + go func(value string) { + var resultMsg share.ShareThaTallyCache + switch entrust.Order.DealType { + case flags.DealTypeLimited: // 限价挂单 + resultMsg = ShareThaConcurrentComputingEntrustLimited(&entrust, newPrice, &wg) + case flags.DealTypeMarket: // 市价挂单(开盘即成交) + resultMsg = ShareThaConcurrentComputingEntrustMarket(&entrust, newPrice, &wg) + } + msg <- resultMsg // 通知管道异步处理订单操作 + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收泰股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到泰股持仓信息:%v", resultMsg) + } + + // 开盘逻辑 + if err = ShareThaLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Warn("%v ShareThaTransactionCalculationEntrust.ShareThaLiquidationEntrust:%v", common.ErrShareTha, err) + continue + } + + // 写入持仓缓存列表 + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Warn("%v ShareThaTransactionCalculationEntrust.Marshal:%v", common.ErrShareTha, err) + continue + } + + // TODO: 写入持仓消息队列 + //if err = uo.mqProducer.Entrust.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareThaTransactionCalculationEntrust.PushNotice:%v", common.ShareThaError, err) + // continue + //} + + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareThaPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("泰股挂单并发计算执行完毕......") +} + +// ShareThaConcurrentComputingEntrustLimited +// +// @Description: 泰股挂单(限价|市价)缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareThaTallyCache +func ShareThaConcurrentComputingEntrustLimited(order *share.ShareThaTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareThaTallyCache { + var deleteCache bool + var dealPrice string + var limitPrice = decimal.RequireFromString(order.Order.LimitPrice) // 限价-价格 + var status = order.Status // 原始价格 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价买入逻辑判定 -> 挂单金额 > 当前价格 + if limitPrice.Cmp(newPrice) > 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + } + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价卖入逻辑判定 -> 挂单金额 < 当前价格 + if limitPrice.Cmp(newPrice) < 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareThaEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareThaConcurrentComputingEntrustLimited.MarketShareThaEntrust.HDel:%v", common.ErrShareTha, err) + order.Status = status + } + } + + wg.Done() + return share.ShareThaTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareThaConcurrentComputingEntrustMarket +// +// @Description: 泰股市价下单进入挂单队列(休市) +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareThaTallyCache +func ShareThaConcurrentComputingEntrustMarket(order *share.ShareThaTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareThaTallyCache { + var deleteCache bool + var dealPrice string + var marketPrice = decimal.RequireFromString(order.Order.MarketPrice) // 市价-价格 + var status = order.Status // 原始价格 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareThaEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareUsConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareTha, err) + order.Status = status + } + } + + wg.Done() + return share.ShareThaTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareBlockThaConcurrentComputingEntrustMarket +// +// @Description: 大宗(泰股)交易 +// @param order +// @param newPrice +// @param wg +// @return share.ShareThaTallyCache +func ShareBlockThaConcurrentComputingEntrustMarket(order *share.ShareThaTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareThaTallyCache { + var status = order.Status // 原始状态 + + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareBlkEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareBlockThaConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareBlk, err) + order.Status = status + } + + wg.Done() + return share.ShareThaTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: newPrice.String(), // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareThaMqOpenBusiness +// +// @Description: TODO: 泰股持仓消息队列 +// @param ctx +// @param uo +func ShareThaMqOpenBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Entrust.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerEntrustMq.ShareThaMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareThaMqOpenBusiness.ShareThaMq err....", common.ErrShareTha) + continue + } + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareThaTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareThaMqOpenBusiness.Unmarshal:%v", common.ErrShareTha, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareThaLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareThaMqOpenBusiness.ShareThaLiquidationEntrust:%v", common.ErrShareTha, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + applogger.Error("这里没有监控到持仓mq队列消息.........") + time.Sleep(2 * time.Second) + } + } +} + +// ShareThaLiquidationEntrust +// +// @Description: 泰股挂单-->开仓业务处理 +// @param ctx +// @param order +// @return error +func ShareThaLiquidationEntrust(ctx context.Context, order *share.ShareThaTallyCache) error { + // 1、开盘 + err := StockThaOpenOrder(ctx, Msql, order.UserId, order.OrderId, order.OpenPrice, order.Order) + if err != nil { + applogger.Error("%v ShareThaLiquidationEntrust.StockThaOpenOrder:%v", common.ErrShareTha, err) + return err + } + + // 大宗(泰股)交易判定 + var entrustKey, adminKey string + if !CheckTypeStatus(order.Order.Type) { + entrustKey = setting.ShareThaSubscribe + adminKey = setting.AdminShareThaSubscribe + } else { + entrustKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // 2、更新用户订阅缓存列表订单状态 + updateKey := virtual.OrderIdListKey(entrustKey, order.UserId) + if err = UpdateShareThaSubscribeHashStatusByOrderId(order.OrderId, updateKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareUsLiquidationEntrust.Entrust.%v:%v", common.ErrShareTha, entrustKey, err) + return err + } + + // 3、更新管理员订阅缓存列表订单状态 + if err = UpdateShareThaSubscribeHashStatusByOrderId(order.OrderId, adminKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareUsLiquidationEntrust.Entrust.%v:%v", common.ErrShareTha, adminKey, err) + return err + } + + return nil +} + +// ShareThaTransactionPosition +// +// @Description: 泰股持仓订单 +// @param ctx +func ShareThaTransactionPosition(ctx context.Context) { + for { + ShareThaTransactionCalculationPosition(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareThaTransactionCalculationPosition +// +// @Description: 泰股持仓缓存队列计算 +// @param ctx +func ShareThaTransactionCalculationPosition(ctx context.Context) { + var wg sync.WaitGroup + + // 判定是否交易 + if CheckGlobalTread(flags.ThaMarket) { + time.Sleep(5 * time.Second) + return + } + // TODO: 获取IPO未支付订单缓存 + userIdMap, _ := GetBotUserArrears(ctx) + // 获取持仓缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareThaPosition).Result() + if err != nil { + applogger.Error("%v ShareThaTransactionCalculationPosition.HGetAll:%v", common.ErrShareTha, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareThaTallyCache, 1) + var entrust share.ShareThaTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareThaTransactionCalculationPosition.Unmarshal:%v", common.ErrShareTha, err) + continue + } + + // TODO: 判定是否未IPO未支付订单-不能平仓 + _, isOk := userIdMap[entrust.UserId] + if isOk { + continue + } + + // 处理时间 + if !CheckShareSystemTime(entrust.ClosingTime) { + applogger.Info("泰股:%v,平仓时间:%v暂未到达...", entrust.Symbol, entrust.ClosingTime) + continue + } + + // TODO: 实时获取强平阈值 + //entrust.Order.System.StrongFlatRatio = GetForcedClosureValue(flags.Tha, entrust.Symbol) + + // 股票实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareThaPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareThaTransactionCalculationPosition.GetShareThaPrice:%v--%v", common.ErrShareTha, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + chg := GetShareChgTha(flags.Tha, entrust.Symbol) // 涨跌幅标识 + if share.CheckOrderThaByChg(setting.MarketShareThaEntrust, entrust, chg) { + //applogger.Warn("当前股票%v订单在挂单状态已达到涨跌幅上限.", entrust.Symbol) + continue + } + + // 判定配额强平 + checkFlattening := GetStrongFlatteningThreshold(entrust.UserId) + + wg.Add(1) + go func(value string) { + resultMsg := ShareThaConcurrentComputingPosition(&entrust, newPrice, &wg, checkFlattening) + msg <- resultMsg + }(value) + + // 处理并发结果 + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Position: // 持仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到泰股持仓信息:%v", resultMsg) + } + case flags.Close: // 平仓 + if !flags.CheckSetting { + applogger.Debug("从信道接收到泰股平仓信息:%v", resultMsg) + } + + // TODO: 平仓操作(优化写入队列中等待平仓) + //var byteStr []byte + //byteStr, err = json.Marshal(resultMsg) + //if err != nil { + // applogger.Error("%v ShareThaTransactionCalculationPosition.Marshal:%v", common.ShareThaError, err) + // continue + //} + //if err = uo.mqProducer.Position.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareThaTransactionCalculationPosition.DealPublish:%v", common.ShareThaError, err) + // continue + //} + + if err = ShareThaLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareThaTransactionCalculationPosition.ShareThaLiquidationPosition:%v", common.ErrShareTha, err) + continue + } + } + } + } + + wg.Wait() + applogger.Info("泰股持仓并发计算执行完毕......") +} + +// ShareThaConcurrentComputingPosition +// +// @Description: 泰股持仓缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareThaTallyCache +func ShareThaConcurrentComputingPosition(order *share.ShareThaTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup, checkFlattening bool) share.ShareThaTallyCache { + var deleteCache, checkBool bool + var dealPrice string + var sellShort decimal.Decimal + var openPrice = decimal.RequireFromString(order.OpenPrice) // 限价 + var orderNumber = decimal.RequireFromString(order.Order.OrderNumber) // 仓位 + + var pryNum decimal.Decimal + lenPryNum := len(utils.ReplaceStr(order.Order.PryNum)) == 0 + if lenPryNum || order.Order.PryNum == flags.SetZero || order.Order.System.UserStatus != flags.SetThree || !utils.IsNumberInt(order.Order.PryNum) { + pryNum = decimal.RequireFromString(flags.SetOne) + } else { + pryNum = decimal.RequireFromString(order.Order.PryNum) + } + + // 下单判定设置(false无设置|true止盈止损) + _, stopWinPrice, stopLossPrice, _ := StockThaVoteStopType(order.Order) + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨(强平) + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,持仓开仓价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买涨:挂止损止盈,止盈价必须<当前价,止损价必须>当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + // 强行平仓(做多) + if !checkBool { + sellShort = newPrice.Sub(openPrice).Mul(orderNumber) + } + case flags.TradeTypeSell: // 买跌(存在强行平仓) + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价持仓买跌下单价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买跌:挂止损止盈,止盈价必须>当前价,止损价必须<当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + // 强行平仓(做空) + if !checkBool { + sellShort = openPrice.Sub(newPrice).Mul(orderNumber) + } + } + /* 强行平仓(做多|做空) + 1、做多:(最新成交价-开仓成交价)*仓位 + 2、做空:(开仓成交价-最新成交价)*仓位 + 3、当浮动盈亏 >= 保证金的70%订单强行平仓 + */ + if sellShort.IsNegative() && checkFlattening { + orderAmount := newPrice.Mul(decimal.RequireFromString(order.Order.OrderNumber)).Div(pryNum) // 订单金额 = 当前价格 * 订单数量 / 杠杆 + floatPrice := orderAmount.Mul(decimal.RequireFromString(order.Order.System.StrongFlatRatio)) + if !flags.CheckSetting { + applogger.Debug("强平保证金:%v,强平浮动70:%v,强行平仓判定:%v", orderAmount, floatPrice, sellShort.Abs().Cmp(floatPrice)) + } + + if sellShort.Abs().Cmp(floatPrice) >= 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + switch order.Order.TradeType { + case flags.TradeTypeBuy: //买涨 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + case flags.TradeTypeSell: // 买跌 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + } + + if checkBool { + deleteCache = true + order.Status = flags.Close + } + + if deleteCache { + // 根据订单ID-删除持仓列表缓存订单 + if err := Reds.HDel(context.Background(), setting.MarketShareThaPosition, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareThaConcurrentComputingPosition.Position.HDel:%v", common.ErrShareTha, err) + } + } + + wg.Done() + return share.ShareThaTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + ClosingPrice: dealPrice, // 平仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareThaMqClosingBusiness +// +// @Description: TODO: 处理泰股平仓消息队列 +// @param ctx +// @param uo +func ShareThaMqClosingBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Position.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerPositionMq.ShareThaMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareThaMqClosingBusiness.ShareThaMq err....", common.ErrShareTha) + continue + } + applogger.Info("接收到平仓信息:%v", string(message)) + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareThaTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareThaMqClosingBusiness.Unmarshal:%v", common.ErrShareTha, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareThaLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareThaMqClosingBusiness.ShareThaLiquidationPosition:%v", common.ErrShareTha, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + time.Sleep(2 * time.Second) + } + } +} + +// ShareThaLiquidationPosition +// +// @Description: 泰股持仓-->平仓业务处理 +// @param ctx +// @param order +// @return error +func ShareThaLiquidationPosition(ctx context.Context, order *share.ShareThaTallyCache) error { + // 1、平仓操作 + err := StockThaClosingOrder(ctx, Msql, order.OrderId, order.ClosingPrice, order.Order) + if err != nil { + applogger.Error("%v ShareUsLiquidationPosition.StockClosingOrder:%v", common.ErrShareTha, err) + return err + } + + // 2、平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareThaSubscribe, order.UserId) + if err = UpdateShareThaSubscribeHashStatusByOrderId(order.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v ShareUsLiquidationPosition.Position.ShareThaSubscribe:%v", common.ErrShareTha, err) + return err + } + + // 3、平仓更新管理员订阅订单状态 + if err = UpdateShareThaSubscribeHashStatusByOrderId(order.OrderId, setting.AdminShareThaSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v ShareUsLiquidationPosition.Position.AdminShareThaSubscribe:%v", common.ErrShareTha, err) + return err + } + + return nil +} + +// StockThaVoteStopType +// +// @Description: 泰股判定取值止损止盈 +// @param order +// @return bool +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func StockThaVoteStopType(order structure.ShareOrder) (bool, decimal.Decimal, decimal.Decimal, error) { + var checkBool bool + var stopWinPrice, stopLossPrice decimal.Decimal + switch order.StopType { + case flags.StopTypeNone: // 暂无设置止盈止损 + checkBool = false + case flags.StopTypeSet: // 设置止盈止损 + checkBool = true + stopWinPrice, _ = decimal.NewFromString(order.StopWinPrice) + stopLossPrice, _ = decimal.NewFromString(order.StopLossPrice) + default: + return checkBool, stopWinPrice, stopLossPrice, flags.ErrContractThirteen + } + + return checkBool, stopWinPrice, stopLossPrice, nil +} + +// GetShareThaPrice +// +// @Description: 获取泰股股票价格 +// @param symbol +// @return decimal.Decimal +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func GetShareThaPrice(symbol string) (decimal.Decimal, error) { + var err error + var priceByte []byte + var newPrice decimal.Decimal + + key := publicData.SymbolCache(flags.Tha, symbol, flags.TradeTypePrice) + priceByte, err = memory.GetShareThaCache(key) + if err != nil { + return decimal.Decimal{}, err + } + + newPrice, err = decimal.NewFromString(string(priceByte)) + if err != nil { + return decimal.Decimal{}, err + } + + applogger.Info("shareThaCode:%v,topIc:%v,shareThaPrice:%v", symbol, key, newPrice) + + return newPrice, nil +} diff --git a/internal/data/subscribe_share_us.go b/internal/data/subscribe_share_us.go new file mode 100644 index 0000000..3c889ea --- /dev/null +++ b/internal/data/subscribe_share_us.go @@ -0,0 +1,1244 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/mq/consumer" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/socket/shareData" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "sync" + "time" +) + +/* +美股行情订阅 +1、接收用户美股下单的交易对美股行情 +2、将订阅行情写入内存中用于并发计算 +3、挂单(市价|限价)缓存队列处理-开仓 +4、持仓缓存队列处理-平仓 +*/ + +// ClientMessage +// @Description: +type ClientMessage struct { + S string `json:"s,omitempty"` // 股票代码 + P decimal.Decimal `json:"p,omitempty"` // 价格 + C []decimal.Decimal `json:"c,omitempty"` // 条件,有关更多信息,请参阅贸易条件术语表 + V int64 `json:"v,omitempty"` // 交易量,代表在相应时间戳处交易的股票数量 + Dp bool `json:"dp,omitempty"` // 暗池真/假 + Ms string `json:"ms,omitempty"` // 市场状态,指示股票市场的当前状态(“开盘”、“收盘”、“延长交易时间”) + T int64 `json:"t,omitempty"` // 以毫秒为单位的时间戳 + Av int64 `json:"av,omitempty"` // 今天累计交易量 + Op decimal.Decimal `json:"op,omitempty"` // 今天正式开盘价格 + Vw decimal.Decimal `json:"vw,omitempty"` // 即时报价的成交量加权平均价格 + Cl decimal.Decimal `json:"cl,omitempty"` // 此聚合窗口的收盘价 + H decimal.Decimal `json:"h,omitempty"` // 此聚合窗口的最高逐笔报价 + L decimal.Decimal `json:"l,omitempty"` // 此聚合窗口的最低价格变动价格 + A decimal.Decimal `json:"a,omitempty"` // 今天的成交量加权平均价格 + Z int64 `json:"z,omitempty"` // 此聚合窗口的平均交易规模 + Se int64 `json:"se,omitempty"` // 此聚合窗口的起始报价的时间戳(以 Unix 毫秒为单位) +} + +// ShareUsSymbol +// @Description: +type ShareUsSymbol struct { + UsMap chan []byte // 订单交易对 -- 用户下单通知订阅 + UsSetMap chan []byte // 订单交易对 -- 用户盘前|盘后行情订阅 + UsMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 + UsSetMapSymbol sync.Map // 订阅交易簿 -- 过滤重复 +} + +// InitCacheSymbolShareUs +// +// @Description: 初始化美股股票代码 +// @param ctx +// @param uo +func InitCacheSymbolShareUs(ctx context.Context, uo *Data) { + for { + stockList, err := GetBotStockListByStockId(ctx, uo) + if err != nil { + return + } + + for _, value := range stockList { + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := uo.redisDB.HExists(context.Background(), setting.MarketShareUs, value).Result() + if err != nil { + applogger.Error("%v InitCacheSymbolShareUs.MarketShareUs.HExists:%v", common.ErrShareUs, err) + continue + } + if !checkBool { + if err = uo.redisDB.HSet(context.Background(), setting.MarketShareUs, value, value).Err(); err != nil { + applogger.Error("%v InitCacheSymbolShareUs.MarketShareUs.HSet:%v", common.ErrShareUs, err) + continue + } + } + if !flags.CheckSetting { + applogger.Info("初始化美股股票代码:%v", value) + } + } + + time.Sleep(10 * time.Second) + } +} + +// InitSubscribeShareUs +// +// @Description: 状态机加载订阅 +// @param ctx +// @param uo +// @param shareUs +func InitSubscribeShareUs(shareUs *ShareUsSymbol, check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkUs // 大宗交易 + } else { + key = setting.MarketShareUs // 美股交易 + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareUs.LoadLRangeList:%v", common.ErrShareUs, err) + return + } + + for _, value := range listSpots { + _, oks := shareUs.UsMapSymbol.Load(value) + if oks { + continue + } + + shareUs.UsMap <- []byte(value) + } + + time.Sleep(10 * time.Second) + } +} + +// InitShareUsCloseCachePrice +// +// @Description: 同步闭盘价 +// @param shareUs +// @param check +func InitShareUsCloseCachePrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkUs // 大宗交易 + } else { + key = setting.MarketShareUs // 美股交易 + } + + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareUs.LoadLRangeList:%v", common.ErrShareUs, err) + return + } + + for _, value := range listSpots { + SubscribeUsClosePrice(value) // 处理闭盘价格 + } + + time.Sleep(20 * time.Second) + } +} + +// InitShareUsCloseNewPrice +// +// @Description: 同步实时行情 +// @param check +func InitShareUsCloseNewPrice(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkUs + } else { + key = setting.MarketShareUs + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitSubscribeShareUs.LoadLRangeList:%v", common.ErrShareUs, err) + time.Sleep(20 * time.Second) + continue + } + for _, value := range listSpots { + SubscribeUsCloseNewPrice(value) + } + + time.Sleep(500 * time.Millisecond) + } +} + +// InitShareUsPriceSetUp +// +// @Description: 同步插针行情 +// @param check +func InitShareUsPriceSetUp(check bool) { + for { + var key string + if check { + key = setting.MarketShareBlkUs + } else { + key = setting.MarketShareUs + } + listSpots, err := LoadLRangeList(key) + if err != nil { + applogger.Error("%v InitShareUsPriceSetUp.LoadLRangeList:%v", common.ErrShareUs, err) + time.Sleep(20 * time.Second) + continue + } + + for _, value := range listSpots { + usKey := publicData.SymbolCache(flags.Us, value, flags.TradeTypePrice) + usSetCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareUsMarketType, value) + vw, err := GetBeforeAndAfterSetPrice(usSetCache) + if err != nil || len(vw) == 0 { + _ = memory.ShareUsPriceSetUp.Delete(usKey) + continue + } + if err = memory.ShareUsPriceSetUp.Set(usKey, []byte(vw)); err != nil { + applogger.Error("%v SubscribeUsPrice.ShareUsPriceSetUp:%v", common.ErrShareUs, err) + } + } + + time.Sleep(500 * time.Millisecond) + } +} + +// SubscribeUsHSetCodeList +// +// @Description: 同步列表缓存 +// @param symbolStr +// @param check +func SubscribeUsHSetCodeList(symbolStr string, check bool) { + var key string + if check { + key = setting.MarketShareBlkUs + } else { + key = setting.MarketShareUs + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + return + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeUsHSetCodeList.%v.HSet:%v", common.ErrShareUs, key, err) + return + } + } +} + +// SubscribeUsCloseNewPrice +// +// @Description: 获取行情价 +// @param symbolStr +// @param check +func SubscribeUsCloseNewPrice(symbolStr string) { + // 获取市场真实开闭盘时间 + timeValue, checkWeekday := MarketCheckOpenAndCloseTime(flags.ShareUsMarketType) + // 判定是否盘中 + if utils.CheckInPlateTime(timeValue) && checkWeekday { + // 盘中实时价格 + realTimePrice, err := Reds.HGet(context.Background(), flags.ShareUsClosingNewPriceKey, symbolStr).Result() + if err != nil { + realTimePrice = decimal.Zero.String() + } + if realTimePrice != decimal.Zero.String() { + keys := publicData.SymbolCache(flags.Us, symbolStr, flags.TradeTypePrice) + if err = memory.ShareUsCache.Set(keys, []byte(realTimePrice)); err != nil { + applogger.Error("%v SubscribeUsCloseNewPrice.ShareUsCache:%v", common.ErrShareUs, err) + } + } + } +} + +// SubscribeUsSetClosePrice +// +// @Description: 获取闭盘价 +// @param symbolStr +func SubscribeUsClosePrice(symbolStr string) { + var err error + var sub = decimal.Zero + var closeNewPrice, closingPrice, price string + + // 闭盘价格 + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareUsClosingNewPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice, err = Reds.HGet(context.Background(), flags.ShareUsClosingPriceKey, symbolStr).Result() + if err != nil || closeNewPrice == decimal.Zero.String() { + closeNewPrice = decimal.Zero.String() + } + } + + // 市价(当前价格) + closingPrice, err = Reds.HGet(context.Background(), flags.ShareUsBeforeClose, symbolStr).Result() + if err != nil { + closingPrice = decimal.Zero.String() + } + + // 判定闭盘取价格 + if closeNewPrice != decimal.Zero.String() { + price = closeNewPrice + } else { + price = closingPrice + } + closeKey := publicData.SymbolCache(flags.Us, symbolStr, flags.TradeTypeClosePrice) + if err = memory.ShareUsClosePrice.Set(closeKey, []byte(price)); err != nil { + applogger.Error("%v ShareUsClosePrice.Set.price:%v", common.ErrShareUs, err) + } + + // 写入涨跌幅价格判定缓存 + cn := closeNewPrice != decimal.Zero.String() + cp := closingPrice != decimal.Zero.String() + lcn := utils.IsNumber(closeNewPrice) + lcp := utils.IsNumber(closingPrice) + if cn && cp && lcn && lcp { + sub = decimal.RequireFromString(closingPrice).Sub(decimal.RequireFromString(closeNewPrice)) + } + chgKey := publicData.SymbolCache(flags.Us, symbolStr, flags.TradeTypeChg) // 涨跌幅标识Key + if err = memory.ShareUsChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v ShareUsChgMark.Set.price:%v", common.ErrShareUs, err) + } +} + +// OrderSubAdminShareUsSubscribeBySum +// +// @Description: 持仓订单浮动盈亏计算 +// @param ctx +// @param uo +func OrderSubAdminShareUsSubscribeBySum(uo *Data) { + for { + var topIc = setting.AdminShareUsSubscribe + hashMap, err := uo.redisDB.HGetAll(context.Background(), topIc).Result() + if err != nil { + applogger.Error("OrderSubAdminShareUsSubscribeBySum.HGetAll:%v", err) + time.Sleep(5 * time.Second) + continue + } + var hashList []share.ShareUsTallyCache + for _, value := range hashMap { + var msg share.ShareUsTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + switch msg.Status { + case flags.Entrust: // 挂单 + case flags.Position: // 持仓 + hashList = append(hashList, msg) + default: // 平仓|撤单 + err = uo.redisDB.HDel(context.Background(), topIc, msg.OrderId).Err() + if err != nil { + applogger.Error("OrderSubAdminShareUsSubscribeBySum.HDel:%v", err) + continue + } + } + } + applogger.Info("美股数据量统计:%v", len(hashList)) + + // 统计美股总持仓订单浮动盈亏 + priceSum := decimal.Zero + for _, value := range hashList { + orderModel := shareData.ShareUsOrderProcessing(topIc, value) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch value.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + price := subPrice.Mul(decimal.RequireFromString(value.Order.OrderNumber)) + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + + // 写入缓存 + if err = memory.ShareUsFloating.Set(flags.FloatingUs, []byte(priceSum.String())); err != nil { + applogger.Error("统计美股持仓订单浮动盈亏错误:%v", err) + time.Sleep(5 * time.Second) + continue + } + applogger.Info("统计美股持仓订单总浮动盈亏:%v", priceSum) + + time.Sleep(1 * time.Second) + } +} + +// SubscribeShareUs +// +// @Description: TODO: 美股订阅 +// @param ctx +// @param uo +// @param shareUs +func SubscribeShareUs(ctx context.Context, shareUs *ShareUsSymbol, check bool) { + for { + select { + case symbol, _ := <-shareUs.UsMap: + symbolStr := string(symbol) + topIc := fmt.Sprintf("%v.%v", symbolStr, flags.CountryUs) + // Handling duplicate subscriptions + _, ok := shareUs.UsMapSymbol.Load(symbolStr) + if ok { + time.Sleep(5 * time.Second) + continue + } + // Transaction determination + var key string + if check { + key = setting.MarketShareBlkUs // 大宗股交易 + } else { + key = setting.MarketShareUs // 美股交易 + } + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := Reds.HExists(context.Background(), key, symbolStr).Result() + if err != nil { + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err := Reds.HSet(context.Background(), key, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeShareUs.%v.HSet:%v", common.ErrShareUs, key, err) + time.Sleep(5 * time.Second) + continue + } + } + + // 处理实时订阅行情数据 + go func() { + symbolStrCache := symbolStr + pubSub := Reds.Subscribe(ctx, topIc) + defer pubSub.Close() + if _, err := pubSub.Receive(ctx); err != nil { + shareUs.UsMapSymbol.Delete(symbolStrCache) + return + } + ch := pubSub.Channel() + for { + select { + case msg, _ := <-ch: + var subMsg ClientMessage + if err := json.Unmarshal([]byte(msg.Payload), &subMsg); err != nil { + applogger.Error("%v SubscribeShareUs.Unmarshal:%v", common.ErrShareUs, err) + time.Sleep(5 * time.Second) + continue + } + SubscribeUsPrice(subMsg.Cl.String(), symbolStr, flags.RealTime) + default: + Reds.Ping(ctx) // 如果没有消息,发送 PING 命令以维护连接 + time.Sleep(10 * time.Second) + } + } + }() + + // 监控盘前|盘后设置价格 + _, okc := shareUs.UsSetMapSymbol.Load(symbolStr) + if !okc { + go func() { + for { + keyCache := fmt.Sprintf("%v%v:%v", flags.StockTradePrices, flags.ShareUsMarketType, symbolStr) + vw, err := GetBeforeAndAfterSetPrice(keyCache) + if err != nil || len(vw) == 0 { + priceCache := publicData.SymbolCache(flags.Us, symbolStr, flags.TradeTypePrice) + memory.ShareUsPriceSetUp.Delete(priceCache) + time.Sleep(15 * time.Second) + continue + } + SubscribeUsPrice(vw, symbolStr, flags.SetUp) + time.Sleep(10 * time.Second) + } + }() + // Write cache to determine whether to repeatedly open the protocol + shareUs.UsSetMapSymbol.Store(symbolStr, symbolStr) + } + + // Write in the map to determine whether to repeat subscription + shareUs.UsMapSymbol.Store(symbolStr, symbolStr) + } + } +} + +// SubscribeUsPrice +// +// @Description: TODO: 订阅获取美股股实时价格或者[盘前|盘后]设置价格 +// @param setPrice +// @param symbolStr +// @param check +func SubscribeUsPrice(setPrice, symbolStr string, check int) { + var err error + var sub = decimal.Zero + + // 计算涨跌幅 + yClosingPrice, err := Reds.HGet(context.Background(), flags.ShareUsClosingPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice, err = Reds.HGet(context.Background(), flags.ShareUsClosingNewPriceKey, symbolStr).Result() + if err != nil || yClosingPrice == decimal.Zero.String() { + yClosingPrice = decimal.Zero.String() + sub = decimal.Zero + } + } + + // 计算涨跌幅 = 最新价格 - 闭盘价格(昨天关闭价格或者上次毕盘价格) + yc := yClosingPrice != decimal.Zero.String() + sp := setPrice != decimal.Zero.String() + lyc := utils.IsNumber(yClosingPrice) + lsp := utils.IsNumber(setPrice) + if yc && sp && lyc && lsp { + sub = decimal.RequireFromString(setPrice).Sub(decimal.RequireFromString(yClosingPrice)) + } + + // 写入涨跌幅价格判定缓存 + chgKey := publicData.SymbolCache(flags.Us, symbolStr, flags.TradeTypeChg) + if err = memory.ShareUsChgMark.Set(chgKey, []byte(sub.String())); err != nil { + applogger.Error("%v SubscribeShareUs.Set.price:%v", common.ErrShareUs, err) + } + if !flags.CheckSetting { + applogger.Debug("涨跌幅交易对内存key:%v,涨跌幅数值:%v", symbolStr, sub) + } + + // 交易类型:0最新价,1买入,2卖出 + price := publicData.SymbolCache(flags.Us, symbolStr, flags.TradeTypePrice) + switch check { + case flags.RealTime: // 实时价格(优先级高) + if err = memory.ShareUsCache.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeUsPrice.ShareUsCache:%v", common.ErrShareUs, err) + } + case flags.SetUp: // 设置[盘前|盘后]价格 + if err = memory.ShareUsPriceSetUp.Set(price, []byte(setPrice)); err != nil { + applogger.Error("%v SubscribeUsPrice.ShareUsPriceSetUp:%v", common.ErrShareUs, err) + } + } + if !flags.CheckSetting { + applogger.Info("股票交易对内存Key:%v,最新价格:%v", price, setPrice) + } +} + +// SubscribeUsSetForcedClosure +// +// @Description: TODO: 处理美股强平阈值 +// @param symbolStr +func SubscribeUsSetForcedClosure(symbolStr string) { + flatRatio := GetCacheForcedClosure(flags.StockUsSystemSetUpKey, symbolStr) + chgKey := publicData.SymbolCache(flags.Us, symbolStr, flags.TradeTypeForcedClosure) + if err := memory.ShareUsForcedClosure.Set(chgKey, []byte(flatRatio.String())); err != nil { + applogger.Error("%v SubscribeUsSetForcedClosure.StockUsSystemSetUpKey err:%v", common.ErrShareUs, err) + return + } +} + +// ShareUsTransactionEntrust +// +// @Description: 美股委托订单 +// @param ctx +func ShareUsTransactionEntrust(ctx context.Context) { + for { + ShareUsTransactionCalculationEntrust(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareUsTransactionCalculationEntrust +// +// @Description: 美股挂单缓存队列计算 +// @param ctx +func ShareUsTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + // 全局变量处理 + if CheckGlobalTread(flags.UsMarket) { + time.Sleep(5 * time.Second) + return + } + // 获取挂单缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareUsEntrust).Result() + if err != nil { + applogger.Error("%v ShareUsTransactionCalculationEntrust.HGetAll:%v", common.ErrShareUs, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareUsTallyCache, 1) + var entrust share.ShareUsTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareUsTransactionCalculationEntrust.Unmarshal:%v", common.ErrShareUs, err) + continue + } + + // 股票实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareUsPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareUsTransactionCalculationPosition.GetShareUsPrice:%v----%v", common.ErrShareUs, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + //chg := GetShareChgUs(flags.Us, entrust.Symbol) // 涨跌幅标识 + //if share.CheckOrderByChg(setting.MarketShareUsEntrust, entrust, chg) { + // applogger.Warn("当前股票订单在挂单状态已达到涨跌幅上限:%v,%v,%v", entrust.Symbol, chg, setting.MarketShareUsEntrust) + // continue + //} + + wg.Add(1) + go func(value string) { + var resultMsg share.ShareUsTallyCache + switch entrust.Order.DealType { + case flags.DealTypeLimited: // 限价挂单 + resultMsg = ShareUsConcurrentComputingEntrustLimited(&entrust, newPrice, &wg) + case flags.DealTypeMarket: // 市价挂单(开盘即成交) + resultMsg = ShareUsConcurrentComputingEntrustMarket(&entrust, newPrice, &wg) + } + msg <- resultMsg // 通知管道异步处理订单操作 + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Debug("从信道接收美股挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Debug("从信道接收到美股持仓信息:%v", resultMsg) + } + + // 开盘逻辑 + if err = ShareUsLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareUsTransactionCalculationEntrust.ShareUsLiquidationEntrust:%v", common.ErrShareUs, err) + continue + } + + var byteStr []byte + byteStr, err = json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v ShareUsTransactionCalculationEntrust.Marshal:%v", common.ErrShareUs, err) + continue + } + + // TODO: 写入持仓消息队列 + //if err = uo.mqProducer.Entrust.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareUsTransactionCalculationEntrust.EntrustPushNotice:%v", common.ShareUsError, err) + // continue + //} + + // 写入持仓队列缓存 + if err = Reds.HSet(context.Background(), setting.MarketShareUsPosition, resultMsg.OrderId, string(byteStr)).Err(); err != nil { + continue + } + } + } + } + + wg.Wait() + applogger.Info("美股挂单并发计算执行完毕......") +} + +// ShareUsConcurrentComputingEntrustLimited +// +// @Description: +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareUsTallyCache +func ShareUsConcurrentComputingEntrustLimited(order *share.ShareUsTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareUsTallyCache { + var deleteCache bool + var dealPrice string + var limitPrice = decimal.RequireFromString(order.Order.LimitPrice) // 限价-价格 + var status = order.Status // 原始价格 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价买入逻辑判定 -> 挂单金额 > 当前价格 + if limitPrice.Cmp(newPrice) > 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + } + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价卖入逻辑判定 -> 挂单金额 < 当前价格 + if limitPrice.Cmp(newPrice) < 0 { + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareUsEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareUsConcurrentComputingEntrustLimited.MarketShareUsEntrust.HDel:%v", common.ErrShareUs, err) + order.Status = status + } + } + + wg.Done() + return share.ShareUsTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareUsConcurrentComputingEntrustMarket +// +// @Description: 美股市价下单进入挂单队列(休市) +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareUsTallyCache +func ShareUsConcurrentComputingEntrustMarket(order *share.ShareUsTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareUsTallyCache { + var deleteCache bool + var dealPrice string + var marketPrice = decimal.RequireFromString(order.Order.MarketPrice) // 市价-价格 + var status = order.Status // 原始价格 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价买入下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 开仓价格 + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Debug("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,原始状态:%v", order.UserId, marketPrice, newPrice, order.Status) + } + + deleteCache = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 开仓价格 + } + + if deleteCache { + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareUsEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareUsConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareUs, err) + order.Status = status + } + } + + wg.Done() + return share.ShareUsTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareBlockUsConcurrentComputingEntrustMarket +// +// @Description: 大宗(美股)挂单成交 +// @param order +// @param newPrice +// @param wg +// @return share.ShareUsTallyCache +func ShareBlockUsConcurrentComputingEntrustMarket(order *share.ShareUsTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) share.ShareUsTallyCache { + var status = order.Status // 原始状态 + + order.Status = flags.Position + if err := Reds.HDel(context.Background(), setting.MarketShareBlkEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareBlockUsConcurrentComputingEntrustMarket.HDel:%v", common.ErrShareBlk, err) + order.Status = status + } + + wg.Done() + return share.ShareUsTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: newPrice.String(), // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareUsMqOpenBusiness +// +// @Description: TODO: 美股持仓消息队列 +// @param ctx +// @param uo +func ShareUsMqOpenBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Entrust.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerEntrustMq.ShareUsMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareUsMqOpenBusiness.ShareUsMq err....", common.ErrShareUs) + continue + } + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareUsTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareUsMqOpenBusiness.Unmarshal:%v", common.ErrShareUs, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareUsLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareUsMqOpenBusiness.ShareUsLiquidationPosition:%v", common.ErrShareUs, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + applogger.Info("这里没有监控到持仓mq队列消息.........") + time.Sleep(2 * time.Second) + } + } +} + +// ShareUsLiquidationEntrust +// +// @Description: 美股挂单-->开仓业务处理 +// @param ctx +// @param order +// @return error +func ShareUsLiquidationEntrust(ctx context.Context, order *share.ShareUsTallyCache) error { + // 1、开盘 + err := StockOpenOrder(ctx, Msql, order.UserId, order.OrderId, order.OpenPrice, order.Order) + if err != nil { + applogger.Error("%v ShareUsLiquidationEntrust.StockOpenOrder:%v", common.ErrShareUs, err) + return err + } + + // 大宗(美股)交易判定 + var entrustKey, adminKey string + if !CheckTypeStatus(order.Order.Type) { + entrustKey = setting.ShareUsSubscribe + adminKey = setting.AdminShareUsSubscribe + } else { + entrustKey = setting.ShareBlkSubscribe + adminKey = setting.AdminShareBlkSubscribe + } + + // 2、更新用户订阅缓存列表订单状态 + updateKey := virtual.OrderIdListKey(entrustKey, order.UserId) + if err = UpdateShareUsSubscribeHashStatusByOrderId(order.OrderId, updateKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareUsLiquidationEntrust.Entrust.%v:%v", common.ErrShareUs, entrustKey, err) + return err + } + + // 3、更新管理员订阅缓存列表订单状态 + if err = UpdateShareUsSubscribeHashStatusByOrderId(order.OrderId, adminKey, flags.Position, order.OpenPrice); err != nil { + applogger.Error("%v ShareUsLiquidationEntrust.Entrust.%v:%v", common.ErrShareUs, adminKey, err) + return err + } + + return nil +} + +// ShareUsTransactionPosition +// +// @Description: 美股持仓订单 +// @param ctx +func ShareUsTransactionPosition(ctx context.Context) { + for { + ShareUsTransactionCalculationPosition(ctx) + time.Sleep(600 * time.Millisecond) + } +} + +// ShareUsTransactionCalculationPosition +// +// @Description: 美股持仓缓存队列计算 +// @param ctx +func ShareUsTransactionCalculationPosition(ctx context.Context) { + var wg sync.WaitGroup + + // 判定是否交易 + if CheckGlobalTread(flags.UsMarket) { + time.Sleep(5 * time.Second) + return + } + + // TODO: 获取IPO未支付订单缓存 + userIdMap, _ := GetBotUserArrears(ctx) + + // 获取持仓缓存列表 + orderMap, err := Reds.HGetAll(context.Background(), setting.MarketShareUsPosition).Result() + if err != nil { + applogger.Error("%v ShareUsTransactionCalculationPosition.HGetAll:%v", common.ErrShareUs, err) + return + } + + for _, value := range orderMap { + var msg = make(chan share.ShareUsTallyCache, 1) + var entrust share.ShareUsTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ShareUsTransactionCalculationPosition.Unmarshal:%v", common.ErrShareUs, err) + continue + } + + // TODO: 判定是否未IPO未支付订单-不能平仓 + _, isOk := userIdMap[entrust.UserId] + if isOk { + continue + } + + // 处理时间 + if !CheckShareSystemTime(entrust.ClosingTime) { + applogger.Warn("美股:%v,平仓时间:%v暂未到达...", entrust.Symbol, entrust.ClosingTime) + continue + } + + // TODO: 实时获取强平阈值 + //entrust.Order.System.StrongFlatRatio = GetForcedClosureValue(flags.Us, entrust.Symbol) + + // 股票实时价格 + var newPrice decimal.Decimal + newPrice, err = GetShareUsPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ShareUsTransactionCalculationPosition.Get:%v---%v", common.ErrShareUs, entrust.Symbol, err) + continue + } + + // 判定涨跌幅 + //chg := GetShareChgUs(flags.Us, entrust.Symbol) // 涨跌幅标识 + //if share.CheckOrderByChg(setting.MarketShareUsEntrust, entrust, chg) { + // continue + //} + + // 判定配额强平 + checkFlattening := GetStrongFlatteningThreshold(entrust.UserId) + + wg.Add(1) + go func(value string) { + resultMsg := ShareUsConcurrentComputingPosition(&entrust, newPrice, &wg, checkFlattening) + msg <- resultMsg + }(value) + + // 处理并发结果 + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Position: // 持仓 + if !flags.CheckSetting { + applogger.Info("从信道接收到美股持仓信息:%v", resultMsg) + } + case flags.Close: // 平仓 + if !flags.CheckSetting { + applogger.Info("从信道接收到美股平仓信息:%v", resultMsg) + } + + // TODO: 平仓操作(优化写入队列中等待平仓) + //var byteStr []byte + //byteStr, err = json.Marshal(resultMsg) + //if err != nil { + // applogger.Error("%v ShareUsTransactionCalculationPosition.Marshal:%v", common.ShareUsError, err) + // continue + //} + //if err = uo.mqProducer.Position.PushNotice(byteStr); err != nil { + // applogger.Error("%v ShareUsTransactionCalculationPosition.DealPublish:%v", common.ShareUsError, err) + // continue + //} + + // 平仓操作 + if err = ShareUsLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareUsTransactionCalculationPosition.ShareUsLiquidationPosition:%v", common.ErrShareUs, err) + continue + } + } + } + } + + wg.Wait() + applogger.Info("美股持仓并发计算执行完毕......") +} + +// ShareUsConcurrentComputingPosition +// +// @Description: 美股持仓缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ShareUsTallyCache +func ShareUsConcurrentComputingPosition(order *share.ShareUsTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup, checkFlattening bool) share.ShareUsTallyCache { + var deleteCache, checkBool bool + var dealPrice string + var sellShort decimal.Decimal + var openPrice = decimal.RequireFromString(order.OpenPrice) // 限价 + var orderNumber = decimal.RequireFromString(order.Order.OrderNumber) // 仓位 + + var pryNum decimal.Decimal + lenPryNum := len(utils.ReplaceStr(order.Order.PryNum)) == 0 + if lenPryNum || order.Order.PryNum == flags.SetZero || order.Order.System.UserStatus != flags.SetThree || !utils.IsNumberInt(order.Order.PryNum) { + pryNum = decimal.RequireFromString(flags.SetOne) + } else { + pryNum = decimal.RequireFromString(order.Order.PryNum) + } + + // 下单判定设置(false无设置|true止盈止损) + _, stopWinPrice, stopLossPrice, _ := StockVoteStopType(order.Order) + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨(强平) + if !flags.CheckSetting { + applogger.Info("用户ID:%v,持仓开仓价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买涨:挂止损止盈,止盈价必须<当前价,止损价必须>当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + // 强行平仓(做多) + if !checkBool { + sellShort = newPrice.Sub(openPrice).Mul(orderNumber) + } + case flags.TradeTypeSell: // 买跌(存在强行平仓) + if !flags.CheckSetting { + applogger.Info("用户ID:%v,限价持仓买跌下单价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + // 买跌:挂止损止盈,止盈价必须>当前价,止损价必须<当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) > 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) < 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) // 设置价差 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + } + } + // 强行平仓(做空) + if !checkBool { + sellShort = openPrice.Sub(newPrice).Mul(orderNumber) + } + } + /* 强行平仓(做多|做空) + 1、做多:(最新成交价-开仓成交价)*仓位 + 2、做空:(开仓成交价-最新成交价)*仓位 + 3、当浮动盈亏 >= 保证金的70%订单强行平仓 + */ + if sellShort.IsNegative() && checkFlattening { + orderAmount := newPrice.Mul(decimal.RequireFromString(order.Order.OrderNumber)).Div(pryNum) // 订单金额 = 当前价格 * 订单数量 / 杠杆 + floatPrice := orderAmount.Mul(decimal.RequireFromString(order.Order.System.StrongFlatRatio)) + if !flags.CheckSetting { + applogger.Info("强平保证金:%v,强平浮动70:%v,强行平仓判定:%v", orderAmount, floatPrice, sellShort.Abs().Cmp(floatPrice)) + } + if sellShort.Abs().Cmp(floatPrice) >= 0 { + checkBool = true + difference := newPrice.Mul(utils.Difference()) + switch order.Order.TradeType { + case flags.TradeTypeBuy: //买涨 + dealPrice = newPrice.Sub(difference).String() // 平仓价格 + case flags.TradeTypeSell: // 买跌 + dealPrice = newPrice.Add(difference).String() // 平仓价格 + } + } + } + + if checkBool { + deleteCache = true + order.Status = flags.Close + } + + if deleteCache { + // 根据订单ID-删除持仓列表缓存订单 + if err := Reds.HDel(context.Background(), setting.MarketShareUsPosition, order.OrderId).Err(); err != nil { + applogger.Error("%v ShareUsConcurrentComputingPosition.Position.HDel:%v", common.ErrShareUs, err) + } + } + + wg.Done() + return share.ShareUsTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + ClosingPrice: dealPrice, // 平仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + ClosingTime: order.ClosingTime, // 平仓时间 + } +} + +// ShareUsMqClosingBusiness +// +// @Description: TODO: 处理美股平仓消息队列 +// @param ctx +// @param uo +func ShareUsMqClosingBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Position.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerPositionMq.ShareUsMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ShareUsMqClosingBusiness.ShareUsMq err....", common.ErrShareUs) + continue + } + + // 持仓订单缓存数据序列化解析 + var resultMsg share.ShareUsTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ShareUsMqClosingBusiness.Unmarshal:%v", common.ErrShareUs, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ShareUsLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ShareUsMqClosingBusiness.ShareUsLiquidationPosition:%v", common.ErrShareUs, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + applogger.Info("这里没有监控到消息mq队列消息.........") + time.Sleep(2 * time.Second) + } + } +} + +// ShareUsLiquidationPosition +// +// @Description: 美股持仓-->平仓业务处理 +// @param ctx +// @param order +// @return error +func ShareUsLiquidationPosition(ctx context.Context, order *share.ShareUsTallyCache) error { + // 1、平仓操作 + err := StockClosingOrder(ctx, Msql, order.OrderId, order.ClosingPrice, order.Order) + if err != nil { + applogger.Error("%v ShareUsLiquidationPosition.StockClosingOrder:%v", common.ErrShareUs, err) + return err + } + + // 2、平仓更新用户订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ShareUsSubscribe, order.UserId) + if err = UpdateShareUsSubscribeHashStatusByOrderId(order.OrderId, userSubKey, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v ShareUsLiquidationPosition.Position.ShareUsSubscribe:%v", common.ErrShareUs, err) + return err + } + + // 3、平仓更新管理员订阅订单状态 + if err = UpdateShareUsSubscribeHashStatusByOrderId(order.OrderId, setting.AdminShareUsSubscribe, flags.Close, flags.SetNull); err != nil { + applogger.Error("%v ShareUsLiquidationPosition.Position.AdminShareUsSubscribe:%v", common.ErrShareUs, err) + return err + } + + return nil +} + +// StockVoteStopType +// +// @Description: 美股判定取值止损止盈 +// @param order +// @return bool +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func StockVoteStopType(order structure.ShareOrder) (bool, decimal.Decimal, decimal.Decimal, error) { + var checkBool bool + var stopWinPrice, stopLossPrice decimal.Decimal + switch order.StopType { + case flags.StopTypeNone: // 暂无设置止盈止损 + checkBool = false + case flags.StopTypeSet: // 设置止盈止损 + checkBool = true + stopWinPrice, _ = decimal.NewFromString(order.StopWinPrice) + stopLossPrice, _ = decimal.NewFromString(order.StopLossPrice) + default: + return checkBool, stopWinPrice, stopLossPrice, flags.ErrContractThirteen + } + + return checkBool, stopWinPrice, stopLossPrice, nil +} + +// GetShareUsPrice +// +// @Description: 获取美股股票价格 +// @param symbol +// @return decimal.Decimal +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func GetShareUsPrice(symbol string) (decimal.Decimal, error) { + var err error + var priceByte []byte + var newPrice decimal.Decimal + + key := publicData.SymbolCache(flags.Us, symbol, flags.TradeTypePrice) + priceByte, err = memory.GetShareUsCache(key) + if err != nil { + return decimal.Decimal{}, err + } + + newPrice, err = decimal.NewFromString(string(priceByte)) + if err != nil { + return decimal.Decimal{}, err + } + + applogger.Info("shareUsCode:%v,topIc:%v,shareUsPrice:%v", symbol, key, newPrice) + + return newPrice, nil +} diff --git a/internal/data/subscribe_virtual_contract.go b/internal/data/subscribe_virtual_contract.go new file mode 100644 index 0000000..3de6092 --- /dev/null +++ b/internal/data/subscribe_virtual_contract.go @@ -0,0 +1,862 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/mq/consumer" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/socket/virtualData" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "sync" + "time" +) + +/* +合约行情订阅 +1、初始化现货订阅信息 +2、接收用户现货下单的交易对 +3、根据交易对订阅现货行情数据 +4、写入内存中用于并发计算 +5、记录在热缓存中 +*/ + +// QuitesContract +// @Description: +type QuitesContract struct { + ServersID string `json:"serversId"` + Content struct { + Ch string `json:"ch"` + Ts int64 `json:"ts"` + Tick struct { + ID int `json:"id"` + Mrid int64 `json:"mrid"` + Open string `json:"open"` + Close string `json:"close"` + High string `json:"high"` + Low string `json:"low"` + Amount string `json:"amount"` + Vol string `json:"vol"` + TradeTurnover string `json:"trade_turnover"` + Count int `json:"count"` + Asks any `json:"asks"` + Bids any `json:"bids"` + } `json:"Tick"` + } `json:"content"` + Symbol string `json:"symbol"` +} + +// ContractSymbol +// @Description: +type ContractSymbol struct { + ContractMap chan []byte // 合约订单交易对 -- 用户合约下单通知订阅 + ContractMapSymbol sync.Map // 合约订阅交易对簿 +} + +// ContractSetUp +// @Description: +type ContractSetUp struct { + SelfContractCode string `json:"selfContractCode"` // 合约交易对 + BeginTime string `json:"BeginTime"` // 开始时间 + Step int `json:"Step"` // 设置时间间隔 + EndTime string `json:"EndTime"` // 结束时间 + Price string `json:"Price"` // 设置价格 +} + +// InitCacheSymbolContract +// +// @Description: +// @param ctx +// @param uo +func InitCacheSymbolContract(ctx context.Context, uo *Data) { + contractList, err := GetBotContractList(ctx, uo) + if err != nil { + return + } + + for _, value := range contractList { + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := uo.redisDB.HExists(context.Background(), setting.MarketContract, value).Result() + if err != nil { + applogger.Error("%v InitCacheSymbolSpots.MarketContract.HExists:%v", common.ErrContract, err) + return + } + applogger.Info("初始化合约交易对:%v", value) + + if !checkBool { + if err = uo.redisDB.HSet(context.Background(), setting.MarketContract, value, value).Err(); err != nil { + applogger.Error("%v InitCacheSymbolSpots.HSet:%v", common.ErrContract, err) + return + } + } + } +} + +// InitSubscribeQuotesContract +// +// @Description: +// @param ctx +// @param uo +// @param contract +func InitSubscribeQuotesContract(contract *ContractSymbol) { + for { + listSpots, err := LoadLRangeList(setting.MarketContract) + if err != nil { + applogger.Error("%v InitSubscribeQuotesContract.LoadLRangeList:%v", common.ErrContract, err) + return + } + + for _, value := range listSpots { + // Prevent duplicate subscription to CtrIp + _, ok := contract.ContractMapSymbol.Load(value) + if ok { + continue + } + + contract.ContractMap <- []byte(value) + } + + time.Sleep(10 * time.Second) + } +} + +// SubscribeQuotesContract +// +// @Description: 合约订阅 +// @param ctx +// @param uo +// @param contract +func SubscribeQuotesContract(ctx context.Context, uo *Data, contract *ContractSymbol) { + for { + select { + case symbol, _ := <-contract.ContractMap: + symbolStr := string(symbol) + + // Prevent duplicate subscription to CtrIp + _, ok := contract.ContractMapSymbol.Load(symbolStr) + if ok { + time.Sleep(5 * time.Second) + continue + } + + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := uo.redisDB.HExists(context.Background(), setting.MarketContract, symbolStr).Result() + if err != nil { + applogger.Error("%v SubscribeQuotesContract.MarketContract.HExists:%v", common.ErrContract, err) + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err = uo.redisDB.HSet(context.Background(), setting.MarketContract, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeQuotesContract.MarketContract.HSet:%v", common.ErrContract, err) + time.Sleep(5 * time.Second) + continue + } + } + + // 订阅插针价格 + go func() { + for { + var data string + data, err = uo.redisDB.Get(context.Background(), flags.ContractSystemPriceSetUp).Result() + if err != nil || data == "[]" { + time.Sleep(5 * time.Second) + continue + } + var dataList []ContractSetUp + if err = json.Unmarshal([]byte(data), &dataList); err != nil { + time.Sleep(5 * time.Second) + continue + } + for _, value := range dataList { + checkStart := len(utils.StrReplace(value.BeginTime)) + checkEnd := len(utils.StrReplace(value.EndTime)) + if checkStart == 0 || checkEnd == 0 { + continue + } + if value.SelfContractCode == symbolStr { + // Determine if it is the current subscription type + priceKey := publicData.SymbolCache(flags.Hy, symbolStr, flags.TradeTypePrice) + if !utils.CheckTimeUTC(value.BeginTime, value.EndTime) { + continue + } + if err = memory.ContractPriceSetUp.Set(priceKey, []byte(utils.DecimalsPrice(value.Price))); err != nil { + applogger.Error("%v SubscribeQuotesContract.ContractPriceSetUp.set:%v", common.ErrContract, err) + continue + } + if !flags.CheckSetting { + applogger.Info("当前写入插针最新价格:%v,%v", priceKey, value.Price) + } + } + } + time.Sleep(2 * time.Second) + } + }() + + // 订阅实时价格 + go func() { + topIc := fmt.Sprintf("market.%v.detail", utils.ReplaceStrByValue(symbolStr, "/")) + pubSub := uo.redisDB.Subscribe(ctx, topIc) + defer pubSub.Close() + if _, err = pubSub.Receive(ctx); err != nil { + applogger.Error("%v SubscribeQuotesContract.Receive:%v", common.ErrContract, err) + return + } + chp := pubSub.Channel() + for msg := range chp { + var subMsg QuitesContract + if err = json.Unmarshal([]byte(msg.Payload), &subMsg); err != nil { + applogger.Error("%v SubscribeQuotesContract.QuitesContract.Unmarshal:%v", common.ErrContract, err) + close(contract.ContractMap) + return + } + // 交易类型:0最新价,1买入,2卖出 + price := publicData.SymbolCache(flags.Hy, symbolStr, flags.TradeTypePrice) + if err = memory.ContractCache.Set(price, []byte(subMsg.Content.Tick.Close)); err != nil { + applogger.Error("%v SubscribeQuotesContract.Set:%v", common.ErrContract, err) + continue + } + if !flags.CheckSetting { + applogger.Info("当前写入最新价格:%v,%v", price, subMsg.Content.Tick.Close) + } + } + }() + + // Write in the map to determine whether to repeat subscription + contract.ContractMapSymbol.Store(symbolStr, symbolStr) + } + } +} + +// OrderSubAdminContractSubscribeBySum +// +// @Description: 持仓订单浮动盈亏计算 +// @param ctx +// @param uo +func OrderSubAdminContractSubscribeBySum(uo *Data) { + for { + topIc := setting.AdminContractSubscribe + hashMap, err := uo.redisDB.HGetAll(context.Background(), topIc).Result() + if err != nil { + applogger.Error("orderSubAdminContractSubscribe.HGetAll:%v", err) + time.Sleep(5 * time.Second) + continue + } + var hashList []virtual.ContractTallyCache + for _, value := range hashMap { + var msg virtual.ContractTallyCache + if err = json.Unmarshal([]byte(value), &msg); err != nil { + time.Sleep(5 * time.Second) + continue + } + switch msg.Status { + case flags.Entrust: // 挂单 + case flags.Position: // 持仓 + hashList = append(hashList, msg) + default: // 平仓|撤单 + err = uo.redisDB.HDel(context.Background(), topIc, msg.OrderId).Err() + if err != nil { + applogger.Error("AdminContractSubscribe.HDel:%v", err) + continue + } + } + } + applogger.Info("合约数据量统计:%v", len(hashList)) + // 统计合约总持仓订单浮动盈亏 + priceSum := decimal.Zero + for _, value := range hashList { + orderModel := virtualData.ContractOrderProcessing(topIc, value) + if orderModel != nil { + var subPrice decimal.Decimal + newPrice, err := decimal.NewFromString(orderModel.Price) + if err != nil { + continue + } + openPrice, err := decimal.NewFromString(orderModel.OpenPrice) + if err != nil { + continue + } + switch value.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 = 新价格 - 开仓价 + subPrice = newPrice.Sub(openPrice) + case flags.TradeTypeSell: // 卖跌 = 开仓价 - 新价格 + subPrice = openPrice.Sub(newPrice) + default: + subPrice = decimal.Zero + } + orderNumber := decimal.RequireFromString(value.Order.OrderNumber) + pryNum := decimal.RequireFromString(value.Order.PryNum) + price := subPrice.Mul(orderNumber).Mul(pryNum) // 合约浮动盈亏计算 + priceSum = priceSum.Add(price) // 累加盈亏统计 + } + } + // 写入缓存 + if err = memory.ContractFloating.Set(flags.FloatingHy, []byte(priceSum.String())); err != nil { + applogger.Error("统计合约持仓订单浮动盈亏错误:%v", err) + time.Sleep(5 * time.Second) + continue + } + applogger.Info("统计合约持仓订单浮动盈亏:%v", priceSum) + + time.Sleep(600 * time.Millisecond) + } +} + +// ContractTransactionEntrust +// +// @Description: 合约委托订单 +// @param ctx +func ContractTransactionEntrust(ctx context.Context) { + for { + ContractTransactionCalculationEntrust(ctx) + time.Sleep(400 * time.Millisecond) + } +} + +// ContractTransactionCalculationEntrust +// +// @Description: +// @param ctx +func ContractTransactionCalculationEntrust(ctx context.Context) { + var wg sync.WaitGroup + + entrustList, err := Reds.HGetAll(context.Background(), setting.MarketContractEntrust).Result() + if err != nil { + applogger.Error("%v ContractTransactionCalculationEntrust.HGetAll:%v", common.ErrContract, err) + return + } + + for _, value := range entrustList { + var msg = make(chan virtual.ContractTallyCache, 1) + var entrust virtual.ContractTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ContractTransactionCalculationEntrust.Unmarshal:%v", common.ErrContract, err) + continue + } + + var newPrice decimal.Decimal + newPrice, err = GetContractPrice(entrust.Symbol) + if err != nil { + applogger.Error("%v ContractTransactionCalculationPosition.GetContractPrice:%v", common.ErrContract, err) + continue + } + + wg.Add(1) + go func(value string) { + resultMsg := ContractConcurrentComputingEntrust(&entrust, newPrice, &wg) + msg <- resultMsg // 通知管道异步处理订单操作 + }(value) + + // 处理并发结果(需要改成通过信道通知) + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: // 挂单中 + if !flags.CheckSetting { + applogger.Info("从信道接收合约挂单信息:%v", resultMsg) + } + case flags.Position: // 持仓中 + if !flags.CheckSetting { + applogger.Info("从信道接收到合约持仓信息:%v", resultMsg) + } + + // 处理开仓逻辑 + if err = ContractLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ContractTransactionCalculationEntrust.ContractLiquidationEntrust:%v", common.ErrContract, err) + continue + } + // 写入持仓缓存列表 + data, err := json.Marshal(resultMsg) + if err != nil { + applogger.Error("%v ContractTransactionCalculationEntrust.Marshal:%v", common.ErrContract, err) + continue + } + + // TODO: 写入持仓消息列表 + //if err = uo.mqProducer.Entrust.PushNotice(data); err != nil { + // applogger.Error("%v ContractTransactionCalculationEntrust.PushNotice:%v", common.ContractError, err) + // continue + //} + + // 写入合约持仓缓存队列 + if err = Reds.HSet(context.Background(), setting.MarketContractPosition, resultMsg.OrderId, string(data)).Err(); err != nil { + applogger.Error("%v ContractTransactionCalculationEntrust.MarketContractPosition.HSet:%v", common.ErrContract, err) + continue + } + } + } + } + + wg.Wait() + applogger.Info("合约挂单并发计算执行完毕......") +} + +// ContractConcurrentComputingEntrust +// +// @Description: 合约挂单缓存列表业务处理 +// @param order +// @param orderOld +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ContractTallyCache +func ContractConcurrentComputingEntrust(order *virtual.ContractTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) virtual.ContractTallyCache { + var deleteCache bool + var dealPrice string + var limitPrice = decimal.RequireFromString(order.Order.LimitPrice) // 限价-价格 + var status = order.Status // 原始价格 + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨 + if !flags.CheckSetting { + applogger.Info("用户ID:%v,限价买入下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价买入逻辑判定 -> 挂单金额 > 当前价格 + if limitPrice.Cmp(newPrice) > 0 { + deleteCache = true + //difference := newPrice.Mul(utils.Difference()) // 设置价差 + //dealPrice = newPrice.Add(difference).String() // 开仓价格 + dealPrice = limitPrice.String() // 开仓价格 + } + case flags.TradeTypeSell: // 买跌 + if !flags.CheckSetting { + applogger.Info("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, newPrice, limitPrice.Cmp(newPrice), order.Status) + } + + // 限价卖入逻辑判定 -> 挂单金额 < 当前价格 + if limitPrice.Cmp(newPrice) < 0 { + deleteCache = true + //difference := newPrice.Mul(utils.Difference()) // 设置价差 + //dealPrice = newPrice.Sub(difference).String() // 开仓价格 + dealPrice = limitPrice.String() // 开仓价格 + } + } + + if deleteCache { + order.Status = flags.Position + // 删除挂单缓存列表 + if err := Reds.HDel(context.Background(), setting.MarketContractEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v ContractConcurrentComputingEntrust.MarketContractEntrust.HDel:%v", common.ErrContract, err) + order.Status = status + dealPrice = decimal.Zero.String() + } + } + + wg.Done() + return virtual.ContractTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + OpenPrice: dealPrice, // 开仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + } +} + +// ContractMqOpenBusiness +// +// @Description: TODO: 合约持仓消息队列 +// @param ctx +// @param uo +func ContractMqOpenBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Entrust.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerEntrustMq.ContractMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ContractMqOpenBusiness.ContractMq err....", common.ErrContract) + continue + } + + // 持仓订单缓存数据序列化解析 + var resultMsg virtual.ContractTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ContractMqOpenBusiness.Unmarshal:%v", common.ErrContract, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ContractLiquidationEntrust(ctx, &resultMsg); err != nil { + applogger.Error("%v ContractMqOpenBusiness.ContractLiquidationEntrust:%v", common.ErrContract, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + applogger.Error("这里没有监控到持仓mq队列消息.........") + time.Sleep(2 * time.Second) + } + } +} + +// ContractLiquidationEntrust +// +// @Description: 合约挂单-->开仓业务处理 +// @param ctx +// @param order +// @return error +func ContractLiquidationEntrust(ctx context.Context, order *virtual.ContractTallyCache) error { + // 1、合约开仓操作 + err := ContractOpenPosition(ctx, Msql, order.UserId, order.OrderId, order.OpenPrice, order.Order) + if err != nil { + applogger.Error("%v ContractLiquidationEntrust.ContractOpenPosition:%v", common.ErrContract, err) + return err + } + + // 2、开仓更新用户合约订阅缓存订单状态 + userSubKey := virtual.OrderIdListKey(setting.ContractSubscribe, order.UserId) + if err = UpdateContractSubscribeHashStatusByOrderId(order.OrderId, userSubKey, flags.Position, order.ClosingPrice); err != nil { + applogger.Error("%v ContractLiquidationEntrust.ContractSubscribe:%v", common.ErrContract, err) + return err + } + + // 3、开仓更新管理员合约订阅缓存订单状态 + if err = UpdateContractSubscribeHashStatusByOrderId(order.OrderId, setting.AdminContractSubscribe, flags.Position, order.ClosingPrice); err != nil { + applogger.Error("%v ContractLiquidationEntrust.AdminContractSubscribe:%v", common.ErrContract, err) + return err + } + + return nil +} + +// ContractTransactionPosition +// +// @Description: 合约-持仓业务处理 +// @param ctx +func ContractTransactionPosition(ctx context.Context) { + for { + ContractTransactionCalculationPosition(ctx) + time.Sleep(400 * time.Millisecond) + } +} + +// ContractTransactionCalculationPosition +// +// @Description: 监控合约持仓缓存列表(注意:止盈止损|强行平仓) +// @param ctx +func ContractTransactionCalculationPosition(ctx context.Context) { + var wg sync.WaitGroup + + entrustList, err := Reds.HGetAll(context.Background(), setting.MarketContractPosition).Result() + if err != nil { + applogger.Error("%v ContractTransactionCalculationPosition.LRange:%v", common.ErrContract, err) + return + } + + for _, value := range entrustList { + var msg = make(chan virtual.ContractTallyCache, 1) + var entrust virtual.ContractTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v ContractTransactionCalculationPosition.Unmarshal:%v", common.ErrContract, err) + continue + } + + var newPrice decimal.Decimal + newPrice, err = GetContractPrice(entrust.Symbol) + if err != nil { + applogger.Warn("%v ContractTransactionCalculationPosition.GetContractPrice:%v", common.ErrContract, err) + continue + } + + wg.Add(1) + go func(value string) { + resultMsg := ContractConcurrentComputingPosition(&entrust, newPrice, &wg) + msg <- resultMsg + }(value) + + // 处理并发结果 + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Position: // 持仓 + if !flags.CheckSetting { + applogger.Info("从信道接收到合约持仓信息:%v", resultMsg) + } + case flags.Close: // 平仓 + if !flags.CheckSetting { + applogger.Info("从信道接收到合约平仓信息:%v", resultMsg) + } + + // TODO: 平仓操作(优化写入队列中等待平仓) + //var byteStr []byte + //byteStr, err = json.Marshal(resultMsg) + //if err != nil { + // applogger.Error("%v ContractTransactionCalculationPosition.Marshal:%v", common.ContractError, err) + // continue + //} + //if err = uo.mqProducer.Position.PushNotice(byteStr); err != nil { + // applogger.Error("%v ContractTransactionCalculationPosition.PushNotice:%v", common.ContractError, err) + // continue + //} + + if err = ContractLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ContractTransactionCalculationPosition.ContractLiquidationPosition:%v", common.ErrContract, err) + continue + } + } + } + } + + wg.Wait() + applogger.Info("合约持仓并发计算执行完毕......") +} + +// ContractConcurrentComputingPosition +// +// @Description: 合约持仓缓存列表业务处理 +// @param order +// @param newPrice +// @param wg +// @return tradedeal.ContractTallyCache +func ContractConcurrentComputingPosition(order *virtual.ContractTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) virtual.ContractTallyCache { + var deleteCache, checkBool bool + var dealPrice string + var sellShort decimal.Decimal + var openPrice = decimal.RequireFromString(order.OpenPrice) // 限价 + var orderNumber = decimal.RequireFromString(order.Order.OrderNumber) // 仓位 + var status = order.Status // 原始状态 + var pryNum = decimal.RequireFromString(order.Order.PryNum) // 杠杆数 + + // 下单判定设置(false无设置|true止盈止损) + _, stopWinPrice, stopLossPrice, _ := ContractVoteStopType(order.Order) + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // 买涨(强平) + if !flags.CheckSetting { + applogger.Info("用户ID:%v,持仓开仓价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + + // 买涨挂止损止盈,止盈价必须<当前价,止损价必须>当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) < 0 { + checkBool = true + //difference := newPrice.Mul(utils.Difference()) // 设置价差 + //dealPrice = newPrice.Sub(difference).String() // 平仓价格 + dealPrice = newPrice.String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) > 0 { + checkBool = true + //difference := newPrice.Mul(utils.Difference()) // 设置价差 + //dealPrice = newPrice.Add(difference).String() // 平仓价格 + dealPrice = newPrice.String() // 平仓价格 + } + } + // 强行平仓(做多) + if !checkBool { + sellShort = newPrice.Sub(openPrice).Mul(orderNumber).Mul(order.Order.System.FaceValue).Mul(pryNum) + } + case flags.TradeTypeSell: // 买跌(存在强行平仓) + if !flags.CheckSetting { + applogger.Info("用户ID:%v,限价持仓买跌下单价格:%v,最新市价:%v,止盈:%v,止损:%v,原始状态:%v", order.UserId, openPrice, newPrice, stopWinPrice, stopLossPrice, order.Status) + } + + // 买跌挂止损止盈,止盈价必须>当前价,止损价必须<当前价; + if !stopWinPrice.IsZero() { + if stopWinPrice.Cmp(newPrice) > 0 { + checkBool = true + //difference := newPrice.Mul(utils.Difference()) // 设置价差 + //dealPrice = newPrice.Add(difference).String() // 平仓价格 + dealPrice = newPrice.String() // 平仓价格 + } + } + if !stopLossPrice.IsZero() { + if stopLossPrice.Cmp(newPrice) < 0 { + checkBool = true + //difference := newPrice.Mul(utils.Difference()) // 设置价差 + //dealPrice = newPrice.Sub(difference).String() // 平仓价格 + dealPrice = newPrice.String() // 平仓价格 + } + } + // 强行平仓(做空) + if !checkBool { + sellShort = openPrice.Sub(newPrice).Mul(orderNumber).Mul(order.Order.System.FaceValue).Mul(pryNum) + } + } + /* 强行平仓(做多|做空) + 1、做多:(最新成交价-开仓成交价)*仓位*杠杆 + 1、做空:(开仓成交价-最新成交价)*仓位*杠杆 + 2、当浮动盈亏 >= 保证金的70%订单强行平仓 + */ + if sellShort.IsNegative() { + orderAmount := decimal.RequireFromString(order.Order.EarnestMoney) + floatPrice := orderAmount.Mul(order.Order.System.CompelNum) + if !flags.CheckSetting { + applogger.Info("强平保证金:%v,强平浮动70%:%v,强行平仓判定:%v", orderAmount, floatPrice, sellShort.Abs().Cmp(floatPrice)) + } + if sellShort.Abs().Cmp(floatPrice) >= 0 { + checkBool = true + //difference := newPrice.Mul(utils.Difference()) // 设置价差 + //switch order.Order.TradeType { + //case flags.TradeTypeBuy: //买涨 + //dealPrice = newPrice.Sub(difference).String() // 平仓价格 + //case flags.TradeTypeSell: // 买跌 + //dealPrice = newPrice.Add(difference).String() // 平仓价格 + //} + dealPrice = newPrice.String() // 平仓价格 + } + } + // 判定订单状态 + if checkBool { + deleteCache = true + order.Status = flags.Close + } + + if deleteCache { + // 删除持仓缓存列表数据 + if err := Reds.HDel(context.Background(), setting.MarketContractPosition, order.OrderId).Err(); err != nil { + applogger.Error("%v ContractConcurrentComputingPosition.MarketContractPosition.HDel:%v", common.ErrContract, err) + order.Status = status + } + } + + wg.Done() + return virtual.ContractTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + ClosingPrice: dealPrice, // 平仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + } +} + +// ContractMqClosingBusiness +// +// @Description: TODO: 处理合约平仓消息队列 +// @param ctx +// @param uo +func ContractMqClosingBusiness(ctx context.Context, uo *Data) { + go func() { + uo.mqConsumer.Position.ConsumerNotice() + }() + for { + select { + case message, ok := <-consumer.ConsumerPositionMq.ContractMq: + if !ok { + time.Sleep(5 * time.Second) + applogger.Error("%v ContractMqClosingBusiness.ContractMq err....", common.ErrContract) + continue + } + applogger.Info("接收到平仓信息:%v", string(message)) + + // 持仓订单缓存数据序列化解析 + var resultMsg virtual.ContractTallyCache + if err := json.Unmarshal(message, &resultMsg); err != nil { + applogger.Error("%v ContractMqClosingBusiness.Unmarshal:%v", common.ErrContract, err) + time.Sleep(5 * time.Second) + continue + } + + // 持仓平仓 + if err := ContractLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v ContractMqClosingBusiness.ContractLiquidationPosition:%v", common.ErrContract, err) + continue + } + default: + // TODO: 是否处理空队列缓存的情况 + time.Sleep(2 * time.Second) + } + } +} + +// ContractLiquidationPosition +// +// @Description: 合约平仓操作 +// @param ctx +// @param order +// @return error +func ContractLiquidationPosition(ctx context.Context, order *virtual.ContractTallyCache) error { + // 1、平仓操作 + err := ContractClosingPosition(ctx, Msql, order.OrderId, order.ClosingPrice, order.Order) + if err != nil { + applogger.Error("%v ContractLiquidationPosition.ContractClosingPosition:%v", common.ErrContract, err) + return err + } + + // 2、平仓更新用户合约订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.ContractSubscribe, order.UserId) + if err = UpdateContractSubscribeHashStatusByOrderId(order.OrderId, userSubKey, flags.Close, order.ClosingPrice); err != nil { + applogger.Error("%v ContractLiquidationPosition.ContractSubscribe:%v", common.ErrContract, err) + return err + } + + // 3、平仓更新管理员合约订阅订单状态 + if err = UpdateContractSubscribeHashStatusByOrderId(order.OrderId, setting.AdminContractSubscribe, flags.Close, order.ClosingPrice); err != nil { + applogger.Error("%v ContractLiquidationPosition.AdminContractSubscribe:%v", common.ErrContract, err) + return err + } + + return nil +} + +// ContractVoteStopType +// +// @Description: 设置合约止盈止损 +// @param order +// @return bool +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func ContractVoteStopType(order structure.ContractOrder) (bool, decimal.Decimal, decimal.Decimal, error) { + var checkBool bool + var stopWinPrice, stopLossPrice decimal.Decimal + switch order.StopType { + case flags.StopTypeNone: // 暂无设置止盈止损 + checkBool = false + case flags.StopTypeSet: // 设置止盈止损 + checkBool = true + if len(order.StopWinPrice) != 0 { + stopWinPrice = decimal.RequireFromString(order.StopWinPrice) + } + if len(order.StopLossPrice) != 0 { + stopLossPrice = decimal.RequireFromString(order.StopLossPrice) + } + default: + return checkBool, stopWinPrice, stopLossPrice, flags.ErrContractThirteen + } + + return checkBool, stopWinPrice, stopLossPrice, nil +} + +// GetContractPrice +// +// @Description: 获取合约价格 +// @param symbol +// @return decimal.Decimal +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func GetContractPrice(symbol string) (decimal.Decimal, error) { + var newPrice decimal.Decimal + + key := publicData.SymbolCache(flags.Hy, symbol, flags.TradeTypePrice) + priceByte, err := memory.GetContractCache(key) + if err != nil { + applogger.Error("%v ContractTransactionCalculationPosition.Get:%v", common.ErrContract, err) + return decimal.Decimal{}, err + } + + newPrice, err = decimal.NewFromString(string(priceByte)) + if err != nil { + return decimal.Decimal{}, err + } + + applogger.Info("contractCode:%v,topIc:%v,contractPrice:%v", symbol, key, newPrice) + + return newPrice, nil +} diff --git a/internal/data/subscribe_virtual_second.go b/internal/data/subscribe_virtual_second.go new file mode 100644 index 0000000..790a1a7 --- /dev/null +++ b/internal/data/subscribe_virtual_second.go @@ -0,0 +1,334 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "sync" + "time" +) + +// SecondSymbol +// @Description: 秒合约Map设置 +type SecondSymbol struct { + SecondMap chan []byte // 秒合约订单交易对 -- 用户秒合约下单通知订阅 + SecondMapSymbol sync.Map // 秒合约订阅交易对簿 +} + +// InitSubscribeQuotesSecond +// +// @Description: 秒合约初始化 +// @param ctx +// @param uo +// @param contract +func InitSubscribeQuotesSecond() { + for { + listSpots, err := LoadLRangeList(setting.MarketContract) + if err != nil { + applogger.Error("%v InitSubscribeQuotesSecond.LoadLRangeList:%v", common.ErrSecond, err) + return + } + + for _, value := range listSpots { + // Prevent duplicate subscription to CtrIp + _, ok := second.SecondMapSymbol.Load(value) + if ok { + continue + } + + second.SecondMap <- []byte(value) + } + + time.Sleep(10 * time.Second) + } +} + +// SubscribeQuotesSecond +// +// @Description: 秒合约订阅 +// @param ctx +// @param uo +// @param contract +func SubscribeQuotesSecond(ctx context.Context, uo *Data, second *SecondSymbol) { + for { + select { + case symbol, _ := <-second.SecondMap: + symbolStr := string(symbol) + + // Prevent duplicate subscription to CtrIp + _, ok := second.SecondMapSymbol.Load(symbolStr) + if ok { + time.Sleep(5 * time.Second) + continue + } + + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := uo.redisDB.HExists(context.Background(), setting.MarketContract, symbolStr).Result() + if err != nil { + applogger.Error("%v SubscribeQuotesSecond.MarketContract.HExists:%v", common.ErrSecond, err) + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err = uo.redisDB.HSet(context.Background(), setting.MarketContract, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeQuotesSecond.MarketContract.HSet:%v", common.ErrSecond, err) + time.Sleep(5 * time.Second) + continue + } + } + + // 订阅插针价格 + go func() { + for { + var data string + data, err = uo.redisDB.Get(context.Background(), flags.ContractSystemPriceSetUp).Result() + if err != nil || data == "[]" { + time.Sleep(5 * time.Second) + continue + } + var dataList []ContractSetUp + if err = json.Unmarshal([]byte(data), &dataList); err != nil { + time.Sleep(5 * time.Second) + continue + } + for _, value := range dataList { + checkStart := len(utils.StrReplace(value.BeginTime)) + checkEnd := len(utils.StrReplace(value.EndTime)) + if checkStart == 0 || checkEnd == 0 { + continue + } + if value.SelfContractCode == symbolStr { + // Determine if it is the current subscription type + priceKey := publicData.SymbolCache(flags.Hy, symbolStr, flags.TradeTypePrice) + if !utils.CheckTimeUTC(value.BeginTime, value.EndTime) { + continue + } + if err = memory.SecondPriceSetUp.Set(priceKey, []byte(utils.DecimalsPrice(value.Price))); err != nil { + applogger.Error("%v SubscribeQuotesSecond.SecondPriceSetUp.set:%v", common.ErrSecond, err) + continue + } + if !flags.CheckSetting { + applogger.Info("当前写入插针最新价格:%v,%v", priceKey, value.Price) + } + } + } + time.Sleep(2 * time.Second) + } + }() + + // 订阅实时价格 + go func() { + topIc := fmt.Sprintf("market.%v.detail", utils.ReplaceStrByValue(symbolStr, "/")) + pubSub := uo.redisDB.Subscribe(ctx, topIc) + defer pubSub.Close() + if _, err = pubSub.Receive(ctx); err != nil { + applogger.Error("%v SubscribeQuotesSecond.Receive:%v", common.ErrSecond, err) + return + } + chp := pubSub.Channel() + for msg := range chp { + var subMsg QuitesContract + if err = json.Unmarshal([]byte(msg.Payload), &subMsg); err != nil { + applogger.Error("%v SubscribeQuotesSecond.QuitesContract.Unmarshal:%v", common.ErrSecond, err) + close(second.SecondMap) + return + } + // 交易类型:0最新价,1买入,2卖出 + price := publicData.SymbolCache(flags.Sd, symbolStr, flags.TradeTypePrice) + if err = memory.SecondCache.Set(price, []byte(subMsg.Content.Tick.Close)); err != nil { + applogger.Error("%v SubscribeQuotesSecond.Set:%v", common.ErrSecond, err) + continue + } + if !flags.CheckSetting { + applogger.Info("当前写入最新价格:%v,%v", price, subMsg.Content.Tick.Close) + } + } + }() + + // Write in the map to determine whether to repeat subscription + second.SecondMapSymbol.Store(symbolStr, symbolStr) + } + } +} + +// SecondTransactionPosition +// +// @Description: 秒合约-持仓业务处理 +// @param ctx +func SecondTransactionPosition(ctx context.Context) { + for { + SecondTransactionCalculationPosition(ctx) + time.Sleep(400 * time.Millisecond) + } +} + +// SecondTransactionCalculationPosition +// +// @Description: 监控秒合约持仓缓存列表(注意:止盈止损|强行平仓) +// @param ctx +func SecondTransactionCalculationPosition(ctx context.Context) { + var wg sync.WaitGroup + + entrustList, err := Reds.HGetAll(context.Background(), setting.MarketSecondPosition).Result() + if err != nil { + applogger.Error("%v SecondTransactionCalculationPosition.LRange:%v", common.ErrSecond, err) + return + } + + for _, value := range entrustList { + var msg = make(chan virtual.ContractTallyCache, 1) + var entrust virtual.ContractTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v SecondTransactionCalculationPosition.Unmarshal:%v", common.ErrSecond, err) + continue + } + + // 查询时间 + var newPrice decimal.Decimal + newPrice, err = GetSecondPrice(entrust.Symbol) + if err != nil { + applogger.Error("%v SecondTransactionCalculationPosition.GetSecondPrice:%v", common.ErrSecond, err) + continue + } + + wg.Add(1) + go func(value string) { + resultMsg := SecondConcurrentComputingPosition(&entrust, newPrice, &wg) + msg <- resultMsg + }(value) + + // 处理并发结果 + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Position: // 持仓 + if !flags.CheckSetting { + applogger.Info("从信道接收到秒合约持仓信息:%v", resultMsg) + } + case flags.Close: // 平仓 + if !flags.CheckSetting { + applogger.Info("从信道接收到秒合约平仓信息:%v", resultMsg) + } + + if err = SecondLiquidationPosition(ctx, &resultMsg); err != nil { + applogger.Error("%v SecondTransactionCalculationPosition.ContractLiquidationPosition:%v", common.ErrSecond, err) + continue + } + } + } + } + + wg.Wait() + applogger.Info("秒合约持仓并发计算执行完毕......") +} + +// SecondConcurrentComputingPosition +// +// @Description: 秒合约持仓缓存列表业务处理 +// @param order +// @param newPrice +// @param bidPrice +// @param askPrice +// @param wg +// @return tradedeal.ContractTallyCache +func SecondConcurrentComputingPosition(order *virtual.ContractTallyCache, newPrice decimal.Decimal, wg *sync.WaitGroup) virtual.ContractTallyCache { + var dealPrice string // 平仓价格 + var checkBool bool // 删除缓存状态 + var status = order.Status // 原始价格 + + time1 := time.Now() // 通过时间判定是否平仓 + time2 := order.Order.StopTime + + if time1.After(time2) { + dealPrice = newPrice.String() // 时间1在时间2之后 + checkBool = true + } else if time1.Equal(time2) { + dealPrice = newPrice.String() // 时间1等于时间2 + checkBool = true + } + + if checkBool { + order.Status = flags.Close // 删除合约持仓缓存列表数据 + if err := Reds.HDel(context.Background(), setting.MarketSecondPosition, order.OrderId).Err(); err != nil { + applogger.Error("%v ContractConcurrentComputingPosition.MarketContractPosition.HDel:%v", common.ErrSecond, err) + order.Status = status + } + } + + wg.Done() + return virtual.ContractTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + ClosingPrice: dealPrice, // 平仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + } +} + +// SecondLiquidationPosition +// +// @Description: 合约平仓操作 +// @param ctx +// @param order +// @return error +func SecondLiquidationPosition(ctx context.Context, order *virtual.ContractTallyCache) error { + // 1、平仓操作 + err := SecondClosingPosition(ctx, Msql, order.OrderId, order.ClosingPrice, order.Order) + if err != nil { + applogger.Error("%v SecondLiquidationPosition.ContractClosingPosition:%v", common.ErrSecond, err) + return err + } + + // 2、平仓更新用户合约订阅订单状态 + userSubKey := virtual.OrderIdListKey(setting.SecondSubscribe, order.UserId) + if err = UpdateContractSubscribeHashStatusByOrderId(order.OrderId, userSubKey, flags.Close, order.ClosingPrice); err != nil { + applogger.Error("%v SecondLiquidationPosition.SecondSubscribe:%v", common.ErrSecond, err) + return err + } + + // 3、平仓更新管理员合约订阅订单状态 + if err = UpdateContractSubscribeHashStatusByOrderId(order.OrderId, setting.AdminSecondSubscribe, flags.Close, order.ClosingPrice); err != nil { + applogger.Error("%v SecondLiquidationPosition.AdminSecondSubscribe:%v", common.ErrSecond, err) + return err + } + + return nil +} + +// GetSecondPrice +// +// @Description: 合约价格 +// @param symbol +// @return decimal.Decimal +// @return decimal.Decimal +// @return decimal.Decimal +// @return error +func GetSecondPrice(symbol string) (decimal.Decimal, error) { + var newPrice decimal.Decimal + + key := publicData.SymbolCache(flags.Sd, symbol, flags.TradeTypePrice) + priceByte, err := memory.GetSecondCache(key) + if err != nil { + applogger.Error("%v GetSecondPrice.Get:%v", common.ErrSecond, err) + return decimal.Decimal{}, err + } + + newPrice, err = decimal.NewFromString(string(priceByte)) + if err != nil { + return decimal.Decimal{}, err + } + + applogger.Info("secondCode:%v,topIc:%v,secondPrice:%v", symbol, key, newPrice) + + return newPrice, nil +} diff --git a/internal/data/subscribe_virtual_spots.go b/internal/data/subscribe_virtual_spots.go new file mode 100644 index 0000000..16a9268 --- /dev/null +++ b/internal/data/subscribe_virtual_spots.go @@ -0,0 +1,365 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/socket/publicData" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "strings" + "sync" + "time" +) + +/* +现货行情订阅 +1、初始化现货订阅信息 +2、接收用户现货下单的交易对 +3、根据交易对订阅现货行情数据 +4、写入内存中用于并发计算 +5、记录在热缓存中 +*/ + +// QuitesSpots +// @Description: +type QuitesSpots struct { + ServersID string `json:"serversId"` + Content struct { + Ch string `json:"ch"` + Ts int64 `json:"ts"` + Tick struct { + Open string `json:"open"` + High string `json:"high"` + Low string `json:"low"` + Close string `json:"close"` + Amount string `json:"amount"` + Count int `json:"count"` + Bid string `json:"bid"` + BidSize string `json:"bidSize"` + Ask string `json:"ask"` + AskSize string `json:"askSize"` + LastPrice string `json:"lastPrice"` + LastSize string `json:"lastSize"` + } `json:"Tick"` + Data any `json:"Data"` + } `json:"content"` + Symbol string `json:"symbol"` +} + +// SpotsSymbol +// @Description: +type SpotsSymbol struct { + SpotsMap chan []byte // 现货订单交易对 -- 用户现货下单通知订阅 + SpotsMapSymbol sync.Map // 现货订阅交易对簿(防止重复订阅情况) +} + +// InitCacheSymbolSpots +// +// @Description: 初始化当前数据表中的现货交易对 +// @param ctx +// @param uo +func InitCacheSymbolSpots(ctx context.Context, uo *Data) { + digitalList, err := GetBotDigitalList(ctx, uo) + if err != nil { + return + } + + for _, value := range digitalList { + vue := strings.ToLower(value) + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := uo.redisDB.HExists(context.Background(), setting.MarketSpots, vue).Result() + if err != nil { + applogger.Error("%v InitCacheSymbolSpots.MarketSpots.HExists:%v", common.ErrSpots, err) + return + } + applogger.Info("初始化现货交易对:%v", value) + + if !checkBool { + if err = uo.redisDB.HSet(context.Background(), setting.MarketSpots, vue, vue).Err(); err != nil { + applogger.Error("%v InitCacheSymbolSpots.HSet:%v", common.ErrSpots, err) + return + } + } + } +} + +// InitSubscribeQuotesSpots +// +// @Description: 状态机加载订阅 +// @param ctx +// @param uo +// @param spots +func InitSubscribeQuotesSpots(spots *SpotsSymbol) { + for { + listSpots, err := LoadLRangeList(setting.MarketSpots) + if err != nil { + applogger.Error("%v InitSubscribeQuotesSpots.LoadLRangeList:%v", common.ErrSpots, err) + return + } + + for _, value := range listSpots { + // Prevent duplicate subscription to CtrIp + _, ok := spots.SpotsMapSymbol.Load(value) + if ok { + continue + } + + spots.SpotsMap <- []byte(value) + } + + time.Sleep(10 * time.Second) + } +} + +// SubscribeQuotesSpots +// +// @Description: 现货订阅 +// @param ctx +// @param uo +// @param spots +func SubscribeQuotesSpots(ctx context.Context, uo *Data, spots *SpotsSymbol) { + for { + select { + case symbol, _ := <-spots.SpotsMap: + symbolStr := string(symbol) + + // Prevent duplicate subscription to CtrIp + _, ok := spots.SpotsMapSymbol.Load(symbolStr) + if ok { + time.Sleep(5 * time.Second) + continue + } + + // Write to the redis list hot cache for initializing subscriptions when the program is pulled up + checkBool, err := uo.redisDB.HExists(context.Background(), setting.MarketSpots, symbolStr).Result() + if err != nil { + applogger.Error("%v SubscribeQuotesSpots.MarketSpots.HExists:%v", common.ErrSpots, err) + time.Sleep(5 * time.Second) + continue + } + if !checkBool { + if err = uo.redisDB.HSet(context.Background(), setting.MarketSpots, symbolStr, symbolStr).Err(); err != nil { + applogger.Error("%v SubscribeQuotesSpots.HSet:%v", common.ErrSpots, err) + time.Sleep(5 * time.Second) + continue + } + } + + go func() { + topIc := fmt.Sprintf("market.%vusdt.ticker", symbolStr) + pubSub := uo.redisDB.Subscribe(ctx, topIc) + defer pubSub.Close() + if _, err = pubSub.Receive(ctx); err != nil { + applogger.Error("%v SubscribeQuotesSpots.Receive:%v", common.ErrSpots, err) + return + } + ch := pubSub.Channel() + for msg := range ch { + var subMsg QuitesSpots + if err = json.Unmarshal([]byte(msg.Payload), &subMsg); err != nil { + applogger.Error("%v SubscribeQuotesSpots.Unmarshal:%v", common.ErrSpots, err) + close(spots.SpotsMap) + return + } + // 交易类型:0最新价,1买入,2卖出 xh-symbol-0 + price := publicData.SymbolCache(flags.Xh, symbolStr, flags.TradeTypePrice) + if err = memory.SpotsCache.Set(price, []byte(subMsg.Content.Tick.Close)); err != nil { + applogger.Error("%v SubscribeQuotesSpots.Set.price:%v", common.ErrSpots, err) + return + } + if !flags.CheckSetting { + applogger.Info("当前写入最新价格:%v,%v", price, subMsg.Content.Tick.Close) + } + } + }() + + // Write in the map to determine whether to repeat subscription + spots.SpotsMapSymbol.Store(symbolStr, symbolStr) + } + } +} + +// SpotsTransaction +// +// @Description: +// @param ctx +func SpotsTransaction() { + for { + SpotsTransactionCalculation() + time.Sleep(400 * time.Millisecond) + } +} + +// SpotsTransactionCalculation +// +// @Description: +// @param ctx +func SpotsTransactionCalculation() { + var wg sync.WaitGroup + + entrustList, err := Reds.HGetAll(context.Background(), setting.MarketSpotsEntrust).Result() + if err != nil { + applogger.Warn("%v SpotsTransactionCalculation.LRange:%v", common.ErrSpots, err) + return + } + + for _, value := range entrustList { + var msg = make(chan virtual.SpotsTallyCache, 1) + var entrust virtual.SpotsTallyCache + if err = json.Unmarshal([]byte(value), &entrust); err != nil { + applogger.Error("%v SpotsTransactionCalculation.Unmarshal:%v", common.ErrSpots, err) + return + } + + var newByte []byte + newByte, err = memory.SpotsCache.Get(publicData.SymbolCache(flags.Xh, entrust.Symbol, flags.TradeTypePrice)) + if err != nil { + applogger.Warn("%v SpotsTransactionCalculation.Get:%v", common.ErrSpots, err) + continue + } + + priceNew := decimal.RequireFromString(string(newByte)) + + wg.Add(1) + go func(value string) { + resultMsg := SpotsConcurrentComputing(&entrust, priceNew, &wg) + msg <- resultMsg + }(value) + + // 处理并发结果 + select { + case resultMsg, _ := <-msg: + switch resultMsg.Status { + case flags.Entrust: + if !flags.CheckSetting { + applogger.Info("现货从信道接收挂单信息:%v", resultMsg) + } + case flags.Close: + if !flags.CheckSetting { + applogger.Info("现货从信道接收平仓信息:%v", resultMsg) + } + SpotLiquidation(&resultMsg) + } + } + } + + wg.Wait() + applogger.Info("现货并发计算执行完毕......") +} + +// SpotsConcurrentComputing +// +// @Description: 现货下单判定 +// @param order +// @param priceNew +// @param wg +// @return tradedeal.SpotsTallyCache +func SpotsConcurrentComputing(order *virtual.SpotsTallyCache, priceNew decimal.Decimal, wg *sync.WaitGroup) virtual.SpotsTallyCache { + limitPrice := decimal.RequireFromString(order.Order.LimitPrice) + status := order.Status + + var deleteCache bool + var dealPrice string + + switch order.Order.TradeType { + case flags.TradeTypeBuy: // buy + if !flags.CheckSetting { + applogger.Info("用户ID:%v,限价买入下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, priceNew, limitPrice.Cmp(priceNew), order.Status) + } + + // 限价买入逻辑判定 -> 买入金额 >= 最优对手价格(市价) + if limitPrice.Cmp(priceNew) >= 0 { + deleteCache = true + difference := priceNew.Mul(utils.Difference()) // 设置价差 + dealPrice = priceNew.Add(difference).String() // 平仓价格 + } + case flags.TradeTypeSell: // sell + if !flags.CheckSetting { + applogger.Info("用户ID:%v,限价卖出下单价格:%v,最新市价:%v,判定结果:%v,原始状态:%v", order.UserId, limitPrice, priceNew, limitPrice.Cmp(priceNew), order.Status) + } + + // 限价卖入逻辑判定 -> 卖出金额 <= 最优对手价格(市价) + if limitPrice.Cmp(priceNew) <= 0 { + deleteCache = true + difference := priceNew.Mul(utils.Difference()) // 设置价差 + dealPrice = priceNew.Sub(difference).String() // 平仓价格 + } + } + // 判定订单状态 + if deleteCache { + order.Status = flags.Close + } + // 清理现货挂单缓存列表 + if deleteCache { + if err := Reds.HDel(context.Background(), setting.MarketSpotsEntrust, order.OrderId).Err(); err != nil { + applogger.Error("%v SpotsConcurrentComputing.MarketSpotsEntrust.HDel:%v", common.ErrSpots, err) + order.Status = status + dealPrice = limitPrice.String() + } + } + + wg.Done() + return virtual.SpotsTallyCache{ + UserId: order.UserId, // 用户Id + OrderId: order.OrderId, // 订单Id + Symbol: order.Symbol, // 下单交易对 + ClosingPrice: dealPrice, // 平仓价格 + Status: order.Status, // 订单状态 + Order: order.Order, // 下单信息 + } +} + +// SpotLiquidation +// +// @Description: 现货平仓操作 +// @param order +func SpotLiquidation(order *virtual.SpotsTallyCache) { + // 现货挂单平仓 + orderId, err := SpotOrdersClosingDB(context.Background(), Msql, order.UserId, order.Order, order.OrderId, order.ClosingPrice) + if err != nil || len(orderId) == 0 { + applogger.Error("%v SpotLiquidation.SpotOrdersClosingDB:%v", common.ErrSpots, err) + return + } + + // 更新用户订单订阅缓存列表 + if err = UpdateSpotsSubscribeStatusHashByOrderId(order.UserId, order.OrderId, setting.SpotsSubscribe, flags.Close); err != nil { + applogger.Error("%v SpotLiquidation.UpdateSpotsSubscribeStatusByOrderId:%v", common.ErrSpots, err) + return + } +} + +// LoadLRangeList +// +// @Description: 加载本地缓存队列数据 +// @param ctx +// @param uo +// @param key +// @return map[string]string +// @return error +func LoadLRangeList(key string) (map[string]string, error) { + elements, err := Reds.HGetAll(context.Background(), key).Result() + if err != nil { + applogger.Error("%v LoadLRangeList.HGetAll:%v", common.ErrSpots, err) + return map[string]string{}, err + } + + return elements, err +} + +// SymbolCache +// +// @Description: 获取现货交易对缓存Key +// @param mark +// @param symbol +// @param types +// @return string +func SymbolCache(mark, symbol string, types int) string { + return fmt.Sprintf("%v-%v-%v", mark, symbol, types) +} diff --git a/internal/data/tradedeal/forex/forex.go b/internal/data/tradedeal/forex/forex.go new file mode 100644 index 0000000..2d18a2c --- /dev/null +++ b/internal/data/tradedeal/forex/forex.go @@ -0,0 +1,126 @@ +package forex + +import ( + "context" + "encoding/json" + "github.com/redis/go-redis/v9" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" +) + +/* +处理外汇下单交易(订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单) +1>写入挂单缓存列表 +2>监控挂单缓存列表 +3>监控持仓缓存列表 +4>处理完成订单 +5>清理缓存列表 +*/ + +// ForexTallyCache +// @Description: +type ForexTallyCache struct { + UserId int64 // 用户ID + OrderId string // 订单ID + Symbol string // 交易对 + Status string // 订单状态 + OpenPrice string // 开仓价格 + ClosingPrice string // 平仓价格 + Order structure.ForexOrder // 下单信息 +} + +// ForexCacheDeal +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param priceNew +// @param order +// @return string +// @return *ForexTallyCache +// @return error +func ForexCacheDeal(ctx context.Context, userId int64, orderId, priceNew string, order structure.ForexOrder) (string, *ForexTallyCache, error) { + var marketStatus string + tallyCache := &ForexTallyCache{ + UserId: userId, // 下单用户ID + OrderId: orderId, // 下单订单ID + Symbol: order.ForexId, // 下单交易对 + Status: flags.Entrust, // 下单挂单状态 + Order: order, // 完整下单信息 + } + + switch order.DealType { + case flags.DealTypeLimited: // 限价(买涨|买跌) + marketStatus = setting.MarketForexEntrust + case flags.DealTypeMarket: // 市价(买涨|买跌) + tallyCache.OpenPrice = priceNew // 市价下单开仓价格(price) + tallyCache.Status = flags.Position // 市价下单持仓状态(status) + marketStatus = setting.MarketForexPosition // (挂单|持仓)缓存列表 + } + + return marketStatus, tallyCache, nil +} + +// ForexSubMarketPrice +// +// @Description: 下单订阅行情数据 +// @param ctx +// @param subKey +// @return string +// @return error +func ForexSubMarketPrice(ctx context.Context, subKey string) (string, error) { + price, err := memory.GetForexCache(subKey) + if err != nil { + return flags.SetNull, err + } + + return string(price), nil +} + +// ForexPushAddCache +// +// @Description: 下单录入(挂单|持仓)缓存列表 +// @param red +// @param cacheKey +// @param tallyCache +// @return error +func ForexPushAddCache(red *redis.Client, cacheKey string, tallyCache *ForexTallyCache) error { + content, err := json.Marshal(tallyCache) + if err != nil { + return err + } + + if err = red.HSet(context.Background(), cacheKey, tallyCache.OrderId, string(content)).Err(); err != nil { + return err + } + + return nil +} + +// ForexHashSetOrderId +// +// @Description: 录入订单ID-Hash缓存列表 +// @param red +// @param cacheKey +// @param order +// @return error +func ForexHashSetOrderId(red *redis.Client, cacheKey string, order *ForexTallyCache) error { + byteStr, err := json.Marshal(order) + if err != nil { + applogger.Error("%v ForexHashSetOrderId.Marshal:%v", common.ErrForex, err) + return err + } + + err = red.HSet(context.Background(), cacheKey, order.OrderId, string(byteStr)).Err() + if err != nil { + applogger.Error("%v ForexHashSetOrderId.HSet:%v", common.ErrForex, err) + return err + } + + return nil +} diff --git a/internal/data/tradedeal/money/money.go b/internal/data/tradedeal/money/money.go new file mode 100644 index 0000000..fb0a67a --- /dev/null +++ b/internal/data/tradedeal/money/money.go @@ -0,0 +1,149 @@ +package money + +import ( + "context" + "encoding/json" + "github.com/redis/go-redis/v9" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" +) + +/* +处理综合下单交易(订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单) +1>写入挂单缓存列表 +2>监控挂单缓存列表 +3>监控持仓缓存列表 +4>处理完成订单 +5>清理缓存列表 +*/ + +// MoneyTallyCache +// @Description: +type MoneyTallyCache struct { + UserId int64 // 用户ID + OrderId string // 订单ID + Symbol string // 交易对 + Status string // 订单状态 + OpenPrice string // 开仓价格 + ClosingPrice string // 平仓价格 + StrongParity string // 强平价格 + Order structure.MoneyOrder // 下单信息 +} + +// MoneyCacheDeal +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param priceNew +// @param order +// @return string +// @return *MoneyTallyCache +// @return error +func MoneyCacheDeal(ctx context.Context, userId int64, orderId, priceNew string, order structure.MoneyOrder) (string, *MoneyTallyCache, error) { + var marketStatus string + tallyCache := &MoneyTallyCache{ + UserId: userId, // 下单用户ID + OrderId: orderId, // 下单订单ID + Symbol: order.StockId, // 下单交易对 + Status: flags.Entrust, // 下单挂单状态 + Order: order, // 完整下单信息 + } + switch order.DealType { + case flags.DealTypeLimited: // 限价(买涨|买跌) + marketStatus = setting.MarketMoneyEntrust + case flags.DealTypeMarket: // 市价(买涨|买跌) + if order.Type == flags.SpotsMarketType { + tallyCache.OpenPrice = priceNew // 现货市价下单开仓价格(price) + tallyCache.Status = flags.Close // 现货市价下单持仓状态(status) + marketStatus = setting.MarketMoneyClose // 现货(平仓)标识 + } else { + tallyCache.OpenPrice = priceNew // (合约|外汇)市价下单开仓价格(price) + tallyCache.Status = flags.Position // (合约|外汇)市价下单持仓状态(status) + marketStatus = setting.MarketMoneyPosition // (合约|外汇)(挂单|持仓)缓存列表 + } + } + + return marketStatus, tallyCache, nil +} + +// MoneySubMarketPrice +// +// @Description: 下单订阅行情数据 +// @param ctx +// @param subKey +// @return string +// @return error +func MoneySubMarketPrice(ctx context.Context, subKey string, marketType int64) (string, error) { + var err error + var price []byte + + switch marketType { + case flags.SpotsMarketType: // 现货即时价格 + price, err = memory.GetMoneySpotsCache(subKey) + if err != nil { + return flags.SetNull, err + } + case flags.ContractMarketType: // 合约即时价格 + price, err = memory.GetMoneyContractCache(subKey) + if err != nil { + return flags.SetNull, err + } + case flags.ForexMarketType: // 外汇即时价格 + price, err = memory.GetMoneyForexCache(subKey) + if err != nil { + return flags.SetNull, err + } + default: + } + + return string(price), nil +} + +// MoneyPushAddCache +// +// @Description: 下单录入(挂单|持仓)缓存列表 +// @param red +// @param cacheKey +// @param tallyCache +// @return error +func MoneyPushAddCache(red *redis.Client, cacheKey string, tallyCache *MoneyTallyCache) error { + content, err := json.Marshal(tallyCache) + if err != nil { + return err + } + + if err = red.HSet(context.Background(), cacheKey, tallyCache.OrderId, string(content)).Err(); err != nil { + return err + } + + return nil +} + +// MoneyHashSetOrderId +// +// @Description: 录入订单ID-Hash缓存列表 +// @param red +// @param cacheKey +// @param order +// @return error +func MoneyHashSetOrderId(red *redis.Client, cacheKey string, order *MoneyTallyCache) error { + byteStr, err := json.Marshal(order) + if err != nil { + applogger.Error("%v MoneyHashSetOrderId.Marshal:%v", common.ErrMoney, err) + return err + } + + err = red.HSet(context.Background(), cacheKey, order.OrderId, string(byteStr)).Err() + if err != nil { + applogger.Error("%v MoneyHashSetOrderId.HSet:%v", common.ErrMoney, err) + return err + } + + return nil +} diff --git a/internal/data/tradedeal/option/option_inr.go b/internal/data/tradedeal/option/option_inr.go new file mode 100644 index 0000000..2b50103 --- /dev/null +++ b/internal/data/tradedeal/option/option_inr.go @@ -0,0 +1,302 @@ +package option + +import ( + "context" + "encoding/json" + "github.com/redis/go-redis/v9" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" +) + +/* +处理印度期权股下单交易(订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单) +1>写入挂单缓存列表 +2>监控挂单缓存列表 +3>监控持仓缓存列表 +4>处理完成订单 +5>清理缓存列表 +*/ + +// OptionInrTallyCache +// @Description: +type OptionInrTallyCache struct { + UserId int64 // 用户ID + OrderId string // 订单ID + Symbol string // 交易对 + Status string // 订单状态 + OpenPrice string // 开仓价格 + ClosingPrice string // 平仓价格 + ClosingTime time.Time // 平仓时间 + Order structure.ShareOrder // 下单信息 +} + +// OptionInrCacheDeal +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param subKey +// @param order +// @param chg +// @param priceNew +// @param closingTime +// @return string +// @return *OptionInrTallyCache +// @return error +func OptionInrCacheDeal(ctx context.Context, userId int64, orderId string, order structure.ShareOrder) (string, *OptionInrTallyCache, error) { + var marketStatus string + tallyCache := OptionInrTallyCache{ + UserId: userId, // 股票期权下单用户Id + OrderId: orderId, // 股票期权下单订单Id + Symbol: order.StockId, // 股票期权下单交易对 + Status: flags.Entrust, // 股票期权下单挂单状态 + Order: order, // 股票期权完整下单信息 + } + + // 股票期权到期时间 + closingTime, err := utils.TimeStopTime(order.StopTime) + if err == nil { + tallyCache.ClosingTime = closingTime + } + + // 股票期权缓存状态 + marketStatus = setting.MarketOptionInrEntrust + + return marketStatus, &tallyCache, nil +} + +// GetOptionOrderInrByChg +// +// @Description: 处理涨跌幅 +// @param priceNew +// @param tallyCache +// @param chg +// @return string +// @return OptionInrTallyCache +func GetOptionOrderInrByChg(priceNew string, tallyCache OptionInrTallyCache, chg string) (string, OptionInrTallyCache) { + var marketStatus string + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买涨涨停,只能挂单......") + } + marketStatus = setting.MarketOptionInrEntrust + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOptionOrderInrMarketPrice(priceNew, tallyCache) + default: + marketStatus = setting.MarketOptionInrEntrust + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOptionOrderInrMarketPrice(priceNew, tallyCache) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买跌跌停,只能挂单......") + } + marketStatus = setting.MarketOptionInrEntrust + default: + marketStatus = setting.MarketOptionInrEntrust + } + default: + marketStatus, tallyCache = GetOptionOrderInrMarketPrice(priceNew, tallyCache) + } + + return marketStatus, tallyCache +} + +// CheckOptionInrOrderByChg +// +// @Description: 股票期权判定涨跌幅业务逻辑 +// @param orderMarket +// @param tallyCache +// @param chg +// @return bool +func CheckOptionInrOrderByChg(orderMarket string, tallyCache OptionInrTallyCache, chg string) bool { + var checkBool bool + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,持仓可以平仓 + checkBool = CheckOptionOrderInrBuyMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,持仓不能平仓 + checkBool = CheckOptionOrderInrSellMarket(orderMarket) + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,持仓不能平仓 + checkBool = CheckOptionOrderInrSellMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,持仓可以平仓 + checkBool = CheckOptionOrderInrBuyMarket(orderMarket) + } + default: + checkBool = false + } + + return checkBool +} + +// CheckOptionOrderInrBuyMarket +// +// @Description: 买涨-涨跌幅 +// @param orderMarket +// @return bool +func CheckOptionOrderInrBuyMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketOptionInrEntrust: // 挂单缓存状态--不到持仓 + checkBool = true + case setting.MarketOptionInrPosition: // 持仓缓存状态--可以平仓 + checkBool = false + } + + return checkBool +} + +// CheckOptionOrderInrSellMarket +// +// @Description: 买跌-涨跌幅 +// @param orderMarket +// @return bool +func CheckOptionOrderInrSellMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketOptionInrEntrust: // 挂单缓存状态-- 到持仓 + checkBool = false + case setting.MarketOptionInrPosition: // 持仓缓存状态-- 不能平仓 + checkBool = true + } + + return checkBool +} + +// GetOptionOrderInrMarketPrice +// +// @Description: 市价下单开仓信息 +// @param priceNew +// @param tallyCache +// @return string +// @return OptionInrTallyCache +func GetOptionOrderInrMarketPrice(priceNew string, tallyCache OptionInrTallyCache) (string, OptionInrTallyCache) { + var marketStatus string + tallyCache.OpenPrice = decimal.RequireFromString(priceNew).String() // 股票期权市价下单开盘价格(price) + tallyCache.Status = flags.Position // 股票期权市价下单持仓状态(status) + marketStatus = setting.MarketOptionInrPosition // 股票期权下单状态(挂单|持仓)缓存列表 + + return marketStatus, tallyCache +} + +// OptionInrSubMarketPrice +// +// @Description: 下单订阅行情数据 +// @param subKey +// @return string +// @return error +func OptionInrSubMarketPrice(subKey string) (string, error) { + price, err := memory.GetOptionInrCache(subKey) + if err != nil { + return flags.SetNull, err + } + + return string(price), nil +} + +// OptionInrHashUserOrder +// +// @Description: 下单录入订阅缓存列表(用户订阅|管理员订阅|挂单|持仓) +// @param red +// @param cacheKey +// @param order +// @return error +func OptionInrHashUserOrder(red *redis.Client, cacheKey string, order *OptionInrTallyCache) error { + orderStr, err := json.Marshal(order) + if err != nil { + applogger.Error("%v OptionInrHashUserOrder.Marshal:%v", common.ErrOptionInr, err) + return err + } + + if err = red.HSet(context.Background(), cacheKey, order.OrderId, string(orderStr)).Err(); err != nil { + applogger.Error("%v OptionInrHashUserOrder.HSet:%v", common.ErrOptionInr, err) + return err + } + + return nil +} + +// UpdateOptionInrHashByOrderId +// +// @Description: 更新缓存列表 +// @param reds +// @param orderId +// @param updateKey +// @param status +// @return error +func UpdateOptionInrHashByOrderId(reds *redis.Client, orderId, updateKey, status string) error { + order, err := reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel OptionInrTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + return nil +} + +// UpdateOptionInrStopByOrderId +// +// @Description: 更新止盈止损设置 +// @param reds +// @param order +// @param updateKey +// @param status +// @return error +func UpdateOptionInrStopByOrderId(reds *redis.Client, order structure.StopOrder, updateKey, status string) error { + orderHash, err := reds.HGet(context.Background(), updateKey, order.OrderId).Result() + if err != nil { + return err + } + + var orderModel OptionInrTallyCache + if err = json.Unmarshal([]byte(orderHash), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderModel.Order.StopType = order.StopType + orderModel.Order.StopLossPrice = order.StopLossPrice + orderModel.Order.StopWinPrice = order.StopWinPrice + + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, order.OrderId, string(orderStr)).Err() + if err != nil { + return err + } + return nil +} diff --git a/internal/data/tradedeal/share/share_blk.go b/internal/data/tradedeal/share/share_blk.go new file mode 100644 index 0000000..7753b06 --- /dev/null +++ b/internal/data/tradedeal/share/share_blk.go @@ -0,0 +1,46 @@ +package share + +import ( + "context" + "encoding/json" + "github.com/redis/go-redis/v9" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "time" +) + +// ShareBlkTallyCache +// @Description: +type ShareBlkTallyCache struct { + UserId int64 // 用户ID + OrderId string // 订单ID + Symbol string // 交易对 + Status string // 订单状态 + OpenPrice string // 开仓价格 + ClosingPrice string // 平仓价格 + ClosingTime time.Time // 平仓时间 + Order structure.ShareOrder // 下单信息 +} + +// ShareBklHashUserOrder +// +// @Description: +// @param red +// @param cacheKey +// @param order +// @return error +func ShareBklHashUserOrder(red *redis.Client, cacheKey string, order *ShareBlkTallyCache) error { + orderStr, err := json.Marshal(order) + if err != nil { + applogger.Error("%v ShareBklHashUserOrder.Marshal:%v", common.ErrShareBlk, err) + return err + } + + if err = red.HSet(context.Background(), cacheKey, order.OrderId, string(orderStr)).Err(); err != nil { + applogger.Error("%v ShareBklHashUserOrder.HSet:%v", common.ErrShareBlk, err) + return err + } + + return nil +} diff --git a/internal/data/tradedeal/share/share_brl.go b/internal/data/tradedeal/share/share_brl.go new file mode 100644 index 0000000..0962704 --- /dev/null +++ b/internal/data/tradedeal/share/share_brl.go @@ -0,0 +1,330 @@ +package share + +import ( + "context" + "encoding/json" + "github.com/redis/go-redis/v9" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" +) + +/* +处理股票股下单交易(订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单) +1>写入挂单缓存列表 +2>监控挂单缓存列表 +3>监控持仓缓存列表 +4>处理完成订单 +5>清理缓存列表 +*/ + +// ShareBrlTallyCache +// @Description: +type ShareBrlTallyCache struct { + UserId int64 // 用户ID + OrderId string // 订单ID + Symbol string // 交易对 + Status string // 订单状态R + OpenPrice string // 开仓价格 + ClosingPrice string // 平仓价格 + ClosingTime time.Time // 平仓时间 + Order structure.ShareOrder // 下单信息 +} + +// ShareBrlCacheDeal +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param subKey +// @param order +// @param chg +// @param priceNew +// @param closingTime +// @return string +// @return *ShareBrlTallyCache +// @return error +func ShareBrlCacheDeal(ctx context.Context, userId int64, + orderId, subKey string, order structure.ShareOrder, + chg, priceNew string, closingTime, blockTime time.Time) (string, *ShareBrlTallyCache, error) { + var marketStatus string + tallyCache := ShareBrlTallyCache{ + UserId: userId, // 股票下单用户Id + OrderId: orderId, // 股票下单订单Id + Symbol: order.StockId, // 股票下单交易对 + Status: flags.Entrust, // 股票下单挂单状态 + Order: order, // 股票完整下单信息 + } + + // TODO: 交易下单判定(是否市价交易) + //switch order.DealType { + //case flags.DealTypeLimited: // 限价(买涨|买跌) + // marketStatus = flags.MarketShareBrlEntrust + //case flags.DealTypeMarket: // 市价(买涨|买跌) + // if len(priceNew) == 0 { + // marketStatus = flags.MarketShareBrlEntrust + // } else { + // marketStatus, tallyCache = GetOrderBrlByChg(priceNew, tallyCache, chg) + // } + //} + + // 交易判定 + if order.Type <= 0 { + marketStatus = setting.MarketShareBrlEntrust + tallyCache.ClosingTime = closingTime // 平仓时间 + } else { + marketStatus = setting.MarketShareBlkEntrust + tallyCache.OpenPrice = priceNew // 开仓价格 + tallyCache.ClosingTime = blockTime // 平仓时间 + } + + return marketStatus, &tallyCache, nil +} + +// GetOrderBrlByChg +// +// @Description: 处理涨跌幅 +// @param priceNew +// @param tallyCache +// @param chg +// @return string +// @return ShareBrlTallyCache +func GetOrderBrlByChg(priceNew string, tallyCache ShareBrlTallyCache, chg string) (string, ShareBrlTallyCache) { + var marketStatus string + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买涨涨停,只能挂单......") + } + + marketStatus = setting.MarketShareBrlEntrust + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderBrlMarketPrice(priceNew, tallyCache) + default: + marketStatus = setting.MarketShareBrlEntrust + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderBrlMarketPrice(priceNew, tallyCache) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买跌跌停,只能挂单......") + } + + marketStatus = setting.MarketShareBrlEntrust + default: + marketStatus = setting.MarketShareBrlEntrust + } + default: + marketStatus, tallyCache = GetOrderBrlMarketPrice(priceNew, tallyCache) + } + + return marketStatus, tallyCache +} + +// CheckOrderBrlByChg +// +// @Description: 股票判定涨跌幅业务逻辑 +// @param orderMarket +// @param tallyCache +// @param chg +// @return bool +func CheckOrderBrlByChg(orderMarket string, tallyCache ShareBrlTallyCache, chg string) bool { + var checkBool bool + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderBrlBuyMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderBrlSellMarket(orderMarket) + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderBrlSellMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderBrlBuyMarket(orderMarket) + } + default: + checkBool = false + } + + return checkBool +} + +// CheckOrderBrlBuyMarket +// +// @Description: 买涨-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderBrlBuyMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareBrlEntrust: // 挂单缓存状态--不到持仓 + checkBool = true + case setting.MarketShareBrlPosition: // 持仓缓存状态--可以平仓 + checkBool = false + } + + return checkBool +} + +// CheckOrderBrlSellMarket +// +// @Description: 买跌-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderBrlSellMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareBrlEntrust: // 挂单缓存状态-- 到持仓 + checkBool = false + case setting.MarketShareBrlPosition: // 持仓缓存状态-- 不能平仓 + checkBool = true + } + + return checkBool +} + +// GetOrderBrlMarketPrice +// +// @Description: 获取市价下单开仓信息 +// @param priceNew +// @param tallyCache +// @return string +// @return ShareSgdTallyCache +func GetOrderBrlMarketPrice(priceNew string, tallyCache ShareBrlTallyCache) (string, ShareBrlTallyCache) { + var marketStatus string + priceS := decimal.RequireFromString(priceNew) // 最新市价 + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买入 + openPrice = priceS.Add(difference) // 开盘价格 + case flags.TradeTypeSell: // 卖出 + openPrice = priceS.Sub(difference) // 开盘价格 + } + tallyCache.OpenPrice = openPrice.String() // 股票市价下单开盘价格(price) + tallyCache.Status = flags.Position // 股票市价下单持仓状态(status) + marketStatus = setting.MarketShareBrlPosition // 股票下单状态(挂单|持仓)缓存列表 + + return marketStatus, tallyCache +} + +// ShareBrlSubMarketPrice +// +// @Description: 获取下单订阅行情数据 +// @param subKey +// @return string +// @return error +func ShareBrlSubMarketPrice(subKey string) (string, error) { + price, err := memory.GetShareBrlCache(subKey) + if err != nil { + return flags.SetNull, err + } + + return string(price), nil +} + +// ShareBrlHashUserOrder +// +// @Description: 下单录入订阅缓存列表(用户订阅|管理员订阅|挂单|持仓) +// @param red +// @param cacheKey +// @param order +// @return error +func ShareBrlHashUserOrder(red *redis.Client, cacheKey string, order *ShareBrlTallyCache) error { + orderStr, err := json.Marshal(order) + if err != nil { + applogger.Error("%v ShareBrlHashUserOrder.Marshal:%v", common.ErrShareBrl, err) + return err + } + + if err = red.HSet(context.Background(), cacheKey, order.OrderId, string(orderStr)).Err(); err != nil { + applogger.Error("%v ShareBrlHashUserOrder.HSet:%v", common.ErrShareBrl, err) + return err + } + + return nil +} + +// UpdateShareBrlHashByOrderId +// +// @Description: 更新缓存列表 +// @param reds +// @param orderId +// @param updateKey +// @param status +// @return error +func UpdateShareBrlHashByOrderId(reds *redis.Client, orderId, updateKey, status string) error { + order, err := reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel ShareBrlTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateShareBrlStopByOrderId +// +// @Description: 設置止盈止損 +// @param reds +// @param order +// @param updateKey +// @param status +// @return error +func UpdateShareBrlStopByOrderId(reds *redis.Client, order structure.StopOrder, updateKey, status string) error { + orderHash, err := reds.HGet(context.Background(), updateKey, order.OrderId).Result() + if err != nil { + return err + } + + var orderModel ShareBrlTallyCache + if err = json.Unmarshal([]byte(orderHash), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderModel.Order.StopType = order.StopType + orderModel.Order.StopLossPrice = order.StopLossPrice + orderModel.Order.StopWinPrice = order.StopWinPrice + + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, order.OrderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} diff --git a/internal/data/tradedeal/share/share_eur.go b/internal/data/tradedeal/share/share_eur.go new file mode 100644 index 0000000..0750122 --- /dev/null +++ b/internal/data/tradedeal/share/share_eur.go @@ -0,0 +1,330 @@ +package share + +import ( + "context" + "encoding/json" + "github.com/redis/go-redis/v9" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" +) + +/* +处理股票股下单交易(订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单) +1>写入挂单缓存列表 +2>监控挂单缓存列表 +3>监控持仓缓存列表 +4>处理完成订单 +5>清理缓存列表 +*/ + +// ShareEurTallyCache +// @Description: +type ShareEurTallyCache struct { + UserId int64 // 用户ID + OrderId string // 订单ID + Symbol string // 交易对 + Status string // 订单状态 + OpenPrice string // 开仓价格 + ClosingPrice string // 平仓价格 + ClosingTime time.Time // 平仓时间 + Order structure.ShareOrder // 下单信息 +} + +// ShareEurCacheDeal +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param subKey +// @param order +// @param chg +// @param priceNew +// @param closingTime +// @return string +// @return *ShareEurTallyCache +// @return error +func ShareEurCacheDeal(ctx context.Context, userId int64, + orderId, subKey string, order structure.ShareOrder, + chg, priceNew string, closingTime, blockTime time.Time) (string, *ShareEurTallyCache, error) { + var marketStatus string + tallyCache := ShareEurTallyCache{ + UserId: userId, // 股票下单用户Id + OrderId: orderId, // 股票下单订单Id + Symbol: order.StockId, // 股票下单交易对 + Status: flags.Entrust, // 股票下单挂单状态 + Order: order, // 股票完整下单信息 + } + + // TODO: 交易下单判定(是否市价交易) + //switch order.DealType { + //case flags.DealTypeLimited: // 限价(买涨|买跌) + // marketStatus = flags.MarketShareEurEntrust + //case flags.DealTypeMarket: // 市价(买涨|买跌) + // if len(priceNew) == 0 { + // marketStatus = flags.MarketShareEurEntrust + // } else { + // marketStatus, tallyCache = GetOrderEurByChg(priceNew, tallyCache, chg) + // } + //} + + // 交易判定 + if order.Type <= 0 { + marketStatus = setting.MarketShareEurEntrust + tallyCache.ClosingTime = closingTime // 平仓时间 + } else { + marketStatus = setting.MarketShareBlkEntrust + tallyCache.OpenPrice = priceNew // 开仓价格 + tallyCache.ClosingTime = blockTime // 平仓时间 + } + + return marketStatus, &tallyCache, nil +} + +// GetOrderEurByChg +// +// @Description: 处理涨跌幅 +// @param priceNew +// @param tallyCache +// @param chg +// @return string +// @return ShareEurTallyCache +func GetOrderEurByChg(priceNew string, tallyCache ShareEurTallyCache, chg string) (string, ShareEurTallyCache) { + var marketStatus string + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买涨涨停,只能挂单......") + } + + marketStatus = setting.MarketShareEurEntrust + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderEurMarketPrice(priceNew, tallyCache) + default: + marketStatus = setting.MarketShareEurEntrust + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderEurMarketPrice(priceNew, tallyCache) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买跌跌停,只能挂单......") + } + + marketStatus = setting.MarketShareEurEntrust + default: + marketStatus = setting.MarketShareEurEntrust + } + default: + marketStatus, tallyCache = GetOrderEurMarketPrice(priceNew, tallyCache) + } + + return marketStatus, tallyCache +} + +// CheckOrderEurByChg +// +// @Description: 股票判定涨跌幅业务逻辑 +// @param orderMarket +// @param tallyCache +// @param chg +// @return bool +func CheckOrderEurByChg(orderMarket string, tallyCache ShareEurTallyCache, chg string) bool { + var checkBool bool + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderEurBuyMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderEurSellMarket(orderMarket) + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderEurSellMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderEurBuyMarket(orderMarket) + } + default: + checkBool = false + } + + return checkBool +} + +// CheckOrderEurBuyMarket +// +// @Description: 买涨-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderEurBuyMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareEurEntrust: // 挂单缓存状态--不到持仓 + checkBool = true + case setting.MarketShareEurPosition: // 持仓缓存状态--可以平仓 + checkBool = false + } + + return checkBool +} + +// CheckOrderEurSellMarket +// +// @Description: 买跌-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderEurSellMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareEurEntrust: // 挂单缓存状态-- 到持仓 + checkBool = false + case setting.MarketShareEurPosition: // 持仓缓存状态-- 不能平仓 + checkBool = true + } + + return checkBool +} + +// GetOrderEurMarketPrice +// +// @Description: 获取市价下单开仓信息 +// @param priceNew +// @param tallyCache +// @return string +// @return ShareSgdTallyCache +func GetOrderEurMarketPrice(priceNew string, tallyCache ShareEurTallyCache) (string, ShareEurTallyCache) { + var marketStatus string + priceS := decimal.RequireFromString(priceNew) // 最新市价 + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买入 + openPrice = priceS.Add(difference) // 开盘价格 + case flags.TradeTypeSell: // 卖出 + openPrice = priceS.Sub(difference) // 开盘价格 + } + tallyCache.OpenPrice = openPrice.String() // 股票市价下单开盘价格(price) + tallyCache.Status = flags.Position // 股票市价下单持仓状态(status) + marketStatus = setting.MarketShareEurPosition // 股票下单状态(挂单|持仓)缓存列表 + + return marketStatus, tallyCache +} + +// ShareEurSubMarketPrice +// +// @Description: 获取下单订阅行情数据 +// @param subKey +// @return string +// @return error +func ShareEurSubMarketPrice(subKey string) (string, error) { + price, err := memory.GetShareEurCache(subKey) + if err != nil { + return flags.SetNull, err + } + + return string(price), nil +} + +// ShareEurHashUserOrder +// +// @Description: 下单录入订阅缓存列表(用户订阅|管理员订阅|挂单|持仓) +// @param red +// @param cacheKey +// @param order +// @return error +func ShareEurHashUserOrder(red *redis.Client, cacheKey string, order *ShareEurTallyCache) error { + orderStr, err := json.Marshal(order) + if err != nil { + applogger.Error("%v ShareEurHashUserOrder.Marshal:%v", common.ErrShareEur, err) + return err + } + + if err = red.HSet(context.Background(), cacheKey, order.OrderId, string(orderStr)).Err(); err != nil { + applogger.Error("%v ShareEurHashUserOrder.HSet:%v", common.ErrShareEur, err) + return err + } + + return nil +} + +// UpdateShareEurHashByOrderId +// +// @Description: 更新缓存列表 +// @param reds +// @param orderId +// @param updateKey +// @param status +// @return error +func UpdateShareEurHashByOrderId(reds *redis.Client, orderId, updateKey, status string) error { + order, err := reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel ShareEurTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateShareEurStopByOrderId +// +// @Description: 設置止盈止損 +// @param reds +// @param order +// @param updateKey +// @param status +// @return error +func UpdateShareEurStopByOrderId(reds *redis.Client, order structure.StopOrder, updateKey, status string) error { + orderHash, err := reds.HGet(context.Background(), updateKey, order.OrderId).Result() + if err != nil { + return err + } + + var orderModel ShareEurTallyCache + if err = json.Unmarshal([]byte(orderHash), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderModel.Order.StopType = order.StopType + orderModel.Order.StopLossPrice = order.StopLossPrice + orderModel.Order.StopWinPrice = order.StopWinPrice + + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, order.OrderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} diff --git a/internal/data/tradedeal/share/share_fur.go b/internal/data/tradedeal/share/share_fur.go new file mode 100644 index 0000000..057d804 --- /dev/null +++ b/internal/data/tradedeal/share/share_fur.go @@ -0,0 +1,330 @@ +package share + +import ( + "context" + "encoding/json" + "github.com/redis/go-redis/v9" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" +) + +/* +处理股票股下单交易(订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单) +1>写入挂单缓存列表 +2>监控挂单缓存列表 +3>监控持仓缓存列表 +4>处理完成订单 +5>清理缓存列表 +*/ + +// ShareEurTallyCache +// @Description: +type ShareFurTallyCache struct { + UserId int64 // 用户ID + OrderId string // 订单ID + Symbol string // 交易对 + Status string // 订单状态 + OpenPrice string // 开仓价格 + ClosingPrice string // 平仓价格 + ClosingTime time.Time // 平仓时间 + Order structure.ShareOrder // 下单信息 +} + +// ShareFurCacheDeal +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param subKey +// @param order +// @param chg +// @param priceNew +// @param closingTime +// @return string +// @return *ShareEurTallyCache +// @return error +func ShareFurCacheDeal(ctx context.Context, userId int64, + orderId, subKey string, order structure.ShareOrder, + chg, priceNew string, closingTime, blockTime time.Time) (string, *ShareFurTallyCache, error) { + var marketStatus string + tallyCache := ShareFurTallyCache{ + UserId: userId, // 股票下单用户Id + OrderId: orderId, // 股票下单订单Id + Symbol: order.StockId, // 股票下单交易对 + Status: flags.Entrust, // 股票下单挂单状态 + Order: order, // 股票完整下单信息 + } + + // TODO: 交易下单判定(是否市价交易) + //switch order.DealType { + //case flags.DealTypeLimited: // 限价(买涨|买跌) + // marketStatus = flags.MarketShareFurEntrust + //case flags.DealTypeMarket: // 市价(买涨|买跌) + // if len(priceNew) == 0 { + // marketStatus = flags.MarketShareFurEntrust + // } else { + // marketStatus, tallyCache = GetOrderFurByChg(priceNew, tallyCache, chg) + // } + //} + + // 交易判定 + if order.Type <= 0 { + marketStatus = setting.MarketShareFurEntrust + tallyCache.ClosingTime = closingTime // 平仓时间 + } else { + marketStatus = setting.MarketShareBlkEntrust + tallyCache.OpenPrice = priceNew // 开仓价格 + tallyCache.ClosingTime = blockTime // 平仓时间 + } + + return marketStatus, &tallyCache, nil +} + +// GetOrderFurByChg +// +// @Description: 处理涨跌幅 +// @param priceNew +// @param tallyCache +// @param chg +// @return string +// @return ShareFurTallyCache +func GetOrderFurByChg(priceNew string, tallyCache ShareFurTallyCache, chg string) (string, ShareFurTallyCache) { + var marketStatus string + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买涨涨停,只能挂单......") + } + + marketStatus = setting.MarketShareFurEntrust + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderFurMarketPrice(priceNew, tallyCache) + default: + marketStatus = setting.MarketShareFurEntrust + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderFurMarketPrice(priceNew, tallyCache) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买跌跌停,只能挂单......") + } + + marketStatus = setting.MarketShareFurEntrust + default: + marketStatus = setting.MarketShareFurEntrust + } + default: + marketStatus, tallyCache = GetOrderFurMarketPrice(priceNew, tallyCache) + } + + return marketStatus, tallyCache +} + +// CheckOrderFurByChg +// +// @Description: 股票判定涨跌幅业务逻辑 +// @param orderMarket +// @param tallyCache +// @param chg +// @return bool +func CheckOrderFurByChg(orderMarket string, tallyCache ShareFurTallyCache, chg string) bool { + var checkBool bool + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderFurBuyMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderFurSellMarket(orderMarket) + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderFurSellMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderFurBuyMarket(orderMarket) + } + default: + checkBool = false + } + + return checkBool +} + +// CheckOrderFurBuyMarket +// +// @Description: 买涨-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderFurBuyMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareFurEntrust: // 挂单缓存状态--不到持仓 + checkBool = true + case setting.MarketShareFurPosition: // 持仓缓存状态--可以平仓 + checkBool = false + } + + return checkBool +} + +// CheckOrderFurSellMarket +// +// @Description: 买跌-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderFurSellMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareFurEntrust: // 挂单缓存状态-- 到持仓 + checkBool = false + case setting.MarketShareFurPosition: // 持仓缓存状态-- 不能平仓 + checkBool = true + } + + return checkBool +} + +// GetOrderFurMarketPrice +// +// @Description: 获取市价下单开仓信息 +// @param priceNew +// @param tallyCache +// @return string +// @return ShareFurTallyCache +func GetOrderFurMarketPrice(priceNew string, tallyCache ShareFurTallyCache) (string, ShareFurTallyCache) { + var marketStatus string + priceS := decimal.RequireFromString(priceNew) // 最新市价 + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买入 + openPrice = priceS.Add(difference) // 开盘价格 + case flags.TradeTypeSell: // 卖出 + openPrice = priceS.Sub(difference) // 开盘价格 + } + tallyCache.OpenPrice = openPrice.String() // 股票市价下单开盘价格(price) + tallyCache.Status = flags.Position // 股票市价下单持仓状态(status) + marketStatus = setting.MarketShareFurPosition // 股票下单状态(挂单|持仓)缓存列表 + + return marketStatus, tallyCache +} + +// ShareFurSubMarketPrice +// +// @Description: 获取下单订阅行情数据 +// @param subKey +// @return string +// @return error +func ShareFurSubMarketPrice(subKey string) (string, error) { + price, err := memory.GetShareFurCache(subKey) + if err != nil { + return flags.SetNull, err + } + + return string(price), nil +} + +// ShareFurHashUserOrder +// +// @Description: 下单录入订阅缓存列表(用户订阅|管理员订阅|挂单|持仓) +// @param red +// @param cacheKey +// @param order +// @return error +func ShareFurHashUserOrder(red *redis.Client, cacheKey string, order *ShareFurTallyCache) error { + orderStr, err := json.Marshal(order) + if err != nil { + applogger.Error("%v ShareFurHashUserOrder.Marshal:%v", common.ErrShareFur, err) + return err + } + + if err = red.HSet(context.Background(), cacheKey, order.OrderId, string(orderStr)).Err(); err != nil { + applogger.Error("%v ShareFurHashUserOrder.HSet:%v", common.ErrShareFur, err) + return err + } + + return nil +} + +// UpdateShareFurHashByOrderId +// +// @Description: 更新缓存列表 +// @param reds +// @param orderId +// @param updateKey +// @param status +// @return error +func UpdateShareFurHashByOrderId(reds *redis.Client, orderId, updateKey, status string) error { + order, err := reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel ShareFurTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateShareFurStopByOrderId +// +// @Description: 設置止盈止損 +// @param reds +// @param order +// @param updateKey +// @param status +// @return error +func UpdateShareFurStopByOrderId(reds *redis.Client, order structure.StopOrder, updateKey, status string) error { + orderHash, err := reds.HGet(context.Background(), updateKey, order.OrderId).Result() + if err != nil { + return err + } + + var orderModel ShareFurTallyCache + if err = json.Unmarshal([]byte(orderHash), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderModel.Order.StopType = order.StopType + orderModel.Order.StopLossPrice = order.StopLossPrice + orderModel.Order.StopWinPrice = order.StopWinPrice + + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, order.OrderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} diff --git a/internal/data/tradedeal/share/share_gbx.go b/internal/data/tradedeal/share/share_gbx.go new file mode 100644 index 0000000..a82081d --- /dev/null +++ b/internal/data/tradedeal/share/share_gbx.go @@ -0,0 +1,316 @@ +package share + +import ( + "context" + "encoding/json" + "github.com/redis/go-redis/v9" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" +) + +/* +处理英股下单交易(订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单) +1>写入挂单缓存列表 +2>监控挂单缓存列表 +3>监控持仓缓存列表 +4>处理完成订单 +5>清理缓存列表 +*/ + +// ShareGbxTallyCache +// @Description: +type ShareGbxTallyCache struct { + UserId int64 // 用户ID + OrderId string // 订单ID + Symbol string // 交易对 + Status string // 订单状态 + OpenPrice string // 开仓价格 + ClosingPrice string // 平仓价格 + ClosingTime time.Time // 平仓时间 + Order structure.ShareOrder // 下单信息 +} + +// ShareGbxCacheDeal +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param subKey +// @param order +// @param chg +// @param priceNew +// @param closingTime +// @return string +// @return *ShareUsTallyCache +// @return error +func ShareGbxCacheDeal(ctx context.Context, userId int64, + orderId, subKey string, order structure.ShareOrder, + chg, priceNew string, closingTime, blockTime time.Time) (string, *ShareGbxTallyCache, error) { + var marketStatus string + tallyCache := ShareGbxTallyCache{ + UserId: userId, // 股票下单用户Id + OrderId: orderId, // 股票下单订单Id + Symbol: order.StockId, // 股票下单交易对 + Status: flags.Entrust, // 股票下单挂单状态 + Order: order, // 股票完整下单信息 + } + + // 交易判定 + if order.Type <= 0 { + marketStatus = setting.MarketShareGbxEntrust + tallyCache.ClosingTime = closingTime // 平仓时间 + } else { + marketStatus = setting.MarketShareBlkEntrust + tallyCache.OpenPrice = priceNew // 开仓价格 + tallyCache.ClosingTime = blockTime // 平仓时间 + } + + return marketStatus, &tallyCache, nil +} + +// GetOrderGbxByChg +// +// @Description: 处理涨跌幅 +// @param priceNew +// @param tallyCache +// @param chg +// @return string +// @return ShareGbxTallyCache +func GetOrderGbxByChg(priceNew string, tallyCache ShareGbxTallyCache, chg string) (string, ShareGbxTallyCache) { + var marketStatus string + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买涨涨停,只能挂单......") + } + + marketStatus = setting.MarketShareGbxEntrust + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderGbxMarketPrice(priceNew, tallyCache) + default: + marketStatus = setting.MarketShareGbxEntrust + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderGbxMarketPrice(priceNew, tallyCache) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买跌跌停,只能挂单......") + } + + marketStatus = setting.MarketShareGbxEntrust + default: + marketStatus = setting.MarketShareGbxEntrust + } + default: + marketStatus, tallyCache = GetOrderGbxMarketPrice(priceNew, tallyCache) + } + + return marketStatus, tallyCache +} + +// CheckGbxOrderByChg +// +// @Description: 股票判定涨跌幅业务逻辑 +// @param orderMarket +// @param tallyCache +// @param chg +// @return bool +func CheckGbxOrderByChg(orderMarket string, tallyCache ShareGbxTallyCache, chg string) bool { + var checkBool bool + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderGbxBuyMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderGbxSellMarket(orderMarket) + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderGbxSellMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderGbxBuyMarket(orderMarket) + } + default: + checkBool = false + } + + return checkBool +} + +// CheckOrderInrBuyMarket +// +// @Description: 买涨-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderGbxBuyMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareGbxEntrust: // 挂单缓存状态--不到持仓 + checkBool = true + case setting.MarketShareGbxPosition: // 持仓缓存状态--可以平仓 + checkBool = false + } + + return checkBool +} + +// CheckOrderInrSellMarket +// +// @Description: 买跌-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderGbxSellMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareGbxEntrust: // 挂单缓存状态-- 到持仓 + checkBool = false + case setting.MarketShareGbxPosition: // 持仓缓存状态-- 不能平仓 + checkBool = true + } + + return checkBool +} + +// GetOrderGbxMarketPrice +// +// @Description: 获取市价下单开仓信息 +// @param priceNew +// @param tallyCache +// @return string +// @return ShareGbxTallyCache +func GetOrderGbxMarketPrice(priceNew string, tallyCache ShareGbxTallyCache) (string, ShareGbxTallyCache) { + var marketStatus string + priceS := decimal.RequireFromString(priceNew) // 最新市价 + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买入 + openPrice = priceS.Add(difference) // 开盘价格 + case flags.TradeTypeSell: // 卖出 + openPrice = priceS.Sub(difference) // 开盘价格 + } + tallyCache.OpenPrice = openPrice.String() // 股票市价下单开盘价格(price) + tallyCache.Status = flags.Position // 股票市价下单持仓状态(status) + marketStatus = setting.MarketShareGbxPosition // 股票下单状态(挂单|持仓)缓存列表 + + return marketStatus, tallyCache +} + +// ShareGbxSubMarketPrice +// +// @Description: 获取下单订阅行情数据 +// @param subKey +// @return string +// @return error +func ShareGbxSubMarketPrice(subKey string) (string, error) { + price, err := memory.GetShareGbxCache(subKey) + if err != nil { + return flags.SetNull, err + } + + return string(price), nil +} + +// ShareGbxHashUserOrder +// +// @Description: 下单录入订阅缓存列表(用户订阅|管理员订阅|挂单|持仓) +// @param red +// @param cacheKey +// @param order +// @return error +func ShareGbxHashUserOrder(red *redis.Client, cacheKey string, order *ShareGbxTallyCache) error { + orderStr, err := json.Marshal(order) + if err != nil { + applogger.Error("%v ShareGbxHashUserOrder.Marshal:%v", common.ErrShareGbx, err) + return err + } + + if err = red.HSet(context.Background(), cacheKey, order.OrderId, string(orderStr)).Err(); err != nil { + applogger.Error("%v ShareGbxHashUserOrder.HSet:%v", common.ErrShareGbx, err) + return err + } + + return nil +} + +// UpdateShareGbxHashByOrderId +// +// @Description: 更新缓存列表 +// @param reds +// @param orderId +// @param updateKey +// @param status +// @return error +func UpdateShareGbxHashByOrderId(reds *redis.Client, orderId, updateKey, status string) error { + order, err := reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel ShareGbxTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + return nil +} + +// UpdateShareGbxStopByOrderId +// +// @Description: 更新止盈止損設置 +// @param reds +// @param order +// @param updateKey +// @param status +// @return error +func UpdateShareGbxStopByOrderId(reds *redis.Client, order structure.StopOrder, updateKey, status string) error { + orderHash, err := reds.HGet(context.Background(), updateKey, order.OrderId).Result() + if err != nil { + return err + } + + var orderModel ShareGbxTallyCache + if err = json.Unmarshal([]byte(orderHash), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderModel.Order.StopType = order.StopType + orderModel.Order.StopLossPrice = order.StopLossPrice + orderModel.Order.StopWinPrice = order.StopWinPrice + + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, order.OrderId, string(orderStr)).Err() + if err != nil { + return err + } + return nil +} diff --git a/internal/data/tradedeal/share/share_hkd.go b/internal/data/tradedeal/share/share_hkd.go new file mode 100644 index 0000000..0400d5d --- /dev/null +++ b/internal/data/tradedeal/share/share_hkd.go @@ -0,0 +1,330 @@ +package share + +import ( + "context" + "encoding/json" + "github.com/redis/go-redis/v9" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" +) + +/* +处理港股下单交易(订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单) +1>写入挂单缓存列表 +2>监控挂单缓存列表 +3>监控持仓缓存列表 +4>处理完成订单 +5>清理缓存列表 +*/ + +// ShareHkdTallyCache +// @Description: +type ShareHkdTallyCache struct { + UserId int64 // 用户ID + OrderId string // 订单ID + Symbol string // 交易对 + Status string // 订单状态 + OpenPrice string // 开仓价格 + ClosingPrice string // 平仓价格 + ClosingTime time.Time // 平仓时间 + Order structure.ShareOrder // 下单信息 +} + +// ShareHkdCacheDeal +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param subKey +// @param order +// @param chg +// @param priceNew +// @param closingTime +// @return string +// @return *ShareHkdTallyCache +// @return error +func ShareHkdCacheDeal(ctx context.Context, userId int64, + orderId, subKey string, order structure.ShareOrder, + chg, priceNew string, closingTime, blockTime time.Time) (string, *ShareHkdTallyCache, error) { + var marketStatus string + tallyCache := ShareHkdTallyCache{ + UserId: userId, // 股票下单用户Id + OrderId: orderId, // 股票下单订单Id + Symbol: order.StockId, // 股票下单交易对 + Status: flags.Entrust, // 股票下单挂单状态 + Order: order, // 股票完整下单信息 + } + + // TODO: 交易下单判定(是否市价交易) + //switch order.DealType { + //case flags.DealTypeLimited: // 限价(买涨|买跌) + // marketStatus = flags.MarketShareHkdEntrust + //case flags.DealTypeMarket: // 市价(买涨|买跌) + // if len(priceNew) == 0 { + // marketStatus = flags.MarketShareHkdEntrust + // } else { + // marketStatus, tallyCache = GetOrderHkdByChg(priceNew, tallyCache, chg) + // } + //} + + // 交易判定 + if order.Type <= 0 { + marketStatus = setting.MarketShareHkdEntrust + tallyCache.ClosingTime = closingTime + } else { + marketStatus = setting.MarketShareBlkEntrust + tallyCache.OpenPrice = priceNew + tallyCache.ClosingTime = blockTime + } + + return marketStatus, &tallyCache, nil +} + +// GetOrderHkdByChg +// +// @Description: 处理涨跌幅 +// @param priceNew +// @param tallyCache +// @param chg +// @return string +// @return ShareHkdTallyCache +func GetOrderHkdByChg(priceNew string, tallyCache ShareHkdTallyCache, chg string) (string, ShareHkdTallyCache) { + var marketStatus string + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买涨涨停,只能挂单......") + } + + marketStatus = setting.MarketShareHkdEntrust + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderHkdMarketPrice(priceNew, tallyCache) + default: + marketStatus = setting.MarketShareHkdEntrust + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderHkdMarketPrice(priceNew, tallyCache) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买跌跌停,只能挂单......") + } + + marketStatus = setting.MarketShareHkdEntrust + default: + marketStatus = setting.MarketShareHkdEntrust + } + default: + marketStatus, tallyCache = GetOrderHkdMarketPrice(priceNew, tallyCache) + } + + return marketStatus, tallyCache +} + +// CheckOrderHkdByChg +// +// @Description: 股票判定涨跌幅业务逻辑 +// @param orderMarket +// @param tallyCache +// @param chg +// @return bool +func CheckOrderHkdByChg(orderMarket string, tallyCache ShareHkdTallyCache, chg string) bool { + var checkBool bool + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderHkdBuyMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderHkdSellMarket(orderMarket) + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderHkdSellMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderHkdBuyMarket(orderMarket) + } + default: + checkBool = false + } + + return checkBool +} + +// CheckOrderHkdBuyMarket +// +// @Description: 买涨-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderHkdBuyMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareHkdEntrust: // 挂单缓存状态--不到持仓 + checkBool = true + case setting.MarketShareHkdPosition: // 持仓缓存状态--可以平仓 + checkBool = false + } + + return checkBool +} + +// CheckOrderHkdSellMarket +// +// @Description: 买跌-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderHkdSellMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareHkdEntrust: // 挂单缓存状态-- 到持仓 + checkBool = false + case setting.MarketShareHkdPosition: // 持仓缓存状态-- 不能平仓 + checkBool = true + } + + return checkBool +} + +// GetOrderHkdMarketPrice +// +// @Description: 市价下单开仓信息 +// @param priceNew +// @param tallyCache +// @return string +// @return ShareHkdTallyCache +func GetOrderHkdMarketPrice(priceNew string, tallyCache ShareHkdTallyCache) (string, ShareHkdTallyCache) { + var marketStatus string + priceS := decimal.RequireFromString(priceNew) // 最新市价 + + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买入 + openPrice = priceS.Add(difference) // 开盘价格 + case flags.TradeTypeSell: // 卖出 + openPrice = priceS.Sub(difference) // 开盘价格 + } + + tallyCache.OpenPrice = openPrice.String() // 股票市价下单开盘价格(price) + tallyCache.Status = flags.Position // 股票市价下单持仓状态(status) + marketStatus = setting.MarketShareHkdPosition // 股票下单状态(挂单|持仓)缓存列表 + + return marketStatus, tallyCache +} + +// ShareHkdSubMarketPrice +// +// @Description: 下单订阅行情数据 +// @param subKey +// @return string +// @return error +func ShareHkdSubMarketPrice(subKey string) (string, error) { + price, err := memory.GetShareHkdCache(subKey) + if err != nil { + return flags.SetNull, err + } + + return string(price), nil +} + +// ShareHkdHashUserOrder +// +// @Description: 下单录入订阅缓存列表(用户订阅|管理员订阅|挂单|持仓) +// @param red +// @param cacheKey +// @param order +// @return error +func ShareHkdHashUserOrder(red *redis.Client, cacheKey string, order *ShareHkdTallyCache) error { + orderStr, err := json.Marshal(order) + if err != nil { + applogger.Error("%v ShareHkdHashUserOrder.Marshal:%v", common.ErrShareHkd, err) + return err + } + + if err = red.HSet(context.Background(), cacheKey, order.OrderId, string(orderStr)).Err(); err != nil { + applogger.Error("%v ShareHkdHashUserOrder.HSet:%v", common.ErrShareHkd, err) + return err + } + + return nil +} + +// UpdateShareHkdHashByOrderId +// +// @Description: 更新缓存列表 +// @param reds +// @param orderId +// @param updateKey +// @param status +// @return error +func UpdateShareHkdHashByOrderId(reds *redis.Client, orderId, updateKey, status string) error { + order, err := reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel ShareHkdTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + return nil +} + +// UpdateShareHkdStopByOrderId +// +// @Description: 更新止盈止損設置 +// @param reds +// @param order +// @param updateKey +// @param status +// @return error +func UpdateShareHkdStopByOrderId(reds *redis.Client, order structure.StopOrder, updateKey, status string) error { + orderHash, err := reds.HGet(context.Background(), updateKey, order.OrderId).Result() + if err != nil { + return err + } + + var orderModel ShareHkdTallyCache + if err = json.Unmarshal([]byte(orderHash), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderModel.Order.StopType = order.StopType + orderModel.Order.StopLossPrice = order.StopLossPrice + orderModel.Order.StopWinPrice = order.StopWinPrice + + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, order.OrderId, string(orderStr)).Err() + if err != nil { + return err + } + return nil +} diff --git a/internal/data/tradedeal/share/share_idn.go b/internal/data/tradedeal/share/share_idn.go new file mode 100644 index 0000000..51d2657 --- /dev/null +++ b/internal/data/tradedeal/share/share_idn.go @@ -0,0 +1,328 @@ +package share + +import ( + "context" + "encoding/json" + "github.com/redis/go-redis/v9" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" +) + +/* +处理印尼股下单交易(订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单) +1>写入挂单缓存列表 +2>监控挂单缓存列表 +3>监控持仓缓存列表 +4>处理完成订单 +5>清理缓存列表 +*/ + +// ShareIdnTallyCache +// @Description: +type ShareIdnTallyCache struct { + UserId int64 // 用户ID + OrderId string // 订单ID + Symbol string // 交易对 + Status string // 订单状态 + OpenPrice string // 开仓价格 + ClosingPrice string // 平仓价格 + ClosingTime time.Time // 平仓时间 + Order structure.ShareOrder // 下单信息 +} + +// ShareIdnCacheDeal +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param subKey +// @param order +// @param chg +// @param priceNew +// @param closingTime +// @return string +// @return *ShareIdnTallyCache +// @return error +func ShareIdnCacheDeal(ctx context.Context, userId int64, + orderId, subKey string, order structure.ShareOrder, + chg, priceNew string, closingTime, blockTime time.Time) (string, *ShareIdnTallyCache, error) { + var marketStatus string + tallyCache := ShareIdnTallyCache{ + UserId: userId, // 股票下单用户Id + OrderId: orderId, // 股票下单订单Id + Symbol: order.StockId, // 股票下单交易对 + Status: flags.Entrust, // 股票下单挂单状态 + Order: order, // 股票完整下单信息 + } + + // TODO: 交易下单判定(是否市价交易) + //switch order.DealType { + //case flags.DealTypeLimited: // 限价(买涨|买跌) + // marketStatus = flags.MarketShareIdnEntrust + //case flags.DealTypeMarket: // 市价(买涨|买跌) + // if len(priceNew) == 0 { + // marketStatus = flags.MarketShareIdnEntrust + // } else { + // marketStatus, tallyCache = GetIdnOrderByChg(priceNew, tallyCache, chg) + // } + //} + + // 交易判定 + if order.Type <= 0 { + marketStatus = setting.MarketShareIdnEntrust + tallyCache.ClosingTime = closingTime + } else { + marketStatus = setting.MarketShareBlkEntrust + tallyCache.OpenPrice = priceNew + tallyCache.ClosingTime = blockTime + } + + return marketStatus, &tallyCache, nil +} + +// GetIdnOrderByChg +// +// @Description: 处理涨跌幅 +// @param priceNew +// @param tallyCache +// @param chg +// @return string +// @return ShareIdnTallyCache +func GetIdnOrderByChg(priceNew string, tallyCache ShareIdnTallyCache, chg string) (string, ShareIdnTallyCache) { + var marketStatus string + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买涨涨停,只能挂单......") + } + + marketStatus = setting.MarketShareIdnEntrust + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetIdnOrderMarketPrice(priceNew, tallyCache) + default: + marketStatus = setting.MarketShareIdnEntrust + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetIdnOrderMarketPrice(priceNew, tallyCache) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买跌跌停,只能挂单......") + } + + marketStatus = setting.MarketShareIdnEntrust + default: + marketStatus = setting.MarketShareIdnEntrust + } + default: + marketStatus, tallyCache = GetIdnOrderMarketPrice(priceNew, tallyCache) + } + + return marketStatus, tallyCache +} + +// CheckIdnOrderByChg +// +// @Description: 股票判定涨跌幅业务逻辑 +// @param orderMarket +// @param tallyCache +// @param chg +// @return bool +func CheckIdnOrderByChg(orderMarket string, tallyCache ShareIdnTallyCache, chg string) bool { + var checkBool bool + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,持仓可以平仓 + checkBool = CheckIdnOrderBuyMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,持仓不能平仓 + checkBool = CheckIdnOrderSellMarket(orderMarket) + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,持仓不能平仓 + checkBool = CheckIdnOrderSellMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,持仓可以平仓 + checkBool = CheckIdnOrderBuyMarket(orderMarket) + } + default: + checkBool = false + } + + return checkBool +} + +// CheckIdnOrderBuyMarket +// +// @Description: 买涨-涨跌幅 +// @param orderMarket +// @return bool +func CheckIdnOrderBuyMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareIdnEntrust: // 挂单缓存状态--不到持仓 + checkBool = true + case setting.MarketShareIdnPosition: // 持仓缓存状态--可以平仓 + checkBool = false + } + + return checkBool +} + +// CheckIdnOrderSellMarket +// +// @Description: +// @param orderMarket +// @return bool +func CheckIdnOrderSellMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareIdnEntrust: // 挂单缓存状态-- 到持仓 + checkBool = false + case setting.MarketShareIdnPosition: // 持仓缓存状态-- 不能平仓 + checkBool = true + } + + return checkBool +} + +// GetIdnOrderMarketPrice +// +// @Description: 获取市价下单开仓信息 +// @param priceNew +// @param tallyCache +// @return string +// @return ShareIdnTallyCache +func GetIdnOrderMarketPrice(priceNew string, tallyCache ShareIdnTallyCache) (string, ShareIdnTallyCache) { + var marketStatus string + priceS := decimal.RequireFromString(priceNew) // 最新市价 + var openPrice decimal.Decimal + difference := utils.RandInt() // 设置价差 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买入 + openPrice = priceS.Add(difference) // 开盘价格 + case flags.TradeTypeSell: // 卖出 + openPrice = priceS.Sub(difference) // 开盘价格 + } + tallyCache.OpenPrice = openPrice.String() // 股票市价下单开盘价格(price) + tallyCache.Status = flags.Position // 股票市价下单持仓状态(status) + marketStatus = setting.MarketShareIdnPosition // 股票下单状态(挂单|持仓)缓存列表 + + return marketStatus, tallyCache +} + +// ShareIdnSubMarketPrice +// +// @Description: 下单订阅行情数据 +// @param subKey +// @return string +// @return error +func ShareIdnSubMarketPrice(subKey string) (string, error) { + price, err := memory.GetShareIdnCache(subKey) + if err != nil { + return flags.SetNull, err + } + + return string(price), nil +} + +// ShareIdnHashUserOrder +// +// @Description: 下单录入订阅缓存列表(用户订阅|管理员订阅|挂单|持仓) +// @param red +// @param cacheKey +// @param order +// @return error +func ShareIdnHashUserOrder(red *redis.Client, cacheKey string, order *ShareIdnTallyCache) error { + orderStr, err := json.Marshal(order) + if err != nil { + applogger.Error("%v ShareIdnHashUserOrder.Marshal:%v", common.ErrShareIdn, err) + return err + } + + if err = red.HSet(context.Background(), cacheKey, order.OrderId, string(orderStr)).Err(); err != nil { + applogger.Error("%v ShareIdnHashUserOrder.HSet:%v", common.ErrShareIdn, err) + return err + } + + return nil +} + +// UpdateShareIdnHashByOrderId +// +// @Description: 更新缓存列表 +// @param reds +// @param orderId +// @param updateKey +// @param status +// @return error +func UpdateShareIdnHashByOrderId(reds *redis.Client, orderId, updateKey, status string) error { + order, err := reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel ShareIdnTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + return nil +} + +// UpdateShareIdnStopByOrderId +// +// @Description: 更新止盈止損設置 +// @param reds +// @param order +// @param updateKey +// @param status +// @return error +func UpdateShareIdnStopByOrderId(reds *redis.Client, order structure.StopOrder, updateKey, status string) error { + orderHash, err := reds.HGet(context.Background(), updateKey, order.OrderId).Result() + if err != nil { + return err + } + + var orderModel ShareIdnTallyCache + if err = json.Unmarshal([]byte(orderHash), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderModel.Order.StopType = order.StopType + orderModel.Order.StopLossPrice = order.StopLossPrice + orderModel.Order.StopWinPrice = order.StopWinPrice + + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, order.OrderId, string(orderStr)).Err() + if err != nil { + return err + } + return nil +} diff --git a/internal/data/tradedeal/share/share_inr.go b/internal/data/tradedeal/share/share_inr.go new file mode 100644 index 0000000..c51654c --- /dev/null +++ b/internal/data/tradedeal/share/share_inr.go @@ -0,0 +1,328 @@ +package share + +import ( + "context" + "encoding/json" + "github.com/redis/go-redis/v9" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" +) + +/* +处理印度股下单交易(订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单) +1>写入挂单缓存列表 +2>监控挂单缓存列表 +3>监控持仓缓存列表 +4>处理完成订单 +5>清理缓存列表 +*/ + +// ShareInrTallyCache +// @Description: +type ShareInrTallyCache struct { + UserId int64 // 用户ID + OrderId string // 订单ID + Symbol string // 交易对 + Status string // 订单状态 + OpenPrice string // 开仓价格 + ClosingPrice string // 平仓价格 + ClosingTime time.Time // 平仓时间 + Order structure.ShareOrder // 下单信息 +} + +// ShareInrCacheDeal +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param subKey +// @param order +// @param chg +// @param priceNew +// @param closingTime +// @return string +// @return *ShareInrTallyCache +// @return error +func ShareInrCacheDeal(ctx context.Context, userId int64, + orderId, subKey string, order structure.ShareOrder, + chg, priceNew string, closingTime, blockTime time.Time) (string, *ShareInrTallyCache, error) { + var marketStatus string + tallyCache := ShareInrTallyCache{ + UserId: userId, // 股票下单用户Id + OrderId: orderId, // 股票下单订单Id + Symbol: order.StockId, // 股票下单交易对 + Status: flags.Entrust, // 股票下单挂单状态 + Order: order, // 股票完整下单信息 + } + + // TODO: 交易下单判定(是否市价交易) + //switch order.DealType { + //case flags.DealTypeLimited: // 限价(买涨|买跌) + // marketStatus = flags.MarketShareInrEntrust + //case flags.DealTypeMarket: // 市价(买涨|买跌) + // if len(priceNew) == 0 { + // marketStatus = flags.MarketShareInrEntrust + // } else { + // marketStatus, tallyCache = GetOrderInrByChg(priceNew, tallyCache, chg) + // } + //} + + // 交易判定 + if order.Type <= 0 { + marketStatus = setting.MarketShareInrEntrust + tallyCache.ClosingTime = closingTime // 平仓时间 + } else { + marketStatus = setting.MarketShareBlkEntrust + tallyCache.OpenPrice = priceNew // 开仓价格 + tallyCache.ClosingTime = blockTime // 平仓时间 + } + + return marketStatus, &tallyCache, nil +} + +// GetOrderInrByChg +// +// @Description: 处理涨跌幅 +// @param priceNew +// @param tallyCache +// @param chg +// @return string +// @return ShareInrTallyCache +func GetOrderInrByChg(priceNew string, tallyCache ShareInrTallyCache, chg string) (string, ShareInrTallyCache) { + var marketStatus string + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买涨涨停,只能挂单......") + } + + marketStatus = setting.MarketShareInrEntrust + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderInrMarketPrice(priceNew, tallyCache) + default: + marketStatus = setting.MarketShareInrEntrust + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderInrMarketPrice(priceNew, tallyCache) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买跌跌停,只能挂单......") + } + + marketStatus = setting.MarketShareInrEntrust + default: + marketStatus = setting.MarketShareInrEntrust + } + default: + marketStatus, tallyCache = GetOrderInrMarketPrice(priceNew, tallyCache) + } + + return marketStatus, tallyCache +} + +// CheckInrOrderByChg +// +// @Description: 股票判定涨跌幅业务逻辑 +// @param orderMarket +// @param tallyCache +// @param chg +// @return bool +func CheckInrOrderByChg(orderMarket string, tallyCache ShareInrTallyCache, chg string) bool { + var checkBool bool + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderInrBuyMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderInrSellMarket(orderMarket) + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderInrSellMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderInrBuyMarket(orderMarket) + } + default: + checkBool = false + } + + return checkBool +} + +// CheckOrderInrBuyMarket +// +// @Description: 买涨-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderInrBuyMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareInrEntrust: // 挂单缓存状态--不到持仓 + checkBool = true + case setting.MarketShareInrPosition: // 持仓缓存状态--可以平仓 + checkBool = false + } + + return checkBool +} + +// CheckOrderInrSellMarket +// +// @Description: 买跌-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderInrSellMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareInrEntrust: // 挂单缓存状态-- 到持仓 + checkBool = false + case setting.MarketShareInrPosition: // 持仓缓存状态-- 不能平仓 + checkBool = true + } + + return checkBool +} + +// GetOrderInrMarketPrice +// +// @Description: 获取市价下单开仓信息 +// @param priceNew +// @param tallyCache +// @return string +// @return ShareInrTallyCache +func GetOrderInrMarketPrice(priceNew string, tallyCache ShareInrTallyCache) (string, ShareInrTallyCache) { + var marketStatus string + priceS := decimal.RequireFromString(priceNew) // 最新市价 + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买入 + openPrice = priceS.Add(difference) // 开盘价格 + case flags.TradeTypeSell: // 卖出 + openPrice = priceS.Sub(difference) // 开盘价格 + } + tallyCache.OpenPrice = openPrice.String() // 股票市价下单开盘价格(price) + tallyCache.Status = flags.Position // 股票市价下单持仓状态(status) + marketStatus = setting.MarketShareInrPosition // 股票下单状态(挂单|持仓)缓存列表 + + return marketStatus, tallyCache +} + +// ShareInrSubMarketPrice +// +// @Description: 获取下单订阅行情数据 +// @param subKey +// @return string +// @return error +func ShareInrSubMarketPrice(subKey string) (string, error) { + price, err := memory.GetShareInrCache(subKey) + if err != nil { + return flags.SetNull, err + } + + return string(price), nil +} + +// ShareInrHashUserOrder +// +// @Description: 下单录入订阅缓存列表(用户订阅|管理员订阅|挂单|持仓) +// @param red +// @param cacheKey +// @param order +// @return error +func ShareInrHashUserOrder(red *redis.Client, cacheKey string, order *ShareInrTallyCache) error { + orderStr, err := json.Marshal(order) + if err != nil { + applogger.Error("%v ShareInrHashUserOrder.Marshal:%v", common.ErrShareInr, err) + return err + } + + if err = red.HSet(context.Background(), cacheKey, order.OrderId, string(orderStr)).Err(); err != nil { + applogger.Error("%v ShareInrHashUserOrder.HSet:%v", common.ErrShareInr, err) + return err + } + + return nil +} + +// UpdateShareInHashByOrderId +// +// @Description: 更新缓存列表 +// @param reds +// @param orderId +// @param updateKey +// @param status +// @return error +func UpdateShareInHashByOrderId(reds *redis.Client, orderId, updateKey, status string) error { + order, err := reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel ShareInrTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + return nil +} + +// UpdateShareInrStopByOrderId +// +// @Description: 更新止盈止損設置 +// @param reds +// @param order +// @param updateKey +// @param status +// @return error +func UpdateShareInrStopByOrderId(reds *redis.Client, order structure.StopOrder, updateKey, status string) error { + orderHash, err := reds.HGet(context.Background(), updateKey, order.OrderId).Result() + if err != nil { + return err + } + + var orderModel ShareInrTallyCache + if err = json.Unmarshal([]byte(orderHash), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderModel.Order.StopType = order.StopType + orderModel.Order.StopLossPrice = order.StopLossPrice + orderModel.Order.StopWinPrice = order.StopWinPrice + + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, order.OrderId, string(orderStr)).Err() + if err != nil { + return err + } + return nil +} diff --git a/internal/data/tradedeal/share/share_jpy.go b/internal/data/tradedeal/share/share_jpy.go new file mode 100644 index 0000000..6f59f21 --- /dev/null +++ b/internal/data/tradedeal/share/share_jpy.go @@ -0,0 +1,330 @@ +package share + +import ( + "context" + "encoding/json" + "github.com/redis/go-redis/v9" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" +) + +/* +处理股票股下单交易(订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单) +1>写入挂单缓存列表 +2>监控挂单缓存列表 +3>监控持仓缓存列表 +4>处理完成订单 +5>清理缓存列表 +*/ + +// ShareEurTallyCache +// @Description: +type ShareJpyTallyCache struct { + UserId int64 // 用户ID + OrderId string // 订单ID + Symbol string // 交易对 + Status string // 订单状态 + OpenPrice string // 开仓价格 + ClosingPrice string // 平仓价格 + ClosingTime time.Time // 平仓时间 + Order structure.ShareOrder // 下单信息 +} + +// ShareJpyCacheDeal +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param subKey +// @param order +// @param chg +// @param priceNew +// @param closingTime +// @return string +// @return *ShareEurTallyCache +// @return error +func ShareJpyCacheDeal(ctx context.Context, userId int64, + orderId, subKey string, order structure.ShareOrder, + chg, priceNew string, closingTime, blockTime time.Time) (string, *ShareJpyTallyCache, error) { + var marketStatus string + tallyCache := ShareJpyTallyCache{ + UserId: userId, // 股票下单用户Id + OrderId: orderId, // 股票下单订单Id + Symbol: order.StockId, // 股票下单交易对 + Status: flags.Entrust, // 股票下单挂单状态 + Order: order, // 股票完整下单信息 + } + + // TODO: 交易下单判定(是否市价交易) + //switch order.DealType { + //case flags.DealTypeLimited: // 限价(买涨|买跌) + // marketStatus = flags.MarketShareJpyEntrust + //case flags.DealTypeMarket: // 市价(买涨|买跌) + // if len(priceNew) == 0 { + // marketStatus = flags.MarketShareJpyEntrust + // } else { + // marketStatus, tallyCache = GetOrderJpyByChg(priceNew, tallyCache, chg) + // } + //} + + // 交易判定 + if order.Type <= 0 { + marketStatus = setting.MarketShareJpyEntrust + tallyCache.ClosingTime = closingTime // 平仓时间 + } else { + marketStatus = setting.MarketShareBlkEntrust + tallyCache.OpenPrice = priceNew // 开仓价格 + tallyCache.ClosingTime = blockTime // 平仓时间 + } + + return marketStatus, &tallyCache, nil +} + +// GetOrderJpyByChg +// +// @Description: 处理涨跌幅 +// @param priceNew +// @param tallyCache +// @param chg +// @return string +// @return ShareJpyTallyCache +func GetOrderJpyByChg(priceNew string, tallyCache ShareJpyTallyCache, chg string) (string, ShareJpyTallyCache) { + var marketStatus string + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买涨涨停,只能挂单......") + } + + marketStatus = setting.MarketShareJpyEntrust + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderJpyMarketPrice(priceNew, tallyCache) + default: + marketStatus = setting.MarketShareJpyEntrust + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderJpyMarketPrice(priceNew, tallyCache) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买跌跌停,只能挂单......") + } + + marketStatus = setting.MarketShareJpyEntrust + default: + marketStatus = setting.MarketShareJpyEntrust + } + default: + marketStatus, tallyCache = GetOrderJpyMarketPrice(priceNew, tallyCache) + } + + return marketStatus, tallyCache +} + +// CheckOrderJpyByChg +// +// @Description: 股票判定涨跌幅业务逻辑 +// @param orderMarket +// @param tallyCache +// @param chg +// @return bool +func CheckOrderJpyByChg(orderMarket string, tallyCache ShareJpyTallyCache, chg string) bool { + var checkBool bool + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderJpyBuyMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderJpySellMarket(orderMarket) + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderJpySellMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderJpyBuyMarket(orderMarket) + } + default: + checkBool = false + } + + return checkBool +} + +// CheckOrderJpyBuyMarket +// +// @Description: 买涨-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderJpyBuyMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareJpyEntrust: // 挂单缓存状态--不到持仓 + checkBool = true + case setting.MarketShareJpyPosition: // 持仓缓存状态--可以平仓 + checkBool = false + } + + return checkBool +} + +// CheckOrderJpySellMarket +// +// @Description: 买跌-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderJpySellMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareJpyEntrust: // 挂单缓存状态-- 到持仓 + checkBool = false + case setting.MarketShareJpyPosition: // 持仓缓存状态-- 不能平仓 + checkBool = true + } + + return checkBool +} + +// GetOrderJpyMarketPrice +// +// @Description: 获取市价下单开仓信息 +// @param priceNew +// @param tallyCache +// @return string +// @return ShareJpyTallyCache +func GetOrderJpyMarketPrice(priceNew string, tallyCache ShareJpyTallyCache) (string, ShareJpyTallyCache) { + var marketStatus string + priceS := decimal.RequireFromString(priceNew) // 最新市价 + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买入 + openPrice = priceS.Add(difference) // 开盘价格 + case flags.TradeTypeSell: // 卖出 + openPrice = priceS.Sub(difference) // 开盘价格 + } + tallyCache.OpenPrice = openPrice.String() // 股票市价下单开盘价格(price) + tallyCache.Status = flags.Position // 股票市价下单持仓状态(status) + marketStatus = setting.MarketShareJpyPosition // 股票下单状态(挂单|持仓)缓存列表 + + return marketStatus, tallyCache +} + +// ShareJpySubMarketPrice +// +// @Description: 获取下单订阅行情数据 +// @param subKey +// @return string +// @return error +func ShareJpySubMarketPrice(subKey string) (string, error) { + price, err := memory.GetShareJpyCache(subKey) + if err != nil { + return flags.SetNull, err + } + + return string(price), nil +} + +// ShareJpyHashUserOrder +// +// @Description: 下单录入订阅缓存列表(用户订阅|管理员订阅|挂单|持仓) +// @param red +// @param cacheKey +// @param order +// @return error +func ShareJpyHashUserOrder(red *redis.Client, cacheKey string, order *ShareJpyTallyCache) error { + orderStr, err := json.Marshal(order) + if err != nil { + applogger.Error("%v ShareJpyHashUserOrder.Marshal:%v", common.ErrShareJpy, err) + return err + } + + if err = red.HSet(context.Background(), cacheKey, order.OrderId, string(orderStr)).Err(); err != nil { + applogger.Error("%v ShareJpyHashUserOrder.HSet:%v", common.ErrShareJpy, err) + return err + } + + return nil +} + +// UpdateShareJpyHashByOrderId +// +// @Description: 更新缓存列表 +// @param reds +// @param orderId +// @param updateKey +// @param status +// @return error +func UpdateShareJpyHashByOrderId(reds *redis.Client, orderId, updateKey, status string) error { + order, err := reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel ShareJpyTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateShareJpyStopByOrderId +// +// @Description: 設置止盈止損 +// @param reds +// @param order +// @param updateKey +// @param status +// @return error +func UpdateShareJpyStopByOrderId(reds *redis.Client, order structure.StopOrder, updateKey, status string) error { + orderHash, err := reds.HGet(context.Background(), updateKey, order.OrderId).Result() + if err != nil { + return err + } + + var orderModel ShareJpyTallyCache + if err = json.Unmarshal([]byte(orderHash), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderModel.Order.StopType = order.StopType + orderModel.Order.StopLossPrice = order.StopLossPrice + orderModel.Order.StopWinPrice = order.StopWinPrice + + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, order.OrderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} diff --git a/internal/data/tradedeal/share/share_mys.go b/internal/data/tradedeal/share/share_mys.go new file mode 100644 index 0000000..3c9e412 --- /dev/null +++ b/internal/data/tradedeal/share/share_mys.go @@ -0,0 +1,330 @@ +package share + +import ( + "context" + "encoding/json" + "github.com/redis/go-redis/v9" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" +) + +/* +处理马股下单交易(订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单) +1>写入挂单缓存列表 +2>监控挂单缓存列表 +3>监控持仓缓存列表 +4>处理完成订单 +5>清理缓存列表 +*/ + +// ShareMysTallyCache +// @Description: +type ShareMysTallyCache struct { + UserId int64 // 用户ID + OrderId string // 订单ID + Symbol string // 交易对 + Status string // 订单状态 + OpenPrice string // 开仓价格 + ClosingPrice string // 平仓价格 + ClosingTime time.Time // 平仓时间 + Order structure.ShareOrder // 下单信息 +} + +// ShareMysCacheDeal +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param subKey +// @param order +// @param chg +// @param priceNew +// @param closingTime +// @return string +// @return *ShareMysTallyCache +// @return error +func ShareMysCacheDeal(ctx context.Context, userId int64, + orderId, subKey string, order structure.ShareOrder, + chg, priceNew string, closingTime, blockTime time.Time) (string, *ShareMysTallyCache, error) { + var marketStatus string + tallyCache := ShareMysTallyCache{ + UserId: userId, // 股票下单用户Id + OrderId: orderId, // 股票下单订单Id + Symbol: order.StockId, // 股票下单交易对 + Status: flags.Entrust, // 股票下单挂单状态 + Order: order, // 股票完整下单信息 + } + + // TODO: 交易下单判定(是否市价交易) + //switch order.DealType { + //case flags.DealTypeLimited: // 限价(买涨|买跌) + // marketStatus = flags.MarketShareMysEntrust + //case flags.DealTypeMarket: // 市价(买涨|买跌) + // if len(priceNew) == 0 { + // marketStatus = flags.MarketShareMysEntrust + // } else { + // marketStatus, tallyCache = GetOrderMysByChg(priceNew, tallyCache, chg) + // } + //} + + // 交易判定 + if order.Type <= 0 { + marketStatus = setting.MarketShareMysEntrust + tallyCache.ClosingTime = closingTime + } else { + marketStatus = setting.MarketShareBlkEntrust + tallyCache.OpenPrice = priceNew + tallyCache.ClosingTime = blockTime + } + + return marketStatus, &tallyCache, nil +} + +// GetOrderMysByChg +// +// @Description: 处理涨跌幅 +// @param priceNew +// @param tallyCache +// @param chg +// @return string +// @return ShareMysTallyCache +func GetOrderMysByChg(priceNew string, tallyCache ShareMysTallyCache, chg string) (string, ShareMysTallyCache) { + var marketStatus string + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买涨涨停,只能挂单......") + } + + marketStatus = setting.MarketShareMysEntrust + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderMysMarketPrice(priceNew, tallyCache) + default: + marketStatus = setting.MarketShareMysEntrust + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderMysMarketPrice(priceNew, tallyCache) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买跌跌停,只能挂单......") + } + + marketStatus = setting.MarketShareMysEntrust + default: + marketStatus = setting.MarketShareMysEntrust + } + default: + marketStatus, tallyCache = GetOrderMysMarketPrice(priceNew, tallyCache) + } + + return marketStatus, tallyCache +} + +// CheckOrderMysByChg +// +// @Description: 股票判定涨跌幅业务逻辑 +// @param orderMarket +// @param tallyCache +// @param chg +// @return bool +func CheckOrderMysByChg(orderMarket string, tallyCache ShareMysTallyCache, chg string) bool { + var checkBool bool + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderMysBuyMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderMysSellMarket(orderMarket) + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderMysSellMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderMysBuyMarket(orderMarket) + } + default: + checkBool = false + } + + return checkBool +} + +// CheckOrderMysBuyMarket +// +// @Description: 买涨-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderMysBuyMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareMysEntrust: // 挂单缓存状态--不到持仓 + checkBool = true + case setting.MarketShareMysPosition: // 持仓缓存状态--可以平仓 + checkBool = false + } + + return checkBool +} + +// CheckOrderMysSellMarket +// +// @Description: 买跌-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderMysSellMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareMysEntrust: // 挂单缓存状态-- 到持仓 + checkBool = false + case setting.MarketShareMysPosition: // 持仓缓存状态-- 不能平仓 + checkBool = true + } + + return checkBool +} + +// GetOrderMysMarketPrice +// +// @Description: 获取市价下单开仓信息 +// @param priceNew +// @param tallyCache +// @return string +// @return ShareMysTallyCache +func GetOrderMysMarketPrice(priceNew string, tallyCache ShareMysTallyCache) (string, ShareMysTallyCache) { + var marketStatus string + priceS := decimal.RequireFromString(priceNew) // 最新市价 + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买入 + openPrice = priceS.Add(difference) // 开盘价格 + case flags.TradeTypeSell: // 卖出 + openPrice = priceS.Sub(difference) // 开盘价格 + } + tallyCache.OpenPrice = openPrice.String() // 股票市价下单开盘价格(price) + tallyCache.Status = flags.Position // 股票市价下单持仓状态(status) + marketStatus = setting.MarketShareMysPosition // 股票下单状态(挂单|持仓)缓存列表 + + return marketStatus, tallyCache +} + +// ShareMysSubMarketPrice +// +// @Description: 获取下单订阅行情数据 +// @param subKey +// @return string +// @return error +func ShareMysSubMarketPrice(subKey string) (string, error) { + price, err := memory.GetShareMysCache(subKey) + if err != nil { + return flags.SetNull, err + } + + return string(price), nil +} + +// ShareMysHashUserOrder +// +// @Description: 下单录入订阅缓存列表(用户订阅|管理员订阅|挂单|持仓) +// @param red +// @param cacheKey +// @param order +// @return error +func ShareMysHashUserOrder(red *redis.Client, cacheKey string, order *ShareMysTallyCache) error { + orderStr, err := json.Marshal(order) + if err != nil { + applogger.Error("%v ShareMysHashUserOrder.Marshal:%v", common.ErrShareMys, err) + return err + } + + if err = red.HSet(context.Background(), cacheKey, order.OrderId, string(orderStr)).Err(); err != nil { + applogger.Error("%v ShareMysHashUserOrder.HSet:%v", common.ErrShareMys, err) + return err + } + + return nil +} + +// UpdateShareMysHashByOrderId +// +// @Description: 更新缓存列表 +// @param reds +// @param orderId +// @param updateKey +// @param status +// @return error +func UpdateShareMysHashByOrderId(reds *redis.Client, orderId, updateKey, status string) error { + order, err := reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel ShareMysTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateShareMysStopByOrderId +// +// @Description: 更新止盈止損設置 +// @param reds +// @param order +// @param updateKey +// @param status +// @return error +func UpdateShareMysStopByOrderId(reds *redis.Client, order structure.StopOrder, updateKey, status string) error { + orderHash, err := reds.HGet(context.Background(), updateKey, order.OrderId).Result() + if err != nil { + return err + } + + var orderModel ShareMysTallyCache + if err = json.Unmarshal([]byte(orderHash), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderModel.Order.StopType = order.StopType + orderModel.Order.StopLossPrice = order.StopLossPrice + orderModel.Order.StopWinPrice = order.StopWinPrice + + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, order.OrderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} diff --git a/internal/data/tradedeal/share/share_sgd.go b/internal/data/tradedeal/share/share_sgd.go new file mode 100644 index 0000000..90faf0f --- /dev/null +++ b/internal/data/tradedeal/share/share_sgd.go @@ -0,0 +1,330 @@ +package share + +import ( + "context" + "encoding/json" + "github.com/redis/go-redis/v9" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" +) + +/* +处理股票股下单交易(订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单) +1>写入挂单缓存列表 +2>监控挂单缓存列表 +3>监控持仓缓存列表 +4>处理完成订单 +5>清理缓存列表 +*/ + +// ShareSgdTallyCache +// @Description: +type ShareSgdTallyCache struct { + UserId int64 // 用户ID + OrderId string // 订单ID + Symbol string // 交易对 + Status string // 订单状态 + OpenPrice string // 开仓价格 + ClosingPrice string // 平仓价格 + ClosingTime time.Time // 平仓时间 + Order structure.ShareOrder // 下单信息 +} + +// ShareSgdCacheDeal +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param subKey +// @param order +// @param chg +// @param priceNew +// @param closingTime +// @return string +// @return *ShareSgdTallyCache +// @return error +func ShareSgdCacheDeal(ctx context.Context, userId int64, + orderId, subKey string, order structure.ShareOrder, + chg, priceNew string, closingTime, blockTime time.Time) (string, *ShareSgdTallyCache, error) { + var marketStatus string + tallyCache := ShareSgdTallyCache{ + UserId: userId, // 股票下单用户Id + OrderId: orderId, // 股票下单订单Id + Symbol: order.StockId, // 股票下单交易对 + Status: flags.Entrust, // 股票下单挂单状态 + Order: order, // 股票完整下单信息 + } + + // TODO: 交易下单判定(是否市价交易) + //switch order.DealType { + //case flags.DealTypeLimited: // 限价(买涨|买跌) + // marketStatus = flags.MarketShareSgdEntrust + //case flags.DealTypeMarket: // 市价(买涨|买跌) + // if len(priceNew) == 0 { + // marketStatus = flags.MarketShareSgdEntrust + // } else { + // marketStatus, tallyCache = GetOrderSgdByChg(priceNew, tallyCache, chg) + // } + //} + + // 交易判定 + if order.Type <= 0 { + marketStatus = setting.MarketShareSgdEntrust + tallyCache.ClosingTime = closingTime // 平仓时间 + } else { + marketStatus = setting.MarketShareBlkEntrust + tallyCache.OpenPrice = priceNew // 开仓价格 + tallyCache.ClosingTime = blockTime // 平仓时间 + } + + return marketStatus, &tallyCache, nil +} + +// GetOrderSgdByChg +// +// @Description: 处理涨跌幅 +// @param priceNew +// @param tallyCache +// @param chg +// @return string +// @return ShareSgdTallyCache +func GetOrderSgdByChg(priceNew string, tallyCache ShareSgdTallyCache, chg string) (string, ShareSgdTallyCache) { + var marketStatus string + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买涨涨停,只能挂单......") + } + + marketStatus = setting.MarketShareSgdEntrust + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderSgdMarketPrice(priceNew, tallyCache) + default: + marketStatus = setting.MarketShareSgdEntrust + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderSgdMarketPrice(priceNew, tallyCache) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买跌跌停,只能挂单......") + } + + marketStatus = setting.MarketShareSgdEntrust + default: + marketStatus = setting.MarketShareSgdEntrust + } + default: + marketStatus, tallyCache = GetOrderSgdMarketPrice(priceNew, tallyCache) + } + + return marketStatus, tallyCache +} + +// CheckOrderSgdByChg +// +// @Description: 股票判定涨跌幅业务逻辑 +// @param orderMarket +// @param tallyCache +// @param chg +// @return bool +func CheckOrderSgdByChg(orderMarket string, tallyCache ShareSgdTallyCache, chg string) bool { + var checkBool bool + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderSgdBuyMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderSgdSellMarket(orderMarket) + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderSgdSellMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderSgdBuyMarket(orderMarket) + } + default: + checkBool = false + } + + return checkBool +} + +// CheckOrderSgdBuyMarket +// +// @Description: 买涨-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderSgdBuyMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareSgdEntrust: // 挂单缓存状态--不到持仓 + checkBool = true + case setting.MarketShareSgdPosition: // 持仓缓存状态--可以平仓 + checkBool = false + } + + return checkBool +} + +// CheckOrderSgdSellMarket +// +// @Description: 买跌-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderSgdSellMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareSgdEntrust: // 挂单缓存状态-- 到持仓 + checkBool = false + case setting.MarketShareSgdPosition: // 持仓缓存状态-- 不能平仓 + checkBool = true + } + + return checkBool +} + +// GetOrderSgdMarketPrice +// +// @Description: 获取市价下单开仓信息 +// @param priceNew +// @param tallyCache +// @return string +// @return ShareSgdTallyCache +func GetOrderSgdMarketPrice(priceNew string, tallyCache ShareSgdTallyCache) (string, ShareSgdTallyCache) { + var marketStatus string + priceS := decimal.RequireFromString(priceNew) // 最新市价 + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买入 + openPrice = priceS.Add(difference) // 开盘价格 + case flags.TradeTypeSell: // 卖出 + openPrice = priceS.Sub(difference) // 开盘价格 + } + tallyCache.OpenPrice = openPrice.String() // 股票市价下单开盘价格(price) + tallyCache.Status = flags.Position // 股票市价下单持仓状态(status) + marketStatus = setting.MarketShareSgdPosition // 股票下单状态(挂单|持仓)缓存列表 + + return marketStatus, tallyCache +} + +// ShareSgdSubMarketPrice +// +// @Description: 获取下单订阅行情数据 +// @param subKey +// @return string +// @return error +func ShareSgdSubMarketPrice(subKey string) (string, error) { + price, err := memory.GetShareSgdCache(subKey) + if err != nil { + return flags.SetNull, err + } + + return string(price), nil +} + +// ShareSgdHashUserOrder +// +// @Description: 下单录入订阅缓存列表(用户订阅|管理员订阅|挂单|持仓) +// @param red +// @param cacheKey +// @param order +// @return error +func ShareSgdHashUserOrder(red *redis.Client, cacheKey string, order *ShareSgdTallyCache) error { + orderStr, err := json.Marshal(order) + if err != nil { + applogger.Error("%v ShareSgdHashUserOrder.Marshal:%v", common.ErrShareSgd, err) + return err + } + + if err = red.HSet(context.Background(), cacheKey, order.OrderId, string(orderStr)).Err(); err != nil { + applogger.Error("%v ShareSgdHashUserOrder.HSet:%v", common.ErrShareSgd, err) + return err + } + + return nil +} + +// UpdateShareSgdHashByOrderId +// +// @Description: 更新缓存列表 +// @param reds +// @param orderId +// @param updateKey +// @param status +// @return error +func UpdateShareSgdHashByOrderId(reds *redis.Client, orderId, updateKey, status string) error { + order, err := reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel ShareSgdTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateShareSgdStopByOrderId +// +// @Description: 設置止盈止損 +// @param reds +// @param order +// @param updateKey +// @param status +// @return error +func UpdateShareSgdStopByOrderId(reds *redis.Client, order structure.StopOrder, updateKey, status string) error { + orderHash, err := reds.HGet(context.Background(), updateKey, order.OrderId).Result() + if err != nil { + return err + } + + var orderModel ShareSgdTallyCache + if err = json.Unmarshal([]byte(orderHash), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderModel.Order.StopType = order.StopType + orderModel.Order.StopLossPrice = order.StopLossPrice + orderModel.Order.StopWinPrice = order.StopWinPrice + + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, order.OrderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} diff --git a/internal/data/tradedeal/share/share_tha.go b/internal/data/tradedeal/share/share_tha.go new file mode 100644 index 0000000..5845bd6 --- /dev/null +++ b/internal/data/tradedeal/share/share_tha.go @@ -0,0 +1,330 @@ +package share + +import ( + "context" + "encoding/json" + "github.com/redis/go-redis/v9" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" +) + +/* +处理泰股下单交易(订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单) +1>写入挂单缓存列表 +2>监控挂单缓存列表 +3>监控持仓缓存列表 +4>处理完成订单 +5>清理缓存列表 +*/ + +// ShareThaTallyCache +// @Description: +type ShareThaTallyCache struct { + UserId int64 // 用户ID + OrderId string // 订单ID + Symbol string // 交易对 + Status string // 订单状态 + OpenPrice string // 开仓价格 + ClosingPrice string // 平仓价格 + ClosingTime time.Time // 平仓时间 + Order structure.ShareOrder // 下单信息 +} + +// ShareThaCacheDeal +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param subKey +// @param order +// @param chg +// @param priceNew +// @param closingTime +// @return string +// @return *ShareThaTallyCache +// @return error +func ShareThaCacheDeal(ctx context.Context, userId int64, + orderId, subKey string, order structure.ShareOrder, + chg, priceNew string, closingTime, blockTime time.Time) (string, *ShareThaTallyCache, error) { + var marketStatus string + tallyCache := ShareThaTallyCache{ + UserId: userId, // 股票下单用户Id + OrderId: orderId, // 股票下单订单Id + Symbol: order.StockId, // 股票下单交易对 + Status: flags.Entrust, // 股票下单挂单状态 + Order: order, // 股票完整下单信息 + } + + // TODO: 交易下单判定(是否市价交易) + //switch order.DealType { + //case flags.DealTypeLimited: // 限价(买涨|买跌) + // marketStatus = flags.MarketShareThaEntrust + //case flags.DealTypeMarket: // 市价(买涨|买跌) + // if len(priceNew) == 0 { + // marketStatus = flags.MarketShareThaEntrust + // } else { + // marketStatus, tallyCache = GetOrderThaByChg(priceNew, tallyCache, chg) + // } + //} + + // 交易判定 + if order.Type <= 0 { + marketStatus = setting.MarketShareThaEntrust + tallyCache.ClosingTime = closingTime // 平仓时间 + } else { + marketStatus = setting.MarketShareBlkEntrust + tallyCache.OpenPrice = priceNew // 开仓价格 + tallyCache.ClosingTime = blockTime // 平仓时间 + } + + return marketStatus, &tallyCache, nil +} + +// GetOrderThaByChg +// +// @Description: 处理涨跌幅 +// @param priceNew +// @param tallyCache +// @param chg +// @return string +// @return ShareThaTallyCache +func GetOrderThaByChg(priceNew string, tallyCache ShareThaTallyCache, chg string) (string, ShareThaTallyCache) { + var marketStatus string + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买涨涨停,只能挂单......") + } + + marketStatus = setting.MarketShareThaEntrust + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderThaMarketPrice(priceNew, tallyCache) + default: + marketStatus = setting.MarketShareThaEntrust + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderThaMarketPrice(priceNew, tallyCache) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买跌跌停,只能挂单......") + } + + marketStatus = setting.MarketShareThaEntrust + default: + marketStatus = setting.MarketShareThaEntrust + } + default: + marketStatus, tallyCache = GetOrderThaMarketPrice(priceNew, tallyCache) + } + + return marketStatus, tallyCache +} + +// CheckOrderThaByChg +// +// @Description: 股票判定涨跌幅业务逻辑 +// @param orderMarket +// @param tallyCache +// @param chg +// @return bool +func CheckOrderThaByChg(orderMarket string, tallyCache ShareThaTallyCache, chg string) bool { + var checkBool bool + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderThaBuyMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderThaSellMarket(orderMarket) + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderThaSellMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderThaBuyMarket(orderMarket) + } + default: + checkBool = false + } + + return checkBool +} + +// CheckOrderThaBuyMarket +// +// @Description: 买涨-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderThaBuyMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareThaEntrust: // 挂单缓存状态--不到持仓 + checkBool = true + case setting.MarketShareThaPosition: // 持仓缓存状态--可以平仓 + checkBool = false + } + + return checkBool +} + +// CheckOrderThaSellMarket +// +// @Description: 买跌-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderThaSellMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareThaEntrust: // 挂单缓存状态-- 到持仓 + checkBool = false + case setting.MarketShareThaPosition: // 持仓缓存状态-- 不能平仓 + checkBool = true + } + + return checkBool +} + +// GetOrderThaMarketPrice +// +// @Description: 获取市价下单开仓信息 +// @param priceNew +// @param tallyCache +// @return string +// @return ShareThaTallyCache +func GetOrderThaMarketPrice(priceNew string, tallyCache ShareThaTallyCache) (string, ShareThaTallyCache) { + var marketStatus string + priceS := decimal.RequireFromString(priceNew) // 最新市价 + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买入 + openPrice = priceS.Add(difference) // 开盘价格 + case flags.TradeTypeSell: // 卖出 + openPrice = priceS.Sub(difference) // 开盘价格 + } + tallyCache.OpenPrice = openPrice.String() // 股票市价下单开盘价格(price) + tallyCache.Status = flags.Position // 股票市价下单持仓状态(status) + marketStatus = setting.MarketShareThaPosition // 股票下单状态(挂单|持仓)缓存列表 + + return marketStatus, tallyCache +} + +// ShareThaSubMarketPrice +// +// @Description: 获取下单订阅行情数据 +// @param subKey +// @return string +// @return error +func ShareThaSubMarketPrice(subKey string) (string, error) { + price, err := memory.GetShareThaCache(subKey) + if err != nil { + return flags.SetNull, err + } + + return string(price), nil +} + +// ShareThaHashUserOrder +// +// @Description: 下单录入订阅缓存列表(用户订阅|管理员订阅|挂单|持仓) +// @param red +// @param cacheKey +// @param order +// @return error +func ShareThaHashUserOrder(red *redis.Client, cacheKey string, order *ShareThaTallyCache) error { + orderStr, err := json.Marshal(order) + if err != nil { + applogger.Error("%v ShareThaHashUserOrder.Marshal:%v", common.ErrShareTha, err) + return err + } + + if err = red.HSet(context.Background(), cacheKey, order.OrderId, string(orderStr)).Err(); err != nil { + applogger.Error("%v ShareThaHashUserOrder.HSet:%v", common.ErrShareTha, err) + return err + } + + return nil +} + +// UpdateShareThaHashByOrderId +// +// @Description: 更新缓存列表 +// @param reds +// @param orderId +// @param updateKey +// @param status +// @return error +func UpdateShareThaHashByOrderId(reds *redis.Client, orderId, updateKey, status string) error { + order, err := reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel ShareThaTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateShareThaStopByOrderId +// +// @Description: 設置止盈止損 +// @param reds +// @param order +// @param updateKey +// @param status +// @return error +func UpdateShareThaStopByOrderId(reds *redis.Client, order structure.StopOrder, updateKey, status string) error { + orderHash, err := reds.HGet(context.Background(), updateKey, order.OrderId).Result() + if err != nil { + return err + } + + var orderModel ShareThaTallyCache + if err = json.Unmarshal([]byte(orderHash), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderModel.Order.StopType = order.StopType + orderModel.Order.StopLossPrice = order.StopLossPrice + orderModel.Order.StopWinPrice = order.StopWinPrice + + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, order.OrderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} diff --git a/internal/data/tradedeal/share/share_us.go b/internal/data/tradedeal/share/share_us.go new file mode 100644 index 0000000..9cbf493 --- /dev/null +++ b/internal/data/tradedeal/share/share_us.go @@ -0,0 +1,326 @@ +package share + +import ( + "context" + "encoding/json" + "github.com/redis/go-redis/v9" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" + "matchmaking-system/internal/pkg/utils" + "time" +) + +/* +处理美股下单交易(订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单) +1>写入挂单缓存列表 +2>监控挂单缓存列表 +3>监控持仓缓存列表 +4>处理完成订单 +5>清理缓存列表 +*/ + +// ShareUsTallyCache +// @Description: +type ShareUsTallyCache struct { + UserId int64 // 用户ID + OrderId string // 订单ID + Symbol string // 交易对 + Status string // 订单状态 + OpenPrice string // 开仓价格 + ClosingPrice string // 平仓价格 + ClosingTime time.Time // 平仓时间 + Order structure.ShareOrder // 下单信息 +} + +// ShareUsCacheDeal +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param subKey +// @param order +// @param chg +// @param priceNew +// @param closingTime +// @return string +// @return *ShareUsTallyCache +// @return error +func ShareUsCacheDeal(ctx context.Context, userId int64, + orderId, subKey string, order structure.ShareOrder, + chg, priceNew string, closingTime, blockTime time.Time) (string, *ShareUsTallyCache, error) { + var marketStatus string + tallyCache := ShareUsTallyCache{ + UserId: userId, // 股票下单用户Id + OrderId: orderId, // 股票下单订单Id + Symbol: order.StockId, // 股票下单交易对 + Status: flags.Entrust, // 股票下单挂单状态 + Order: order, // 股票完整下单信息 + } + + // TODO: 交易下单判定(是否市价交易) + //switch order.DealType { + //case flags.DealTypeLimited: // 限价(买涨|买跌) + // marketStatus = flags.MarketShareUsEntrust + //case flags.DealTypeMarket: // 市价(买涨|买跌) + // if len(priceNew) == 0 { + // marketStatus = flags.MarketShareUsEntrust + // } else { + // marketStatus, tallyCache = GetOrderByChg(priceNew, tallyCache, chg) + // } + //} + + // 交易判定 + if order.Type <= 0 { + marketStatus = setting.MarketShareUsEntrust + tallyCache.ClosingTime = closingTime // 平仓时间 + } else { + marketStatus = setting.MarketShareBlkEntrust + tallyCache.OpenPrice = priceNew // 开仓价格 + tallyCache.ClosingTime = blockTime // 平仓时间 + } + + return marketStatus, &tallyCache, nil +} + +// GetOrderByChg +// +// @Description: 处理涨跌幅 +// @param priceNew +// @param tallyCache +// @param chg +// @return string +// @return ShareUsTallyCache +func GetOrderByChg(priceNew string, tallyCache ShareUsTallyCache, chg string) (string, ShareUsTallyCache) { + var marketStatus string + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买涨涨停,只能挂单......") + } + marketStatus = setting.MarketShareUsEntrust + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderMarketPrice(priceNew, tallyCache) + default: + marketStatus = setting.MarketShareUsEntrust + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,不能平仓 + marketStatus, tallyCache = GetOrderMarketPrice(priceNew, tallyCache) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,可以平仓 + if !flags.CheckSetting { + applogger.Debug("下单股票买跌跌停,只能挂单......") + } + marketStatus = setting.MarketShareUsEntrust + default: + marketStatus = setting.MarketShareUsEntrust + } + default: + marketStatus, tallyCache = GetOrderMarketPrice(priceNew, tallyCache) + } + + return marketStatus, tallyCache +} + +// CheckOrderByChg +// +// @Description: 股票判定涨跌幅业务逻辑 +// @param orderMarket +// @param tallyCache +// @param chg +// @return bool +func CheckOrderByChg(orderMarket string, tallyCache ShareUsTallyCache, chg string) bool { + var checkBool bool + switch chg { + case flags.UpLimit: // 涨停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:涨停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderBuyMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:涨停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderSellMarket(orderMarket) + } + case flags.DownLimit: // 跌停 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买涨:跌停-下单到持仓,持仓不能平仓 + checkBool = CheckOrderSellMarket(orderMarket) + case flags.TradeTypeSell: // 买跌:跌停-下单不到持仓,持仓可以平仓 + checkBool = CheckOrderBuyMarket(orderMarket) + } + default: + checkBool = false + } + + return checkBool +} + +// CheckOrderBuyMarket +// +// @Description: 买涨-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderBuyMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareUsEntrust: // 挂单缓存状态--不到持仓 + checkBool = true + case setting.MarketShareUsPosition: // 持仓缓存状态--可以平仓 + checkBool = false + } + + return checkBool +} + +// CheckOrderSellMarket +// +// @Description: 买跌-涨跌幅 +// @param orderMarket +// @return bool +func CheckOrderSellMarket(orderMarket string) bool { + var checkBool bool + switch orderMarket { + case setting.MarketShareUsEntrust: // 挂单缓存状态-- 到持仓 + checkBool = false + case setting.MarketShareUsPosition: // 持仓缓存状态-- 不能平仓 + checkBool = true + } + + return checkBool +} + +// GetOrderMarketPrice +// +// @Description: 获取市价下单开仓信息 +// @param priceNew +// @param tallyCache +// @return string +// @return ShareUsTallyCache +func GetOrderMarketPrice(priceNew string, tallyCache ShareUsTallyCache) (string, ShareUsTallyCache) { + var marketStatus string + priceS := decimal.RequireFromString(priceNew) // 最新市价 + var openPrice decimal.Decimal + difference := priceS.Mul(utils.Difference()) // 设置价差 + switch tallyCache.Order.TradeType { + case flags.TradeTypeBuy: // 买入 + openPrice = priceS.Add(difference) // 开盘价格 + case flags.TradeTypeSell: // 卖出 + openPrice = priceS.Sub(difference) // 开盘价格 + } + tallyCache.OpenPrice = openPrice.String() // 股票市价下单开盘价格(price) + tallyCache.Status = flags.Position // 股票市价下单持仓状态(status) + marketStatus = setting.MarketShareUsPosition // 股票下单状态(挂单|持仓)缓存列表 + + return marketStatus, tallyCache +} + +// ShareUsSubMarketPrice +// +// @Description: 获取下单订阅行情数据 +// @param subKey +// @return string +// @return error +func ShareUsSubMarketPrice(subKey string) (string, error) { + price, err := memory.GetShareUsCache(subKey) + if err != nil { + return flags.SetNull, err + } + + return string(price), nil +} + +// ShareUsHashUserOrder +// +// @Description: 下单录入订阅缓存列表(用户订阅|管理员订阅|挂单|持仓) +// @param red +// @param cacheKey +// @param order +// @return error +func ShareUsHashUserOrder(red *redis.Client, cacheKey string, order *ShareUsTallyCache) error { + orderStr, err := json.Marshal(order) + if err != nil { + applogger.Error("%v ShareUsHaseUserOrder.Marshal:%v", common.ErrShareUs, err) + return err + } + + if err = red.HSet(context.Background(), cacheKey, order.OrderId, string(orderStr)).Err(); err != nil { + applogger.Error("%v ShareUsHaseUserOrder.HSet:%v", common.ErrShareUs, err) + return err + } + + return nil +} + +// UpdateShareUsHashByOrderId +// +// @Description: 更新缓存列表 +// @param reds +// @param orderId +// @param updateKey +// @param status +// @return error +func UpdateShareUsHashByOrderId(reds *redis.Client, orderId, updateKey, status string) error { + order, err := reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel ShareUsTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + return nil +} + +// UpdateShareUsStopByOrderId +// +// @Description: 更新止盈止損設置 +// @param reds +// @param order +// @param updateKey +// @param status +// @return error +func UpdateShareUsStopByOrderId(reds *redis.Client, order structure.StopOrder, updateKey, status string) error { + orderHash, err := reds.HGet(context.Background(), updateKey, order.OrderId).Result() + if err != nil { + return err + } + + var orderModel ShareUsTallyCache + if err = json.Unmarshal([]byte(orderHash), &orderModel); err != nil { + return err + } + + orderModel.Status = status + orderModel.Order.StopType = order.StopType + orderModel.Order.StopLossPrice = order.StopLossPrice + orderModel.Order.StopWinPrice = order.StopWinPrice + + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = reds.HSet(context.Background(), updateKey, order.OrderId, string(orderStr)).Err() + if err != nil { + return err + } + return nil +} diff --git a/internal/data/tradedeal/virtual/virtual_contract.go b/internal/data/tradedeal/virtual/virtual_contract.go new file mode 100644 index 0000000..357b923 --- /dev/null +++ b/internal/data/tradedeal/virtual/virtual_contract.go @@ -0,0 +1,137 @@ +package virtual + +import ( + "context" + "encoding/json" + "github.com/redis/go-redis/v9" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" +) + +/* +处理合约下单交易(订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单) +1>写入挂单缓存列表 +2>监控挂单缓存列表 +3>监控持仓缓存列表 +4>处理完成订单 +5>清理缓存列表 +*/ + +// ContractTallyCache +// @Description: +type ContractTallyCache struct { + UserId int64 // 用户ID + OrderId string // 订单ID + Symbol string // 交易对 + Status string // 订单状态 + OpenPrice string // 开仓价格 + ClosingPrice string // 平仓价格 + Order structure.ContractOrder // 下单信息 +} + +// ContractCacheDeal +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param priceNew +// @param order +// @return string +// @return *ContractTallyCache +// @return error +func ContractCacheDeal(ctx context.Context, userId int64, orderId, priceNew string, order structure.ContractOrder) (string, *ContractTallyCache, error) { + var marketStatus string + tallyCache := &ContractTallyCache{ + UserId: userId, // 下单用户ID + OrderId: orderId, // 下单订单ID + Symbol: order.ContractId, // 下单交易对 + Status: flags.Entrust, // 下单挂单状态 + Order: order, // 完整下单信息 + } + + switch order.DealType { + case flags.DealTypeLimited: // 限价(买涨|买跌) + marketStatus = setting.MarketContractEntrust + case flags.DealTypeMarket: // 市价(买涨|买跌) + priceS := decimal.RequireFromString(priceNew) // 当前下单合约最新市价 + // TODO: 设置价差 + //var openPrice decimal.Decimal + //difference := priceS.Mul(utils.Difference()) // 设置价差 + //switch order.TradeType { + //case flags.TradeTypeBuy: // 买涨 + // openPrice = priceS.Add(difference) // 开仓价格 + //case flags.TradeTypeSell: // 买跌 + // openPrice = priceS.Sub(difference) // 开仓价格 + //} + tallyCache.OpenPrice = priceS.String() // 市价下单开仓价格(price) + tallyCache.Status = flags.Position // 市价下单持仓状态(status) + marketStatus = setting.MarketContractPosition // (挂单|持仓)缓存列表 + } + + return marketStatus, tallyCache, nil +} + +// ContractSubMarketPrice +// +// @Description: 下单订阅行情数据 +// @param ctx +// @param subKey +// @return string +// @return error +func ContractSubMarketPrice(ctx context.Context, subKey string) (string, error) { + price, err := memory.GetContractCache(subKey) + if err != nil { + return flags.SetNull, err + } + + return string(price), nil +} + +// ContractPushAddCache +// +// @Description: 下单录入(挂单|持仓)缓存列表 +// @param red +// @param cacheKey +// @param tallyCache +// @return error +func ContractPushAddCache(red *redis.Client, cacheKey string, tallyCache *ContractTallyCache) error { + content, err := json.Marshal(tallyCache) + if err != nil { + return err + } + + if err = red.HSet(context.Background(), cacheKey, tallyCache.OrderId, string(content)).Err(); err != nil { + return err + } + + return nil +} + +// ContractHashSetOrderId +// +// @Description: 录入订单ID-Hash缓存列表 +// @param red +// @param cacheKey +// @param order +// @return error +func ContractHashSetOrderId(red *redis.Client, cacheKey string, order *ContractTallyCache) error { + byteStr, err := json.Marshal(order) + if err != nil { + applogger.Error("%v ContractHashSetOrderId.Marshal:%v", common.ErrContract, err) + return err + } + + err = red.HSet(context.Background(), cacheKey, order.OrderId, string(byteStr)).Err() + if err != nil { + applogger.Error("%v ContractHashSetOrderId.HSet:%v", common.ErrContract, err) + return err + } + + return nil +} diff --git a/internal/data/tradedeal/virtual/virtual_second.go b/internal/data/tradedeal/virtual/virtual_second.go new file mode 100644 index 0000000..67577de --- /dev/null +++ b/internal/data/tradedeal/virtual/virtual_second.go @@ -0,0 +1,117 @@ +package virtual + +import ( + "context" + "encoding/json" + "github.com/redis/go-redis/v9" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" +) + +/* +处理秒合约下单交易(订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单) +1>写入挂单缓存列表 +2>监控挂单缓存列表 +3>监控持仓缓存列表 +4>处理完成订单 +5>清理缓存列表 +*/ + +// SecondCacheDeal +// +// @Description: +// @param ctx +// @param userId +// @param orderId +// @param priceNew +// @param order +// @return string +// @return *ContractTallyCache +// @return error +func SecondCacheDeal(ctx context.Context, userId int64, orderId, priceNew string, order structure.ContractOrder) (string, *ContractTallyCache, error) { + var marketStatus string + tallyCache := &ContractTallyCache{ + UserId: userId, // 下单用户ID + OrderId: orderId, // 下单订单ID + Symbol: order.ContractId, // 下单交易对 + Status: flags.Entrust, // 下单挂单状态 + Order: order, // 完整下单信息 + } + + switch order.DealType { + case flags.DealTypeLimited: // TODO: 暂无-限价(买涨|买跌) + marketStatus = setting.MarketSecondPosition + case flags.DealTypeMarket: // 市价(买涨|买跌) + tallyCache.OpenPrice = priceNew // 市价下单开仓价格(price) + tallyCache.Status = flags.Position // 市价下单持仓状态(status) + marketStatus = setting.MarketSecondPosition // (挂单|持仓)缓存列表 + default: + } + + return marketStatus, tallyCache, nil +} + +// SecondSubMarketPrice +// +// @Description: 下单订阅行情数据 +// @param ctx +// @param subKey +// @return string +// @return error +func SecondSubMarketPrice(ctx context.Context, subKey string) (string, error) { + price, err := memory.GetSecondCache(subKey) + if err != nil { + return flags.SetNull, err + } + + return string(price), nil +} + +// SecondPushAddCache +// +// @Description: 下单录入(挂单|持仓)缓存列表 +// @param red +// @param cacheKey +// @param tallyCache +// @return error +func SecondPushAddCache(red *redis.Client, cacheKey string, tallyCache *ContractTallyCache) error { + content, err := json.Marshal(tallyCache) + if err != nil { + applogger.Error("%v ContractSecondPushAddCache.Marshal:%v", common.ErrSecond, err) + return err + } + + if err = red.HSet(context.Background(), cacheKey, tallyCache.OrderId, string(content)).Err(); err != nil { + applogger.Error("%v ContractSecondPushAddCache.HSet:%v", common.ErrSecond, err) + return err + } + + return nil +} + +// SecondHashSetOrderId +// +// @Description: 录入订单ID-Hash缓存列表 +// @param red +// @param cacheKey +// @param order +// @return error +func SecondHashSetOrderId(red *redis.Client, cacheKey string, order *ContractTallyCache) error { + byteStr, err := json.Marshal(order) + if err != nil { + applogger.Error("%v ContractSecondHashSetOrderId.Marshal:%v", common.ErrSecond, err) + return err + } + + err = red.HSet(context.Background(), cacheKey, order.OrderId, string(byteStr)).Err() + if err != nil { + applogger.Error("%v ContractSecondHashSetOrderId.HSet:%v", common.ErrSecond, err) + return err + } + + return nil +} diff --git a/internal/data/tradedeal/virtual/virtual_spots.go b/internal/data/tradedeal/virtual/virtual_spots.go new file mode 100644 index 0000000..e00df28 --- /dev/null +++ b/internal/data/tradedeal/virtual/virtual_spots.go @@ -0,0 +1,105 @@ +package virtual + +import ( + "context" + "encoding/json" + "fmt" + "github.com/redis/go-redis/v9" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/setting" +) + +/* +处理现货下单交易(订单状态:0-挂单(委托),2-已撤单,3-完成订单) +1>限价 + 1、写入挂单缓存列表 + 2、监控挂单缓存列表 + 3、处理完成订单 + 4、清理缓存列表 +2>市价 + 1.平仓操作 +*/ + +// SpotsTallyCache +// @Description: +type SpotsTallyCache struct { + UserId int64 // 用户ID + OrderId string // 订单ID + Symbol string // 交易对 + Status string // 订单状态 + OpenPrice string // 开仓价格 + ClosingPrice string // 平仓价格 + Order structure.SpotsOrder // 下单信息 +} + +// DealSpotsLimitedPrice +// +// @Description: +// @param red +// @param userId +// @param order +// @param Symbol +// @param orderId +// @return error +func DealSpotsLimitedPrice(red *redis.Client, userId int64, order structure.SpotsOrder, Symbol, orderId string) error { + data := &SpotsTallyCache{ + OrderId: orderId, // 下单生成订单ID + Symbol: Symbol, // 下单用户交易对 + Status: flags.Entrust, // 下单用户挂单状态 + Order: order, // 下单信息 + UserId: userId, // 下单用户ID + } + content, err := json.Marshal(data) + if err != nil { + applogger.Error("%v DealSpotsLimitedPrice.Marshal:%v", common.ErrSpots, err) + return flags.ErrCacheDB + } + if !flags.CheckSetting { + applogger.Debug("挂单信息:%v", string(content)) + } + + // 写入限价下单挂单缓存列表 + if err = red.HSet(context.Background(), setting.MarketSpotsEntrust, orderId, string(content)).Err(); err != nil { + applogger.Error("%v DealSpotsLimitedPrice.MarketSpotsEntrust.HSet:%v", common.ErrSpots, err) + return flags.ErrCacheDB + } + + // 写入用户订单订阅缓存hash列表 + cacheKey := OrderIdListKey(setting.SpotsSubscribe, userId) + if err = red.HSet(context.Background(), cacheKey, orderId, string(content)).Err(); err != nil { + applogger.Error("%v DealSpotsLimitedPrice.SpotsSubscribe.HSet:%v", common.ErrSpots, err) + return flags.ErrCacheDB + } + + return nil +} + +// DealSpotsMarketPrice +// +// @Description: +// @param ctx +// @param subKey +// @return string +// @return error +func DealSpotsMarketPrice(ctx context.Context, subKey string) (string, error) { + price, err := memory.SpotsCache.Get(subKey) + if err != nil { + return flags.SetNull, err + } + + return string(price), err +} + +// OrderIdListKey +// +// @Description: +// @param topIc +// @param userId +// @return string +func OrderIdListKey(topIc string, userId int64) string { + return fmt.Sprintf("%v-%v", topIc, userId) +} diff --git a/internal/data/utils_check.go b/internal/data/utils_check.go new file mode 100644 index 0000000..7674afd --- /dev/null +++ b/internal/data/utils_check.go @@ -0,0 +1,2249 @@ +package data + +import ( + "context" + "encoding/json" + "fmt" + "github.com/go-kratos/kratos/v2/transport" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/redis" + "matchmaking-system/internal/data/tradedeal/option" + "matchmaking-system/internal/data/tradedeal/share" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "matchmaking-system/internal/pkg/utils" + "strconv" + "strings" + "time" + + forexd "matchmaking-system/internal/data/tradedeal/forex" + moneyd "matchmaking-system/internal/data/tradedeal/money" + models "matchmaking-system/internal/pkg/model" +) + +// CheckToken +// +// @Description: Verify token +// @receiver uo +// @param ctx +// @return int +// @return error +func (uo *userOrderRepo) CheckToken(ctx context.Context) (int, error) { + tr, checkBool := transport.FromServerContext(ctx) + if !checkBool { + return 0, nil + } + header := tr.RequestHeader() + + var token string + switch flags.CheckNetwork { + case flags.CheckTest: // locale + authorization := header.Get(flags.TokenTest) + authorizationLen := len(authorization) + if len(authorization) >= 7 { + token = authorization[7:authorizationLen] + } + case flags.CheckOnLine: // Online environment(test|onLine) + token = header.Get(flags.TokenOnLine) + default: + applogger.Error("CheckToken:Please enter the initialized environment variable.") + } + + tokenStr := fmt.Sprintf("%v%v", flags.UserToken, token) + + if !flags.CheckSetting { + applogger.Debug("Splicing Token Information:%v", tokenStr) + } + + userId, err := redis.GetCacheData(ctx, uo.data.redisDB, tokenStr) + if err != nil || len(userId) == 0 { + return 0, err + } + + userID, err := strconv.Atoi(userId) + if err != nil || userID == 0 { + return 0, err + } + + return userID, nil +} + +// GetBotUser +// +// @Description: get user id +// @receiver uo +// @param ctx +// @param token +// @return int +// @return error +func (uo *userOrderRepo) GetBotUser(token string) (int, error) { + var userModel []models.BotUsers + if err := uo.data.mysqlDB.Table(flags.BotUsers). + Where("access_token = ?", token). + Where("status = 1"). + Find(&userModel); err != nil { + return 0, err + } + + var userId int + for _, value := range userModel { + userId = int(value.UserId) + } + + return userId, nil +} + +// GetBotUserIsRealByUserId +// +// @Description: Query user identity authentication based on user ID +// @receiver uo +// @param ctx +// @param userId +// @return bool +// @return error +func (uo *userOrderRepo) GetBotUserIsRealByUserId(ctx context.Context, userId int) bool { + var checkBool bool + var userModel []models.BotUsers + if err := uo.data.mysqlDB.Table(flags.BotUsers). + Where("user_id = ?", userId). + Where("status = 1"). + Find(&userModel); err != nil { + return checkBool + } + + for _, value := range userModel { + switch value.IsReal { + case 0: // 未实名 + checkBool = false + case 1: // 实名 + checkBool = true + default: + checkBool = false + } + } + + return checkBool +} + +// GetBotStockListByStockName +// +// @Description: +// @receiver uo +// @param ctx +// @param stockId +// @return string +// @return error +func (uo *userOrderRepo) GetBotStockListByStockName(ctx context.Context, stockId string) (string, error) { + var stockList []models.BotStockList + if err := uo.data.mysqlDB.Table(flags.BotStockList). + Where("stock_name = ?", stockId). + Find(&stockList); err != nil { + return flags.SetNull, err + } + + for _, value := range stockList { + return value.StockName, nil + } + + return flags.SetNull, nil +} + +// GetBotDigitalListByDigitalName +// +// @Description: +// @receiver uo +// @param ctx +// @param digitalId +// @return string +// @return error +func (uo *userOrderRepo) GetBotDigitalListByDigitalName(ctx context.Context, digitalId string) (string, error) { + var digitalList []models.BotDigitalList + if err := uo.data.mysqlDB.Table(flags.BotDigitalList). + Where("trade_name = ?", digitalId). + Find(&digitalList); err != nil { + return flags.SetNull, err + } + + for _, value := range digitalList { + return value.TradeName, nil + } + + return flags.SetNull, nil +} + +// GetBotContractListByContractName +// +// @Description: +// @receiver uo +// @param ctx +// @param contractId +// @return string +// @return error +func (uo *userOrderRepo) GetBotContractListByContractName(ctx context.Context, contractId string) (string, error) { + var contractList []models.BotContractList + if err := uo.data.mysqlDB.Table(flags.BotContractList). + Where("trade_name = ?", contractId). + Find(&contractList); err != nil { + return flags.SetNull, err + } + for _, value := range contractList { + return value.TradeName, nil + } + + return flags.SetNull, nil +} + +// GetBotUserStockByStockId +// +// @Description: +// @receiver uo +// @param ctx +// @param userId +// @param stockId +// @return *models.BotUserStock +// @return error +func (uo *userOrderRepo) GetBotUserStockByStockId(ctx context.Context, userId, stockId int64) (*models.BotUserStock, error) { + var botUserStockList []models.BotUserStock + if err := uo.data.mysqlDB.Table(flags.BotUserStock). + Where("user_id = ?", userId). + Where("stock_id = ?", stockId). + Find(&botUserStockList); err != nil { + return nil, err + } + var botUserStock models.BotUserStock + for _, value := range botUserStockList { + botUserStock = value + } + + return &botUserStock, nil +} + +// GetBotUserDigitalByDigitalId +// +// @Description: +// @receiver uo +// @param ctx +// @param userId +// @param stockId +// @return *models.BotUserDigital +// @return error +func (uo *userOrderRepo) GetBotUserDigitalByDigitalId(ctx context.Context, userId, stockId int64) (*models.BotUserDigital, error) { + var botUserDigitalList []models.BotUserDigital + if err := uo.data.mysqlDB.Table(flags.BotUserDigital). + Where("user_id = ?", userId). + Where("digital_id = ?", stockId). + Find(&botUserDigitalList); err != nil { + return nil, err + } + var botUserDigital models.BotUserDigital + for _, value := range botUserDigitalList { + botUserDigital = value + } + + return &botUserDigital, nil +} + +// GetBotUserContractByContractId +// +// @Description: +// @receiver uo +// @param ctx +// @param userId +// @param stockId +// @return *models.BotUserContract +// @return error +func (uo *userOrderRepo) GetBotUserContractByContractId(ctx context.Context, userId, stockId int64) (*models.BotUserContract, error) { + var botUserContractList []models.BotUserContract + if err := uo.data.mysqlDB.Table(flags.BotUserContract). + Where("user_id = ?", userId). + Where("contract_id = ?", stockId). + Find(&botUserContractList); err != nil { + return nil, err + } + var botUserContract models.BotUserContract + for _, value := range botUserContractList { + botUserContract = value + } + + return &botUserContract, nil +} + +// HSetRedisKey +// +// @Description: Write cache list data +// @receiver uo +// @param ctx +// @param key +// @param value +// @return error +func (uo *userOrderRepo) HSetRedisKey(ctx context.Context, key, value string) error { + code := strings.ToUpper(value) + if err := uo.data.redisDB.HSet(ctx, key, code, code).Err(); err != nil { + applogger.Error("HSetRedisKey.HSet:%v", err) + return err + } + return nil +} + +// UpdateSpotsSubscribeStatusHashByOrderId +// +// @Description: 更新(用户)现货订阅缓存hash列表订单状态 +// @param userId +// @param orderId +// @param updateKey +// @param status +// @return error +func UpdateSpotsSubscribeStatusHashByOrderId(userId int64, orderId, updateKey, status string) error { + // 查询hash缓存列表数据 + cacheKey := virtual.OrderIdListKey(updateKey, userId) + order, err := Reds.HGet(context.Background(), cacheKey, orderId).Result() + if err != nil { + return err + } + + // 序列化json数据 + var orderModel virtual.SpotsTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + // 修改数据状态 + orderModel.Status = status + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + // 更新hash订阅缓存数据 + err = Reds.HSet(context.Background(), cacheKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateContractSubscribeHashStatusByOrderId +// +// @Description: 更新(用户|管理员)合约订阅缓存列表订单状态 +// @param orderId +// @param updateKey +// @param status +// @return error +func UpdateContractSubscribeHashStatusByOrderId(orderId, updateKey, status, closePrice string) error { + order, err := Reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel virtual.ContractTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + if len(utils.ReplaceStr(orderModel.ClosingPrice)) == 0 { + orderModel.ClosingPrice = closePrice + } + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateForexSubscribeHashStatusByOrderId +// +// @Description: 更新(用户|管理员)外汇订阅缓存列表订单状态 +// @param orderId +// @param updateKey +// @param status +// @param closePrice +// @return error +func UpdateForexSubscribeHashStatusByOrderId(orderId, updateKey, status, closePrice string) error { + order, err := Reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel forexd.ForexTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + if len(utils.ReplaceStr(orderModel.ClosingPrice)) == 0 { + orderModel.ClosingPrice = closePrice + } + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateMoneySubscribeHashStatusByOrderId +// +// @Description: 更新(用户|管理员)综合(现货|合约|外汇)订阅缓存列表订单状态 +// @param orderId +// @param updateKey +// @param status +// @param closePrice +// @return error +func UpdateMoneySubscribeHashStatusByOrderId(orderId, updateKey, status, closePrice string) error { + order, err := Reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel moneyd.MoneyTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + if len(utils.ReplaceStr(orderModel.ClosingPrice)) == 0 { + orderModel.ClosingPrice = closePrice + } + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateShareUsSubscribeHashStatusByOrderId +// +// @Description: 更新(用户|管理员)美股订阅缓存列表订单状态 +// @param orderId +// @param updateKey +// @param status +// @return error +func UpdateShareUsSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error { + order, err := Reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel share.ShareUsTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + if status == flags.Position { + orderModel.OpenPrice = openPrice + } + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateShareIdnSubscribeHashStatusByOrderId +// +// @Description: 更新(用户|管理员)印尼股订阅缓存列表订单状态 +// @param orderId +// @param updateKey +// @param status +// @return error +func UpdateShareIdnSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error { + order, err := Reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel share.ShareIdnTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + if status == flags.Position { + orderModel.OpenPrice = openPrice + } + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateShareHkdSubscribeHashStatusByOrderId +// +// @Description: +// @param orderId +// @param updateKey +// @param status +// @param openPrice +// @return error +func UpdateShareHkdSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error { + order, err := Reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel share.ShareHkdTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + if status == flags.Position { + orderModel.OpenPrice = openPrice + } + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateShareInrSubscribeHashStatusByOrderId +// +// @Description: 更新(用户|管理员)印度股订阅缓存列表订单状态 +// @param orderId +// @param updateKey +// @param status +// @return error +func UpdateShareInrSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error { + order, err := Reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel share.ShareInrTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + if status == flags.Position { + orderModel.OpenPrice = openPrice + } + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateShareGbxSubscribeHashStatusByOrderId +// +// @Description: 更新(用户|管理员)英股订阅缓存列表订单状态 +// @param orderId +// @param updateKey +// @param status +// @param openPrice +// @return error +func UpdateShareGbxSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error { + order, err := Reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel share.ShareGbxTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + if status == flags.Position { + orderModel.OpenPrice = openPrice + } + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateOptionInrSubscribeHashStatusByOrderId +// +// @Description: +// @param orderId +// @param updateKey +// @param status +// @param openPrice +// @return error +func UpdateOptionInrSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error { + order, err := Reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel option.OptionInrTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + if status == flags.Position { + orderModel.OpenPrice = openPrice + } + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateShareMysSubscribeHashStatusByOrderId +// +// @Description: 更新(用户|管理员)马股订阅缓存列表订单状态 +// @param orderId +// @param updateKey +// @param status +// @return error +func UpdateShareMysSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error { + order, err := Reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel share.ShareMysTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + if status == flags.Position { + orderModel.OpenPrice = openPrice + } + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateShareThaSubscribeHashStatusByOrderId +// +// @Description: 更新(用户|管理员)泰股订阅缓存列表订单状态 +// @param orderId +// @param updateKey +// @param status +// @return error +func UpdateShareThaSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error { + order, err := Reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel share.ShareThaTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + if status == flags.Position { + orderModel.OpenPrice = openPrice + } + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateShareSgdSubscribeHashStatusByOrderId +// +// @Description: 更新(用户|管理员)泰股订阅缓存列表订单状态 +// @param orderId +// @param updateKey +// @param status +// @param openPrice +// @return error +func UpdateShareSgdSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error { + order, err := Reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel share.ShareSgdTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + if status == flags.Position { + orderModel.OpenPrice = openPrice + } + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateShareEurSubscribeHashStatusByOrderId +// +// @Description: 更新(用户|管理员)德股订阅缓存列表订单状态 +// @param orderId +// @param updateKey +// @param status +// @param openPrice +// @return error +func UpdateShareEurSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error { + order, err := Reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel share.ShareEurTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + if status == flags.Position { + orderModel.OpenPrice = openPrice + } + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateShareBrlSubscribeHashStatusByOrderId +// +// @Description: 更新(用户|管理员)巴西股订阅缓存列表订单状态 +// @param orderId +// @param updateKey +// @param status +// @param openPrice +// @return error +func UpdateShareBrlSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error { + order, err := Reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel share.ShareBrlTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + if status == flags.Position { + orderModel.OpenPrice = openPrice + } + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateShareFurSubscribeHashStatusByOrderId +// +// @Description: 更新(用户|管理员)法股订阅缓存列表订单状态 +// @param orderId +// @param updateKey +// @param status +// @param openPrice +// @return error +func UpdateShareFurSubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error { + order, err := Reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel share.ShareFurTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + if status == flags.Position { + orderModel.OpenPrice = openPrice + } + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// UpdateShareJpySubscribeHashStatusByOrderId +// +// @Description: 更新(用户|管理员)日股订阅缓存列表订单状态 +// @param orderId +// @param updateKey +// @param status +// @param openPrice +// @return error +func UpdateShareJpySubscribeHashStatusByOrderId(orderId, updateKey, status, openPrice string) error { + order, err := Reds.HGet(context.Background(), updateKey, orderId).Result() + if err != nil { + return err + } + + var orderModel share.ShareJpyTallyCache + if err = json.Unmarshal([]byte(order), &orderModel); err != nil { + return err + } + + orderModel.Status = status + if status == flags.Position { + orderModel.OpenPrice = openPrice + } + orderStr, err := json.Marshal(&orderModel) + if err != nil { + return err + } + + err = Reds.HSet(context.Background(), updateKey, orderId, string(orderStr)).Err() + if err != nil { + return err + } + + return nil +} + +// GetBotDigitalList +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotDigitalList(ctx context.Context, uo *Data) ([]string, error) { + var digitalList []models.BotDigitalList + if err := uo.mysqlDB.Table(flags.BotDigitalList). + Where("status = 1"). + Find(&digitalList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range digitalList { + codeList = append(codeList, value.TradeName) + } + + return codeList, nil +} + +// GetBotContractList +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotContractList(ctx context.Context, uo *Data) ([]string, error) { + var contractList []models.BotContractList + if err := uo.mysqlDB.Table(flags.BotContractList). + Where("status = 1"). + Find(&contractList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range contractList { + codeList = append(codeList, value.TradeName) + } + + return codeList, nil +} + +// GetBotForexList +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotForexList(ctx context.Context, uo *Data) ([]string, error) { + var forexList []models.BotForexList + if err := uo.mysqlDB.Table(flags.BotForexList). + Where("status = 1"). + Find(&forexList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range forexList { + codeList = append(codeList, value.TradeName) + } + + return codeList, nil +} + +// GetBotMoneyList +// +// @Description: 联合查询统计合约|现货|外汇交易对列表 +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotMoneyList(ctx context.Context, uo *Data) ([]string, error) { + // 外汇数据 + var forexList []models.BotForexList + if err := uo.mysqlDB.Table(flags.BotForexList).Where("status = 1").Find(&forexList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range forexList { + codeList = append(codeList, value.TradeName) + } + // 合约数据 + var contractList []models.BotContractList + if err := uo.mysqlDB.Table(flags.BotContractList).Where("status = 1").Find(&contractList); err != nil { + return []string{}, err + } + for _, value := range contractList { + codeList = append(codeList, strings.Replace(strings.ToUpper(value.TradeName), "USDT", "USD", -1)) + } + // 现货数据 + var spotsList []models.BotDigitalList + if err := uo.mysqlDB.Table(flags.BotDigitalList).Where("status = 1").Find(&spotsList); err != nil { + return []string{}, err + } + for _, value := range spotsList { + codeList = append(codeList, strings.Replace(strings.ToUpper(value.TradeName), "USDT", "USD", -1)) + } + + return codeList, nil +} + +// GetBotStockList +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockList(ctx context.Context, uo *Data) ([]string, error) { + var stockList []models.BotStockList + if err := uo.mysqlDB.Table(flags.BotStockList). + Where("status = 1"). + Find(&stockList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range stockList { + codeList = append(codeList, value.StockCode) + } + + return codeList, nil +} + +// GetBotStockListByStockId +// +// @Description: 查询交易订单股票类型用来订阅行情 +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockListByStockId(ctx context.Context, uo *Data) ([]string, error) { + var stockList []models.BotStockTrade + if err := uo.mysqlDB.Table(flags.BotStockTrade). + Distinct("stock_id"). + Find(&stockList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range stockList { + codeList = append(codeList, value.StockId) + } + + return codeList, nil +} + +// GetBotStockMysList +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockMysList(ctx context.Context, uo *Data) ([]string, error) { + var stockList []models.BotStockMysList + if err := uo.mysqlDB.Table(flags.BotStockMysList). + Where("status = 1"). + Find(&stockList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range stockList { + codeList = append(codeList, value.StockCode) + } + + return codeList, nil +} + +// GetBotStockMysListByStockId +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockMysListByStockId(ctx context.Context, uo *Data) ([]string, error) { + var stockList []models.BotStockMysTrade + if err := uo.mysqlDB.Table(flags.BotStockMysTrade). + Distinct("stock_id"). + Find(&stockList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range stockList { + codeList = append(codeList, value.StockId) + } + + return codeList, nil +} + +// GetBotStockIdnList +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockIdnList(ctx context.Context, uo *Data) ([]string, error) { + var stockList []models.BotStockIdnList + if err := uo.mysqlDB.Table(flags.BotStockIdnList). + Where("status = 1"). + Find(&stockList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range stockList { + codeList = append(codeList, value.StockCode) + } + + return codeList, nil +} + +// GetBotStockIdnListByStockId +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockIdnListByStockId(ctx context.Context, uo *Data) ([]string, error) { + var stockList []models.BotStockIdnTrade + if err := uo.mysqlDB.Table(flags.BotStockIdnTrade). + Distinct("stock_id"). + Find(&stockList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range stockList { + codeList = append(codeList, value.StockId) + } + + return codeList, nil +} + +// GetBotStockHkdList +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockHkdList(ctx context.Context, uo *Data) ([]string, error) { + var stockList []models.BotStockHkdList + if err := uo.mysqlDB.Table(flags.BotStockHkdList). + Where("status = 1"). + Find(&stockList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range stockList { + codeList = append(codeList, value.StockCode) + } + + return codeList, nil +} + +// GetBotStockHkdListByStockId +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockHkdListByStockId(ctx context.Context, uo *Data) ([]string, error) { + var stockList []models.BotStockHkdTrade + if err := uo.mysqlDB.Table(flags.BotStockHkdTrade). + Distinct("stock_id"). + Find(&stockList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range stockList { + codeList = append(codeList, value.StockId) + } + + return codeList, nil +} + +// GetBotStockBlockList +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockBlockList(ctx context.Context, uo *Data) (map[int64][]string, error) { + var stockList []models.BotStockBlockList + if err := uo.mysqlDB.Table(flags.BotStockBlockList). + Where("status = 1"). + Find(&stockList); err != nil { + return map[int64][]string{}, err + } + + codeList := make(map[int64][]string, 0) + + for _, value := range stockList { + typeStatus := int64(value.Type) + codeList[typeStatus] = append(codeList[int64(value.Type)], value.StockCode) + } + + return codeList, nil +} + +// GetBotStockBlockListByStockId +// +// @Description: +// @param ctx +// @param uo +// @return map[int64][]string +// @return error +func GetBotStockBlockListByStockId(ctx context.Context, uo *Data) (map[int64][]string, error) { + var stockList []models.BotStockBlockTrade + if err := uo.mysqlDB.Table(flags.BotStockBlockTrade). + Distinct("stock_id"). + Find(&stockList); err != nil { + return map[int64][]string{}, err + } + + codeList := make(map[int64][]string, 0) + + for _, value := range stockList { + typeStatus := int64(value.Type) + codeList[typeStatus] = append(codeList[int64(value.Type)], value.StockId) + } + + return codeList, nil +} + +// GetBotStockInList +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockInList(ctx context.Context, uo *Data) ([]string, error) { + var stockList []models.BotStockInList + if err := uo.mysqlDB.Table(flags.BotStockInList). + Where("status = 1"). + Find(&stockList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range stockList { + codeList = append(codeList, value.StockCode) + } + + return codeList, nil +} + +// GetBotStockInListByStockId +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockInListByStockId(ctx context.Context, uo *Data) ([]string, error) { + var stockList []models.BotStockInTrade + if err := uo.mysqlDB.Table(flags.BotStockInTrade). + Distinct("stock_id"). + Find(&stockList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range stockList { + codeList = append(codeList, value.StockId) + } + + return codeList, nil +} + +// GetBotStockGbxListByStockId +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockGbxListByStockId(ctx context.Context, uo *Data) ([]string, error) { + var stockList []models.BotStockGbxTrade + if err := uo.mysqlDB.Table(flags.BotStockGbxTrade). + Distinct("stock_id"). + Find(&stockList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range stockList { + codeList = append(codeList, value.StockId) + } + + return codeList, nil +} + +// GetBotStockOptionInrList +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockOptionInrList(ctx context.Context, uo *Data) ([]string, error) { + var stockList []models.BotStockOptionInrList + if err := uo.mysqlDB.Table(flags.BotStockOptionInrList). + Where("status = 1"). + Find(&stockList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range stockList { + codeList = append(codeList, value.StockCode) + } + + return codeList, nil +} + +// GetBotStockOptionInrListByStockId +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockOptionInrListByStockId(ctx context.Context, uo *Data) ([]string, error) { + var stockList []models.BotStockOptionInrTrade + if err := uo.mysqlDB.Table(flags.BotStockOptionInrTrade). + Distinct("stock_id"). + Find(&stockList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range stockList { + codeList = append(codeList, value.StockCode) + } + + return codeList, nil +} + +// GetBotStockThaList +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockThaList(ctx context.Context, uo *Data) ([]string, error) { + var stockList []models.BotStockThaList + if err := uo.mysqlDB.Table(flags.BotStockThaList). + Where("status = 1"). + Find(&stockList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range stockList { + codeList = append(codeList, value.StockCode) + } + + return codeList, nil +} + +// GetBotStockThaListByStockId +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockThaListByStockId(ctx context.Context, uo *Data) ([]string, error) { + var stockList []models.BotStockThaTrade + if err := uo.mysqlDB.Table(flags.BotStockThaTrade). + Distinct("stock_id"). + Find(&stockList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range stockList { + codeList = append(codeList, value.StockId) + } + + return codeList, nil +} + +// GetBotStockSgdList +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockSgdList(ctx context.Context, uo *Data) ([]string, error) { + var stockList []models.BotStockSgdList + if err := uo.mysqlDB.Table(flags.BotStockSgdList). + Where("status = 1"). + Find(&stockList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range stockList { + codeList = append(codeList, value.StockCode) + } + + return codeList, nil +} + +// GetBotStockSgdListByStockId +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockSgdListByStockId(ctx context.Context, uo *Data) ([]string, error) { + var stockList []models.BotStockSgdTrade + if err := uo.mysqlDB.Table(flags.BotStockSgdTrade). + Distinct("stock_id"). + Find(&stockList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range stockList { + codeList = append(codeList, value.StockId) + } + + return codeList, nil +} + +// GetBotStockEurListByStockId +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockEurListByStockId(ctx context.Context, uo *Data) ([]string, error) { + var stockList []models.BotStockEurTrade + if err := uo.mysqlDB.Table(flags.BotStockEurTrade). + Distinct("stock_id"). + Find(&stockList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range stockList { + codeList = append(codeList, value.StockId) + } + + return codeList, nil +} + +// GetBotStockBrlListByStockId +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockBrlListByStockId(ctx context.Context, uo *Data) ([]string, error) { + var stockList []models.BotStockBrlTrade + if err := uo.mysqlDB.Table(flags.BotStockBrlTrade). + Distinct("stock_id"). + Find(&stockList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range stockList { + codeList = append(codeList, value.StockId) + } + + return codeList, nil +} + +// GetBotStockFurListByStockId +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockFurListByStockId(ctx context.Context, uo *Data) ([]string, error) { + var stockList []models.BotStockFurTrade + if err := uo.mysqlDB.Table(flags.BotStockFurTrade). + Distinct("stock_id"). + Find(&stockList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range stockList { + codeList = append(codeList, value.StockId) + } + + return codeList, nil +} + +// GetBotStockJpyListByStockId +// +// @Description: +// @param ctx +// @param uo +// @return []string +// @return error +func GetBotStockJpyListByStockId(ctx context.Context, uo *Data) ([]string, error) { + var stockList []models.BotStockJpTrade + if err := uo.mysqlDB.Table(flags.BotStockJpyTrade). + Distinct("stock_id"). + Find(&stockList); err != nil { + return []string{}, err + } + + var codeList []string + for _, value := range stockList { + codeList = append(codeList, value.StockId) + } + + return codeList, nil +} + +// NegativeValue +// +// @Description: Negative Number Definition Prefix +// @param value +// @return string +func NegativeValue(value string) string { + return fmt.Sprintf("-%v", value) +} + +// GetContractSystemSetUp +// +// @Description: Contract Order System Settings +// @param symbol +// @return *structure.ContractSystem +// @return error +func GetContractSystemSetUp(symbol string) (*structure.ContractSystem, error) { + keySymbol := fmt.Sprintf("%v%v", flags.ContractSystemSetUpKey, symbol) + + symbolMap, err := Reds.HGetAll(context.Background(), keySymbol).Result() + if err != nil { + applogger.Error("%v GetContractSystemSetUp.HGetAll", common.ErrContract, err) + return nil, err + } + var systemModel structure.ContractSystem + for filed, value := range symbolMap { + switch filed { + case "face_value": + systemModel.FaceValue = decimal.RequireFromString("1") + case "max_pry": + systemModel.MaxPry = decimal.RequireFromString(value) + case "min_pry": + systemModel.MinPry = decimal.RequireFromString(value) + case "compel_num": + systemModel.CompelNum = decimal.RequireFromString(flags.SetOne).Sub(decimal.RequireFromString(value)) + default: + + } + } + + return &systemModel, nil +} + +// GetForexSystemSetUp +// +// @Description: +// @param symbol +// @return *structure.ForexSystem +// @return error +func GetForexSystemSetUp(symbol string) (*structure.ForexSystem, error) { + keySymbol := fmt.Sprintf("%v%v", flags.ForexSystemSetUpKey, symbol) + + symbolMap, err := Reds.HGetAll(context.Background(), keySymbol).Result() + if err != nil { + applogger.Error("%v GetForexSystemSetUp.HGetAll", common.ErrForex, err) + return nil, err + } + var systemModel structure.ForexSystem + for filed, value := range symbolMap { + switch filed { + case "face_value": + systemModel.FaceValue = decimal.RequireFromString("1") + case "max_pry": + systemModel.MaxPry = decimal.RequireFromString(value) + case "min_pry": + systemModel.MinPry = decimal.RequireFromString(value) + case "compel_num": + systemModel.CompelNum = decimal.RequireFromString(flags.SetOne).Sub(decimal.RequireFromString(value)) + default: + } + } + + return &systemModel, nil +} + +// GetContractSystemSecond +// +// @Description: System settings for second contract orders +// @return map[int64]structure.ProportionSystem +// @return error +func GetContractSystemSecond() (map[int64]structure.ProportionSystem, error) { + symbolMap, err := Reds.Get(context.Background(), flags.ContractSystemSecond).Result() + if err != nil { + applogger.Error("%v GetContractSystemSecond.Get:%v", common.ErrSecond, err) + return nil, err + } + + var statusTime []structure.ContractTimeSetting + if err = json.Unmarshal([]byte(symbolMap), &statusTime); err != nil { + applogger.Error("%v GetContractSystemSecond.Unmarshal:%v", common.ErrSecond, err) + return nil, err + } + + systemModel := make(map[int64]structure.ProportionSystem) + for _, value := range statusTime { + if value.TimeStep == 0 { + continue + } + model := structure.ProportionSystem{ + Value: strconv.Itoa(int(value.EarningsNum)), + } + systemModel[value.TimeStep] = model + } + + return systemModel, nil +} + +// GetKeepDecimal +// +// @Description: (合约|现货|股票)交易对保留小数 +// @param steUpKey +// @param symbol +// @return int +func GetKeepDecimal(steUpKey, symbol string) int { + keySymbol := fmt.Sprintf("%v%v", steUpKey, symbol) + + kDStr, err := Reds.HGet(context.Background(), keySymbol, "keep_decimal").Result() + if err != nil { + //applogger.Error("GetCacheKeepDecimal.HGetAll:%v", err) + return 0 + } + + keepDecimal, err := strconv.Atoi(kDStr) + if err != nil { + return 0 + } + + return keepDecimal +} + +// GetStockName +// +// @Description: +// @param steUpKey +// @param symbol +// @return string +func GetStockName(steUpKey, symbol string) string { + keySymbol := fmt.Sprintf("%v%v", steUpKey, symbol) + + sNStr, err := Reds.HGet(context.Background(), keySymbol, "stock_name").Result() + if err != nil { + applogger.Error("GetStockName.HGet:%v", err) + return symbol + } + + return sNStr +} + +// GetCacheForcedClosure +// +// @Description: Setting the Strong Leveling Threshold for Stock Trading +// @param steUpKey +// @param symbol +// @return decimal.Decimal +func GetCacheForcedClosure(steUpKey, symbol string) decimal.Decimal { + keySymbol := fmt.Sprintf("%v%v", steUpKey, symbol) + + symbolMap, err := Reds.HGetAll(context.Background(), keySymbol).Result() + if err != nil { + applogger.Error("GetCacheForcedClosure.HGetAll:%v", err) + return decimal.RequireFromString(flags.ForcedClosure) + } + + var forcedClosure decimal.Decimal + for filed, value := range symbolMap { + switch filed { + case "forced_closure": + forcedClosure = decimal.RequireFromString(flags.DecimalOne).Sub(decimal.RequireFromString(value)) + default: + + } + } + + if forcedClosure.IsZero() { + return decimal.RequireFromString(flags.ForcedClosure) + } + + return forcedClosure +} + +// GetCacheNumericCode +// +// @Description: +// @param steUpKey +// @param symbol +// @return string +func GetCacheNumericCode(keys string) string { + symbolMap, err := Reds.HGetAll(context.Background(), keys).Result() + if err != nil { + applogger.Error("GetCacheNumericCode.HGetAll:%v", err) + return "" + } + + var numericCode string + for filed, value := range symbolMap { + switch filed { + case "numeric_code": + numericCode = value + default: + + } + } + + return numericCode +} + +// GetOptionInrForcedClosure +// +// @Description: 获取期权保证金比例 +// @param steUpKey +// @param symbol +// @return decimal.Decimal +func GetOptionInrForcedClosure(steUpKey, symbol string) decimal.Decimal { + keySymbol := fmt.Sprintf("%v%v", steUpKey, symbol) + + symbolMap, err := Reds.HGetAll(context.Background(), keySymbol).Result() + if err != nil { + applogger.Error("GetCacheForcedClosure.HGetAll:%v", err) + return decimal.RequireFromString(flags.ForcedRate) + } + + var forcedClosure decimal.Decimal + for filed, value := range symbolMap { + switch filed { + case "rate": + forcedClosure = decimal.RequireFromString(flags.DecimalOne).Sub(decimal.RequireFromString(value)) + default: + + } + } + + if forcedClosure.IsZero() { + return decimal.RequireFromString(flags.ForcedRate) + } + + return forcedClosure +} + +// GetCacheLimitOrDown +// +// @Description: Setting the limit up and down threshold for stock trading +// @param steUpKey +// @param symbol +// @return decimal.Decimal +func GetCacheLimitOrDown(steUpKey, symbol string) decimal.Decimal { + keySymbol := fmt.Sprintf("%v%v", steUpKey, symbol) + + symbolMap, err := Reds.HGetAll(context.Background(), keySymbol).Result() + if err != nil { + applogger.Error("GetCacheForcedClosure.HGetAll:%v", err) + return decimal.RequireFromString(flags.LimitTen) + } + + var limit decimal.Decimal + for filed, value := range symbolMap { + switch filed { + case "up_limit": + limit = decimal.RequireFromString(value) + case "down_limit": + limit = decimal.RequireFromString(value) + default: + limit = decimal.RequireFromString(flags.LimitTen) + } + } + + return limit +} + +// GetCacheStockMarketStatus +// +// @Description: 股市交易设置 +// @param steUpKey +// @param symbol +// @return bool +func GetCacheStockMarketStatus(steUpKey, symbol string) bool { + keySymbol := fmt.Sprintf("%v%v", steUpKey, symbol) + + symbolMap, err := Reds.HGetAll(context.Background(), keySymbol).Result() + if err != nil { + //applogger.Error("GetCacheKeepDecimal.HGetAll:%v", err) + return false + } + + var status bool + for filed, value := range symbolMap { + switch filed { + case "status": + switch value { + case flags.SetOne: // 启用 + status = false + case flags.SetTwo: // 禁用 + status = true + default: + status = true + } + default: + + } + } + + return status +} + +// GetCacheStockBlockStatus +// +// @Description: 大宗交易设置 +// @param steUpKey +// @param symbol +// @return bool +func GetCacheStockBlockStatus(steUpKey, symbol string) (bool, string, int, time.Time) { + keySymbol := fmt.Sprintf("%v%v", steUpKey, symbol) + + symbolMap, err := Reds.HGetAll(context.Background(), keySymbol).Result() + if err != nil { + //applogger.Error("GetCacheKeepDecimal.HGetAll:%v", err) + return false, "", 0, time.Now() + } + + var status bool + var minNum, today int + var startTime, endTime, openPrice string + for filed, value := range symbolMap { + if len(value) == 0 { + continue + } + switch filed { + case "status": + switch value { + case flags.SetOne: // 启用 + status = false + case flags.SetTwo: // 禁用 + status = true + default: + status = true + } + case "min": + minNum, err = strconv.Atoi(value) + if err != nil { + minNum = 0 + } + case "start_time": + startTime = value + case "end_time": + endTime = value + case "price": + openPrice = value + case "today_add": + today, err = strconv.Atoi(value) + if err != nil { + today = 0 + } + default: + } + } + + // 判定时间 + if !utils.CheckTimeUTC(startTime, endTime) { + return true, "", 0, time.Now() + } + // 处理大宗交易开仓价格 + if utils.ReplaceStr(openPrice) == "" { + openPrice = "0" + } + + return status, openPrice, minNum, utils.TimeAddDayZero(today) +} + +// GetCacheStockMarketStatusT +// +// @Description: 股票收盘交易设置 +// @param steUpKey +// @param symbol +// @return int +func GetCacheStockMarketStatusT(steUpKey, symbol string) int { + keySymbol := fmt.Sprintf("%v%v", steUpKey, symbol) + + symbolMap, err := Reds.HGetAll(context.Background(), keySymbol).Result() + if err != nil { + //applogger.Error("GetCacheKeepDecimal.HGetAll:%v", err) + return 0 + } + + var checkTime int + for filed, value := range symbolMap { + switch filed { + case "trade_day_type": + switch value { + case flags.CloseOne: // T+0 + checkTime = 0 + case flags.CloseTwo: // T+1 + checkTime = 1 + case flags.CloseThree: // T+2 + checkTime = 2 + case flags.CloseFour: // T+3 + checkTime = 3 + default: + checkTime = 0 + } + default: + + } + } + + return checkTime +} + +// GetCacheStockMarketLeverStatus +// +// @Description: 股票市场设置 +// @param key +// @param code +// @return *structure.ShareSystem +func GetCacheStockMarketLeverStatus(key, code string) *structure.ShareSystem { + keySymbol := fmt.Sprintf("%v%v", key, code) + + symbolMap, err := Reds.HGetAll(context.Background(), keySymbol).Result() + if err != nil { + //applogger.Error("GetCacheKeepDecimal.HGetAll:%v", err) + return nil + } + + var shareSystem structure.ShareSystem + for filed, value := range symbolMap { + if len(utils.StrReplace(value)) == 0 { + continue + } + switch filed { + case "lever_status": // 杠杆状态 + shareSystem.Status = decimal.RequireFromString(value) + case "stock_min": // 触发杠杆最小值 + shareSystem.StockMin = decimal.RequireFromString(value) + case "lever_min": // 杠杆最小值 + shareSystem.LevelMin = decimal.RequireFromString(value) + case "lever_max": // 杠杆最大值 + shareSystem.LevelMax = decimal.RequireFromString(value) + default: + + } + } + + return &shareSystem +} + +// SystemTimeGenerate +// +// @Description: Obtain individual stock system settings +// @param market +// @param share +// @param orderTime +// @return time.Time +func SystemTimeGenerate(market, share string, orderTime time.Time) time.Time { + to := GetCacheStockMarketStatusT(market, share) + timeNewAfterTwoDays := orderTime.AddDate(0, 0, to) + + return timeNewAfterTwoDays +} + +// SystemShareMarketLeverStatus +// +// @Description: Obtain stock market system settings +// @param market +// @param code +// @return structure.ShareSystem +func SystemShareMarketLeverStatus(market, code string, userId int64) *structure.ShareSystem { + shareLever := GetCacheStockMarketLeverStatus(market, code) + if shareLever == nil { + return &structure.ShareSystem{} + } + + // Determine whether the user has activated the lever + cacheKey := fmt.Sprintf("%v%v", flags.StockTradePryNum, userId) + setV, err := Reds.Get(context.Background(), cacheKey).Result() + if err != nil || setV != flags.SetThree { + return &structure.ShareSystem{} + } + + shareLever.UserStatus = setV + + return shareLever +} + +// SystemDealWithLever +// +// @Description: Handling leverage values +// @param order +// @return decimal.Decimal +func SystemDealWithLever(order structure.ShareOrder) decimal.Decimal { + // 杠杆设定缓存值 + pryNum, err := Reds.Get(context.Background(), fmt.Sprintf("%v%v", flags.StockTradePryNumSet, order.UserId)).Result() + if err != nil { + pryNum, err = Reds.Get(context.Background(), fmt.Sprintf("%v%v", flags.StockTradePryNumSet, 0)).Result() + if err != nil { + pryNum = flags.SetOne + } + } + pryNumValue := decimal.RequireFromString(pryNum) + + orderNumber := decimal.RequireFromString(order.OrderNumber) + switch order.System.Status.String() { + case flags.SetOne: // 开启 + // 判定用户是否开启杠杆 + if order.System.UserStatus != flags.SetThree { + return pryNumValue + } + + // 判定是否达到最小面值 + if orderNumber.IsZero() { + return pryNumValue + } + if orderNumber.Cmp(order.System.StockMin) < 0 { + return pryNumValue + } + + // 判定杠杆范围 + if len(utils.ReplaceStr(pryNum)) == 0 || !utils.IsNumberInt(pryNum) { + return pryNumValue + } + if pryNumValue.Cmp(order.System.LevelMin) < 0 || pryNumValue.Cmp(order.System.LevelMax) > 0 { + return pryNumValue + } + } + + return pryNumValue +} + +// CheckShareSystemTime +// +// @Description: Check if the stock system setting time requires closing positions +// @param timeStr +// @return bool +func CheckShareSystemTime(timeStr time.Time) bool { + timeNew := time.Now().Format(flags.TimeFormat) + timeOld := timeStr.Format(flags.TimeFormat) + + if timeNew >= timeOld { + return true + } else { + return false + } +} + +// GetStrongFlatteningThreshold +// +// @Description: Determine whether there is a strong balance +// @return bool +func GetStrongFlatteningThreshold(userId int64) bool { + keys := fmt.Sprintf("%v%v", flags.StockTradePryNum, strconv.Itoa(int(userId))) + setV, err := Reds.Get(context.Background(), keys).Result() + if err != nil { + return false + } + + if setV == flags.SetThree { + return true + } + + return false +} + +// CheckTypeStatus +// +// @Description: 大宗交易判定 +// @param status +// @return bool +func CheckTypeStatus(status int64) bool { + if status <= 0 { + return false + } else { + return true + } +} + +// PryNumInit +// +// @Description: 杠杆初始化 +// @param order +// @return structure.ShareOrder +func PryNumInit(order structure.ShareOrder) structure.ShareOrder { + if len(utils.ReplaceStr(order.PryNum)) == 0 || order.PryNum == flags.SetZero { + order.PryNum = flags.SetOne + } + return order +} + +// GetBotUserArrears +// +// @Description: +// @param ctx +// @param userId +// @return map[string]string +// @return error +func GetBotUserArrears(ctx context.Context) (map[int64]int64, error) { + var botInr []models.BotUserArrears + if err := Msql.Table(flags.BotUserArrears). + Distinct("user_id"). + Where("status = 0"). + Find(&botInr); err != nil { + applogger.Error("GetBotUserArrears Find:%v", err) + return nil, err + } + + inrMap := make(map[int64]int64, 0) + for _, value := range botInr { + inrMap[int64(value.UserId)] = int64(value.UserId) + } + + return inrMap, nil +} + +// QuerySystemCache +// +// @Description: 系统配置开闭盘时间 +// @return amOpenTime +// @return pmOpenTime +// @return amCloseTime +// @return pmCloseTime +func QuerySystemCache(marketType int) (timeValue flags.TimeValue) { + // 判定开闭盘时间 + usMarkerCacheKey := fmt.Sprintf("%v%v", flags.StockMarketList, marketType) + symbol, err := Reds.HGetAll(context.Background(), usMarkerCacheKey).Result() + if err != nil { + applogger.Error("InitShareUsCloseNewPrice.HGetAll:%v", err) + return + } + var amOpenTime, amCloseTime, pmOpenTime, pmCloseTime time.Time + for filed, value := range symbol { + switch filed { + case "am_open_time": + amOpenTime, _ = time.Parse(flags.LayoutOne, value) + case "am_close_time": + amCloseTime, _ = time.Parse(flags.LayoutOne, value) + case "pm_open_time": + pmOpenTime, _ = time.Parse(flags.LayoutOne, value) + case "pm_close_time": + pmCloseTime, _ = time.Parse(flags.LayoutOne, value) + default: + } + } + + return flags.TimeValue{ + AmOpenTime: amOpenTime, + AmCloseTime: amCloseTime, + PmOpenTime: pmOpenTime, + PmCloseTime: pmCloseTime, + } +} + +// MarketCheckOpenAndCloseTime +// +// @Description: 市场真实开闭盘时间 +// @param marketType +// @return amOpenTime +// @return pmOpenTime +// @return amCloseTime +// @return pmCloseTime +func MarketCheckOpenAndCloseTime(marketType int) (timeValue flags.TimeValue, checkWeekday bool) { + var week int + var weekDayCheck bool + var weekday = time.Now().Weekday() + switch weekday { + case time.Monday: // 星期一 + week = 1 + weekDayCheck = true + case time.Tuesday: // 星期二 + week = 2 + weekDayCheck = true + case time.Wednesday: // 星期三 + week = 3 + weekDayCheck = true + case time.Thursday: // 星期四 + week = 4 + weekDayCheck = true + case time.Friday: // 星期五 + week = 5 + weekDayCheck = true + default: // 星期六|星期天|未知星期 + //return timeValue, weekDayCheck + weekDayCheck = true + } + + switch marketType { + case flags.ShareIdnMarketType: // 印尼 + if week != 5 { + // 类型4: (周一到周四) 10:00 - 13:00(上午盘) 14:30 - 17:10(下午盘) + timeValue = TimeResult(marketType) + } else { + // 类型40: (周五) 10:00 - 12:30(上午盘) 15:00 - 17:10(下午盘) + timeValue = TimeResult(40) + } + default: + timeValue = TimeResult(marketType) + } + + return timeValue, weekDayCheck +} + +// TimeResult +// +// @Description: +// @param marketType +// @return amOpenTime +// @return pmOpenTime +// @return amCloseTime +// @return pmCloseTime +func TimeResult(marketType int) flags.TimeValue { + amOpenTime, _ := time.Parse(flags.LayoutOne, flags.TimeMapType[marketType].AmOpenTime) + amCloseTime, _ := time.Parse(flags.LayoutOne, flags.TimeMapType[marketType].AmCloseTime) + pmOpenTime, _ := time.Parse(flags.LayoutOne, flags.TimeMapType[marketType].PmOpenTime) + pmCloseTime, _ := time.Parse(flags.LayoutOne, flags.TimeMapType[marketType].PmCloseTime) + + return flags.TimeValue{AmOpenTime: amOpenTime, AmCloseTime: amCloseTime, PmOpenTime: pmOpenTime, PmCloseTime: pmCloseTime} +} diff --git a/internal/data/utils_check_test.go b/internal/data/utils_check_test.go new file mode 100644 index 0000000..e937e45 --- /dev/null +++ b/internal/data/utils_check_test.go @@ -0,0 +1,1926 @@ +package data + +import ( + "context" + "fmt" + "github.com/go-kratos/kratos/v2/log" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + models "matchmaking-system/internal/pkg/model" + "reflect" + "strconv" + "strings" + "testing" + "time" +) + +func TestCheckShareSystemTime(t *testing.T) { + var makeType int + var err error + symbol := "moneySubscribe-19" + if strings.Contains(symbol, "-") { + splitStr := strings.Split(symbol, "-") + applogger.Debug("Subscribe type:%v", symbol) + if len(splitStr) == 2 { + symbol = splitStr[0] + makeType, err = strconv.Atoi(splitStr[1]) + if err != nil { + makeType = 0 + } + } + applogger.Debug("Subscribe type:%v", symbol) + } else { + makeType = 0 + } + applogger.Error("Subscribe type:%v---%v", makeType, symbol) + + return + // 市场开闭盘时间 + timeValue, checkWeekday := MarketCheckOpenAndCloseTime(3) + + dateTime, _ := time.Parse(flags.LayoutOne, time.Now().Format(flags.LayoutOne)) + fmt.Println("当前时间:", dateTime) + fmt.Println("上午开盘时间:", timeValue.AmOpenTime) + fmt.Println("上午闭盘时间:", timeValue.AmCloseTime) + fmt.Println("下午开盘时间:", timeValue.PmOpenTime) + fmt.Println("下午闭盘时间:", timeValue.PmCloseTime) + fmt.Println("不是节假日:", checkWeekday) + + // 判定上午盘 + checkAmTime := dateTime.Equal(timeValue.AmOpenTime) || dateTime.Equal(timeValue.AmCloseTime) + if timeValue.AmOpenTime.Before(timeValue.AmCloseTime) { + fmt.Println("上午同天盘判定。。。。。") + // 同一天 + if dateTime.After(timeValue.AmOpenTime) && dateTime.Before(timeValue.AmCloseTime) || checkAmTime { + fmt.Println("上午正常的开盘时间。。。。。") + } + } else { + fmt.Println("上午跨天盘判定。。。。。") + // 跨天 + if dateTime.After(timeValue.AmOpenTime) || dateTime.Before(timeValue.AmCloseTime) || checkAmTime { + fmt.Println("上午正常的开盘时间。。。。。") + } + } + // 判定下午盘 + checkPmTime := dateTime.Equal(timeValue.PmOpenTime) || dateTime.Equal(timeValue.PmCloseTime) + if timeValue.PmOpenTime.Before(timeValue.PmCloseTime) { + fmt.Println("下午同天盘判定。。。。。") + // 同一天 + if dateTime.After(timeValue.PmOpenTime) && dateTime.Before(timeValue.PmCloseTime) || checkPmTime { + fmt.Println("下午正常的开盘时间。。。。。") + } + } else { + fmt.Println("下午跨天盘判定。。。。。") + // 跨天 + if dateTime.After(timeValue.PmOpenTime) || dateTime.Before(timeValue.PmCloseTime) || checkPmTime { + fmt.Println("下午正常的开盘时间。。。。。") + } + } + + return + + type args struct { + timeStr time.Time + } + tests := []struct { + name string + args args + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CheckShareSystemTime(tt.args.timeStr); got != tt.want { + t.Errorf("CheckShareSystemTime() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCheckTypeStatus(t *testing.T) { + type args struct { + status int64 + } + tests := []struct { + name string + args args + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CheckTypeStatus(tt.args.status); got != tt.want { + t.Errorf("CheckTypeStatus() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotContractList(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotContractList(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotContractList() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotContractList() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotDigitalList(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotDigitalList(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotDigitalList() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotDigitalList() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockBlockList(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want map[int64][]string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockBlockList(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockBlockList() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockBlockList() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockBlockListByStockId(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want map[int64][]string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockBlockListByStockId(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockBlockListByStockId() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockBlockListByStockId() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockBrlListByStockId(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockBrlListByStockId(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockBrlListByStockId() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockBrlListByStockId() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockEurListByStockId(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockEurListByStockId(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockEurListByStockId() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockEurListByStockId() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockFurListByStockId(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockFurListByStockId(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockFurListByStockId() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockFurListByStockId() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockGbxListByStockId(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockGbxListByStockId(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockGbxListByStockId() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockGbxListByStockId() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockHkdList(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockHkdList(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockHkdList() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockHkdList() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockHkdListByStockId(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockHkdListByStockId(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockHkdListByStockId() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockHkdListByStockId() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockIdnList(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockIdnList(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockIdnList() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockIdnList() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockIdnListByStockId(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockIdnListByStockId(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockIdnListByStockId() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockIdnListByStockId() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockInList(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockInList(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockInList() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockInList() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockInListByStockId(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockInListByStockId(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockInListByStockId() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockInListByStockId() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockList(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockList(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockList() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockList() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockListByStockId(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockListByStockId(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockListByStockId() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockListByStockId() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockMysList(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockMysList(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockMysList() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockMysList() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockMysListByStockId(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockMysListByStockId(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockMysListByStockId() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockMysListByStockId() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockOptionInrList(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockOptionInrList(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockOptionInrList() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockOptionInrList() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockOptionInrListByStockId(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockOptionInrListByStockId(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockOptionInrListByStockId() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockOptionInrListByStockId() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockSgdList(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockSgdList(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockSgdList() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockSgdList() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockSgdListByStockId(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockSgdListByStockId(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockSgdListByStockId() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockSgdListByStockId() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockThaList(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockThaList(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockThaList() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockThaList() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotStockThaListByStockId(t *testing.T) { + type args struct { + ctx context.Context + uo *Data + } + tests := []struct { + name string + args args + want []string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotStockThaListByStockId(tt.args.ctx, tt.args.uo) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockThaListByStockId() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotStockThaListByStockId() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBotUserArrears(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + args args + want map[int64]int64 + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetBotUserArrears(tt.args.ctx) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotUserArrears() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotUserArrears() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetCacheForcedClosure(t *testing.T) { + type args struct { + steUpKey string + symbol string + } + tests := []struct { + name string + args args + want decimal.Decimal + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := GetCacheForcedClosure(tt.args.steUpKey, tt.args.symbol); !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetCacheForcedClosure() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetCacheLimitOrDown(t *testing.T) { + type args struct { + steUpKey string + symbol string + } + tests := []struct { + name string + args args + want decimal.Decimal + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := GetCacheLimitOrDown(tt.args.steUpKey, tt.args.symbol); !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetCacheLimitOrDown() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetCacheNumericCode(t *testing.T) { + type args struct { + keys string + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := GetCacheNumericCode(tt.args.keys); got != tt.want { + t.Errorf("GetCacheNumericCode() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetCacheStockBlockStatus(t *testing.T) { + type args struct { + steUpKey string + symbol string + } + tests := []struct { + name string + args args + want bool + want1 string + want2 int + want3 time.Time + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, got1, got2, got3 := GetCacheStockBlockStatus(tt.args.steUpKey, tt.args.symbol) + if got != tt.want { + t.Errorf("GetCacheStockBlockStatus() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("GetCacheStockBlockStatus() got1 = %v, want %v", got1, tt.want1) + } + if got2 != tt.want2 { + t.Errorf("GetCacheStockBlockStatus() got2 = %v, want %v", got2, tt.want2) + } + if !reflect.DeepEqual(got3, tt.want3) { + t.Errorf("GetCacheStockBlockStatus() got3 = %v, want %v", got3, tt.want3) + } + }) + } +} + +func TestGetCacheStockMarketLeverStatus(t *testing.T) { + type args struct { + key string + code string + } + tests := []struct { + name string + args args + want *structure.ShareSystem + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := GetCacheStockMarketLeverStatus(tt.args.key, tt.args.code); !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetCacheStockMarketLeverStatus() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetCacheStockMarketStatus(t *testing.T) { + type args struct { + steUpKey string + symbol string + } + tests := []struct { + name string + args args + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := GetCacheStockMarketStatus(tt.args.steUpKey, tt.args.symbol); got != tt.want { + t.Errorf("GetCacheStockMarketStatus() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetCacheStockMarketStatusT(t *testing.T) { + type args struct { + steUpKey string + symbol string + } + tests := []struct { + name string + args args + want int + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := GetCacheStockMarketStatusT(tt.args.steUpKey, tt.args.symbol); got != tt.want { + t.Errorf("GetCacheStockMarketStatusT() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetContractSystemSecond(t *testing.T) { + tests := []struct { + name string + want map[int64]structure.ProportionSystem + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetContractSystemSecond() + if (err != nil) != tt.wantErr { + t.Errorf("GetContractSystemSecond() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetContractSystemSecond() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetContractSystemSetUp(t *testing.T) { + type args struct { + symbol string + } + tests := []struct { + name string + args args + want *structure.ContractSystem + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GetContractSystemSetUp(tt.args.symbol) + if (err != nil) != tt.wantErr { + t.Errorf("GetContractSystemSetUp() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetContractSystemSetUp() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetKeepDecimal(t *testing.T) { + type args struct { + steUpKey string + symbol string + } + tests := []struct { + name string + args args + want int + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := GetKeepDecimal(tt.args.steUpKey, tt.args.symbol); got != tt.want { + t.Errorf("GetKeepDecimal() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetOptionInrForcedClosure(t *testing.T) { + type args struct { + steUpKey string + symbol string + } + tests := []struct { + name string + args args + want decimal.Decimal + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := GetOptionInrForcedClosure(tt.args.steUpKey, tt.args.symbol); !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetOptionInrForcedClosure() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetStockName(t *testing.T) { + type args struct { + steUpKey string + symbol string + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := GetStockName(tt.args.steUpKey, tt.args.symbol); got != tt.want { + t.Errorf("GetStockName() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetStrongFlatteningThreshold(t *testing.T) { + type args struct { + userId int64 + } + tests := []struct { + name string + args args + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := GetStrongFlatteningThreshold(tt.args.userId); got != tt.want { + t.Errorf("GetStrongFlatteningThreshold() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMarketCheckOpenAndCloseTime(t *testing.T) { + type args struct { + marketType int + } + tests := []struct { + name string + args args + wantTimeValue flags.TimeValue + wantCheckWeekday bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + gotTimeValue, gotCheckWeekday := MarketCheckOpenAndCloseTime(tt.args.marketType) + if !reflect.DeepEqual(gotTimeValue, tt.wantTimeValue) { + t.Errorf("MarketCheckOpenAndCloseTime() gotTimeValue = %v, want %v", gotTimeValue, tt.wantTimeValue) + } + if gotCheckWeekday != tt.wantCheckWeekday { + t.Errorf("MarketCheckOpenAndCloseTime() gotCheckWeekday = %v, want %v", gotCheckWeekday, tt.wantCheckWeekday) + } + }) + } +} + +func TestNegativeValue(t *testing.T) { + type args struct { + value string + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NegativeValue(tt.args.value); got != tt.want { + t.Errorf("NegativeValue() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestPryNumInit(t *testing.T) { + type args struct { + order structure.ShareOrder + } + tests := []struct { + name string + args args + want structure.ShareOrder + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := PryNumInit(tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("PryNumInit() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestQuerySystemCache(t *testing.T) { + type args struct { + marketType int + } + tests := []struct { + name string + args args + wantTimeValue flags.TimeValue + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if gotTimeValue := QuerySystemCache(tt.args.marketType); !reflect.DeepEqual(gotTimeValue, tt.wantTimeValue) { + t.Errorf("QuerySystemCache() = %v, want %v", gotTimeValue, tt.wantTimeValue) + } + }) + } +} + +func TestSystemDealWithLever(t *testing.T) { + type args struct { + order structure.ShareOrder + } + tests := []struct { + name string + args args + want decimal.Decimal + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := SystemDealWithLever(tt.args.order); !reflect.DeepEqual(got, tt.want) { + t.Errorf("SystemDealWithLever() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestSystemShareMarketLeverStatus(t *testing.T) { + type args struct { + market string + code string + userId int64 + } + tests := []struct { + name string + args args + want *structure.ShareSystem + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := SystemShareMarketLeverStatus(tt.args.market, tt.args.code, tt.args.userId); !reflect.DeepEqual(got, tt.want) { + t.Errorf("SystemShareMarketLeverStatus() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestSystemTimeGenerate(t *testing.T) { + type args struct { + market string + share string + orderTime time.Time + } + tests := []struct { + name string + args args + want time.Time + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := SystemTimeGenerate(tt.args.market, tt.args.share, tt.args.orderTime); !reflect.DeepEqual(got, tt.want) { + t.Errorf("SystemTimeGenerate() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestTimeResult(t *testing.T) { + type args struct { + marketType int + } + tests := []struct { + name string + args args + want flags.TimeValue + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := TimeResult(tt.args.marketType); !reflect.DeepEqual(got, tt.want) { + t.Errorf("TimeResult() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUpdateContractSubscribeHashStatusByOrderId(t *testing.T) { + type args struct { + orderId string + updateKey string + status string + closePrice string + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := UpdateContractSubscribeHashStatusByOrderId(tt.args.orderId, tt.args.updateKey, tt.args.status, tt.args.closePrice); (err != nil) != tt.wantErr { + t.Errorf("UpdateContractSubscribeHashStatusByOrderId() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestUpdateOptionInrSubscribeHashStatusByOrderId(t *testing.T) { + type args struct { + orderId string + updateKey string + status string + openPrice string + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := UpdateOptionInrSubscribeHashStatusByOrderId(tt.args.orderId, tt.args.updateKey, tt.args.status, tt.args.openPrice); (err != nil) != tt.wantErr { + t.Errorf("UpdateOptionInrSubscribeHashStatusByOrderId() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestUpdateShareBrlSubscribeHashStatusByOrderId(t *testing.T) { + type args struct { + orderId string + updateKey string + status string + openPrice string + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := UpdateShareBrlSubscribeHashStatusByOrderId(tt.args.orderId, tt.args.updateKey, tt.args.status, tt.args.openPrice); (err != nil) != tt.wantErr { + t.Errorf("UpdateShareBrlSubscribeHashStatusByOrderId() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestUpdateShareEurSubscribeHashStatusByOrderId(t *testing.T) { + type args struct { + orderId string + updateKey string + status string + openPrice string + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := UpdateShareEurSubscribeHashStatusByOrderId(tt.args.orderId, tt.args.updateKey, tt.args.status, tt.args.openPrice); (err != nil) != tt.wantErr { + t.Errorf("UpdateShareEurSubscribeHashStatusByOrderId() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestUpdateShareFurSubscribeHashStatusByOrderId(t *testing.T) { + type args struct { + orderId string + updateKey string + status string + openPrice string + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := UpdateShareFurSubscribeHashStatusByOrderId(tt.args.orderId, tt.args.updateKey, tt.args.status, tt.args.openPrice); (err != nil) != tt.wantErr { + t.Errorf("UpdateShareFurSubscribeHashStatusByOrderId() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestUpdateShareGbxSubscribeHashStatusByOrderId(t *testing.T) { + type args struct { + orderId string + updateKey string + status string + openPrice string + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := UpdateShareGbxSubscribeHashStatusByOrderId(tt.args.orderId, tt.args.updateKey, tt.args.status, tt.args.openPrice); (err != nil) != tt.wantErr { + t.Errorf("UpdateShareGbxSubscribeHashStatusByOrderId() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestUpdateShareHkdSubscribeHashStatusByOrderId(t *testing.T) { + type args struct { + orderId string + updateKey string + status string + openPrice string + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := UpdateShareHkdSubscribeHashStatusByOrderId(tt.args.orderId, tt.args.updateKey, tt.args.status, tt.args.openPrice); (err != nil) != tt.wantErr { + t.Errorf("UpdateShareHkdSubscribeHashStatusByOrderId() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestUpdateShareIdnSubscribeHashStatusByOrderId(t *testing.T) { + type args struct { + orderId string + updateKey string + status string + openPrice string + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := UpdateShareIdnSubscribeHashStatusByOrderId(tt.args.orderId, tt.args.updateKey, tt.args.status, tt.args.openPrice); (err != nil) != tt.wantErr { + t.Errorf("UpdateShareIdnSubscribeHashStatusByOrderId() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestUpdateShareInrSubscribeHashStatusByOrderId(t *testing.T) { + type args struct { + orderId string + updateKey string + status string + openPrice string + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := UpdateShareInrSubscribeHashStatusByOrderId(tt.args.orderId, tt.args.updateKey, tt.args.status, tt.args.openPrice); (err != nil) != tt.wantErr { + t.Errorf("UpdateShareInrSubscribeHashStatusByOrderId() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestUpdateShareMysSubscribeHashStatusByOrderId(t *testing.T) { + type args struct { + orderId string + updateKey string + status string + openPrice string + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := UpdateShareMysSubscribeHashStatusByOrderId(tt.args.orderId, tt.args.updateKey, tt.args.status, tt.args.openPrice); (err != nil) != tt.wantErr { + t.Errorf("UpdateShareMysSubscribeHashStatusByOrderId() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestUpdateShareSgdSubscribeHashStatusByOrderId(t *testing.T) { + type args struct { + orderId string + updateKey string + status string + openPrice string + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := UpdateShareSgdSubscribeHashStatusByOrderId(tt.args.orderId, tt.args.updateKey, tt.args.status, tt.args.openPrice); (err != nil) != tt.wantErr { + t.Errorf("UpdateShareSgdSubscribeHashStatusByOrderId() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestUpdateShareThaSubscribeHashStatusByOrderId(t *testing.T) { + type args struct { + orderId string + updateKey string + status string + openPrice string + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := UpdateShareThaSubscribeHashStatusByOrderId(tt.args.orderId, tt.args.updateKey, tt.args.status, tt.args.openPrice); (err != nil) != tt.wantErr { + t.Errorf("UpdateShareThaSubscribeHashStatusByOrderId() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestUpdateShareUsSubscribeHashStatusByOrderId(t *testing.T) { + type args struct { + orderId string + updateKey string + status string + openPrice string + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := UpdateShareUsSubscribeHashStatusByOrderId(tt.args.orderId, tt.args.updateKey, tt.args.status, tt.args.openPrice); (err != nil) != tt.wantErr { + t.Errorf("UpdateShareUsSubscribeHashStatusByOrderId() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestUpdateSpotsSubscribeStatusHashByOrderId(t *testing.T) { + type args struct { + userId int64 + orderId string + updateKey string + status string + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := UpdateSpotsSubscribeStatusHashByOrderId(tt.args.userId, tt.args.orderId, tt.args.updateKey, tt.args.status); (err != nil) != tt.wantErr { + t.Errorf("UpdateSpotsSubscribeStatusHashByOrderId() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func Test_userOrderRepo_CheckToken(t *testing.T) { + type fields struct { + data *Data + log *log.Helper + } + type args struct { + ctx context.Context + } + tests := []struct { + name string + fields fields + args args + want int + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + uo := &userOrderRepo{ + data: tt.fields.data, + log: tt.fields.log, + } + got, err := uo.CheckToken(tt.args.ctx) + if (err != nil) != tt.wantErr { + t.Errorf("CheckToken() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("CheckToken() got = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_userOrderRepo_GetBotContractListByContractName(t *testing.T) { + type fields struct { + data *Data + log *log.Helper + } + type args struct { + ctx context.Context + contractId string + } + tests := []struct { + name string + fields fields + args args + want string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + uo := &userOrderRepo{ + data: tt.fields.data, + log: tt.fields.log, + } + got, err := uo.GetBotContractListByContractName(tt.args.ctx, tt.args.contractId) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotContractListByContractName() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("GetBotContractListByContractName() got = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_userOrderRepo_GetBotDigitalListByDigitalName(t *testing.T) { + type fields struct { + data *Data + log *log.Helper + } + type args struct { + ctx context.Context + digitalId string + } + tests := []struct { + name string + fields fields + args args + want string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + uo := &userOrderRepo{ + data: tt.fields.data, + log: tt.fields.log, + } + got, err := uo.GetBotDigitalListByDigitalName(tt.args.ctx, tt.args.digitalId) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotDigitalListByDigitalName() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("GetBotDigitalListByDigitalName() got = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_userOrderRepo_GetBotStockListByStockName(t *testing.T) { + type fields struct { + data *Data + log *log.Helper + } + type args struct { + ctx context.Context + stockId string + } + tests := []struct { + name string + fields fields + args args + want string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + uo := &userOrderRepo{ + data: tt.fields.data, + log: tt.fields.log, + } + got, err := uo.GetBotStockListByStockName(tt.args.ctx, tt.args.stockId) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotStockListByStockName() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("GetBotStockListByStockName() got = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_userOrderRepo_GetBotUser(t *testing.T) { + type fields struct { + data *Data + log *log.Helper + } + type args struct { + token string + } + tests := []struct { + name string + fields fields + args args + want int + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + uo := &userOrderRepo{ + data: tt.fields.data, + log: tt.fields.log, + } + got, err := uo.GetBotUser(tt.args.token) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotUser() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("GetBotUser() got = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_userOrderRepo_GetBotUserContractByContractId(t *testing.T) { + type fields struct { + data *Data + log *log.Helper + } + type args struct { + ctx context.Context + userId int64 + stockId int64 + } + tests := []struct { + name string + fields fields + args args + want *models.BotUserContract + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + uo := &userOrderRepo{ + data: tt.fields.data, + log: tt.fields.log, + } + got, err := uo.GetBotUserContractByContractId(tt.args.ctx, tt.args.userId, tt.args.stockId) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotUserContractByContractId() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotUserContractByContractId() got = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_userOrderRepo_GetBotUserDigitalByDigitalId(t *testing.T) { + type fields struct { + data *Data + log *log.Helper + } + type args struct { + ctx context.Context + userId int64 + stockId int64 + } + tests := []struct { + name string + fields fields + args args + want *models.BotUserDigital + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + uo := &userOrderRepo{ + data: tt.fields.data, + log: tt.fields.log, + } + got, err := uo.GetBotUserDigitalByDigitalId(tt.args.ctx, tt.args.userId, tt.args.stockId) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotUserDigitalByDigitalId() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotUserDigitalByDigitalId() got = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_userOrderRepo_GetBotUserIsRealByUserId(t *testing.T) { + type fields struct { + data *Data + log *log.Helper + } + type args struct { + ctx context.Context + userId int + } + tests := []struct { + name string + fields fields + args args + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + uo := &userOrderRepo{ + data: tt.fields.data, + log: tt.fields.log, + } + if got := uo.GetBotUserIsRealByUserId(tt.args.ctx, tt.args.userId); got != tt.want { + t.Errorf("GetBotUserIsRealByUserId() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_userOrderRepo_GetBotUserStockByStockId(t *testing.T) { + type fields struct { + data *Data + log *log.Helper + } + type args struct { + ctx context.Context + userId int64 + stockId int64 + } + tests := []struct { + name string + fields fields + args args + want *models.BotUserStock + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + uo := &userOrderRepo{ + data: tt.fields.data, + log: tt.fields.log, + } + got, err := uo.GetBotUserStockByStockId(tt.args.ctx, tt.args.userId, tt.args.stockId) + if (err != nil) != tt.wantErr { + t.Errorf("GetBotUserStockByStockId() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetBotUserStockByStockId() got = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_userOrderRepo_HSetRedisKey(t *testing.T) { + type fields struct { + data *Data + log *log.Helper + } + type args struct { + ctx context.Context + key string + value string + } + tests := []struct { + name string + fields fields + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + uo := &userOrderRepo{ + data: tt.fields.data, + log: tt.fields.log, + } + if err := uo.HSetRedisKey(tt.args.ctx, tt.args.key, tt.args.value); (err != nil) != tt.wantErr { + t.Errorf("HSetRedisKey() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} diff --git a/internal/data/utils_other.go b/internal/data/utils_other.go new file mode 100644 index 0000000..e3474cd --- /dev/null +++ b/internal/data/utils_other.go @@ -0,0 +1,3171 @@ +package data + +import ( + "context" + "fmt" + "github.com/go-xorm/xorm" + "github.com/shopspring/decimal" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/data/memory" + "matchmaking-system/internal/data/socket/publicData" + forexd "matchmaking-system/internal/data/tradedeal/forex" + "matchmaking-system/internal/data/tradedeal/virtual" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/pkg/logging/common" + "strconv" + "time" + + orders "matchmaking-system/internal/data/convert" + models "matchmaking-system/internal/pkg/model" +) + +// userLevelRebate +// @Description: +type userLevelRebate struct { + RebatePrice decimal.Decimal + Level int +} + +// SetPrice +// @Description: +type SetPrice struct { + PreStatus string + PreStartTime string + PreLimit string + PrePrices string + AfterStatus string + AfterStartTime string + AfterLimit string + AfterPrices string + Status string + Price string +} + +// CalculateHandlingFees +// +// @Description: 手续费 +// @receiver uo +// @param ctx +// @param session +// @param userId 用户Id +// @param marketType 市场类型:现货|合约|美股 +// @param tradeType 交易类型:买入|卖出 +// @param orderId 订单Id +// @param dealPrice 成交价格(开仓|平仓) +// @param faceValue +// @return string +// @return error +func (uo *userOrderRepo) CalculateHandlingFees(ctx context.Context, session *xorm.Session, userId, marketType, tradeType int, orderId, dealPrice, faceValue string) (string, error) { + var feeData decimal.Decimal + var feeList []models.BotFeeSetting + if err := session.Table(flags.BotFeeSetting). + Where("market_type = ?", marketType). + Find(&feeList); err != nil { + return flags.SetNull, flags.ErrMySqlDB + } + + priceNew := decimal.RequireFromString(dealPrice) + for _, value := range feeList { + switch tradeType { + case flags.TradeTypeBuy: + feeData = decimal.RequireFromString(value.BuyFee).Mul(priceNew).Mul(decimal.RequireFromString(faceValue)) + case flags.TradeTypeSell: + feeData = decimal.RequireFromString(value.SaleFee).Mul(priceNew).Mul(decimal.RequireFromString(faceValue)) + default: + return flags.SetNull, flags.ErrOrderOne + } + } + + tradeFee := orders.CreatBotTradeFee(ctx, userId, marketType, tradeType, feeData.String(), orderId) + _, err := session.Table(flags.BotTradeFee).Insert(&tradeFee) + if err != nil { + return flags.SetNull, flags.ErrMySqlDB + } + + return feeData.String(), nil +} + +// CalculateHandlingFeesShare +// +// @Description: 现货、合约、股票-手续费 +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param marketType +// @param tradeType +// @param orderId +// @param dealPrice +// @return string +// @return error +func (uo *userOrderRepo) CalculateHandlingFeesShare(ctx context.Context, session *xorm.Session, userId, marketType, tradeType int, orderId, dealPrice string) (string, error) { + var feeData decimal.Decimal + var feeList []models.BotFeeSetting + if err := session.Table(flags.BotFeeSetting). + Where("market_type = ?", marketType). + Find(&feeList); err != nil { + return flags.SetNull, flags.ErrMySqlDB + } + + priceNew := decimal.RequireFromString(dealPrice) + for _, value := range feeList { + switch tradeType { + case flags.TradeTypeBuy: + feeData = decimal.RequireFromString(value.BuyFee).Mul(priceNew) + case flags.TradeTypeSell: + feeData = decimal.RequireFromString(value.SaleFee).Mul(priceNew) + default: + return flags.SetNull, flags.ErrOrderOne + } + } + + tradeFee := orders.CreatBotTradeFee(ctx, userId, marketType, tradeType, feeData.String(), orderId) + _, err := session.Table(flags.BotTradeFee).Insert(&tradeFee) + if err != nil { + return flags.SetNull, flags.ErrMySqlDB + } + + return feeData.String(), nil +} + +// CalculateHandlingFeesOption +// +// @Description: 期权手续费 +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param marketType +// @param tradeType +// @param orderId +// @param dealPrice +// @return string +// @return error +func (uo *userOrderRepo) CalculateHandlingFeesOption(ctx context.Context, session *xorm.Session, userId, marketType, tradeType int, orderId, dealPrice, quantity string) (string, error) { + var feeData decimal.Decimal + var feeList []models.BotFeeSetting + if err := session.Table(flags.BotFeeSetting). + Where("market_type = ?", marketType). + Find(&feeList); err != nil { + return flags.SetNull, flags.ErrMySqlDB + } + + //手续费(Total Fee) + // 1> 固定费用:Total Fee = Total Fee Fix Value(固定费用) + // 2> 按比例结算:Total Fee = Total Fee Ratio(总费用比例) * Option Filled Price(开仓价格) * Quantity(订单数量) + // 3> 按张结算:Total Fee = Total Fee Per Contract(每份费用) * Quantity(订单数量) + priceNew := decimal.RequireFromString(dealPrice) + orderNum := decimal.RequireFromString(quantity) + for _, value := range feeList { + switch tradeType { + case flags.TradeTypeBuy: // 开仓手续费 + feeData = OptionFeeByPayType(value.PayType, priceNew, orderNum, decimal.RequireFromString(value.BuyFee)) + case flags.TradeTypeSell: // 平仓手续费 + feeData = OptionFeeByPayType(value.PayType, priceNew, orderNum, decimal.RequireFromString(value.SaleFee)) + default: + return flags.SetNull, flags.ErrOrderOne + } + } + + tradeFee := orders.CreatBotTradeFee(ctx, userId, marketType, tradeType, feeData.String(), orderId) + _, err := session.Table(flags.BotTradeFee).Insert(&tradeFee) + if err != nil { + return flags.SetNull, flags.ErrMySqlDB + } + + return feeData.String(), nil +} + +// OptionFeeByPayType +// +// @Description: 通过手续费类型计算手续费 +// @param payType +// @param price +// @param orderNum +// @param fee +// @return decimal.Decimal +func OptionFeeByPayType(payType int, price, orderNum, fee decimal.Decimal) decimal.Decimal { + var feeData decimal.Decimal + + switch payType { + case flags.FixedCosts: // 固定费用 + feeData = fee + case flags.RatioCosts: // 按比例结算 + feeData = price.Mul(orderNum).Mul(fee) + case flags.FixCosts: // 按张结算 + feeData = fee.Mul(orderNum) + default: + feeData = decimal.Zero + } + + return feeData +} + +// SpotsRebateCalculation +// +// @Description: 现货返佣 +// @receiver uo +// @param ctx +// @param session +// @param userId 用户Id +// @param marketType 市场类型:1现货|2合约|3美股 +// @param brokType 返佣类型:0注册,1开仓,2平仓 +// @param rebateCode 用户资金变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-账户转出,8-账户转入,9-注册返佣,10-开仓返佣,11-平仓返佣,12-调整加钱,13-调整减钱,14-手续费 +// @param cost 手续费(计算返佣金额) +// @param orderId +// @return error +func (uo *userOrderRepo) SpotsRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string) error { + rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost) + if err != nil { + return err + } + + // 写入返佣记录表|更新用户资产表|记录交易明细 + for key, value := range rebateMap { + if value == nil { + return flags.ErrOrderThree + } + if !flags.CheckSetting { + applogger.Debug("接收返佣的用户ID:%v,接收返佣的用户返佣金额:%v", key, value) + } + + // 写入返佣记录表 + brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId) + _, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage) + if err != nil { + return err + } + + // 更新资产信息表(查询|更新) + var usableOld decimal.Decimal + usableOld, _, _, err = uo.GetBotUserDigital(session, int64(key), flags.BasicUnit) + if err != nil { + return err + } + usableNew := usableOld.Add(value.RebatePrice) + var checkNum int64 + userDigitalUSDT := orders.UpdateBotUserDigitalByUsableNum(ctx, usableNew.String()) + checkNum, err = session.Table(flags.BotUserDigital). + Where("user_id = ?", key). + Where("digital_id = ?", flags.BasicUnit). + Update(&userDigitalUSDT) + if err != nil || checkNum < 0 { + return err + } + + if !flags.CheckSetting { + applogger.Debug("用户返佣对应代理原有资产:%v,%v", key, usableOld) + applogger.Debug("用户返佣更新对应代理资产:%v,%v", key, usableNew) + } + + // 写入资金明细表(平仓返佣) + if err = uo.CreatBotUserDigitalLogByRebate(ctx, session, int64(key), int64(rebateCode), value.RebatePrice.String(), orderId); err != nil { + return err + } + } + + return nil +} + +// ContractRebateCalculation +// +// @Description: 返佣 +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param marketType +// @param brokType +// @param rebateCode +// @param cost +// @param orderId +// @return error +func (uo *userOrderRepo) ContractRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string) error { + rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost) + if err != nil { + return err + } + + // 写入返佣记录表|更新用户资产表|记录交易明细 + for key, value := range rebateMap { + if value == nil { + return flags.ErrOrderFour + } + if !flags.CheckSetting { + applogger.Debug("用户返佣记录:%v,%v", key, value) + } + + brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId) + _, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage) + if err != nil { + applogger.Error("%v ContractRebateCalculation.Insert:%v", common.ErrContract, err) + return err + } + + // 查询资产信息表 + var usableOld, frozenOld decimal.Decimal + usableOld, frozenOld, _, err = uo.GetBotUserContract(session, int64(key), flags.BasicUnit) + if err != nil { + applogger.Error("%v ContractRebateCalculation.GetBotUserContract:%v", common.ErrContract, err) + return err + } + usableNew := usableOld.Add(value.RebatePrice) + + if !flags.CheckSetting { + applogger.Debug("用户返佣对应代理原有资产:%v", key, usableOld) + applogger.Debug("用户返佣更新对应代理资产:%v", key, usableNew) + } + + // 更新返佣用户资产信息 + userContractUSDT := orders.UpdateBotUserContract(ctx, usableNew.String(), frozenOld.String()) + if err = uo.UpdateBotUserContract(session, int64(key), flags.BasicUnit, userContractUSDT); err != nil { + applogger.Error("%v ContractRebateCalculation.UpdateBotUserContract:%v", common.ErrContract, err) + return err + } + + // 写入资金明细表(返佣) + uData := orders.CreatBotUserContractLog(ctx, int64(key), int64(rebateCode), flags.BasicUnit, value.RebatePrice.String(), orderId) + if err = uo.CreatBotUserContractLogByRebate(session, uData); err != nil { + applogger.Error("%v ContractRebateCalculation.CreatBotUserContractLogByRebate:%v", common.ErrContract, err) + return err + } + } + + return nil +} +func (uo *userOrderRepo) ForexRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string) error { + rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost) + if err != nil { + return err + } + + // 写入返佣记录表|更新用户资产表|记录交易明细 + for key, value := range rebateMap { + if value == nil { + return flags.ErrOrderFour + } + if !flags.CheckSetting { + applogger.Debug("用户返佣记录:%v,%v", key, value) + } + + brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId) + _, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage) + if err != nil { + applogger.Error("%v ContractRebateCalculation.Insert:%v", common.ErrForex, err) + return err + } + + // 查询资产信息表 + var usableOld, frozenOld decimal.Decimal + usableOld, frozenOld, _, err = uo.GetBotUserForex(session, int64(key), flags.ForexUnit) + if err != nil { + applogger.Error("%v ContractRebateCalculation.GetBotUserForex:%v", common.ErrForex, err) + return err + } + usableNew := usableOld.Add(value.RebatePrice) + + if !flags.CheckSetting { + applogger.Debug("用户返佣对应代理原有资产:%v", key, usableOld) + applogger.Debug("用户返佣更新对应代理资产:%v", key, usableNew) + } + + // 更新返佣用户资产信息 + userForexUSDT := orders.UpdateBotUserForex(ctx, usableNew.String(), frozenOld.String()) + if err = uo.UpdateBotUserForex(session, int64(key), flags.ForexUnit, userForexUSDT); err != nil { + applogger.Error("%v ContractRebateCalculation.UpdateBotUserForex:%v", common.ErrForex, err) + return err + } + + // 写入资金明细表(返佣) + uData := orders.CreatBotUserForexLog(ctx, int64(key), int64(rebateCode), flags.ForexUnit, value.RebatePrice.String(), orderId) + if err = uo.CreatBotUserForexLogByRebate(session, uData); err != nil { + applogger.Error("%v ContractRebateCalculation.CreatBotUserForexLogByRebate:%v", common.ErrForex, err) + return err + } + } + + return nil +} +func (uo *userOrderRepo) MoneyRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string) error { + rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost) + if err != nil { + return err + } + + // 写入返佣记录表|更新用户资产表|记录交易明细 + for key, value := range rebateMap { + if value == nil { + return flags.ErrOrderFour + } + if !flags.CheckSetting { + applogger.Debug("用户返佣记录:%v,%v", key, value) + } + + brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId) + _, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage) + if err != nil { + applogger.Error("%v ContractRebateCalculation.Insert:%v", common.ErrForex, err) + return err + } + + // 查询资产信息表 + var usableOld, frozenOld decimal.Decimal + usableOld, frozenOld, _, err = uo.GetBotUserMoney(session, int64(key), flags.ForexUnit) + if err != nil { + applogger.Error("%v ContractRebateCalculation.GetBotUserMoney:%v", common.ErrForex, err) + return err + } + usableNew := usableOld.Add(value.RebatePrice) + + if !flags.CheckSetting { + applogger.Debug("用户返佣对应代理原有资产:%v", key, usableOld) + applogger.Debug("用户返佣更新对应代理资产:%v", key, usableNew) + } + + // 更新返佣用户资产信息 + userMoneyUSDT := orders.UpdateBotUserMoney(ctx, usableNew.String(), frozenOld.String()) + if err = uo.UpdateBotUserMoney(session, int64(key), flags.MoneyUnit, userMoneyUSDT); err != nil { + applogger.Error("%v ContractRebateCalculation.UpdateBotUserMoney:%v", common.ErrForex, err) + return err + } + + // 写入资金明细表(返佣) + uData := orders.CreatBotUserMoneyLog(ctx, int64(key), int64(rebateCode), flags.MoneyUnit, value.RebatePrice.String(), orderId) + if err = uo.CreatBotUserMoneyLogByRebate(session, uData); err != nil { + applogger.Error("%v ContractRebateCalculation.CreatBotUserMoneyLogByRebate:%v", common.ErrForex, err) + return err + } + } + + return nil +} + +// ShareUsRebateCalculation +// +// @Description: 美股返佣 +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param marketType +// @param brokType +// @param rebateCode +// @param cost +// @param orderId +// @return error +func (uo *userOrderRepo) ShareUsRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error { + rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost) + if err != nil { + return err + } + + // 写入返佣记录表|更新用户资产表|记录交易明细 + for key, value := range rebateMap { + if value == nil { + return flags.ErrOrderFour + } + if !flags.CheckSetting { + applogger.Debug("用户返佣记录:%v", key, value) + } + + brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId) + _, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage) + if err != nil { + applogger.Error("%v ShareUsRebateCalculation.Insert:%v", common.ErrShareUs, err) + return err + } + + // 查询资产信息表 + var usableOld, frozenOld decimal.Decimal + userStockUsd, err := uo.GetBotUserStockByUserIdAndStockId(session, int64(key), flags.ShareUsBasicUnit) + if err != nil || userStockUsd == nil { + applogger.Error("%v ShareUsRebateCalculation.GetBotUserStockByUserIdAndStockId:%v", common.ErrShareUs, err) + return err + } + usableNew := usableOld.Add(value.RebatePrice) + if !flags.CheckSetting { + applogger.Debug("用户返佣对应代理原有资产:%v", key, usableOld) + applogger.Debug("用户返佣更新对应代理资产:%v", key, usableNew) + } + + // 更新返佣用户资产信息 + userStockUSD := orders.UpdateBotUserStock(ctx, usableNew.String(), frozenOld.String()) + if err = uo.UpdateBotUserStockByUserIdAndStockId(session, int64(key), flags.ShareUsBasicUnit, userStockUSD); err != nil { + applogger.Error("%v ShareUsRebateCalculation.UpdateBotUserStockByUserIdAndStockId:%v", common.ErrShareUs, err) + return err + } + + // 写入资金明细表(返佣) + if !CheckTypeStatus(typeStatus) { + uData := orders.CreatBotUserStockLog(ctx, int64(key), int64(rebateCode), flags.ShareUsBasicUnit, value.RebatePrice.String(), orderId) + if err = uo.CreatBotUserStockLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareUsRebateCalculation.CreatBotUserStockLogByRebate:%v", common.ErrShareUs, err) + return err + } + } else { + uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareUsBasicUnit, value.RebatePrice.String(), orderId, typeStatus) + if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareUsRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareUs, err) + return err + } + } + } + + return nil +} + +// ShareHkdRebateCalculation +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param marketType +// @param brokType +// @param rebateCode +// @param cost +// @param orderId +// @return error +func (uo *userOrderRepo) ShareHkdRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error { + rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost) + if err != nil { + return err + } + + // 写入返佣记录表|更新用户资产表|记录交易明细 + for key, value := range rebateMap { + if value == nil { + return flags.ErrOrderFour + } + if !flags.CheckSetting { + applogger.Debug("用户返佣记录:%v", key, value) + } + + brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId) + _, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage) + if err != nil { + applogger.Error("%v ShareHkdRebateCalculation.Insert:%v", common.ErrShareHkd, err) + return err + } + + // 查询资产信息表 + var usableOld, frozenOld decimal.Decimal + userStockUsd, err := uo.GetBotUserStockHkdByUserIdAndStockId(session, int64(key), flags.ShareHkdBasicUnit) + if err != nil || userStockUsd == nil { + applogger.Error("%v ShareHkdRebateCalculation.GetBotUserStockHkdByUserIdAndStockId:%v", common.ErrShareHkd, err) + return err + } + usableNew := usableOld.Add(value.RebatePrice) + if !flags.CheckSetting { + applogger.Debug("用户返佣对应代理原有资产:%v", key, usableOld) + applogger.Debug("用户返佣更新对应代理资产:%v", key, usableNew) + } + + // 更新返佣用户资产信息 + userStockUSD := orders.UpdateBotUserStockHkd(ctx, usableNew.String(), frozenOld.String()) + if err = uo.UpdateBotUserStockHkdByUserIdAndStockId(session, int64(key), flags.ShareHkdBasicUnit, userStockUSD); err != nil { + applogger.Error("%v ShareHkdRebateCalculation.UpdateBotUserStockByUserIdAndStockId:%v", common.ErrShareHkd, err) + return err + } + + // 写入资金明细表(返佣) + if !CheckTypeStatus(typeStatus) { + uData := orders.CreatBotUserStockHkdLog(ctx, int64(key), int64(rebateCode), flags.ShareHkdBasicUnit, value.RebatePrice.String(), orderId) + if err = uo.CreatBotUserStockHkdLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareHkdRebateCalculation.CreatBotUserStockHkdLogByRebate:%v", common.ErrShareHkd, err) + return err + } + } else { + uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareHkdBasicUnit, value.RebatePrice.String(), orderId, typeStatus) + if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareHkdRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareHkd, err) + return err + } + } + } + + return nil +} + +// ShareIdnRebateCalculation +// +// @Description: 印尼股返佣 +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param marketType +// @param brokType +// @param rebateCode +// @param cost +// @param orderId +// @return error +func (uo *userOrderRepo) ShareIdnRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error { + rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost) + if err != nil { + return err + } + + // 写入返佣记录表|更新用户资产表|记录交易明细 + for key, value := range rebateMap { + if value == nil { + return flags.ErrOrderFour + } + if !flags.CheckSetting { + applogger.Debug("用户返佣记录:%v", key, value) + } + + brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId) + _, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage) + if err != nil { + applogger.Error("%v ShareIdnRebateCalculation.Insert:%v", common.ErrShareIdn, err) + return err + } + + // 查询资产信息表 + var usableOld, frozenOld decimal.Decimal + userStockIdr, err := uo.GetBotUserStockIdnByUserIdAndStockId(session, int64(key), flags.ShareIdnBasicUnit) + if err != nil || userStockIdr == nil { + applogger.Error("%v ShareIdnRebateCalculation.GetBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareIdn, err) + return err + } + usableNew := usableOld.Add(value.RebatePrice) + if !flags.CheckSetting { + applogger.Debug("用户返佣对应代理原有资产:%v", key, usableOld) + applogger.Debug("用户返佣更新对应代理资产:%v", key, usableNew) + } + + // 更新返佣用户资产信息 + userStockIDR := orders.UpdateBotUserStockIdn(ctx, usableNew.String(), frozenOld.String()) + if err = uo.UpdateBotUserStockIdnByUserIdAndStockId(session, int64(key), flags.ShareIdnBasicUnit, userStockIDR); err != nil { + applogger.Error("%v ShareIdnRebateCalculation.UpdateBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareIdn, err) + return err + } + + // 写入资金明细表(返佣) + if !CheckTypeStatus(typeStatus) { + uData := orders.CreatBotUserStockIdnLog(ctx, int64(key), int64(rebateCode), flags.ShareIdnBasicUnit, value.RebatePrice.String(), orderId) + if err = uo.CreatBotUserStockIdnLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareUsRebateCalculation.CreatBotUserStockIdnLogByRebate:%v", common.ErrShareIdn, err) + return err + } + } else { + uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareIdnBasicUnit, value.RebatePrice.String(), orderId, typeStatus) + if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareUsRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareIdn, err) + return err + } + } + } + + return nil +} + +// ShareInrRebateCalculation +// +// @Description: 印度股返佣 +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param marketType +// @param brokType +// @param rebateCode +// @param cost +// @param orderId +// @return error +func (uo *userOrderRepo) ShareInrRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error { + rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost) + if err != nil { + return err + } + + // 写入返佣记录表|更新用户资产表|记录交易明细 + for key, value := range rebateMap { + if value == nil { + return flags.ErrOrderFour + } + if !flags.CheckSetting { + applogger.Debug("用户返佣记录:%v", key, value) + } + + brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId) + _, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage) + if err != nil { + applogger.Error("%v ShareInrRebateCalculation.Insert:%v", common.ErrShareInr, err) + return err + } + + // 查询资产信息表 + var usableOld, frozenOld decimal.Decimal + userStockIdr, err := uo.GetBotUserStockInByUserIdAndStockId(session, int64(key), flags.ShareInrBasicUnit) + if err != nil || userStockIdr == nil { + applogger.Error("%v ShareInrRebateCalculation.GetBotUserStockInByUserIdAndStockId:%v", common.ErrShareInr, err) + return err + } + usableNew := usableOld.Add(value.RebatePrice) + if !flags.CheckSetting { + applogger.Debug("用户返佣对应代理原有资产:%v", key, usableOld) + applogger.Debug("用户返佣更新对应代理资产:%v", key, usableNew) + } + + // 更新返佣用户资产信息 + userStockIDR := orders.UpdateBotUserStockIn(ctx, usableNew.String(), frozenOld.String()) + if err = uo.UpdateBotUserStockInByUserIdAndStockId(session, int64(key), flags.ShareInrBasicUnit, userStockIDR); err != nil { + applogger.Error("%v ShareInrRebateCalculation.UpdateBotUserStockIdnByUserIdAndStockId:%v", common.ErrShareInr, err) + return err + } + + // TODO: 写入资金明细表(返佣) + if !CheckTypeStatus(typeStatus) { + uData := orders.CreatBotUserStockInLog(ctx, int64(key), int64(rebateCode), flags.ShareInrBasicUnit, value.RebatePrice.String(), orderId) + if err = uo.CreatBotUserStockInLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareInrRebateCalculation.CreatBotUserStockInLogByRebate:%v", common.ErrShareInr, err) + return err + } + } else { + uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareInrBasicUnit, value.RebatePrice.String(), orderId, typeStatus) + if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareInrRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareInr, err) + return err + } + } + } + + return nil +} + +// ShareGbxRebateCalculation +// +// @Description: 英股返佣 +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param marketType +// @param brokType +// @param rebateCode +// @param cost +// @param orderId +// @param typeStatus +// @return error +func (uo *userOrderRepo) ShareGbxRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error { + rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost) + if err != nil { + return err + } + + // 写入返佣记录表|更新用户资产表|记录交易明细 + for key, value := range rebateMap { + if value == nil { + return flags.ErrOrderFour + } + if !flags.CheckSetting { + applogger.Debug("用户返佣记录:%v", key, value) + } + + brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId) + _, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage) + if err != nil { + applogger.Error("%v ShareGbxRebateCalculation.Insert:%v", common.ErrShareGbx, err) + return err + } + + // 查询资产信息表 + var usableOld, frozenOld decimal.Decimal + userStockIdr, err := uo.GetBotUserStockGbxByUserIdAndStockId(session, int64(key), flags.ShareGbxBasicUnit) + if err != nil || userStockIdr == nil { + applogger.Error("%v ShareGbxRebateCalculation.GetBotUserStockGbxByUserIdAndStockId:%v", common.ErrShareGbx, err) + return err + } + usableNew := usableOld.Add(value.RebatePrice) + if !flags.CheckSetting { + applogger.Debug("用户返佣对应代理原有资产:%v", key, usableOld) + applogger.Debug("用户返佣更新对应代理资产:%v", key, usableNew) + } + + // 更新返佣用户资产信息 + userStockIDR := orders.UpdateBotUserStockGbx(ctx, usableNew.String(), frozenOld.String()) + if err = uo.UpdateBotUserStockGbxByUserIdAndStockId(session, int64(key), flags.ShareGbxBasicUnit, userStockIDR); err != nil { + applogger.Error("%v ShareGbxRebateCalculation.UpdateBotUserStockGbxByUserIdAndStockId:%v", common.ErrShareGbx, err) + return err + } + + // TODO: 写入资金明细表(返佣) + if !CheckTypeStatus(typeStatus) { + uData := orders.CreatBotUserStockGbxLog(ctx, int64(key), int64(rebateCode), flags.ShareGbxBasicUnit, value.RebatePrice.String(), orderId) + if err = uo.CreatBotUserStockGbxLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareGbxRebateCalculation.CreatBotUserStockGbxLogByRebate:%v", common.ErrShareGbx, err) + return err + } + } else { + uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareGbxBasicUnit, value.RebatePrice.String(), orderId, typeStatus) + if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareGbxRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareGbx, err) + return err + } + } + } + + return nil +} + +// ShareMysRebateCalculation +// +// @Description: 马股返佣 +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param marketType +// @param brokType +// @param rebateCode +// @param cost +// @param orderId +// @return error +func (uo *userOrderRepo) ShareMysRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error { + rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost) + if err != nil { + return err + } + + // 写入返佣记录表|更新用户资产表|记录交易明细 + for key, value := range rebateMap { + if value == nil { + return flags.ErrOrderFour + } + if !flags.CheckSetting { + applogger.Debug("用户返佣记录:%v", key, value) + } + + brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId) + _, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage) + if err != nil { + applogger.Error("%v ShareMysRebateCalculation.Insert:%v", common.ErrShareMys, err) + return err + } + + // 查询资产信息表 + var usableOld, frozenOld decimal.Decimal + userStockIdr, err := uo.GetBotUserStockMysByUserIdAndStockId(session, int64(key), flags.ShareMysBasicUnit) + if err != nil || userStockIdr == nil { + applogger.Error("%v ShareMysRebateCalculation.GetBotUserStockMysByUserIdAndStockId:%v", common.ErrShareMys, err) + return err + } + usableNew := usableOld.Add(value.RebatePrice) + if !flags.CheckSetting { + applogger.Debug("用户返佣对应代理原有资产:%v", key, usableOld) + applogger.Debug("用户返佣更新对应代理资产:%v", key, usableNew) + } + + // 更新返佣用户资产信息 + userStockMYR := orders.UpdateBotUserStockMys(ctx, usableNew.String(), frozenOld.String()) + if err = uo.UpdateBotUserStockMysByUserIdAndStockId(session, int64(key), flags.ShareMysBasicUnit, userStockMYR); err != nil { + applogger.Error("%v ShareMysRebateCalculation.UpdateBotUserStockMysByUserIdAndStockId:%v", common.ErrShareMys, err) + return err + } + + // 写入资金明细表(返佣) + if !CheckTypeStatus(typeStatus) { + uData := orders.CreatBotUserStockMysLog(ctx, int64(key), int64(rebateCode), flags.ShareMysBasicUnit, value.RebatePrice.String(), orderId) + if err = uo.CreatBotUserStockMysLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareMysRebateCalculation.CreatBotUserStockMysLogByRebate:%v", common.ErrShareMys, err) + return err + } + } else { + uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareMysBasicUnit, value.RebatePrice.String(), orderId, typeStatus) + if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareMysRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareMys, err) + return err + } + } + } + + return nil +} + +// ShareThaRebateCalculation +// +// @Description: 泰股返佣 +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param marketType +// @param brokType +// @param rebateCode +// @param cost +// @param orderId +// @return error +func (uo *userOrderRepo) ShareThaRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error { + rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost) + if err != nil { + return err + } + + // 写入返佣记录表|更新用户资产表|记录交易明细 + for key, value := range rebateMap { + if value == nil { + return flags.ErrOrderFour + } + if !flags.CheckSetting { + applogger.Debug("用户返佣记录:%v", key, value) + } + + brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId) + _, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage) + if err != nil { + applogger.Error("%v ShareThaRebateCalculation.Insert:%v", common.ErrShareTha, err) + return err + } + + // 查询资产信息表 + var usableOld, frozenOld decimal.Decimal + userStockThb, err := uo.GetBotUserStockThaByUserIdAndStockId(session, int64(key), flags.ShareThaBasicUnit) + if err != nil || userStockThb == nil { + applogger.Error("%v ShareThaRebateCalculation.GetBotUserStockThaByUserIdAndStockId:%v", common.ErrShareTha, err) + return err + } + usableNew := usableOld.Add(value.RebatePrice) + if !flags.CheckSetting { + applogger.Info("用户返佣对应代理原有资产:%v", key, usableOld) + applogger.Info("用户返佣更新对应代理资产:%v", key, usableNew) + } + + // 更新返佣用户资产信息 + userStockTHB := orders.UpdateBotUserStockTha(ctx, usableNew.String(), frozenOld.String()) + if err = uo.UpdateBotUserStockThaByUserIdAndStockId(session, int64(key), flags.ShareThaBasicUnit, userStockTHB); err != nil { + applogger.Error("%v ShareThaRebateCalculation.UpdateBotUserStockThaByUserIdAndStockId:%v", common.ErrShareTha, err) + return err + } + + // 写入资金明细表(返佣) + if !CheckTypeStatus(typeStatus) { + uData := orders.CreatBotUserStockThaLog(ctx, int64(key), int64(rebateCode), flags.ShareThaBasicUnit, value.RebatePrice.String(), orderId) + if err = uo.CreatBotUserStockThaLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareThaRebateCalculation.CreatBotUserStockThaLogByRebate:%v", common.ErrShareTha, err) + return err + } + } else { + uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareThaBasicUnit, value.RebatePrice.String(), orderId, typeStatus) + if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareThaRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareTha, err) + return err + } + } + } + + return nil +} + +// ShareSgdRebateCalculation +// +// @Description: 新加坡返佣 +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param marketType +// @param brokType +// @param rebateCode +// @param cost +// @param orderId +// @return error +func (uo *userOrderRepo) ShareSgdRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error { + rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost) + if err != nil { + return err + } + + // 写入返佣记录表|更新用户资产表|记录交易明细 + for key, value := range rebateMap { + if value == nil { + return flags.ErrOrderFour + } + if !flags.CheckSetting { + applogger.Info("用户返佣记录:%v", key, value) + } + + brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId) + _, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage) + if err != nil { + applogger.Error("%v ShareSgdRebateCalculation.Insert:%v", common.ErrShareSgd, err) + return err + } + + // 查询资产信息表 + var usableOld, frozenOld decimal.Decimal + userStockThb, err := uo.GetBotUserStockSgdByUserIdAndStockId(session, int64(key), flags.ShareSgdBasicUnit) + if err != nil || userStockThb == nil { + applogger.Error("%v ShareSgdRebateCalculation.GetBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareSgd, err) + return err + } + usableNew := usableOld.Add(value.RebatePrice) + if !flags.CheckSetting { + applogger.Info("用户返佣对应代理原有资产:%v", key, usableOld) + applogger.Info("用户返佣更新对应代理资产:%v", key, usableNew) + } + + // 更新返佣用户资产信息 + userStockTHB := orders.UpdateBotUserStockSgd(ctx, usableNew.String(), frozenOld.String()) + if err = uo.UpdateBotUserStockSgdByUserIdAndStockId(session, int64(key), flags.ShareSgdBasicUnit, userStockTHB); err != nil { + applogger.Error("%v ShareSgdRebateCalculation.UpdateBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareSgd, err) + return err + } + + // TODO: 写入资金明细表(返佣) + if !CheckTypeStatus(typeStatus) { + uData := orders.CreatBotUserStockSgdLog(ctx, int64(key), int64(rebateCode), flags.ShareSgdBasicUnit, value.RebatePrice.String(), orderId) + if err = uo.CreatBotUserStockSgdLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareSgdRebateCalculation.CreatBotUserStockSgdLogByRebate:%v", common.ErrShareSgd, err) + return err + } + } else { + uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareSgdBasicUnit, value.RebatePrice.String(), orderId, typeStatus) + if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareSgdRebateCalculation.CreatBotUserStockSgdLogByRebate:%v", common.ErrShareSgd, err) + return err + } + } + } + + return nil +} + +// ShareEurRebateCalculation +// +// @Description: 德返佣 +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param marketType +// @param brokType +// @param rebateCode +// @param cost +// @param orderId +// @return error +func (uo *userOrderRepo) ShareEurRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error { + rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost) + if err != nil { + return err + } + + // 写入返佣记录表|更新用户资产表|记录交易明细 + for key, value := range rebateMap { + if value == nil { + return flags.ErrOrderFour + } + if !flags.CheckSetting { + applogger.Info("用户返佣记录:%v", key, value) + } + + brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId) + _, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage) + if err != nil { + applogger.Error("%v ShareEurRebateCalculation.Insert:%v", common.ErrShareEur, err) + return err + } + + // 查询资产信息表 + var usableOld, frozenOld decimal.Decimal + userStockThb, err := uo.GetBotUserStockEurByUserIdAndStockId(session, int64(key), flags.ShareEurBasicUnit) + if err != nil || userStockThb == nil { + applogger.Error("%v ShareEurRebateCalculation.GetBotUserStockEurByUserIdAndStockId:%v", common.ErrShareEur, err) + return err + } + usableNew := usableOld.Add(value.RebatePrice) + if !flags.CheckSetting { + applogger.Info("用户返佣对应代理原有资产:%v", key, usableOld) + applogger.Info("用户返佣更新对应代理资产:%v", key, usableNew) + } + + // 更新返佣用户资产信息 + userStockTHB := orders.UpdateBotUserStockEur(ctx, usableNew.String(), frozenOld.String()) + if err = uo.UpdateBotUserStockEurByUserIdAndStockId(session, int64(key), flags.ShareEurBasicUnit, userStockTHB); err != nil { + applogger.Error("%v ShareEurRebateCalculation.UpdateBotUserStockSgdByUserIdAndStockId:%v", common.ErrShareEur, err) + return err + } + + // TODO: 写入资金明细表(返佣) + if !CheckTypeStatus(typeStatus) { + uData := orders.CreatBotUserStockEurLog(ctx, int64(key), int64(rebateCode), flags.ShareEurBasicUnit, value.RebatePrice.String(), orderId) + if err = uo.CreatBotUserStockEurLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareEurRebateCalculation.CreatBotUserStockEurLogByRebate:%v", common.ErrShareEur, err) + return err + } + } else { + uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareEurBasicUnit, value.RebatePrice.String(), orderId, typeStatus) + if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareEurRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareEur, err) + return err + } + } + } + + return nil +} + +// ShareBrlRebateCalculation +// +// @Description: 巴西返佣 +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param marketType +// @param brokType +// @param rebateCode +// @param cost +// @param orderId +// @param typeStatus +// @return error +func (uo *userOrderRepo) ShareBrlRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error { + rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost) + if err != nil { + return err + } + + // 写入返佣记录表|更新用户资产表|记录交易明细 + for key, value := range rebateMap { + if value == nil { + return flags.ErrOrderFour + } + if !flags.CheckSetting { + applogger.Info("用户返佣记录:%v", key, value) + } + + brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId) + _, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage) + if err != nil { + applogger.Error("%v ShareBrlRebateCalculation.Insert:%v", common.ErrShareBrl, err) + return err + } + + // 查询资产信息表 + var usableOld, frozenOld decimal.Decimal + userStockThb, err := uo.GetBotUserStockBrlByUserIdAndStockId(session, int64(key), flags.ShareBrlBasicUnit) + if err != nil || userStockThb == nil { + applogger.Error("%v ShareBrlRebateCalculation.GetBotUserStockBrlByUserIdAndStockId:%v", common.ErrShareBrl, err) + return err + } + usableNew := usableOld.Add(value.RebatePrice) + if !flags.CheckSetting { + applogger.Info("用户返佣对应代理原有资产:%v", key, usableOld) + applogger.Info("用户返佣更新对应代理资产:%v", key, usableNew) + } + + // 更新返佣用户资产信息 + userStockTHB := orders.UpdateBotUserStockBrl(ctx, usableNew.String(), frozenOld.String()) + if err = uo.UpdateBotUserStockBrlByUserIdAndStockId(session, int64(key), flags.ShareBrlBasicUnit, userStockTHB); err != nil { + applogger.Error("%v ShareBrlRebateCalculation.UpdateBotUserStockBrlByUserIdAndStockId:%v", common.ErrShareBrl, err) + return err + } + + // TODO: 写入资金明细表(返佣) + if !CheckTypeStatus(typeStatus) { + uData := orders.CreatBotUserStockBrlLog(ctx, int64(key), int64(rebateCode), flags.ShareBrlBasicUnit, value.RebatePrice.String(), orderId) + if err = uo.CreatBotUserStockBrlLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareBrlRebateCalculation.CreatBotUserStockBrlLogByRebate:%v", common.ErrShareBrl, err) + return err + } + } else { + uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareBrlBasicUnit, value.RebatePrice.String(), orderId, typeStatus) + if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareBrlRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareBrl, err) + return err + } + } + } + + return nil +} + +// ShareEurRebateCalculation +// +// @Description: 法返佣 +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param marketType +// @param brokType +// @param rebateCode +// @param cost +// @param orderId +// @return error +func (uo *userOrderRepo) ShareFurRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error { + rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost) + if err != nil { + return err + } + + // 写入返佣记录表|更新用户资产表|记录交易明细 + for key, value := range rebateMap { + if value == nil { + return flags.ErrOrderFour + } + if !flags.CheckSetting { + applogger.Info("用户返佣记录:%v", key, value) + } + + brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId) + _, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage) + if err != nil { + applogger.Error("%v ShareFurRebateCalculation.Insert:%v", common.ErrShareFur, err) + return err + } + + // 查询资产信息表 + var usableOld, frozenOld decimal.Decimal + userStockThb, err := uo.GetBotUserStockFurByUserIdAndStockId(session, int64(key), flags.ShareFurBasicUnit) + if err != nil || userStockThb == nil { + applogger.Error("%v ShareFurRebateCalculation.GetBotUserStockFurByUserIdAndStockId:%v", common.ErrShareFur, err) + return err + } + usableNew := usableOld.Add(value.RebatePrice) + if !flags.CheckSetting { + applogger.Info("用户返佣对应代理原有资产:%v", key, usableOld) + applogger.Info("用户返佣更新对应代理资产:%v", key, usableNew) + } + + // 更新返佣用户资产信息 + userStockTHB := orders.UpdateBotUserStockFur(ctx, usableNew.String(), frozenOld.String()) + if err = uo.UpdateBotUserStockFurByUserIdAndStockId(session, int64(key), flags.ShareFurBasicUnit, userStockTHB); err != nil { + applogger.Error("%v ShareFurRebateCalculation.UpdateBotUserStockFurByUserIdAndStockId:%v", common.ErrShareFur, err) + return err + } + + // TODO: 写入资金明细表(返佣) + if !CheckTypeStatus(typeStatus) { + uData := orders.CreatBotUserStockFurLog(ctx, int64(key), int64(rebateCode), flags.ShareFurBasicUnit, value.RebatePrice.String(), orderId) + if err = uo.CreatBotUserStockFurLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareFurRebateCalculation.CreatBotUserStockFurLogByRebate:%v", common.ErrShareFur, err) + return err + } + } else { + uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareFurBasicUnit, value.RebatePrice.String(), orderId, typeStatus) + if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareFurRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareFur, err) + return err + } + } + } + + return nil +} + +// ShareJpyRebateCalculation +// +// @Description: +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param marketType +// @param brokType +// @param rebateCode +// @param cost +// @param orderId +// @param typeStatus +// @return error +func (uo *userOrderRepo) ShareJpyRebateCalculation(ctx context.Context, session *xorm.Session, userId, marketType, brokType, rebateCode int, cost, orderId string, typeStatus int64) error { + rebateMap, err := uo.MapSetRebateMySqlDB(session, userId, brokType, cost) + if err != nil { + return err + } + + // 写入返佣记录表|更新用户资产表|记录交易明细 + for key, value := range rebateMap { + if value == nil { + return flags.ErrOrderFour + } + if !flags.CheckSetting { + applogger.Info("用户返佣记录:%v", key, value) + } + + brokerage := orders.CreatBotUserBrokerage(ctx, marketType, key, value.Level, cost, value.RebatePrice.String(), orderId) + _, err = session.Table(flags.BotUserBrokerage).Insert(&brokerage) + if err != nil { + applogger.Error("%v ShareFurRebateCalculation.Insert:%v", common.ErrShareJpy, err) + return err + } + + // 查询资产信息表 + var usableOld, frozenOld decimal.Decimal + userStockThb, err := uo.GetBotUserStockJpyByUserIdAndStockId(session, int64(key), flags.ShareJpyBasicUnit) + if err != nil || userStockThb == nil { + applogger.Error("%v ShareJpyRebateCalculation.GetBotUserStockJpyByUserIdAndStockId:%v", common.ErrShareJpy, err) + return err + } + usableNew := usableOld.Add(value.RebatePrice) + if !flags.CheckSetting { + applogger.Info("用户返佣对应代理原有资产:%v", key, usableOld) + applogger.Info("用户返佣更新对应代理资产:%v", key, usableNew) + } + + // 更新返佣用户资产信息 + userStockTHB := orders.UpdateBotUserStockJpy(ctx, usableNew.String(), frozenOld.String()) + if err = uo.UpdateBotUserStockJpyByUserIdAndStockId(session, int64(key), flags.ShareJpyBasicUnit, userStockTHB); err != nil { + applogger.Error("%v ShareFurRebateCalculation.UpdateBotUserStockJpyByUserIdAndStockId:%v", common.ErrShareJpy, err) + return err + } + + // TODO: 写入资金明细表(返佣) + if !CheckTypeStatus(typeStatus) { + uData := orders.CreatBotUserStockJpyLog(ctx, int64(key), int64(rebateCode), flags.ShareJpyBasicUnit, value.RebatePrice.String(), orderId) + if err = uo.CreatBotUserStockJpyLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareJpyRebateCalculation.CreatBotUserStockJpyLogByRebate:%v", common.ErrShareJpy, err) + return err + } + } else { + uData := orders.CreatBotUserStockBlockLog(ctx, int64(key), int64(rebateCode), flags.ShareJpyBasicUnit, value.RebatePrice.String(), orderId, typeStatus) + if err = uo.CreatBotUserStockBlockLogByRebate(session, uData); err != nil { + applogger.Error("%v ShareJpyRebateCalculation.CreatBotUserStockBlockLogByRebate:%v", common.ErrShareJpy, err) + return err + } + } + } + + return nil +} + +// MapSetRebate +// +// @Description: 返佣层级关系 +// @receiver uo +// @param ctx +// @param userId +// @param brokType +// @param cost +// @return map[int]*userLevelRebate +// @return error +func (uo *userOrderRepo) MapSetRebate(userId, brokType int, cost string) (map[int]*userLevelRebate, error) { + var level models.BotUserLevel + keyData := fmt.Sprintf("%v%v", flags.UserLevel, userId) + userLevel, err := Reds.HGetAll(context.Background(), keyData).Result() + if err != nil { + applogger.Error("%v MapSetRebate.HGetAll:%v", common.ErrContract, err) + return nil, err + } + for key, value := range userLevel { + valueId, err := strconv.Atoi(value) + if err != nil { + applogger.Error("%v MapSetRebate.Atoi:%v", common.ErrContract, err) + return nil, err + } + switch key { + case "user_id": + level.UserId = valueId + case "parent_id": + level.ParentId = valueId + case "grandpa_id": + level.GrandpaId = valueId + case "top_id": + level.TopId = valueId + } + } + if level.UserId == 0 { + return nil, flags.ErrOrderSix + } + + // 查询当前用户--返佣计算比例 + var setting map[string]string + var parentFee, grandpaFee, topFee decimal.Decimal + switch brokType { + case flags.Register: // 0 注册返佣 + setting, err = Reds.HGetAll(context.Background(), flags.RegSetting).Result() + if err != nil { + applogger.Error("%v MapSetRebate.HGetAll:%v", common.ErrContract, err) + return nil, err + } + case flags.OpenPosition: // 1 开仓返佣 BROKERAGE:BUY:SETTING + setting, err = Reds.HGetAll(context.Background(), flags.BuySetting).Result() + if err != nil { + applogger.Error("%v MapSetRebate.HGetAll:%v", common.ErrContract, err) + return nil, err + } + case flags.ClosingPosition: // 2 平仓返佣 BROKERAGE:SALE:SETTING + setting, err = Reds.HGetAll(context.Background(), flags.SaleSetting).Result() + if err != nil { + applogger.Error("%v MapSetRebate.HGetAll:%v", common.ErrContract, err) + return nil, err + } + default: + return nil, flags.ErrOrderFive + } + for key, value := range setting { + switch key { + case "parent_fee": + parentFee = decimal.RequireFromString(value) + case "grandpa_fee": + grandpaFee = decimal.RequireFromString(value) + case "top_fee": + topFee = decimal.RequireFromString(value) + default: + continue + } + } + + if !flags.CheckSetting { + applogger.Info("父级返佣比例ID:%v", parentFee) + applogger.Info("爷级返佣比例ID:%v", grandpaFee) + applogger.Info("祖级返佣比例ID:%v", topFee) + } + + mapLevelFee := make(map[int]*userLevelRebate) + if level.ParentId > 0 { + mapLevelFee[level.ParentId] = &userLevelRebate{ + RebatePrice: parentFee.Mul(decimal.RequireFromString(cost)), + Level: flags.ParentId, + } + } + if level.GrandpaId > 0 { + mapLevelFee[level.GrandpaId] = &userLevelRebate{ + RebatePrice: grandpaFee.Mul(decimal.RequireFromString(cost)), + Level: flags.GrandpaId, + } + } + if level.TopId > 0 { + mapLevelFee[level.TopId] = &userLevelRebate{ + RebatePrice: topFee.Mul(decimal.RequireFromString(cost)), + Level: flags.TopId, + } + } + + return mapLevelFee, nil +} + +// MapSetRebateMySqlDB +// +// @Description: 返佣比例 +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param brokType +// @param cost +// @return map[int]*userLevelRebate +// @return error +func (uo *userOrderRepo) MapSetRebateMySqlDB(session *xorm.Session, userId, brokType int, cost string) (map[int]*userLevelRebate, error) { + // 获取用户等级-从缓存中取 + var levelList []models.BotUserLevel + if err := session.Table(flags.BotUserLevel). + Where("user_id = ?", userId). + Find(&levelList); err != nil { + return map[int]*userLevelRebate{}, err + } + + // 获取返佣比例-从缓存中取 + var brokerSetList []models.BotBrokerageSetting + if err := session.Table(flags.BotBrokerageSetting). + Where("brok_type = ?", brokType). + Find(&brokerSetList); err != nil { + return nil, err + } + + if !flags.CheckSetting { + applogger.Info("查询用户返佣关系:%v", levelList) + } + + // 统计需要返佣的用户数据 + var parentFee, grandpaFee, topFee decimal.Decimal + for _, value := range brokerSetList { + parentFee = decimal.RequireFromString(value.ParentFee) + grandpaFee = decimal.RequireFromString(value.GrandpaFee) + topFee = decimal.RequireFromString(value.TopFee) + } + + if !flags.CheckSetting { + applogger.Info("父级返佣比例ID:%v", parentFee) + applogger.Info("爷级返佣比例ID:%v", grandpaFee) + applogger.Info("祖级返佣比例ID:%v", topFee) + } + + mapLevelFee := make(map[int]*userLevelRebate) + for _, value := range levelList { + if value.ParentId > 0 { + if !parentFee.IsZero() { + mapLevelFee[value.ParentId] = &userLevelRebate{ + RebatePrice: parentFee.Mul(decimal.RequireFromString(cost)), + Level: flags.ParentId, + } + } + } + if value.GrandpaId > 0 { + if !grandpaFee.IsZero() { + mapLevelFee[value.GrandpaId] = &userLevelRebate{ + RebatePrice: grandpaFee.Mul(decimal.RequireFromString(cost)), + Level: flags.GrandpaId, + } + } + } + if value.TopId > 0 { + if !topFee.IsZero() { + mapLevelFee[value.TopId] = &userLevelRebate{ + RebatePrice: topFee.Mul(decimal.RequireFromString(cost)), + Level: flags.TopId, + } + } + } + } + + if !flags.CheckSetting { + applogger.Info("展示数据:%v", mapLevelFee) + } + + return mapLevelFee, nil +} + +// CreatBotUserDigitalLog +// +// @Description: 资产--录入交易明细 +// @receiver uo +// @param ctx +// @param session +// @param userId 用户Id +// @param tradeType 用户资金变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-账户转出,8-账户转入,9-注册返佣,10-开仓返佣,11-平仓返佣,12-调整加钱,13-调整减钱,14-手续费 +// @param symbol 数字币代码 +// @param changeNum 变动资产数量 +// @param orderNum 变动资产数量 +// @param cost +// @param orderId +// @return error +func (uo *userOrderRepo) CreatBotUserDigitalLog(ctx context.Context, session *xorm.Session, userId, tradeType int64, symbol, changeNum, orderNum, cost, orderId string) error { + var codeUSDT, codeFUSDT int64 + switch tradeType { + case flags.TradeTypeBuy: // 买入 + changeNum = NegativeValue(changeNum) + if symbol != flags.BasicUnit { + codeUSDT = flags.TransferOut // 用户账户转出 + codeFUSDT = flags.ChangeInto // 用户账户非转入 + } + case flags.TradeTypeSell: // 卖出 + orderNum = NegativeValue(orderNum) + if symbol != flags.BasicUnit { + codeUSDT = flags.ChangeInto // 用户账户转入 + codeFUSDT = flags.TransferOut // 用户账户非转出 + } + default: + return nil + } + + // 记录用户资产变动详情 + uData := orders.CreatBotUserDigitalLog(ctx, userId, codeUSDT, flags.BasicUnit, changeNum, orderId) + _, err := session.Table(flags.BotUserDigitalLog).Insert(&uData) + if err != nil { + return err + } + + // 记录用户非资产变动详情 + qData := orders.CreatBotUserDigitalLog(ctx, userId, codeFUSDT, symbol, orderNum, orderId) + _, err = session.Table(flags.BotUserDigitalLog).Insert(&qData) + if err != nil { + return err + } + + // 记录用户(买入|卖出)手续费变动详情 + cData := orders.CreatBotUserDigitalLog(ctx, userId, flags.CostMoney, flags.BasicUnit, NegativeValue(cost), orderId) + _, err = session.Table(flags.BotUserDigitalLog).Insert(&cData) + if err != nil { + return err + } + + return nil +} +func (uo *userOrderRepo) CreatBotUserMoneyLog(ctx context.Context, session *xorm.Session, userId, tradeType int64, symbol, changeNum, orderNum, cost, orderId string) error { + var codeUSDT, codeFUSDT int64 + switch tradeType { + case flags.TradeTypeBuy: // 买入 + changeNum = NegativeValue(changeNum) + if symbol != flags.MoneyUnit { + codeUSDT = flags.TransferOut // 用户账户转出 + codeFUSDT = flags.ChangeInto // 用户账户非转入 + } + case flags.TradeTypeSell: // 卖出 + orderNum = NegativeValue(orderNum) + if symbol != flags.MoneyUnit { + codeUSDT = flags.ChangeInto // 用户账户转入 + codeFUSDT = flags.TransferOut // 用户账户非转出 + } + default: + return nil + } + + // 记录用户资产变动详情 + uData := orders.CreatBotUserMoneyLog(ctx, userId, codeUSDT, flags.MoneyUnit, changeNum, orderId) + _, err := session.Table(flags.BotUserMoneyLog).Insert(&uData) + if err != nil { + return err + } + + // 记录用户非资产变动详情 + qData := orders.CreatBotUserMoneyLog(ctx, userId, codeFUSDT, symbol, orderNum, orderId) + _, err = session.Table(flags.BotUserMoneyLog).Insert(&qData) + if err != nil { + return err + } + + // 记录用户(买入|卖出)手续费变动详情 + cData := orders.CreatBotUserMoneyLog(ctx, userId, flags.CostMoney, flags.MoneyUnit, NegativeValue(cost), orderId) + _, err = session.Table(flags.BotUserMoneyLog).Insert(&cData) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserDigitalLogFreeze +// +// @Description: 创建现货交易日志信息 +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param code +// @param symbol +// @param changeNum +// @param orderId +// @return error +func (uo *userOrderRepo) CreatBotUserDigitalLogFreeze(ctx context.Context, session *xorm.Session, userId, code int64, symbol, changeNum, orderId string) error { + uData := orders.CreatBotUserDigitalLog(ctx, userId, code, symbol, changeNum, orderId) + _, err := session.Table(flags.BotUserDigitalLog).Insert(&uData) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserDigitalLogByRebate +// +// @Description: 返佣--录入交易明细 +// @receiver uo +// @param ctx +// @param session +// @param userId 用户Id +// @param tradeType 用户资金变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-账户转出,8-账户转入,9-注册返佣,10-开仓返佣,11-平仓返佣,12-调整加钱,13-调整减钱,14-手续费 +// @param changeNum 变动资产数量(返佣) +// @param orderId +// @return error +func (uo *userOrderRepo) CreatBotUserDigitalLogByRebate(ctx context.Context, session *xorm.Session, userId, tradeType int64, changeNum, orderId string) error { + uData := orders.CreatBotUserDigitalLog(ctx, userId, tradeType, flags.BasicUnit, changeNum, orderId) + _, err := session.Table(flags.BotUserDigitalLog).Insert(&uData) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserContractLog +// +// @Description: 合约日志详情:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param changeType +// @param symbol +// @param changeNum +// @param orderId +// @return error +func (uo *userOrderRepo) CreatBotUserContractLog(ctx context.Context, session *xorm.Session, userId, changeType int64, symbol, changeNum, orderId string) error { + qData := orders.CreatBotUserContractLog(ctx, userId, changeType, symbol, changeNum, orderId) + _, err := session.Table(flags.BotUserContractLog).Insert(&qData) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserContractLogList +// +// @Description: 合约日志列表记录 +// @receiver uo +// @param ctx +// @param session +// @param list +// @return error +func (uo *userOrderRepo) CreatBotUserContractLogList(session *xorm.Session, list []models.BotUserContractLog) error { + _, err := session.Table(flags.BotUserContractLog).Insert(&list) + if err != nil { + return err + } + + return nil +} +func (uo *userOrderRepo) CreatBotUserForexLogList(session *xorm.Session, list []models.BotUserForexLog) error { + _, err := session.Table(flags.BotUserForexLog).Insert(&list) + if err != nil { + return err + } + + return nil +} +func (uo *userOrderRepo) CreatBotUserMoneyLogList(session *xorm.Session, list []models.BotUserMoneyLog) error { + _, err := session.Table(flags.BotUserMoneyLog).Insert(&list) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserContractSecLogList +// +// @Description: 秒合约日志详情:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param list +// @return error +func (uo *userOrderRepo) CreatBotUserContractSecLogList(session *xorm.Session, list []models.BotUserContractSecLog) error { + _, err := session.Table(flags.BotUserContractSecLog).Insert(&list) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserContractLogNew +// +// @Description: 创建合约交易日志信息 +// @receiver uo +// @param ctx +// @param session +// @param log +// @return error +func (uo *userOrderRepo) CreatBotUserContractLogNew(session *xorm.Session, log models.BotUserContractLog) error { + _, err := session.Table(flags.BotUserContractLog).Insert(&log) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockLog +// +// @Description: 美股交易日志记录 +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param changeType +// @param symbol +// @param changeNum +// @param orderId +// @return error +func (uo *userOrderRepo) CreatBotUserStockLog(ctx context.Context, session *xorm.Session, userId, changeType int64, symbol, changeNum, orderId string) error { + qData := orders.CreatBotUserStockLog(ctx, userId, changeType, symbol, changeNum, orderId) + _, err := session.Table(flags.BotUserStockLog).Insert(&qData) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockLogList +// +// @Description: 美股交易列表日志记录 +// @receiver uo +// @param session +// @param list +// @return error +func (uo *userOrderRepo) CreatBotUserStockLogList(session *xorm.Session, list []models.BotUserStockLog) error { + _, err := session.Table(flags.BotUserStockLog).Insert(&list) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockBlockLogList +// +// @Description: 大宗交易列表日志记录 +// @receiver uo +// @param session +// @param list +// @return error +func (uo *userOrderRepo) CreatBotUserStockBlockLogList(session *xorm.Session, list []models.BotUserStockBlockLog) error { + _, err := session.Table(flags.BotUserStockBlockLog).Insert(&list) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockHkdLogList +// +// @Description: +// @receiver uo +// @param session +// @param list +// @return error +func (uo *userOrderRepo) CreatBotUserStockHkdLogList(session *xorm.Session, list []models.BotUserStockHkdLog) error { + _, err := session.Table(flags.BotUserStockHkdLog).Insert(&list) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockIdnLog +// +// @Description: 印尼股日志详情:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param changeType +// @param symbol +// @param changeNum +// @param orderId +// @return error +func (uo *userOrderRepo) CreatBotUserStockIdnLog(ctx context.Context, session *xorm.Session, userId, changeType int64, symbol, changeNum, orderId string) error { + qData := orders.CreatBotUserStockIdnLog(ctx, userId, changeType, symbol, changeNum, orderId) + _, err := session.Table(flags.BotUserStockIdnLog).Insert(&qData) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockIdnLogList +// +// @Description: 印尼股列表日志记录 +// @receiver uo +// @param session +// @param list +// @return error +func (uo *userOrderRepo) CreatBotUserStockIdnLogList(session *xorm.Session, list []models.BotUserStockIdnLog) error { + _, err := session.Table(flags.BotUserStockIdnLog).Insert(&list) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockInLog +// +// @Description: 印度股日志详情:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param changeType +// @param symbol +// @param changeNum +// @param orderId +// @return error +func (uo *userOrderRepo) CreatBotUserStockInLog(ctx context.Context, session *xorm.Session, userId, changeType int64, symbol, changeNum, orderId string) error { + qData := orders.CreatBotUserStockInLog(ctx, userId, changeType, symbol, changeNum, orderId) + _, err := session.Table(flags.BotUserStockInLog).Insert(&qData) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockInLogList +// +// @Description: 印度股日志列表记录 +// @receiver uo +// @param session +// @param list +// @return error +func (uo *userOrderRepo) CreatBotUserStockInLogList(session *xorm.Session, list []models.BotUserStockInLog) error { + _, err := session.Table(flags.BotUserStockInLog).Insert(&list) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockGbxLogList +// +// @Description: 英股日志列表记录 +// @receiver uo +// @param session +// @param list +// @return error +func (uo *userOrderRepo) CreatBotUserStockGbxLogList(session *xorm.Session, list []models.BotUserStockGbxLog) error { + _, err := session.Table(flags.BotUserStockGbxLog).Insert(&list) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockOptionInrLogList +// +// @Description: 期权-印度股列表日志记录 +// @receiver uo +// @param session +// @param list +// @return error +func (uo *userOrderRepo) CreatBotUserStockOptionInrLogList(session *xorm.Session, list []models.BotUserStockOptionInrLog) error { + _, err := session.Table(flags.BotUserStockOptionInrLog).Insert(&list) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockMysLog +// +// @Description: 马股日志详情:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param changeType +// @param symbol +// @param changeNum +// @param orderId +// @return error +func (uo *userOrderRepo) CreatBotUserStockMysLog(ctx context.Context, session *xorm.Session, userId, changeType int64, symbol, changeNum, orderId string) error { + qData := orders.CreatBotUserStockMysLog(ctx, userId, changeType, symbol, changeNum, orderId) + _, err := session.Table(flags.BotUserStockMysLog).Insert(&qData) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockMysLogList +// +// @Description: 马股列表日志详情:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param session +// @param list +// @return error +func (uo *userOrderRepo) CreatBotUserStockMysLogList(session *xorm.Session, list []models.BotUserStockMysLog) error { + _, err := session.Table(flags.BotUserStockMysLog).Insert(&list) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockThaLog +// +// @Description: 马股日志详情:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param userId +// @param changeType +// @param symbol +// @param changeNum +// @param orderId +// @return error +func (uo *userOrderRepo) CreatBotUserStockThaLog(ctx context.Context, session *xorm.Session, userId, changeType int64, symbol, changeNum, orderId string) error { + qData := orders.CreatBotUserStockThaLog(ctx, userId, changeType, symbol, changeNum, orderId) + _, err := session.Table(flags.BotUserStockThaLog).Insert(&qData) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockThaLogList +// +// @Description: 马股列表日志详情:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param list +// @return error +func (uo *userOrderRepo) CreatBotUserStockThaLogList(session *xorm.Session, list []models.BotUserStockThaLog) error { + _, err := session.Table(flags.BotUserStockThaLog).Insert(&list) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockSgdLogList +// +// @Description: 新加坡股日志详情:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param list +// @return error +func (uo *userOrderRepo) CreatBotUserStockSgdLogList(session *xorm.Session, list []models.BotUserStockSgdLog) error { + _, err := session.Table(flags.BotUserStockSgdLog).Insert(&list) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockEurLogList +// +// @Description: 德国股日志详情:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param list +// @return error +func (uo *userOrderRepo) CreatBotUserStockEurLogList(session *xorm.Session, list []models.BotUserStockEurLog) error { + _, err := session.Table(flags.BotUserStockEurLog).Insert(&list) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockBrlLogList +// +// @Description: 巴西国股日志详情:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param session +// @param list +// @return error +func (uo *userOrderRepo) CreatBotUserStockBrlLogList(session *xorm.Session, list []models.BotUserStockBrlLog) error { + _, err := session.Table(flags.BotUserStockBrlLog).Insert(&list) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockFurLogList +// +// @Description: 法国股日志详情:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param list +// @return error +func (uo *userOrderRepo) CreatBotUserStockFurLogList(session *xorm.Session, list []models.BotUserStockFurLog) error { + _, err := session.Table(flags.BotUserStockFurLog).Insert(&list) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockJpyLogList +// +// @Description: 日国股日志详情:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param list +// @return error +func (uo *userOrderRepo) CreatBotUserStockJpyLogList(session *xorm.Session, list []models.BotUserStockJpLog) error { + _, err := session.Table(flags.BotUserStockJpyLog).Insert(&list) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserContractLogByRebate +// +// @Description: 德国列表股日志详情-手续费:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param log +// @return error +func (uo *userOrderRepo) CreatBotUserContractLogByRebate(session *xorm.Session, log models.BotUserContractLog) error { + _, err := session.Table(flags.BotUserContractLog).Insert(&log) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserForexLogByRebate +// +// @Description: 外汇列表股日志详情-手续费:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param log +// @return error +func (uo *userOrderRepo) CreatBotUserForexLogByRebate(session *xorm.Session, log models.BotUserForexLog) error { + _, err := session.Table(flags.BotUserForexLog).Insert(&log) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserMoneyLogByRebate +// +// @Description: 综合(现货|合约|外汇)列表股日志详情-手续费:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param session +// @param log +// @return error +func (uo *userOrderRepo) CreatBotUserMoneyLogByRebate(session *xorm.Session, log models.BotUserMoneyLog) error { + _, err := session.Table(flags.BotUserMoneyLog).Insert(&log) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockLogByRebate +// +// @Description: 美股日志详情-手续费:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param log +// @return error +func (uo *userOrderRepo) CreatBotUserStockLogByRebate(session *xorm.Session, log models.BotUserStockLog) error { + _, err := session.Table(flags.BotUserStockLog).Insert(&log) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockBlockLogByRebate +// +// @Description: 大宗(美股)交易日志详情-手续费:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param session +// @param log +// @return error +func (uo *userOrderRepo) CreatBotUserStockBlockLogByRebate(session *xorm.Session, log models.BotUserStockBlockLog) error { + _, err := session.Table(flags.BotUserStockBlockLog).Insert(&log) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockHkdLogByRebate +// +// @Description: +// @receiver uo +// @param session +// @param log +// @return error +func (uo *userOrderRepo) CreatBotUserStockHkdLogByRebate(session *xorm.Session, log models.BotUserStockHkdLog) error { + _, err := session.Table(flags.BotUserStockHkdLog).Insert(&log) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockIdnLogByRebate +// +// @Description: 印尼股日志详情-手续费:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param log +// @return error +func (uo *userOrderRepo) CreatBotUserStockIdnLogByRebate(session *xorm.Session, log models.BotUserStockIdnLog) error { + _, err := session.Table(flags.BotUserStockIdnLog).Insert(&log) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockInLogByRebate +// +// @Description: 印度股日志详情-手续费:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param log +// @return error +func (uo *userOrderRepo) CreatBotUserStockInLogByRebate(session *xorm.Session, log models.BotUserStockInLog) error { + _, err := session.Table(flags.BotUserStockInLog).Insert(&log) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockGbxLogByRebate +// +// @Description: 英股日志详情-手续费:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param session +// @param log +// @return error +func (uo *userOrderRepo) CreatBotUserStockGbxLogByRebate(session *xorm.Session, log models.BotUserStockGbxLog) error { + _, err := session.Table(flags.BotUserStockGbxLog).Insert(&log) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockOptionInrLogByRebate +// +// @Description: 期权印度股日志详情-手续费:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param session +// @param log +// @return error +func (uo *userOrderRepo) CreatBotUserStockOptionInrLogByRebate(session *xorm.Session, log models.BotUserStockOptionInrLog) error { + _, err := session.Table(flags.BotUserStockOptionInrLog).Insert(&log) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockMysLogByRebate +// +// @Description: 马股股日志详情-手续费:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param log +// @return error +func (uo *userOrderRepo) CreatBotUserStockMysLogByRebate(session *xorm.Session, log models.BotUserStockMysLog) error { + _, err := session.Table(flags.BotUserStockMysLog).Insert(&log) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockThaLogByRebate +// +// @Description: 泰度股日志详情-手续费:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param log +// @return error +func (uo *userOrderRepo) CreatBotUserStockThaLogByRebate(session *xorm.Session, log models.BotUserStockThaLog) error { + _, err := session.Table(flags.BotUserStockThaLog).Insert(&log) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockSgdLogByRebate +// +// @Description: 新加坡股日志详情-手续费:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param log +// @return error +func (uo *userOrderRepo) CreatBotUserStockSgdLogByRebate(session *xorm.Session, log models.BotUserStockSgdLog) error { + _, err := session.Table(flags.BotUserStockSgdLog).Insert(&log) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockEurLogByRebate +// +// @Description: 德股日志详情-手续费:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param log +// @return error +func (uo *userOrderRepo) CreatBotUserStockEurLogByRebate(session *xorm.Session, log models.BotUserStockEurLog) error { + _, err := session.Table(flags.BotUserStockEurLog).Insert(&log) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockBrlLogByRebate +// +// @Description: 巴西股日志详情-手续费:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param session +// @param log +// @return error +func (uo *userOrderRepo) CreatBotUserStockBrlLogByRebate(session *xorm.Session, log models.BotUserStockBrlLog) error { + _, err := session.Table(flags.BotUserStockBrlLog).Insert(&log) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockFurLogByRebate +// +// @Description: 法股日志详情-手续费:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param log +// @return error +func (uo *userOrderRepo) CreatBotUserStockFurLogByRebate(session *xorm.Session, log models.BotUserStockFurLog) error { + _, err := session.Table(flags.BotUserStockFurLog).Insert(&log) + if err != nil { + return err + } + + return nil +} + +// CreatBotUserStockJpyLogByRebate +// +// @Description: 日股日志详情-手续费:转出|转出|冻结|手续费|返佣费 +// @receiver uo +// @param ctx +// @param session +// @param log +// @return error +func (uo *userOrderRepo) CreatBotUserStockJpyLogByRebate(session *xorm.Session, log models.BotUserStockJpLog) error { + _, err := session.Table(flags.BotUserStockJpyLog).Insert(&log) + if err != nil { + return err + } + + return nil +} + +// CheckGlobalTread +// +// @Description: true:开启交易 false:关闭交易 +// +// 股票:冷静期停止所有交易(全局设置) +// 熔断机制(后台配置冷静期) +// 触发幅度:10%,交易暂停15分钟 +// 触发幅度:15%,交易暂停30分钟 +// 触发幅度:20%,剩余交易时间(重新交易到休市时间) +// +// @param symbol +// @return bool +func CheckGlobalTread(symbol string) bool { + check := GetCacheStockMarketStatus(flags.StockMarketList, symbol) + + return check +} + +// CheckBlockTread +// +// @Description: true:开启交易 false:关闭交易 +// +// 股票:冷静期停止所有交易(全局设置) +// 熔断机制(后台配置冷静期) +// 触发幅度:10%,交易暂停15分钟 +// 触发幅度:15%,交易暂停30分钟 +// 触发幅度:20%,剩余交易时间(重新交易到休市时间) +// +// @param cacheKey +// @param symbol +// @return bool +// @return string +// @return int +// @return time.Time +func CheckBlockTread(cacheKey, symbol string) (bool, string, int, time.Time) { + check, openPrice, minNum, today := GetCacheStockBlockStatus(cacheKey, symbol) + if check { + return check, openPrice, minNum, today + } + + return check, openPrice, minNum, today +} + +// GetShareChgUs +// +// @Description: 股票美股涨跌幅 +// @param ctx +// @param share +// @param symbol +// @return string +func GetShareChgUs(share, symbol string) string { + closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg) + chg, err := memory.ShareUsChgMark.Get(closingKey) + if err != nil { + return flags.SetZero + } + if len(string(chg)) == 0 { + chg = []byte(flags.SetOne) + } + chgV := decimal.RequireFromString(string(chg)) + shareUsChg := GetCacheLimitOrDown(flags.StockUsSystemSetUpKey, symbol) // 股票涨跌停读取缓存 + + var checkBoll bool + if chgV.Abs().Cmp(shareUsChg) >= 0 { + checkBoll = true // 到达涨跌幅上限 + } + + var checkChg string + if checkBoll { + if chgV.IsNegative() { + checkChg = flags.DownLimit // 跌停 + } else { + checkChg = flags.UpLimit // 涨停 + } + } + + return checkChg +} + +// GetShareChgIdn +// +// @Description: 股票印尼股涨跌幅 +// @param ctx +// @param share +// @param symbol +// @return string +func GetShareChgIdn(share, symbol string) string { + closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg) + chg, err := memory.ShareIdnChgMark.Get(closingKey) + if err != nil { + return flags.SetZero + } + if len(string(chg)) == 0 { + chg = []byte(flags.SetOne) + } + chgV := decimal.RequireFromString(string(chg)) + shareUsChg := GetCacheLimitOrDown(flags.StockYNSystemSetUpKey, symbol) // 股票涨跌停读取缓存 + + var checkBoll bool + if chgV.Abs().Cmp(shareUsChg) >= 0 { + checkBoll = true // 到达涨跌幅上限 + } + + var checkChg string + if checkBoll { + if chgV.IsNegative() { + checkChg = flags.DownLimit // 跌停 + } else { + checkChg = flags.UpLimit // 涨停 + } + } + + return checkChg +} + +// GetShareChgHkd +// +// @Description: +// @param share +// @param symbol +// @return string +func GetShareChgHkd(share, symbol string) string { + closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg) + chg, err := memory.ShareHkdChgMark.Get(closingKey) + if err != nil { + return flags.SetZero + } + if len(string(chg)) == 0 { + chg = []byte(flags.SetOne) + } + chgV := decimal.RequireFromString(string(chg)) + shareUsChg := GetCacheLimitOrDown(flags.StockHKDSystemSetUpKey, symbol) // 股票涨跌停读取缓存 + + var checkBoll bool + if chgV.Abs().Cmp(shareUsChg) >= 0 { + checkBoll = true // 到达涨跌幅上限 + } + + var checkChg string + if checkBoll { + if chgV.IsNegative() { + checkChg = flags.DownLimit // 跌停 + } else { + checkChg = flags.UpLimit // 涨停 + } + } + + return checkChg +} + +// GetShareChgInr +// +// @Description: 股票印度股涨跌幅 +// @param ctx +// @param share +// @param symbol +// @return string +func GetShareChgInr(share, symbol string) string { + closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg) + chg, err := memory.ShareInrChgMark.Get(closingKey) + if err != nil { + return flags.SetZero + } + if len(string(chg)) == 0 { + chg = []byte(flags.SetOne) + } + chgV := decimal.RequireFromString(string(chg)) + shareUsChg := GetCacheLimitOrDown(flags.StockYDSystemSetUpKey, symbol) // 股票涨跌停读取缓存 + + var checkBoll bool + if chgV.Abs().Cmp(shareUsChg) >= 0 { + checkBoll = true // 到达涨跌幅上限 + } + + var checkChg string + if checkBoll { + if chgV.IsNegative() { + checkChg = flags.DownLimit // 跌停 + } else { + checkChg = flags.UpLimit // 涨停 + } + } + + return checkChg +} + +// GetShareChgGbx +// +// @Description: +// @param share +// @param symbol +// @return string +func GetShareChgGbx(share, symbol string) string { + closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg) + chg, err := memory.ShareGbxChgMark.Get(closingKey) + if err != nil { + return flags.SetZero + } + if len(string(chg)) == 0 { + chg = []byte(flags.SetOne) + } + chgV := decimal.RequireFromString(string(chg)) + shareUsChg := GetCacheLimitOrDown(flags.StockUkSystemSetUpKey, symbol) // 股票涨跌停读取缓存 + + var checkBoll bool + if chgV.Abs().Cmp(shareUsChg) >= 0 { + checkBoll = true // 到达涨跌幅上限 + } + + var checkChg string + if checkBoll { + if chgV.IsNegative() { + checkChg = flags.DownLimit // 跌停 + } else { + checkChg = flags.UpLimit // 涨停 + } + } + + return checkChg +} + +// GetOptionChgInr +// +// @Description: 期权印度股涨跌幅 +// @param share +// @param symbol +// @return string +func GetOptionChgInr(share, symbol string) string { + closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg) + chg, err := memory.OptionInrChgMark.Get(closingKey) + if err != nil { + return flags.SetZero + } + if len(string(chg)) == 0 { + chg = []byte(flags.SetOne) + } + chgV := decimal.RequireFromString(string(chg)) + optionInrChg := GetCacheLimitOrDown(flags.OptionOpiSystemSetUpKey, symbol) // 股票涨跌停读取缓存 + + var checkBoll bool + if chgV.Abs().Cmp(optionInrChg) >= 0 { + checkBoll = true // 到达涨跌幅上限 + } + + var checkChg string + if checkBoll { + if chgV.IsNegative() { + checkChg = flags.DownLimit // 跌停 + } else { + checkChg = flags.UpLimit // 涨停 + } + } + + return checkChg +} + +// GetShareChgMys +// +// @Description: 股票马股涨跌幅 +// @param ctx +// @param share +// @param symbol +// @return string +func GetShareChgMys(share, symbol string) string { + closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg) + chg, err := memory.ShareMysChgMark.Get(closingKey) + if err != nil { + return flags.SetZero + } + if len(string(chg)) == 0 { + chg = []byte(flags.SetOne) + } + chgV := decimal.RequireFromString(string(chg)) + shareUsChg := GetCacheLimitOrDown(flags.StockMGSystemSetUpKey, symbol) // 股票涨跌停读取缓存 + + var checkBoll bool + if chgV.Abs().Cmp(shareUsChg) >= 0 { + checkBoll = true // 到达涨跌幅上限 + } + + var checkChg string + if checkBoll { + if chgV.IsNegative() { + checkChg = flags.DownLimit // 跌停 + } else { + checkChg = flags.UpLimit // 涨停 + } + } + + return checkChg +} + +// GetShareChgTha +// +// @Description: 股票泰股涨跌幅 +// @param ctx +// @param share +// @param symbol +// @return string +func GetShareChgTha(share, symbol string) string { + closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg) + chg, err := memory.ShareThaChgMark.Get(closingKey) + if err != nil { + return flags.SetZero + } + if len(string(chg)) == 0 { + chg = []byte(flags.SetOne) + } + chgV := decimal.RequireFromString(string(chg)) + shareUsChg := GetCacheLimitOrDown(flags.StockTGSystemSetUpKey, symbol) // 股票涨跌停读取缓存 + + var checkBoll bool + if chgV.Abs().Cmp(shareUsChg) >= 0 { + checkBoll = true // 到达涨跌幅上限 + } + + var checkChg string + if checkBoll { + if chgV.IsNegative() { + checkChg = flags.DownLimit // 跌停 + } else { + checkChg = flags.UpLimit // 涨停 + } + } + + return checkChg +} + +// GetShareChgSgd +// +// @Description: 股票新加坡股涨跌幅 +// @param ctx +// @param share +// @param symbol +// @return string +func GetShareChgSgd(share, symbol string) string { + closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg) + chg, err := memory.ShareSgdChgMark.Get(closingKey) + if err != nil { + return flags.SetZero + } + if len(string(chg)) == 0 { + chg = []byte(flags.SetOne) + } + chgV := decimal.RequireFromString(string(chg)) + shareUsChg := GetCacheLimitOrDown(flags.StockSGDSystemSetUpKey, symbol) // 股票涨跌停读取缓存 + + var checkBoll bool + if chgV.Abs().Cmp(shareUsChg) >= 0 { + checkBoll = true // 到达涨跌幅上限 + } + + var checkChg string + if checkBoll { + if chgV.IsNegative() { + checkChg = flags.DownLimit // 跌停 + } else { + checkChg = flags.UpLimit // 涨停 + } + } + + return checkChg +} + +// GetShareChgEur +// +// @Description: 股票德股涨跌幅 +// @param ctx +// @param share +// @param symbol +// @return string +func GetShareChgEur(share, symbol string) string { + closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg) + chg, err := memory.ShareEurChgMark.Get(closingKey) + if err != nil { + return flags.SetZero + } + if len(string(chg)) == 0 { + chg = []byte(flags.SetOne) + } + chgV := decimal.RequireFromString(string(chg)) + shareUsChg := GetCacheLimitOrDown(flags.StockEURSystemSetUpKey, symbol) // 股票涨跌停读取缓存 + + var checkBoll bool + if chgV.Abs().Cmp(shareUsChg) >= 0 { + checkBoll = true // 到达涨跌幅上限 + } + + var checkChg string + if checkBoll { + if chgV.IsNegative() { + checkChg = flags.DownLimit // 跌停 + } else { + checkChg = flags.UpLimit // 涨停 + } + } + + return checkChg +} + +// GetShareChgBrl +// +// @Description: 股票巴西股涨跌幅 +// @param share +// @param symbol +// @return string +func GetShareChgBrl(share, symbol string) string { + closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg) + chg, err := memory.ShareBrlChgMark.Get(closingKey) + if err != nil { + return flags.SetZero + } + if len(string(chg)) == 0 { + chg = []byte(flags.SetOne) + } + chgV := decimal.RequireFromString(string(chg)) + shareUsChg := GetCacheLimitOrDown(flags.StockBRLSystemSetUpKey, symbol) // 股票涨跌停读取缓存 + + var checkBoll bool + if chgV.Abs().Cmp(shareUsChg) >= 0 { + checkBoll = true // 到达涨跌幅上限 + } + + var checkChg string + if checkBoll { + if chgV.IsNegative() { + checkChg = flags.DownLimit // 跌停 + } else { + checkChg = flags.UpLimit // 涨停 + } + } + + return checkChg +} + +// GetShareChgFur +// +// @Description: 股票法股涨跌幅 +// @param ctx +// @param share +// @param symbol +// @return string +func GetShareChgFur(share, symbol string) string { + closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg) + chg, err := memory.ShareFurChgMark.Get(closingKey) + if err != nil { + return flags.SetZero + } + if len(string(chg)) == 0 { + chg = []byte(flags.SetOne) + } + chgV := decimal.RequireFromString(string(chg)) + shareUsChg := GetCacheLimitOrDown(flags.StockFURSystemSetUpKey, symbol) // 股票涨跌停读取缓存 + + var checkBoll bool + if chgV.Abs().Cmp(shareUsChg) >= 0 { + checkBoll = true // 到达涨跌幅上限 + } + + var checkChg string + if checkBoll { + if chgV.IsNegative() { + checkChg = flags.DownLimit // 跌停 + } else { + checkChg = flags.UpLimit // 涨停 + } + } + + return checkChg +} + +// GetShareChgJpy +// +// @Description: 股票日股涨跌幅 +// @param share +// @param symbol +// @return string +func GetShareChgJpy(share, symbol string) string { + closingKey := publicData.SymbolCache(share, symbol, flags.TradeTypeChg) + chg, err := memory.ShareJpyChgMark.Get(closingKey) + if err != nil { + return flags.SetZero + } + if len(string(chg)) == 0 { + chg = []byte(flags.SetOne) + } + chgV := decimal.RequireFromString(string(chg)) + shareUsChg := GetCacheLimitOrDown(flags.StockJPYSystemSetUpKey, symbol) // 股票涨跌停读取缓存 + + var checkBoll bool + if chgV.Abs().Cmp(shareUsChg) >= 0 { + checkBoll = true // 到达涨跌幅上限 + } + + var checkChg string + if checkBoll { + if chgV.IsNegative() { + checkChg = flags.DownLimit // 跌停 + } else { + checkChg = flags.UpLimit // 涨停 + } + } + + return checkChg +} + +// GetBeforeAndAfterSetPrice +// +// @Description: 股票盘前和盘后下单 【pre_status|after_status 1、开启 2、关闭】 +// @param ctx +// @param keyCache +// @return string +// @return error +func GetBeforeAndAfterSetPrice(keyCache string) (string, error) { + var setPrice string + setBAPrice, err := Reds.HGetAll(context.Background(), keyCache).Result() + if err != nil { + return setPrice, err + } + + setModel := &SetPrice{} + for key, value := range setBAPrice { + switch key { + case "status": // 开启|关闭状态 + setModel.Status = value + case "price": // 价格 + setModel.Price = value + default: + } + } + + if setModel != nil { + switch setModel.Status { + case flags.SetTwo: + setPrice = "" + case flags.SetOne: + return setModel.Price, nil + default: + } + } + + return setPrice, nil +} + +// GetOrderByStatusSort +// +// @Description: 查询列表数据排序 +// +// 1、持仓订单:持仓时间越近越前; +// 2、委托订单:委托时间越近越前; +// 3、撤销订单:撤销时间越近越前; +// 4、平仓订单:平仓时间越近越前; +// +// @param status +// @return string +func GetOrderByStatusSort(status int64) string { + switch status { + case flags.EntrustStatus: // 委托 + return "update_time" + case flags.PositionStatus: // 持仓 + return "update_time" + case flags.CancelStatus: // 撤单 + return "update_time" + case flags.CloseStatus: // 平仓 + return "closing_time" + default: + return "create_time" + } +} + +// GetForcedClosureValue +// +// @Description: 缓存强平阈值 +// @param name +// @param symbol +// @return string +func GetForcedClosureValue(name, symbol string) string { + chgKey := publicData.SymbolCache(name, symbol, flags.TradeTypeForcedClosure) + switch name { + case flags.Us: + fb, err := memory.ShareUsForcedClosure.Get(chgKey) + if err != nil || len(string(fb)) == 0 { + return flags.ForcedClosure + } + return string(fb) + case flags.Tha: + fb, err := memory.ShareThaForcedClosure.Get(chgKey) + if err != nil || len(string(fb)) == 0 { + return flags.ForcedClosure + } + return string(fb) + case flags.Mys: + fb, err := memory.ShareMysForcedClosure.Get(chgKey) + if err != nil || len(string(fb)) == 0 { + return flags.ForcedClosure + } + return string(fb) + case flags.Idn: + fb, err := memory.ShareIdnForcedClosure.Get(chgKey) + if err != nil || len(string(fb)) == 0 { + return flags.ForcedClosure + } + return string(fb) + case flags.Inr: + fb, err := memory.ShareInrForcedClosure.Get(chgKey) + if err != nil || len(string(fb)) == 0 { + return flags.ForcedClosure + } + return string(fb) + case flags.Hkd: + fb, err := memory.ShareHkdForcedClosure.Get(chgKey) + if err != nil || len(string(fb)) == 0 { + return flags.ForcedClosure + } + return string(fb) + case flags.Sgd: + fb, err := memory.ShareSgdForcedClosure.Get(chgKey) + if err != nil || len(string(fb)) == 0 { + return flags.ForcedClosure + } + return string(fb) + case flags.Gbx: + fb, err := memory.ShareGbxForcedClosure.Get(chgKey) + if err != nil || len(string(fb)) == 0 { + return flags.ForcedClosure + } + return string(fb) + case flags.Opi: + fb, err := memory.OptionInrForcedClosure.Get(chgKey) + if err != nil || len(string(fb)) == 0 { + return flags.ForcedClosure + } + return string(fb) + default: + return flags.ForcedClosure + } +} + +// GetDigitalCurrencyPrice +// +// @Description: (现货|合约)最新价格 +// @param ctx +// @param identifying +// @param symbol +// @return string +// @return error +func GetDigitalCurrencyPrice(ctx context.Context, identifying, symbol string) (string, error) { + var num int // 计数器 + var err error // 错误定义 + var priceNew string // 交易对最新价格 + for { + subKey := publicData.SymbolCache(identifying, symbol, flags.TradeTypePrice) + switch identifying { + case flags.Hy: + priceNew, err = virtual.ContractSubMarketPrice(ctx, subKey) // 合约交易币价 + case flags.Sd: + priceNew, err = virtual.SecondSubMarketPrice(ctx, subKey) // 秒合约交易币价 + case flags.Xh: + priceNew, err = virtual.DealSpotsMarketPrice(ctx, subKey) // 现货交易币价 + case flags.Wh: + priceNew, err = forexd.ForexSubMarketPrice(ctx, subKey) // 外汇交易币价 + default: + break + } + if err != nil { + applogger.Error("%v CreateBotContractTrade.ContractSubMarketPrice:%v", common.ErrContract, err) + time.Sleep(1 * time.Second) + num = num + 1 + if num == 4 { + break + } + continue + } + break + } + + return priceNew, err +} + +// GetDigitalCurrencyForexPrice +// +// @Description: 外汇买一卖一最新报价 +// @param ctx +// @param identifying +// @param symbol +// @param tradeType +// @return string +// @return error +func GetDigitalCurrencyForexPrice(ctx context.Context, identifying, symbol string, tradeType int64) (string, error) { + var num int // 计数器 + var err error // 错误定义 + var priceNew string // 交易对最新价格 + for { + switch tradeType { + case 1: // 买入 + subKey := publicData.SymbolCache(identifying, symbol, flags.TradeTypeBuy) + priceNew, err = forexd.ForexSubMarketPrice(ctx, subKey) // 外汇交易对买一最新报价 + case 2: // 卖出 + subKey := publicData.SymbolCache(identifying, symbol, flags.TradeTypeSell) + priceNew, err = forexd.ForexSubMarketPrice(ctx, subKey) // 外汇交易对卖一最新报价 + default: + break + } + if err != nil { + applogger.Error("%v GetDigitalCurrencyForexPrice.ForexSubMarketPrice:%v", common.ErrForex, err) + time.Sleep(1 * time.Second) + num = num + 1 + if num == 4 { + break + } + continue + } + break + } + + return priceNew, err +} + +// GetOptionInrCostPrice +// +// @Description: 期权-计算保证金 +// @receiver uo +// @param order +// @return decimal.Decimal +func GetOptionInrCostPrice(limitOrMarketPrice decimal.Decimal, order structure.ShareOrder) decimal.Decimal { + // 保证金(Margin Ratio) + // 1> buy call & buy put:Margin = Open Filled Price(开仓价格) * Quantity(订单数量) + // 2> sell call & sell put:Margin = (Stock Price(行权价) * Option Multiplier(期权乘数)) * Margin Ratio(保证金比率) * Quantity(订单数量) + quantity := decimal.RequireFromString(order.OrderNumber) + stockPrice := decimal.RequireFromString(order.StrikePrice) + multiplier := decimal.RequireFromString(order.Multiplier) + ratio := decimal.RequireFromString(order.Ratio) + + // 保证金计算 + marginBuy := limitOrMarketPrice.Mul(quantity) + marginSell := stockPrice.Mul(multiplier).Mul(ratio.Div(decimal.RequireFromString(flags.DecimalOne))).Mul(quantity) + + var marginRatio decimal.Decimal + switch order.TradeType { + case flags.OptionCalls: // CallS + switch order.TradingType { + case flags.OptionBuy: // buy + marginRatio = marginBuy + case flags.OptionSell: // sell + marginRatio = marginSell + default: + } + case flags.OptionPuts: // PUTS + switch order.TradingType { + case flags.OptionBuy: // buy + marginRatio = marginBuy + case flags.OptionSell: // sell + marginRatio = marginSell + default: + } + default: + } + + return marginRatio +} + +// GetOptionInrFloatingPL +// +// @Description: 期权-计算浮动盈亏 +// @param order +// @param closePrice +// @param costPrice +// @param orderNumber +// @param totalAmount +// @return decimal.Decimal +func GetOptionInrFloatingPL(order structure.ShareOrder, openPrice, closePrice, orderNumber decimal.Decimal) decimal.Decimal { + // 一、浮动盈亏(P/L) + // 1>buy call & buy put: P/L = (Last Price(开仓价格) - Cost Price(当前价格)) * Contracts Quantity + // 2>sell call & sell put: P/L = (Cost Price(当前价格) - Last Price(开仓价格)) * Contracts Quantity + var resultPrice decimal.Decimal + switch order.TradeType { + case flags.OptionCalls: // CallS + switch order.TradingType { + case flags.OptionBuy: // buy + resultPrice = openPrice.Sub(closePrice).Mul(orderNumber) + case flags.OptionSell: // sell + resultPrice = closePrice.Sub(openPrice).Mul(orderNumber) + default: + } + case flags.OptionPuts: // PUTS + switch order.TradingType { + case flags.OptionBuy: // buy + resultPrice = openPrice.Sub(closePrice).Mul(orderNumber) + case flags.OptionSell: // sell + resultPrice = closePrice.Sub(openPrice).Mul(orderNumber) + default: + } + default: + } + + return resultPrice +} diff --git a/internal/errors/error_encoder.go b/internal/errors/error_encoder.go new file mode 100644 index 0000000..edf2361 --- /dev/null +++ b/internal/errors/error_encoder.go @@ -0,0 +1,58 @@ +package errors + +import ( + "fmt" + "net/http" + + "github.com/go-kratos/kratos/v2/errors" +) + +// NewHTTPError +// +// @Description: +// @param code +// @param data +// @param detail +// @return *HTTPError +func NewHTTPError(code int, data interface{}, detail string) *HTTPError { + return &HTTPError{ + Code: code, + Data: data, + Message: detail, + } +} + +// HTTPError +// @Description: +type HTTPError struct { + Message string `json:"message"` + Code int `json:"code"` + Data interface{} `json:"data"` +} + +// Error +// +// @Description: +// @receiver e +// @return string +func (e *HTTPError) Error() string { + return fmt.Sprintf("HTTPError: %d", e.Code) +} + +// FromError +// +// @Description: +// @param err +// @return *HTTPError +func FromError(err error) *HTTPError { + if err == nil { + return nil + } + if se := new(HTTPError); errors.As(err, &se) { + return se + } + if se := new(errors.Error); errors.As(err, &se) { + return NewHTTPError(int(se.Code), nil, se.Message) + } + return NewHTTPError(http.StatusBadRequest, new(struct{}), "error") +} diff --git a/internal/errors/error_encoder_test.go b/internal/errors/error_encoder_test.go new file mode 100644 index 0000000..d753ca4 --- /dev/null +++ b/internal/errors/error_encoder_test.go @@ -0,0 +1,75 @@ +package errors + +import ( + "reflect" + "testing" +) + +func TestFromError(t *testing.T) { + type args struct { + err error + } + tests := []struct { + name string + args args + want *HTTPError + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := FromError(tt.args.err); !reflect.DeepEqual(got, tt.want) { + t.Errorf("FromError() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestHTTPError_Error(t *testing.T) { + type fields struct { + Message string + Code int + Data interface{} + } + tests := []struct { + name string + fields fields + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + e := &HTTPError{ + Message: tt.fields.Message, + Code: tt.fields.Code, + Data: tt.fields.Data, + } + if got := e.Error(); got != tt.want { + t.Errorf("Error() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestNewHTTPError(t *testing.T) { + type args struct { + code int + data interface{} + detail string + } + tests := []struct { + name string + args args + want *HTTPError + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewHTTPError(tt.args.code, tt.args.data, tt.args.detail); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewHTTPError() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/pkg/flags/market_time.go b/internal/pkg/flags/market_time.go new file mode 100644 index 0000000..d59272b --- /dev/null +++ b/internal/pkg/flags/market_time.go @@ -0,0 +1,99 @@ +package flags + +import "time" + +type TimeType struct { + AmOpenTime string + AmCloseTime string + PmOpenTime string + PmCloseTime string +} + +type TimeValue struct { + AmOpenTime time.Time + AmCloseTime time.Time + PmOpenTime time.Time + PmCloseTime time.Time +} + +// 构造股票市场开闭盘时间节点 +var TimeMapType = map[int]TimeType{ + 3: { // 美股 21:30 次日 4:00 + AmOpenTime: "21:30", + AmCloseTime: "04:00", + PmOpenTime: "21:30", + PmCloseTime: "04:00", + }, + 4: { // 印尼 (周一到周四) 10:00 - 13:00(上午盘) 14:30 - 17:10(下午盘) + AmOpenTime: "10:00", + AmCloseTime: "13:00", + PmOpenTime: "14:30", + PmCloseTime: "17:10", + }, + 40: { // 印尼 周五 10:00 - 12:30(上午盘) 15:00 - 17:10(下午盘) + AmOpenTime: "10:00", + AmCloseTime: "12:30", + PmOpenTime: "15:00", + PmCloseTime: "17:10", + }, + 5: { // 马股 09:00 - 12:30(上午盘) 14:30 - 17:00(下午盘) + AmOpenTime: "09:00", + AmCloseTime: "12:30", + PmOpenTime: "14:30", + PmCloseTime: "17:00", + }, + 6: { // 泰股 10:55 - 13:30(上午盘) 15:25 - 17:30(下午盘) + AmOpenTime: "10:55", + AmCloseTime: "13:30", + PmOpenTime: "15:25", + PmCloseTime: "17:30", + }, + 7: { // 印度 11:45 – 18:00 + AmOpenTime: "11:45", + AmCloseTime: "18:00", + PmOpenTime: "11:45", + PmCloseTime: "18:00", + }, + 9: { // 新加坡 09:00 - 12:00(上午盘) 12:55 - 17:00(下午盘) + AmOpenTime: "09:00", + AmCloseTime: "12:00", + PmOpenTime: "12:55", + PmCloseTime: "17:00", + }, + 12: { // 香港 9:30 - 12:00(上午盘) 13:00 - 16:00(下午盘) + AmOpenTime: "09:30", + AmCloseTime: "12:00", + PmOpenTime: "13:00", + PmCloseTime: "16:00", + }, + 14: { // 英国 15:00 - 23:30 + AmOpenTime: "15:00", + AmCloseTime: "23:30", + PmOpenTime: "15:00", + PmCloseTime: "23:30", + }, + 15: { // 法国 15:00 - 23:30 + AmOpenTime: "15:00", + AmCloseTime: "23:30", + PmOpenTime: "15:00", + PmCloseTime: "23:30", + }, + 16: { // 德国 15:00 - 23:30 + AmOpenTime: "15:00", + AmCloseTime: "23:30", + PmOpenTime: "15:00", + PmCloseTime: "23:30", + }, + 17: { // 巴西 21:00 次日 4:00 + AmOpenTime: "21:00", + AmCloseTime: "04:00", + PmOpenTime: "21:00", + PmCloseTime: "04:00", + }, + 18: { // 日本 08:00 - 10:30(上午盘) 11:30 - 14:00(下午盘) + AmOpenTime: "08:00", + AmCloseTime: "10:30", + PmOpenTime: "11:30", + PmCloseTime: "14:00", + }, +} diff --git a/internal/pkg/flags/message.go b/internal/pkg/flags/message.go new file mode 100644 index 0000000..28ab1cc --- /dev/null +++ b/internal/pkg/flags/message.go @@ -0,0 +1,108 @@ +package flags + +import ( + "errors" +) + +/* +股票|数字币提示语言 +1、买涨提示语: + + 买涨涨停无法开仓:"无法开仓:由于涨停限制,目前无法买入该股票" + 买涨跌停无法平仓:"跌停限制:该股票的涨幅已经达到了交易所规定的跌停幅度,暂停交易" + +2、买跌提示语: + + 买跌跌停无法开仓:"跌停限制:该股票的跌幅已经达到了交易所规定的跌停幅度,暂停交易" + 买跌涨停无法平仓:"无法平仓:由于涨停限制,目前无法卖出该股票 + +3、休市提示语 + + 管理员后台手动强制休市:"休市":因突发情况进行休市,暂停交易. + 股市午间休息时间:"午间休市":市场午间休息状态,暂停交易. + 股市交易日正常闭市:"闭市":市场已到闭市时间,暂停交易. +*/ +var ( + ErrPublicOne = errors.New("Insufficient funds, please recharge.") + ErrPublicTow = errors.New("Insufficient funds in the ordering account.") + ErrPublicThree = errors.New("Insufficient closing funds, please contact the administrator.") + ErrPublicFour = errors.New("Please enter a valid order number.") + ErrPublicFive = errors.New("Failed to place order, incorrect delegation method.") + ErrPublicSix = errors.New("Parameter error.") + ErrPublicServe = errors.New("You have an unpaid IPO allotment order pending. Please complete the payment soon for the new stock listing. Happy investing!") +) + +// Transaction system prompt language configuration +var ( + ErrNetWorkMessage = errors.New("Network issue, failed to place order, please try again.") + ErrPriceUpdate = errors.New("Quote update, please resubmit!") + ErrMySqlDB = errors.New("Data anomaly detected. Please contact customer service for assistance.") // Data exception, please contact customer service for handling - database exception + ErrPosition = errors.New("Price discrepancy detected. Please resubmit your request!") // Exception - Error reported due to inability to obtain market information: (quotation exception, please resubmit!) - Place order | close position | one click close position | cancel order | Set stop profit and stop loss + ErrStopTread = errors.New("Market closed. Trading temporarily suspended.") // Reminder for stock market not yet open and no pre - and post market prices set in the background: (closed time, trading suspended) - Place order | close position | one click close position + ErrBuyStopWinPrice = errors.New("Place an order with a limit price increase, and the stop profit price must be greater than the limit price.") // When placing an order with a limit price increase, the stop profit price must be greater than the limit price + ErrBuyStopLossPrice = errors.New("Place an order with a limit price increase, and the stop loss price must be less than the limit price.") // Limit price buy up order, stop loss price must be less than the limit price + ErrSellStopWinPrice = errors.New("Limit price buy down order, stop profit price must be less than the limit price.") // Limit price buy down order, stop profit price must be less than the limit price + ErrSellStopLossPrice = errors.New("Limit price buy down order, stop loss price must be greater than the limit price.") // Limit price buy down order, stop loss price must be greater than the limit price + ErrTokenError = errors.New("redis: nil") // token absent + ErrTokenMessage = errors.New("Token validation error.") // token abnormal + ErrIsReal = errors.New("No real name authentication.") // Real name authentication + ErrIsParameter = errors.New("Incorrect parameter verification.") // Parameter verification error + ErrCacheDB = errors.New("Cache data exception, please contact the administrator.") // Cache data exception, please contact the administrator. +) + +var ( + ErrBuyStopWinPriceOption = errors.New("Bullish orders with a stop profit price greater than the buy price.") // 看涨下单,止盈价大于买一价 + ErrBuyStopLossPriceOption = errors.New("Place a bullish order with a stop loss price lower than the selling price.") // 看涨下单,止损价小于卖一价 + ErrBuyLimitPriceOption = errors.New("Bullish orders, opening price less than selling price.") // 看涨下单,开仓价格小于卖一价 + ErrSellStopWinPriceOption = errors.New("Place a bearish order with a stop profit price lower than the sell price.") // 看跌下单,止盈价小于卖一价 + ErrSellStopLossPriceOption = errors.New("Place a bearish order with a stop loss price greater than the buy price.") // 看跌下单,止损价大于买一价 + ErrSellLimitPriceOption = errors.New("Bullish orders, opening price greater than buy price.") // 看涨下单,开仓价格大于买一价 + +) + +var ( + ErrOrderOne = errors.New("Wrong transaction type for placing an order.") + ErrOrderTow = errors.New("Please enter the correct stock market.") + ErrOrderThree = errors.New("Error in obtaining commission return relationship.") + ErrOrderFour = errors.New("Error in obtaining user commission information.") + ErrOrderFive = errors.New("The return commission type is incorrect. Please contact the administrator.") + ErrOrderSix = errors.New("Error in obtaining user commission level relationship.") + ErrOrderSeven = errors.New("NewHTTPServer:Please enter the initialized environment variable.") +) + +// Spot reminder +var ( + ErrSpotMsgOne = errors.New("Wrong delegation method, failed to place order.") + ErrSpotMsgTow = errors.New("Failed to write transaction details table.") + ErrSpotsMsgThree = errors.New("One click spot exchange error, please contact the administrator.") + ErrSpotsMsgFour = errors.New("Market price order type error.") + ErrSpotsMsgSix = errors.New("The amount does not meet the order requirements.") + ErrSpotsMsgSeven = errors.New("Failed to place order, incorrect transaction type.") +) + +// Contract reminder language +var ( + ErrContractOne = errors.New("Error in obtaining contract face value.") + ErrContractTow = errors.New("Contract leverage setting error.") + ErrContractThree = errors.New("There is an error in placing the order transaction, please check.") + ErrContractFive = errors.New("Contract closing error, please contact the administrator.") + ErrContractSeven = errors.New("The contract cancellation data is incorrect.") + ErrContractEight = errors.New("Error in obtaining the optimal closing price for the current transaction, closing failed. Please contact the administrator.") + ErrContractTen = errors.New("Set stop profit and stop loss, and stop profit and stop loss cannot both be zero.") + ErrContractEleven = errors.New("Error in modifying stop loss and stop gain settings.") + ErrContractTwelve = errors.New("Failed to place order, wrong transaction type.") + ErrContractThirteen = errors.New("Failed to place order, incorrect stop loss and stop gain settings.") +) + +// Stock reminder language +var ( + ErrShareOne = errors.New("Sufficient funds, please recharge.") + ErrShareTow = errors.New("Share closing error, please share the administrator.") + ErrShareThree = errors.New("Insufficient frozen assets in stocks.") + ErrShareFour = errors.New("Error setting order.") + ErrShareFive = errors.New("Closing error, please contact the administrator.") + ErrShareSeven = errors.New("During a calm period, trading is prohibited.") + ErrShareNine = errors.New("Insufficient USD frozen assets in stocks.") + ErrShareSix = errors.New("Order parameters incorrect") + ErrShareTen = errors.New("Order market identification error.") +) diff --git a/internal/pkg/flags/share.go b/internal/pkg/flags/share.go new file mode 100644 index 0000000..fa9f4db --- /dev/null +++ b/internal/pkg/flags/share.go @@ -0,0 +1,132 @@ +package flags + +var ( + // 股票交易|杠杆判定 + SetZero = "0" // 判定杠杆值是否为零 + SetOne = "1" // 交易开启|默认值(数字币面值|股票杠杆) + SetTwo = "2" // 交易关闭 + SetThree = "3" // 值等于3时通过,[其他值|没有]则不通过 + + // 股票闭盘涨跌幅标识 + UpLimit = "up" // 涨停 + DownLimit = "down" // 跌停 + + // 股票各个市场 + UsMarket = "3" // 美股--T+0 + IdnMarket = "4" // 印尼--T+3 + MysMarket = "5" // 马股--T+1 + ThaMarket = "6" // 泰股--T+2 + InrMarket = "7" // 印度--T+0 + SgdMarket = "9" // 新加坡--T+2 + OpiMarket = "11" // 期权印度--T+0 + HkdMarket = "12" // 香港--T+0 + GbxMarket = "14" // 英国--T+0 + FurMarket = "15" // 法国--T+0 + EurMarket = "16" // 德国--T+0 + BrlMarket = "17" // 巴西--T+0 + JpyMarket = "18" // 日本--T+0 + + // 大宗交易系统设置 + UsBlk = "US:BLOCK:LIST:" // 大宗(美股)交易 + ThaBlk = "THA:BLOCK:LIST:" // 大宗(泰股)交易 + MysBlk = "MYS:BLOCK:LIST:" // 大宗(马股)交易 + IdnBlk = "IDN:BLOCK:LIST:" // 大宗(印尼股)交易 + InBlk = "IN:BLOCK:LIST:" // 大宗(印度股)交易 + SgdBlk = "SGD:BLOCK:LIST:" // 大宗(新加坡股)交易 + HkdBlk = "HKD:BLOCK:LIST:" // 大宗(港股)交易 + GbxBlk = "GBX:BLOCK:LIST:" // 大宗(英股)交易 + FurBlk = "FUR:BLOCK:LIST" // 大宗(法股)交易 + EurBlk = "EUR:BLOCK:LIST" // 大宗(德股)交易 + BrlBlk = "BRL:BLOCK:LIST" // 大宗(巴西股)交易 + JpyBlk = "JPY:BLOCK:LIST" // 大宗(日本股)交易 + + // 平仓时间设置[T+0,T+1,T+2.....],下单交易设置 + CloseOne = "1" + CloseTwo = "2" + CloseThree = "3" + CloseFour = "4" + + // 订阅行情-国家名称 + CountryUs = "US" // 美股 + CountryMys = "Malaysia" // 马股 + CountryIdn = "Indonesia" // 印尼股 + CountryTha = "Thailand" // 泰股 + CountryInr = "India" // 印度股 + CountrySgd = "Singapore" // 新加坡股 + CountryHkd = "HongKong" // 港股 + CountryGbx = "UK" // 英股 + CountryEur = "Germany" // 德股 + CountryFur = "France" // 法股 + CountryBrl = "Brazil" // 巴西股 + CountryJpy = "Japan" // 日本股 + CountryOptionInr = "Option:India:List:" // 期权印度股 + + // 股票系统全局缓存配置 + StockMarketList = "STOCK_MARKET:LIST:" // 股票市场阈值设置 + StockTradePrices = "STOCK_PRICES:" // 股票市场盘前|盘后下单设置 + StockTradePryNum = "USER:LEVER_STATUS:" // 股票用户杠杆是否开启(数值为3通过) + StockTradePryNumSet = "LEVERAGE:" // 股票用户杠杆设置 + StockIpoList = "USER:ARREAR:ORDER:" // 用户IPO未支付订单OrderNo + + StockUsSystemSetUpKey = "US:STOCK:LIST:" // 股票-美股阈值设置 + ShareUsClosingPriceKey = "Stock:US:ClosePrice" // 股票-美股闭盘价格 + ShareUsClosingNewPriceKey = "Stock:US:CloseNewPrice" // 股票-美股上次闭盘价格 + ShareUsBeforeClose = "Stock:US:BeforeClose" // 股票-美股当天开盘价格 + + StockUkSystemSetUpKey = "UK:STOCK:LIST:" // 股票-英股阈值设置 + ShareUkClosingPriceKey = "Stock:UK:ClosePrice" // 股票-英股闭盘价格 + ShareUkClosingNewPriceKey = "Stock:UK:CloseNewPrice" // 股票-英股上次闭盘价格 + ShareUkBeforeClose = "Stock:UK:BeforeClose" // 股票-英股当天开盘价格 + + StockMGSystemSetUpKey = "MYS:STOCK:LIST:" // 股票-马股阈值设置 + ShareMalaysiaClosingPriceKey = "Stock:Malaysia:ClosePrice" // 股票-马股闭盘价格 + ShareMalaysiaClosingNewPriceKey = "Stock:Malaysia:CloseNewPrice" // 股票-马股上次闭盘价格 + ShareMalaysiaBeforeClose = "Stock:Malaysia:BeforeClose" // 股票-马股当天开盘价格 + + StockTGSystemSetUpKey = "THA:STOCK:LIST:" // 股票-泰股阈值设置 + ShareThailandClosingPriceKey = "Stock:Thailand:ClosePrice" // 股票-泰股闭盘价格 + ShareThailandClosingNewPriceKey = "Stock:Thailand:CloseNewPrice" // 股票-泰股上次闭盘价格 + ShareThailandBeforeClose = "Stock:Thailand:BeforeClose" // 股票-泰股当天开盘价格 + + StockYNSystemSetUpKey = "IDN:STOCK:LIST:" // 股票-印尼阈值设置 + ShareIndonesiaClosingPriceKey = "Stock:Indonesia:ClosePrice" // 股票-印尼闭盘价格 + ShareIndonesiaClosingNewPriceKey = "Stock:Indonesia:CloseNewPrice" // 股票-印尼上次闭盘价格 + ShareIndonesiaBeforeClose = "Stock:Indonesia:BeforeClose" // 股票-印尼股当天开盘价格 + + StockYDSystemSetUpKey = "IN:STOCK:LIST:" // 股票-印度阈值设置 + ShareIndiaClosingPriceKey = "Stock:India:ClosePrice" // 股票-印度闭盘价格 + ShareIndiaClosingNewPriceKey = "Stock:India:CloseNewPrice" // 股票-印度上次闭盘价格 + ShareIndiaBeforeClose = "Stock:India:BeforeClose" // 股票-印度股当天开盘价格 + + StockSGDSystemSetUpKey = "SGD:STOCK:LIST:" // 股票-新加坡股阈值设置 + ShareSingaporeClosingPriceKey = "Stock:Singapore:ClosePrice" // 股票-新加坡股闭盘价格 + ShareSingaporeClosingNewPriceKey = "Stock:Singapore:CloseNewPrice" // 股票-新加坡股上次闭盘价格 + ShareSingaporeBeforeClose = "Stock:Singapore:BeforeClose" // 股票-新加坡股当天开盘价格 + + StockEURSystemSetUpKey = "EUR:STOCK:LIST:" // 股票-德股阈值设置 + ShareGermanyClosingPriceKey = "Stock:Germany:ClosePrice" // 股票-德股闭盘价格 + ShareGermanyClosingNewPriceKey = "Stock:Germany:CloseNewPrice" // 股票-德股上次闭盘价格 + ShareGermanyBeforeClose = "Stock:Germany:BeforeClose" // 股票-德股当天开盘价格 + + StockBRLSystemSetUpKey = "BR:STOCK:LIST:" // 股票-巴西股阈值设置 + ShareBrazilClosingPriceKey = "Stock:Brazil:ClosePrice" // 股票-巴西股闭盘价格 + ShareBrazilClosingNewPriceKey = "Stock:Brazil:CloseNewPrice" // 股票-巴西股上次闭盘价格 + ShareBrazilBeforeClose = "Stock:Brazil:BeforeClose" // 股票-巴西股当天开盘价格 + + StockFURSystemSetUpKey = "FUR:STOCK:LIST:" // 股票-法股阈值设置 + ShareFranceClosingPriceKey = "Stock:France:ClosePrice" // 股票-法股闭盘价格 + ShareFranceClosingNewPriceKey = "Stock:France:CloseNewPrice" // 股票-法股上次闭盘价格 + ShareFranceBeforeClose = "Stock:France:BeforeClose" // 股票-法股当天开盘价格 + + StockJPYSystemSetUpKey = "JPY:STOCK:LIST:" // 股票-日股阈值设置 + ShareJapanClosingPriceKey = "Stock:Japan:ClosePrice" // 股票-日股闭盘价格 + ShareJapanClosingNewPriceKey = "Stock:Japan:CloseNewPrice" // 股票-日股上次闭盘价格 + ShareJapanBeforeClose = "Stock:Japan:BeforeClose" // 股票-日股当天开盘价格 + + StockHKDSystemSetUpKey = "HKD:STOCK:LIST:" // 股票-香港股阈值设置 + ShareHongKongClosingPriceKey = "Stock:HongKong:ClosePrice" // 股票-香港股闭盘价格 + ShareHongKongClosingNewPriceKey = "Stock:HongKong:CloseNewPrice" // 股票-香港股上次闭盘价格 + ShareHongKongBeforeClose = "Stock:HongKong:BeforeClose" // 股票-香港股当天开盘价格 + + OptionOpiSystemSetUpKey = "OPI:OPTION:LIST:" // 期权-印度股票阈值设置 +) diff --git a/internal/pkg/flags/system.go b/internal/pkg/flags/system.go new file mode 100644 index 0000000..cc6a8c4 --- /dev/null +++ b/internal/pkg/flags/system.go @@ -0,0 +1,275 @@ +package flags + +var ( + // 系统程序常量配置 + SetNull = "" // 系统空字符设置 + CheckNetwork = "" // 网络环境 + CheckEnvironment = "" // 服务环境 + CheckTest = "test" // 测试环境 + CheckOnLine = "onLine" // 线上环境 + TokenTest = "Authorization" // 测试token + TokenOnLine = "token" // 线上token + CheckSetting = true // 设置网络环境 + CheckAdminService = "" // 设置管理员交易订阅 + + // 时间格式转换 + TimeFormat = "2006-01-02" // 时间序列格式 + TimeLayout = "2006-01-02 15:04:05.000" // 时间序列格式 + LayoutTime = "2006-01-02 15:04:05" // 时间序列格式 + LayoutZero = "2006-01-02 00:00:00" // 时间序列格式 + LayoutOne = "15:04" // 时间序列格式 + + // 秒合约: 0-平局, 1-盈利, 2-亏损 + OrderSetZero = 0 + OrderSetOne = 1 + OrderSetTwo = 2 + + // 系统配比设置 + SetPreOne = 1 // 新股申购默认值为1 + MinDifference = 0.0001 // (合约|股票)设置价差 + MaxDifference = 0.0005 // (合约|股票)设置价差 + AdministratorsId = int64(9999999999) // 管理员用户 + ForcedClosure = "0.7" // 默认强平阈值 + ForcedRate = "0.3" // 保证金比例 + OrderCheck = "0.01" // 设置下单资金判定比例 + LimitTen = "10" // 设置止盈止损-涨跌幅 + DecimalOne = "100" // 默认阈值 + + // 用户Token + UserToken = "TOKEN:USER:" // 用户调用服务身份校验 + UserLevel = "USER:LEVEL:" // 用户返佣级别关系 + RegSetting = "BROKERAGE:REG:SETTING" // 注冊返佣 + BuySetting = "BROKERAGE:BUY:SETTING" // 开仓返佣 + SaleSetting = "BROKERAGE:SALE:SETTING" // 平仓返佣 + + // (数字币|股票)最小基本单位 + BasicUnit = "USDT" // 数字币最小基本单位 + ForexUnit = "USD" // 外汇最小基本单位 + MoneyUnit = "USD" // 综合最小基本单位 + ShareUsBasicUnit = "USD" // 美股最小基本单位 + ShareMysBasicUnit = "MYR" // 马股最小基本单位 + ShareThaBasicUnit = "THB" // 泰股最小基本单位 + ShareIdnBasicUnit = "IDR" // 印尼股最小基本单位 + ShareInrBasicUnit = "INR" // 印度股最小基本单位 + ShareSgdBasicUnit = "SGD" // 新加坡股最小基本单位 + ShareHkdBasicUnit = "HKD" // 港股最小基本单位 + ShareGbxBasicUnit = "GBX" // 英股最小基本单位 + ShareEurBasicUnit = "EUR" // 德股最小基本单位 + ShareFurBasicUnit = "EUR" // 法股最小基本单位 + ShareBrlBasicUnit = "BRL" // 巴西股最小基本单位 + ShareJpyBasicUnit = "JPY" // 日股最小基本单位 + OptionInrBasicUnit = "INR" // 期权-印度股最小基本单位 + + // 系统分类启动服务名称 + CheckSymbolInit = "digitalInit" // 交易对初始化 + CheckShareInit = "shareInit" // 股票代码初始化 + CheckCacheInit = "shareCache" // 初始化订单缓存 + CheckClearInit = "shareClearCache" // 清理缓存订单 + CheckByOrderNoInit = "checkByOrderNo" // 恢复OrderNo匹配OrderId + CheckSport = "spots" // 现货服务 + CheckContract = "contract" // 合约服务 + CheckSecond = "second" // 秒合约服务 + CheckForex = "forex" // 外汇服务 + CheckMoney = "money" // 综合服务 + CheckShareUs = "shareUs" // 美股服务 + CheckShareMys = "shareMys" // 马股服务 + CheckShareTha = "shareTha" // 泰股服务 + CheckShareIdn = "shareIdn" // 印尼股服务 + CheckShareInr = "shareInr" // 印度股服务 + CheckShareSgd = "shareSgd" // 新加坡股服务 + CheckShareHkd = "shareHkd" // 港股服务 + CheckShareGbx = "shareGbx" // 英股服务 + CheckShareEur = "shareEur" // 德股服务 + CheckShareFur = "shareFur" // 法股服务 + CheckShareBrl = "shareBrl" // 巴西股服务 + CheckShareJpy = "shareJpy" // 日股服务 + CheckShareBlk = "shareBlk" // 大宗交易服务 + CheckAdmin = "admin" // 管理员订单订阅服务 + CheckAdminBlk = "adminBlk" // 管理员大宗交易订单订阅服务 + CheckOptionInr = "optionInr" // 期权印度股用户订阅服务 + CheckBackend = "backend" // 后台数据服务 + + // 订单Wss订阅类型 + AdminWss = "order-wss" // 管理员订单订阅 + AdminBlkWss = "order-block-wss" // 管理员大宗交易订单订阅 + SpotsWss = "order-spots-wss" // 现货订单订阅 + ContractWss = "order-contract-wss" // 合约订单订阅 + SecondWss = "order-second-wss" // 秒合约订阅 + ForexWss = "order-forex-wss" // 外汇订阅 + MoneyWss = "order-money-wss" // 综合订阅 + ShareUsWss = "order-shareUs-wss" // 美股订单订阅 + ShareMysWss = "order-shareMys-wss" // 马股订单订阅 + ShareThaWss = "order-shareTha-wss" // 泰股订单订阅 + ShareIdnWss = "order-shareIdn-wss" // 印尼股订单订阅 + ShareInrWss = "order-shareInr-wss" // 印度股订单订阅 + ShareSgdWss = "order-shareSgd-wss" // 新加坡股订单订阅 + ShareHkdWss = "order-shareHkd-wss" // 港股订单订阅 + ShareGbxWss = "order-shareGbx-wss" // 英股订单订阅 + ShareEurWss = "order-shareEur-wss" // 德股订单订阅 + ShareFurWss = "order-shareFur-wss" // 法股订单订阅 + ShareBrlWss = "order-shareBrl-wss" // 巴西股订单订阅 + ShareJpyWss = "order-shareJpy-wss" // 日股订单订阅 + ShareBlkWss = "order-shareBlk-wss" // 大宗交易订单订阅 + OptionInrWss = "order-optionInr-wss" // 印度期权股用户订单订阅 + + // (现货|合约)系统配置 + SpotsSystemSetUpKey = "DIGITAL:LIST:" // 现货阈值设置 + ContractSystemSetUpKey = "CONTRACT:LIST:" // 合约阈值设置 + ForexSystemSetUpKey = "FOREX:LIST:" // 外汇阈值设置 + ContractSystemPriceSetUp = "contract_hq_setting" // 合约插针设置 + ContractSystemSecond = "contract_time_setting" // 秒合约设置 + + // (数字币|股票)市价订阅标识 + Xh = "xh" // 现货(xh) + Hy = "hy" // 合约(hy) + Sd = "sd" // 秒合约 + Zh = "zh" // 综合 + Wh = "wh" // 外汇 + Us = "us" // 美股(us) + Mys = "mys" // 马股(mys) + Tha = "tha" // 泰股(tha) + Idn = "idn" // 印尼股(idn) + Inr = "inr" // 印度股(inr) + Sgd = "sgd" // 新加坡股(sgd) + Hkd = "hkd" // 港股(hkd) + Gbx = "gbx" // 英股(gbx) + Eur = "eur" // 德股(eur) + Fur = "fur" // 法股(fur) + Brl = "brl" // 巴西股(brl) + Jpy = "Jpy" // 日股(Jpy) + Opi = "opi" // 期权-印度股(opi) + OpiStk = "opiStk" // 期权-行权价(opiStk) + + // 管理员订阅(数字币|股票)浮动盈亏key + FloatingHy = "floating-Hy" // 合约 + FloatingWh = "floating-Wh" // 外汇 + FloatingZh = "floating-Zh" // 综合 + FloatingUs = "floating-Us" // 美股 + FloatingMys = "floating-Mys" // 马股 + FloatingTha = "floating-Tha" // 泰股 + FloatingIdn = "floating-Idn" // 印尼股 + FloatingInr = "floating-Inr" // 印度股 + FloatingSgd = "floating-Sgd" // 新加坡股 + FloatingHkd = "floating-Hkd" // 港股 + FloatingGbx = "floating-Gbx" // 英股 + FloatingEur = "floating-Eur" // 德股 + FloatingFur = "floating-Fur" // 法股 + FloatingBrl = "floating-Brl" // 巴西股 + FloatingJpy = "floating-Jpy" // 日股 + FloatingOpi = "floating-Opi" // 期权印度股 + FloatingBlk = "floating-Blk" // 大宗交易股 + + // 订单状态字符串类型 + Entrust = "0" // 挂单(委托) + Position = "1" // 持仓订单 + Cancel = "2" // 已撤单 + Close = "3" // 完成订单 + StrongParity = "4" // 强平订单 + + // 期权交易 + OptionCalls = int64(1) + OptionPuts = int64(2) + OptionBuy = int64(1) + OptionSell = int64(2) +) + +// (数字币|股票)价格设置取值 +const ( + RealTime = 1 // 市价行情订阅 + SetUp = 2 // 盘前|盘后价格设置 +) + +// 操作类型 +const ( + OpenBrokType = 1 // 开仓 + ClosingBrokType = 2 // 平仓 +) + +// 市场类型 +const ( + SpotsMarketType = 1 // 现货 + ContractMarketType = 2 // 合约 + ShareUsMarketType = 3 // 美股 + ShareIdnMarketType = 4 // 印尼 + ShareMysMarketType = 5 // 马股 + ShareThaMarketType = 6 // 泰股 + ShareInrMarketType = 7 // 印度 + ShareSgdMarketType = 9 // 新加坡 + OptionInrMarketType = 11 // 期权-印度股 + ShareHkdMarketType = 12 // 港股 + ShareGbxMarketType = 14 // 英股 + ShareFurMarketType = 15 // 法股 + ShareEurMarketType = 16 // 德股 + ShareBrlMarketType = 17 // 巴西股 + ShareJpyMarketType = 18 // 日股 + ForexMarketType = 19 // 外汇 +) + +// 返佣类型 +const ( + Register = iota // 注册 + OpenPosition // 开仓 + ClosingPosition // 平仓 +) + +// 手续费类型 +const ( + FixedCosts = iota // 固定费用 + RatioCosts // 按比例结算 + FixCosts // 按张结算 +) + +// 交易类型 +const ( + TradeTypePrice = iota // 价格 + TradeTypeBuy // 买入价格 + TradeTypeSell // 卖出价格 + TradeTypeChg // 涨跌幅价差 + TradeTypeClosePrice // 闭盘价格 + TradeTypeForcedClosure // 强平阈值 + TradeTypeAdminPrice // 管理员订阅缓存key +) + +const ( + OptionPrice = 0 // 期权-交易价格 + OptionBid = 1 // 期权-买一价 + OptionAsk = 2 // 期权-卖一价 +) + +// 委托方式 +const ( + DealTypeLimited = 1 // 限价 + DealTypeMarket = 2 // 市价 +) + +// 止损止盈设置 +const ( + StopTypeNone = iota // 无设置 + StopTypeSet // 止损止盈 +) + +// 返佣层级界定 +const ( + ParentId = 1 + GrandpaId = 2 + TopId = 3 +) + +// 订单状态整型 +const ( + EntrustStatus = iota // 挂单(委托) + PositionStatus // 持仓订单 + CancelStatus // 已撤单 + CloseStatus // 完成订单 +) + +// 用户资金变动类型 +const ( + Freeze = 5 // 冻结 + Thaw = 6 // 解冻 + TransferOut = 7 // 账户转出 + ChangeInto = 8 // 账户转入 + OpenMRebate = 10 // 开仓返佣 + CloseMRebate = 11 // 平仓返佣 + CostMoney = 14 // 手续费 +) diff --git a/internal/pkg/flags/table.go b/internal/pkg/flags/table.go new file mode 100644 index 0000000..0ca2b23 --- /dev/null +++ b/internal/pkg/flags/table.go @@ -0,0 +1,113 @@ +package flags + +var ( + BotBrokerageSetting = "bot_brokerage_setting" + BotContractList = "bot_contract_list" + BotContractTrade = "bot_contract_trade" + BotContractSecTrade = "bot_contract_sec_trade" + BotDigitalList = "bot_digital_list" + BotDigitalTrade = "bot_digital_trade" + BotFeeSetting = "bot_fee_setting" + BotTradeFee = "bot_trade_fee" + BotUserBrokerage = "bot_user_brokerage" + BotUserLevel = "bot_user_level" + BotUsers = "bot_users" + BotUserArrears = "bot_user_arrears" + // 股票代码列表 + BotStockList = "bot_stock_list" + BotForexList = "bot_forex_list" + BotStockMysList = "bot_stock_mys_list" + BotStockThaList = "bot_stock_tha_list" + BotStockIdnList = "bot_stock_idn_list" + BotStockInList = "bot_stock_in_list" + BotStockSgdList = "bot_stock_sgd_list" + BotStockHkdList = "bot_stock_hkd_list" + BotStockGbxList = "bot_stock_gbx_list" + BotStockEurList = "bot_stock_eur_list" + BotStockFurList = "bot_stock_fur_list" + BotStockBrlList = "bot_stock_brl_list" + BotStockJpyList = "bot_stock_jp_list" + BotStockBlockList = "bot_stock_block_list" + BotStockOptionInrList = "bot_stock_option_inr_list" + // 股票交易订单列表 + BotStockTrade = "bot_stock_trade" + BotForexTrade = "bot_forex_trade" + BotMoneyTrade = "bot_money_trade" + BotStockMysTrade = "bot_stock_mys_trade" + BotStockThaTrade = "bot_stock_tha_trade" + BotStockIdnTrade = "bot_stock_idn_trade" + BotStockInTrade = "bot_stock_in_trade" + BotStockSgdTrade = "bot_stock_sgd_trade" + BotStockHkdTrade = "bot_stock_hkd_trade" + BotStockGbxTrade = "bot_stock_gbx_trade" + BotStockEurTrade = "bot_stock_eur_trade" + BotStockFurTrade = "bot_stock_fur_trade" + BotStockBrlTrade = "bot_stock_brl_trade" + BotStockJpyTrade = "bot_stock_jp_trade" + BotStockBlockTrade = "bot_stock_block_trade" + BotStockOptionInrTrade = "bot_stock_option_inr_trade" + // 股票交易资金和交易日志列表 + BotUserMoney = "bot_user_money" + BotUserMoneyLog = "bot_user_money_log" + BotUserForex = "bot_user_forex" + BotUserForexLog = "bot_user_forex_log" + BotUserContract = "bot_user_contract" + BotUserContractLog = "bot_user_contract_log" + BotUserContractSec = "bot_user_contract_sec" + BotUserContractSecLog = "bot_user_contract_sec_log" + BotUserDigital = "bot_user_digital" + BotUserDigitalLog = "bot_user_digital_log" + BotUserStock = "bot_user_stock" + BotUserStockLog = "bot_user_stock_log" + BotUserStockIdn = "bot_user_stock_idn" + BotUserStockIdnLog = "bot_user_stock_idn_log" + BotUserStockMys = "bot_user_stock_mys" + BotUserStockMysLog = "bot_user_stock_mys_log" + BotUserStockTha = "bot_user_stock_tha" + BotUserStockThaLog = "bot_user_stock_tha_log" + BotUserStockIn = "bot_user_stock_in" + BotUserStockInLog = "bot_user_stock_in_log" + BotUserStockSgd = "bot_user_stock_sgd" + BotUserStockSgdLog = "bot_user_stock_sgd_log" + BotUserStockHkd = "bot_user_stock_hkd" + BotUserStockHkdLog = "bot_user_stock_hkd_log" + BotUserStockGbx = "bot_user_stock_gbx" + BotUserStockGbxLog = "bot_user_stock_gbx_log" + BotUserStockEur = "bot_user_stock_eur" + BotUserStockEurLog = "bot_user_stock_eur_log" + BotUserStockFur = "bot_user_stock_fur" + BotUserStockFurLog = "bot_user_stock_fur_log" + BotUserStockJpy = "bot_user_stock_jp" + BotUserStockJpyLog = "bot_user_stock_jp_log" + BotUserStockBrl = "bot_user_stock_brl" + BotUserStockBrlLog = "bot_user_stock_brl_log" + BotUserStockBlockLog = "bot_user_stock_block_log" + BotUserStockOptionInr = "bot_user_stock_option_inr" + BotUserStockOptionInrLog = "bot_user_stock_option_inr_log" + // IPO订单列表 + BotUserIdnPreStockOrder = "bot_user_idn_pre_stock_order" + BotUserMysPreStockOrder = "bot_user_mys_pre_stock_order" + BotUserThaPreStockOrder = "bot_user_tha_pre_stock_order" + BotUserUsPreStockOrder = "bot_user_us_pre_stock_order" + BotUserInPreStockOrder = "bot_user_in_pre_stock_order" + BotUserSgdPreStockOrder = "bot_user_sgd_pre_stock_order" + BotUserHkdPreStockOrder = "bot_user_hkd_pre_stock_order" + BotUserGbxPreStockOrder = "bot_user_gbx_pre_stock_order" + BotUserEurPreStockOrder = "bot_user_eur_pre_stock_order" + BotUserFurPreStockOrder = "bot_user_fur_pre_stock_order" + BotUserBrlPreStockOrder = "bot_user_brl_pre_stock_order" + BotUserJpyPreStockOrder = "bot_user_jp_pre_stock_order" + + BotUserIdnGiveStockOrder = "bot_user_idn_give_stock_order" + BotUserMysGiveStockOrder = "bot_user_mys_give_stock_order" + BotUserThaGiveStockOrder = "bot_user_tha_give_stock_order" + BotUserUsGiveStockOrder = "bot_user_us_give_stock_order" + BotUserInGiveStockOrder = "bot_user_in_give_stock_order" + BotUserSgdGiveStockOrder = "bot_user_sgd_give_stock_order" + BotUserGbxGiveStockOrder = "bot_user_gbx_give_stock_order" + BotUserHkdGiveStockOrder = "bot_user_hkd_give_stock_order" + BotUserEurGiveStockOrder = "bot_user_eur_give_stock_order" + BotUserFurGiveStockOrder = "bot_user_fur_give_stock_order" + BotUserBrlGiveStockOrder = "bot_user_brl_give_stock_order" + BotUserJpyGiveStockOrder = "bot_user_jp_give_stock_order" +) diff --git a/internal/pkg/gzip/gzip.go b/internal/pkg/gzip/gzip.go new file mode 100644 index 0000000..02f6a01 --- /dev/null +++ b/internal/pkg/gzip/gzip.go @@ -0,0 +1,61 @@ +package gzip + +import ( + "bytes" + "compress/gzip" + "io" +) + +// GUnzipData 解压数据 +// +// @Description: +// @param data +// @return resData +// @return err +func GUnzipData(data []byte) (resData []byte, err error) { + b := bytes.NewBuffer(data) + + var r io.Reader + r, err = gzip.NewReader(b) + if err != nil { + return + } + + var resB bytes.Buffer + _, err = resB.ReadFrom(r) + if err != nil { + return + } + + resData = resB.Bytes() + + return +} + +// GZipData 压缩数据 +// +// @Description: +// @param data +// @return compressedData +// @return err +func GZipData(data []byte) (compressedData []byte, err error) { + var b bytes.Buffer + gz := gzip.NewWriter(&b) + + _, err = gz.Write(data) + if err != nil { + return + } + + if err = gz.Flush(); err != nil { + return + } + + if err = gz.Close(); err != nil { + return + } + + compressedData = b.Bytes() + + return +} diff --git a/internal/pkg/gzip/gzip_test.go b/internal/pkg/gzip/gzip_test.go new file mode 100644 index 0000000..1b5dfd0 --- /dev/null +++ b/internal/pkg/gzip/gzip_test.go @@ -0,0 +1,103 @@ +package gzip + +import ( + "encoding/json" + "fmt" + "log" + "reflect" + "testing" +) + +// TestGzip +// +// @Description: +// @param t +func TestGzip(t *testing.T) { + var strList = []string{"hello", "world", "0123", "456", "789"} + data, err := json.Marshal(strList) + if err != nil { + print(err) + } + + // define original data + fmt.Println("original data:", data) + fmt.Println("original data len:", len(data)) + + // 压缩数据信息 + compressedData, err := GZipData(data) + if err != nil { + log.Fatal(err) + } + + fmt.Println("compressed data:", compressedData) + fmt.Println("compressed data len:", len(compressedData)) + + // 解压数据信息 + uncompressedData, err := GUnzipData(compressedData) + if err != nil { + log.Fatal(err) + } + + fmt.Println("uncompressed data:", string(uncompressedData)) + fmt.Println("uncompressed data len:", len(uncompressedData)) +} + +// TestGUnzipData 测试解压数据 +// +// @Description: +// @param t +func TestGUnzipData(t *testing.T) { + type args struct { + data []byte + } + tests := []struct { + name string + args args + wantResData []byte + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + gotResData, err := GUnzipData(tt.args.data) + if (err != nil) != tt.wantErr { + t.Errorf("GUnzipData() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(gotResData, tt.wantResData) { + t.Errorf("GUnzipData() gotResData = %v, want %v", gotResData, tt.wantResData) + } + }) + } +} + +// TestGZipData 测试压缩数据 +// +// @Description: +// @param t +func TestGZipData(t *testing.T) { + type args struct { + data []byte + } + tests := []struct { + name string + args args + wantCompressedData []byte + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + gotCompressedData, err := GZipData(tt.args.data) + if (err != nil) != tt.wantErr { + t.Errorf("GZipData() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(gotCompressedData, tt.wantCompressedData) { + t.Errorf("GZipData() gotCompressedData = %v, want %v", gotCompressedData, tt.wantCompressedData) + } + }) + } +} diff --git a/internal/pkg/logging/applogger/applogger.go b/internal/pkg/logging/applogger/applogger.go new file mode 100644 index 0000000..f182a39 --- /dev/null +++ b/internal/pkg/logging/applogger/applogger.go @@ -0,0 +1,92 @@ +package applogger + +import ( + "go.uber.org/zap" + "go.uber.org/zap/zapcore" + "os" +) + +var sugaredLogger *zap.SugaredLogger +var atomicLevel zap.AtomicLevel + +// init +// +// @Description: +func init() { + encoderCfg := zapcore.EncoderConfig{ + TimeKey: "time", + MessageKey: "msg", + LevelKey: "level", + EncodeLevel: zapcore.CapitalColorLevelEncoder, + EncodeTime: zapcore.ISO8601TimeEncoder, + } + + // define default level as debug level + atomicLevel = zap.NewAtomicLevel() + atomicLevel.SetLevel(zapcore.DebugLevel) + + core := zapcore.NewCore(zapcore.NewConsoleEncoder(encoderCfg), os.Stdout, atomicLevel) + sugaredLogger = zap.New(core).Sugar() +} + +// SetLevel +// +// @Description: +// @param level +func SetLevel(level zapcore.Level) { + atomicLevel.SetLevel(level) +} + +// Fatal +// +// @Description: +// @param template +// @param args +func Fatal(template string, args ...interface{}) { + sugaredLogger.Fatalf(template, args...) +} + +// Error +// +// @Description: +// @param template +// @param args +func Error(template string, args ...interface{}) { + sugaredLogger.Errorf(template, args...) +} + +// Panic +// +// @Description: +// @param template +// @param args +func Panic(template string, args ...interface{}) { + sugaredLogger.Panicf(template, args...) +} + +// Warn +// +// @Description: +// @param template +// @param args +func Warn(template string, args ...interface{}) { + sugaredLogger.Warnf(template, args...) +} + +// Info +// +// @Description: +// @param template +// @param args +func Info(template string, args ...interface{}) { + sugaredLogger.Infof(template, args...) +} + +// Debug +// +// @Description: +// @param template +// @param args +func Debug(template string, args ...interface{}) { + sugaredLogger.Debugf(template, args...) +} diff --git a/internal/pkg/logging/applogger/applogger_test.go b/internal/pkg/logging/applogger/applogger_test.go new file mode 100644 index 0000000..b09d675 --- /dev/null +++ b/internal/pkg/logging/applogger/applogger_test.go @@ -0,0 +1,256 @@ +package applogger + +import ( + "go.uber.org/zap/zapcore" + "testing" +) + +func TestDebug(t *testing.T) { + type args struct { + template string + args []interface{} + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + Debug(tt.args.template, tt.args.args...) + }) + } +} + +func TestError(t *testing.T) { + type args struct { + template string + args []interface{} + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + Error(tt.args.template, tt.args.args...) + }) + } +} + +func TestFatal(t *testing.T) { + type args struct { + template string + args []interface{} + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + Fatal(tt.args.template, tt.args.args...) + }) + } +} + +func TestInfo(t *testing.T) { + type args struct { + template string + args []interface{} + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + Info(tt.args.template, tt.args.args...) + }) + } +} + +func TestPanic(t *testing.T) { + type args struct { + template string + args []interface{} + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + Panic(tt.args.template, tt.args.args...) + }) + } +} + +func TestSetLevel(t *testing.T) { + type args struct { + level zapcore.Level + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + SetLevel(tt.args.level) + }) + } +} + +func TestWarn(t *testing.T) { + type args struct { + template string + args []interface{} + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + Warn(tt.args.template, tt.args.args...) + }) + } +} + +func TestDebug1(t *testing.T) { + type args struct { + template string + args []interface{} + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + Debug(tt.args.template, tt.args.args...) + }) + } +} + +func TestError1(t *testing.T) { + type args struct { + template string + args []interface{} + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + Error(tt.args.template, tt.args.args...) + }) + } +} + +func TestFatal1(t *testing.T) { + type args struct { + template string + args []interface{} + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + Fatal(tt.args.template, tt.args.args...) + }) + } +} + +func TestInfo1(t *testing.T) { + type args struct { + template string + args []interface{} + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + Info(tt.args.template, tt.args.args...) + }) + } +} + +func TestPanic1(t *testing.T) { + type args struct { + template string + args []interface{} + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + Panic(tt.args.template, tt.args.args...) + }) + } +} + +func TestSetLevel1(t *testing.T) { + type args struct { + level zapcore.Level + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + SetLevel(tt.args.level) + }) + } +} + +func TestWarn1(t *testing.T) { + type args struct { + template string + args []interface{} + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + Warn(tt.args.template, tt.args.args...) + }) + } +} diff --git a/internal/pkg/logging/common/common.go b/internal/pkg/logging/common/common.go new file mode 100644 index 0000000..05174c6 --- /dev/null +++ b/internal/pkg/logging/common/common.go @@ -0,0 +1,25 @@ +package common + +// 全局日志打印设置 +const ( + ErrSpots = "ErrSpots-->" + ErrSecond = "ErrSecond-->" + ErrContract = "ErrContract-->" + ErrForex = "ErrForex-->" + ErrMoney = "ErrMoney-->" + ErrSharePre = "ErrSharePre-->" + ErrShareUs = "ErrShareUs-->" + ErrShareMys = "ErrShareMys-->" + ErrShareTha = "ErrShareTha-->" + ErrShareIdn = "ErrShareIdn-->" + ErrShareInr = "ErrShareInr-->" + ErrShareSgd = "ErrShareSgd-->" + ErrShareEur = "ErrShareEur-->" + ErrShareFur = "ErrShareFur-->" + ErrShareBrl = "ErrShareBrl-->" + ErrShareHkd = "ErrShareHkd-->" + ErrShareBlk = "ErrShareBlk-->" + ErrOptionInr = "ErrOptionInr-->" + ErrShareGbx = "ErrShareGbx-->" + ErrShareJpy = "ErrShareJpy-->" +) diff --git a/internal/pkg/logging/perflogger/performancelogger.go b/internal/pkg/logging/perflogger/performancelogger.go new file mode 100644 index 0000000..1b83ebf --- /dev/null +++ b/internal/pkg/logging/perflogger/performancelogger.go @@ -0,0 +1,104 @@ +package perflogger + +import ( + "fmt" + "log" + "matchmaking-system/internal/pkg/flags" + "os" + "strings" + "time" +) + +// The global PerformanceLogger instance +var performanceLogger *PerformanceLogger + +// The global switch for Performance logging +var logEnabled = false + +// PerformanceLogger +// @Description: +type PerformanceLogger struct { + logger *log.Logger + enable bool + file *os.File + index int + start time.Time +} + +// Enable +// +// @Description: performance logger and initialize the global instance +// @param enable +func Enable(enable bool) { + logEnabled = enable + if logEnabled && performanceLogger == nil { + performanceLogger = new(PerformanceLogger).init() + } +} + +// GetInstance +// +// @Description: +// @return *PerformanceLogger +func GetInstance() *PerformanceLogger { + return performanceLogger +} + +// init +// +// @Description: +// @receiver p +// @return *PerformanceLogger +func (p *PerformanceLogger) init() *PerformanceLogger { + if logEnabled { + var err error + fileName := time.Now().Format("20060102_150405.txt") + p.file, err = os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) + if err != nil { + log.Fatalln("Failed to open file: ", fileName) + } + p.logger = log.New(p.file, flags.SetNull, 0) + p.index = 1 + } + + return p +} + +// Start +// +// @Description: timer +// @receiver p +func (p *PerformanceLogger) Start() { + if logEnabled { + p.start = time.Now() + } +} + +// StopAndLog +// +// @Description: +// @receiver p +// @param method +// @param url +func (p *PerformanceLogger) StopAndLog(method string, url string) { + if logEnabled { + duration := time.Since(p.start).Milliseconds() + + // Strip parameters + i := strings.IndexByte(url, '?') + var path string + if i > 0 { + path = url[0:i] + } else { + path = url + } + + // Log the header before first record + if p.index == 1 { + p.logger.Println("Index, Duration(ms), URL") + } + p.logger.Println(fmt.Sprintf("%d, %d, %s %s", p.index, duration, method, path)) + + p.index++ + } +} diff --git a/internal/pkg/logging/perflogger/performancelogger_test.go b/internal/pkg/logging/perflogger/performancelogger_test.go new file mode 100644 index 0000000..ca7f67a --- /dev/null +++ b/internal/pkg/logging/perflogger/performancelogger_test.go @@ -0,0 +1,259 @@ +package perflogger + +import ( + "log" + "os" + "reflect" + "testing" + "time" +) + +func TestEnable(t *testing.T) { + type args struct { + enable bool + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + Enable(tt.args.enable) + }) + } +} + +func TestGetInstance(t *testing.T) { + tests := []struct { + name string + want *PerformanceLogger + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := GetInstance(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetInstance() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestPerformanceLogger_Start(t *testing.T) { + type fields struct { + logger *log.Logger + enable bool + file *os.File + index int + start time.Time + } + tests := []struct { + name string + fields fields + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + p := &PerformanceLogger{ + logger: tt.fields.logger, + enable: tt.fields.enable, + file: tt.fields.file, + index: tt.fields.index, + start: tt.fields.start, + } + p.Start() + }) + } +} + +func TestPerformanceLogger_StopAndLog(t *testing.T) { + type fields struct { + logger *log.Logger + enable bool + file *os.File + index int + start time.Time + } + type args struct { + method string + url string + } + tests := []struct { + name string + fields fields + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + p := &PerformanceLogger{ + logger: tt.fields.logger, + enable: tt.fields.enable, + file: tt.fields.file, + index: tt.fields.index, + start: tt.fields.start, + } + p.StopAndLog(tt.args.method, tt.args.url) + }) + } +} + +func TestPerformanceLogger_init(t *testing.T) { + type fields struct { + logger *log.Logger + enable bool + file *os.File + index int + start time.Time + } + tests := []struct { + name string + fields fields + want *PerformanceLogger + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + p := &PerformanceLogger{ + logger: tt.fields.logger, + enable: tt.fields.enable, + file: tt.fields.file, + index: tt.fields.index, + start: tt.fields.start, + } + if got := p.init(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("init() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestEnable1(t *testing.T) { + type args struct { + enable bool + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + Enable(tt.args.enable) + }) + } +} + +func TestGetInstance1(t *testing.T) { + tests := []struct { + name string + want *PerformanceLogger + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := GetInstance(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetInstance() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestPerformanceLogger_Start1(t *testing.T) { + type fields struct { + logger *log.Logger + enable bool + file *os.File + index int + start time.Time + } + tests := []struct { + name string + fields fields + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + p := &PerformanceLogger{ + logger: tt.fields.logger, + enable: tt.fields.enable, + file: tt.fields.file, + index: tt.fields.index, + start: tt.fields.start, + } + p.Start() + }) + } +} + +func TestPerformanceLogger_StopAndLog1(t *testing.T) { + type fields struct { + logger *log.Logger + enable bool + file *os.File + index int + start time.Time + } + type args struct { + method string + url string + } + tests := []struct { + name string + fields fields + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + p := &PerformanceLogger{ + logger: tt.fields.logger, + enable: tt.fields.enable, + file: tt.fields.file, + index: tt.fields.index, + start: tt.fields.start, + } + p.StopAndLog(tt.args.method, tt.args.url) + }) + } +} + +func TestPerformanceLogger_init1(t *testing.T) { + type fields struct { + logger *log.Logger + enable bool + file *os.File + index int + start time.Time + } + tests := []struct { + name string + fields fields + want *PerformanceLogger + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + p := &PerformanceLogger{ + logger: tt.fields.logger, + enable: tt.fields.enable, + file: tt.fields.file, + index: tt.fields.index, + start: tt.fields.start, + } + if got := p.init(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("init() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/pkg/middleware/auth/auth.go b/internal/pkg/middleware/auth/auth.go new file mode 100644 index 0000000..e1c96fc --- /dev/null +++ b/internal/pkg/middleware/auth/auth.go @@ -0,0 +1,98 @@ +package auth + +import ( + "context" + "errors" + "fmt" + "github.com/go-kratos/kratos/v2/middleware" + "github.com/go-kratos/kratos/v2/transport" + "github.com/golang-jwt/jwt/v4" + "strings" + "time" +) + +var currentUserKey struct{} + +type CurrentUser struct { + UserID uint +} + +// GenerateToken +// +// @Description: +// @param secret +// @param userid +// @return string +func GenerateToken(secret string, userid uint) string { + token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{ + "userid": userid, + "nbf": time.Date(2015, 10, 10, 12, 0, 0, 0, time.UTC).Unix(), + }) + + // Sign and get the complete encoded token as a string using the secret + tokenString, err := token.SignedString([]byte(secret)) + if err != nil { + panic(err) + } + return tokenString +} + +// JWTAuth +// +// @Description: +// @param secret +// @return middleware.Middleware +func JWTAuth(secret string) middleware.Middleware { + return func(handler middleware.Handler) middleware.Handler { + return func(ctx context.Context, req interface{}) (reply interface{}, err error) { + if tr, ok := transport.FromServerContext(ctx); ok { + tokenString := tr.RequestHeader().Get("Authorization") + auths := strings.SplitN(tokenString, " ", 2) + if len(auths) != 2 || !strings.EqualFold(auths[0], "Token") { + return nil, errors.New("jwt token missing") + } + + token, err := jwt.Parse(auths[1], func(token *jwt.Token) (interface{}, error) { + // Don't forget to validate the alg is what you expect: + if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok { + return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"]) + } + return []byte(secret), nil + }) + + if err != nil { + return nil, err + } + + if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid { + // put CurrentUser into ctx + if u, ok := claims["userid"]; ok { + ctx = WithContext(ctx, &CurrentUser{UserID: uint(u.(float64))}) + } + } else { + return nil, errors.New("Token Invalid") + } + } + return handler(ctx, req) + } + } +} + +// FromContext +// +// @Description: +// @param ctx +// @return *CurrentUser +func FromContext(ctx context.Context) *CurrentUser { + return ctx.Value(currentUserKey).(*CurrentUser) +} + +// WithContext +// +// @Description: +// @param ctx +// @param user +// @return context.Context +func WithContext(ctx context.Context, user *CurrentUser) context.Context { + return context.WithValue(ctx, currentUserKey, user) +} diff --git a/internal/pkg/middleware/auth/auth_test.go b/internal/pkg/middleware/auth/auth_test.go new file mode 100644 index 0000000..a96d516 --- /dev/null +++ b/internal/pkg/middleware/auth/auth_test.go @@ -0,0 +1,97 @@ +package auth + +import ( + "context" + "github.com/go-kratos/kratos/v2/middleware" + "reflect" + "testing" + + "github.com/davecgh/go-spew/spew" +) + +func TestGenerateToken(t *testing.T) { + tk := GenerateToken("matchmaking-system", 11) + spew.Dump(tk) +} + +func TestFromContext(t *testing.T) { + type args struct { + ctx context.Context + } + tests := []struct { + name string + args args + want *CurrentUser + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := FromContext(tt.args.ctx); !reflect.DeepEqual(got, tt.want) { + t.Errorf("FromContext() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGenerateToken1(t *testing.T) { + type args struct { + secret string + userid uint + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := GenerateToken(tt.args.secret, tt.args.userid); got != tt.want { + t.Errorf("GenerateToken() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestJWTAuth(t *testing.T) { + type args struct { + secret string + } + tests := []struct { + name string + args args + want middleware.Middleware + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := JWTAuth(tt.args.secret); !reflect.DeepEqual(got, tt.want) { + t.Errorf("JWTAuth() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestWithContext(t *testing.T) { + type args struct { + ctx context.Context + user *CurrentUser + } + tests := []struct { + name string + args args + want context.Context + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := WithContext(tt.args.ctx, tt.args.user); !reflect.DeepEqual(got, tt.want) { + t.Errorf("WithContext() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/pkg/model/bot_account.go b/internal/pkg/model/bot_account.go new file mode 100644 index 0000000..f674081 --- /dev/null +++ b/internal/pkg/model/bot_account.go @@ -0,0 +1,22 @@ +package models + +type BotAccount struct { + Avatar string `xorm:"default '' comment('头像') VARCHAR(255)"` + CreateTime int64 `xorm:"comment('创建时间') BIGINT"` + Desc string `xorm:"comment('个人简介') VARCHAR(255)"` + Email string `xorm:"comment('邮箱') VARCHAR(50)"` + Id int `xorm:"not null pk autoincr comment('ID') INT"` + InviteCode string `xorm:"not null default '' comment('邀请码') CHAR(6)"` + LoginFailure int `xorm:"not null default 0 comment('失败次数') TINYINT"` + LoginIp string `xorm:"comment('登录IP') VARCHAR(50)"` + LoginTime int64 `xorm:"comment('登录时间') BIGINT"` + Mobile string `xorm:"default '' comment('手机号码') VARCHAR(11)"` + NickName string `xorm:"default '' comment('昵称') VARCHAR(50)"` + Password string `xorm:"default '' comment('密码') VARCHAR(32)"` + Remark string `xorm:"comment('备注') VARCHAR(255)"` + RoleId int `xorm:"comment('角色ID') INT"` + Status int `xorm:"not null default 1 comment('状态: 1:正常 2 禁用') TINYINT"` + Token string `xorm:"default '' comment('Session标识') VARCHAR(300)"` + UpdateTime int64 `xorm:"comment('更新时间') BIGINT"` + UserName string `xorm:"default '' comment('用户名') unique VARCHAR(20)"` +} diff --git a/internal/pkg/model/bot_admin.go b/internal/pkg/model/bot_admin.go new file mode 100644 index 0000000..5805ead --- /dev/null +++ b/internal/pkg/model/bot_admin.go @@ -0,0 +1,19 @@ +package models + +type BotAdmin struct { + Avatar string `xorm:"default '' comment('头像') VARCHAR(255)"` + Createtime int64 `xorm:"comment('创建时间') BIGINT"` + Email string `xorm:"default '' comment('电子邮箱') VARCHAR(100)"` + Id int `xorm:"not null pk autoincr comment('ID') INT"` + Loginfailure int `xorm:"not null default 0 comment('失败次数') TINYINT"` + Loginip string `xorm:"comment('登录IP') VARCHAR(50)"` + Logintime int64 `xorm:"comment('登录时间') BIGINT"` + Mobile string `xorm:"default '' comment('手机号码') VARCHAR(11)"` + Nickname string `xorm:"default '' comment('昵称') VARCHAR(50)"` + Password string `xorm:"default '' comment('密码') VARCHAR(32)"` + Salt string `xorm:"default '' comment('密码盐') VARCHAR(30)"` + Status string `xorm:"not null default 'normal' comment('状态') VARCHAR(30)"` + Token string `xorm:"default '' comment('Session标识') VARCHAR(59)"` + Updatetime int64 `xorm:"comment('更新时间') BIGINT"` + Username string `xorm:"default '' comment('用户名') unique VARCHAR(20)"` +} diff --git a/internal/pkg/model/bot_admin_log.go b/internal/pkg/model/bot_admin_log.go new file mode 100644 index 0000000..f44e512 --- /dev/null +++ b/internal/pkg/model/bot_admin_log.go @@ -0,0 +1,19 @@ +package models + +import ( + "time" +) + +type BotAdminLog struct { + AdminId int `xorm:"not null comment('管理员ID') INT"` + BodyParam string `xorm:"comment('body请求参数') JSON"` + CreateDate time.Time `xorm:"comment('返款日期') index DATE"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + Host string `xorm:"VARCHAR(255)"` + Id int `xorm:"not null pk autoincr comment('ID') INT"` + Ip string `xorm:"VARCHAR(255)"` + PathInfo string `xorm:"VARCHAR(255)"` + RequestParam string `xorm:"comment('request参数') JSON"` + Ua string `xorm:"VARCHAR(255)"` + Uri string `xorm:"VARCHAR(255)"` +} diff --git a/internal/pkg/model/bot_announcement.go b/internal/pkg/model/bot_announcement.go new file mode 100644 index 0000000..39a205b --- /dev/null +++ b/internal/pkg/model/bot_announcement.go @@ -0,0 +1,19 @@ +package models + +import ( + "time" +) + +type BotAnnouncement struct { + Content string `xorm:"not null comment('内容') TEXT"` + CreateTime time.Time `xorm:"not null DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + IsDelete int `xorm:"not null default 1 comment('是否删除 1 未删除 2 已删除') index SMALLINT"` + IsPopUps int `xorm:"not null default 1 TINYINT"` + Lang int `xorm:"not null default 0 comment('语言') index INT"` + Name string `xorm:"not null default '' comment('名称') VARCHAR(255)"` + Status int `xorm:"not null default 1 comment('1 上架 2下架') SMALLINT"` + Title string `xorm:"not null default '' comment('标题') VARCHAR(255)"` + UpdateTime time.Time `xorm:"not null DATETIME"` + Weight int `xorm:"not null default 0 comment('权重') INT"` +} diff --git a/internal/pkg/model/bot_attachment.go b/internal/pkg/model/bot_attachment.go new file mode 100644 index 0000000..0a0b85d --- /dev/null +++ b/internal/pkg/model/bot_attachment.go @@ -0,0 +1,22 @@ +package models + +type BotAttachment struct { + AdminId int `xorm:"not null default 0 comment('管理员ID') INT"` + Category string `xorm:"default '' comment('类别') VARCHAR(50)"` + Createtime int64 `xorm:"comment('创建日期') BIGINT"` + Extparam string `xorm:"default '' comment('透传数据') VARCHAR(255)"` + Filename string `xorm:"default '' comment('文件名称') VARCHAR(100)"` + Filesize int `xorm:"not null default 0 comment('文件大小') INT"` + Id int `xorm:"not null pk autoincr comment('ID') INT"` + Imageframes int `xorm:"not null default 0 comment('图片帧数') INT"` + Imageheight string `xorm:"default '' comment('高度') VARCHAR(30)"` + Imagetype string `xorm:"default '' comment('图片类型') VARCHAR(30)"` + Imagewidth string `xorm:"default '' comment('宽度') VARCHAR(30)"` + Mimetype string `xorm:"default '' comment('mime类型') VARCHAR(100)"` + Sha1 string `xorm:"default '' comment('文件 sha1编码') VARCHAR(40)"` + Storage string `xorm:"not null default 'local' comment('存储位置') VARCHAR(100)"` + Updatetime int64 `xorm:"comment('更新时间') BIGINT"` + Uploadtime int64 `xorm:"comment('上传时间') BIGINT"` + Url string `xorm:"default '' comment('物理路径') VARCHAR(255)"` + UserId int `xorm:"not null default 0 comment('会员ID') INT"` +} diff --git a/internal/pkg/model/bot_auth_group.go b/internal/pkg/model/bot_auth_group.go new file mode 100644 index 0000000..b8bb5fe --- /dev/null +++ b/internal/pkg/model/bot_auth_group.go @@ -0,0 +1,11 @@ +package models + +type BotAuthGroup struct { + Createtime int64 `xorm:"comment('创建时间') BIGINT"` + Id int `xorm:"not null pk autoincr INT"` + Name string `xorm:"default '' comment('组名') VARCHAR(100)"` + Pid int `xorm:"not null default 0 comment('父组别') INT"` + Rules string `xorm:"not null comment('规则ID') TEXT"` + Status string `xorm:"default '' comment('状态') VARCHAR(30)"` + Updatetime int64 `xorm:"comment('更新时间') BIGINT"` +} diff --git a/internal/pkg/model/bot_auth_group_access.go b/internal/pkg/model/bot_auth_group_access.go new file mode 100644 index 0000000..f6b40bb --- /dev/null +++ b/internal/pkg/model/bot_auth_group_access.go @@ -0,0 +1,6 @@ +package models + +type BotAuthGroupAccess struct { + GroupId int `xorm:"not null pk comment('级别ID') index unique(uid_group_id) INT"` + Uid int `xorm:"not null pk comment('会员ID') index unique(uid_group_id) INT"` +} diff --git a/internal/pkg/model/bot_auth_menu.go b/internal/pkg/model/bot_auth_menu.go new file mode 100644 index 0000000..9bcae7f --- /dev/null +++ b/internal/pkg/model/bot_auth_menu.go @@ -0,0 +1,20 @@ +package models + +type BotAuthMenu struct { + Component string `xorm:"comment('组件路径') VARCHAR(255)"` + CreateTime int64 `xorm:"comment('创建时间') BIGINT"` + Icon string `xorm:"default '' comment('图标') VARCHAR(50)"` + Id int `xorm:"not null pk autoincr INT"` + Name string `xorm:"default '' comment('规则名称') unique VARCHAR(100)"` + Path string `xorm:"default '' comment('规则URL') VARCHAR(255)"` + Permission string `xorm:"comment('权限标识') VARCHAR(255)"` + Pid int `xorm:"not null default 0 comment('父ID') index INT"` + Redirect string `xorm:"comment('访问目录菜单时的跳转地址') VARCHAR(255)"` + Remark string `xorm:"default '' comment('备注') VARCHAR(255)"` + Show int `xorm:"comment('是否显示:1,显示,2,隐藏') TINYINT"` + Sort int `xorm:"not null default 0 comment('排序') index INT"` + Status int `xorm:"default 1 comment('状态:1正常,2禁用') TINYINT"` + Title string `xorm:"default '' comment('规则名称') VARCHAR(50)"` + Type string `xorm:"not null default 'file' comment('catelog为目录,menu为菜单,file为权限节点') ENUM('catelog','file','menu')"` + UpdateTime int64 `xorm:"comment('更新时间') BIGINT"` +} diff --git a/internal/pkg/model/bot_auth_role.go b/internal/pkg/model/bot_auth_role.go new file mode 100644 index 0000000..4e4edf6 --- /dev/null +++ b/internal/pkg/model/bot_auth_role.go @@ -0,0 +1,12 @@ +package models + +type BotAuthRole struct { + CreateTime int64 `xorm:"comment('创建时间') BIGINT"` + Id int `xorm:"not null pk autoincr INT"` + Name string `xorm:"default '' comment('组名') VARCHAR(100)"` + Remark string `xorm:"comment('备注') VARCHAR(255)"` + Rules string `xorm:"comment('规则ID') TEXT"` + Sort int `xorm:"comment('排序') TINYINT"` + Status int `xorm:"default 1 comment('状态:1 启用,2 停用') TINYINT"` + UpdateTime int64 `xorm:"comment('更新时间') BIGINT"` +} diff --git a/internal/pkg/model/bot_auth_rule.go b/internal/pkg/model/bot_auth_rule.go new file mode 100644 index 0000000..38a7c54 --- /dev/null +++ b/internal/pkg/model/bot_auth_rule.go @@ -0,0 +1,22 @@ +package models + +type BotAuthRule struct { + Condition string `xorm:"default '' comment('条件') VARCHAR(255)"` + Createtime int64 `xorm:"comment('创建时间') BIGINT"` + Extend string `xorm:"default '' comment('扩展属性') VARCHAR(255)"` + Icon string `xorm:"default '' comment('图标') VARCHAR(50)"` + Id int `xorm:"not null pk autoincr INT"` + Ismenu int `xorm:"not null default 0 comment('是否为菜单') TINYINT"` + Menutype string `xorm:"comment('菜单类型') ENUM('addtabs','ajax','blank','dialog')"` + Name string `xorm:"default '' comment('规则名称') unique VARCHAR(100)"` + Pid int `xorm:"not null default 0 comment('父ID') index INT"` + Pinyin string `xorm:"default '' comment('拼音') VARCHAR(100)"` + Py string `xorm:"default '' comment('拼音首字母') VARCHAR(30)"` + Remark string `xorm:"default '' comment('备注') VARCHAR(255)"` + Status string `xorm:"default '' comment('状态') VARCHAR(30)"` + Title string `xorm:"default '' comment('规则名称') VARCHAR(50)"` + Type string `xorm:"not null default 'file' comment('menu为菜单,file为权限节点') ENUM('file','menu')"` + Updatetime int64 `xorm:"comment('更新时间') BIGINT"` + Url string `xorm:"default '' comment('规则URL') VARCHAR(255)"` + Weigh int `xorm:"not null default 0 comment('权重') index INT"` +} diff --git a/internal/pkg/model/bot_banner.go b/internal/pkg/model/bot_banner.go new file mode 100644 index 0000000..67446bd --- /dev/null +++ b/internal/pkg/model/bot_banner.go @@ -0,0 +1,18 @@ +package models + +import ( + "time" +) + +type BotBanner struct { + Content string `xorm:"not null comment('内容') LONGTEXT"` + CreateTime time.Time `xorm:"not null DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + IsDelete int `xorm:"not null default 1 comment('是否删除 1未删除 2已删除') index SMALLINT"` + Lang int `xorm:"not null default 0 comment('语言') index INT"` + Name string `xorm:"not null default '' comment('名称') VARCHAR(255)"` + Path string `xorm:"not null default '' comment('图片路径') VARCHAR(255)"` + Status int `xorm:"not null default 1 comment('1 上架 2下架') index SMALLINT"` + Title string `xorm:"not null default '' comment('标题') VARCHAR(255)"` + UpdateTime time.Time `xorm:"not null DATETIME"` +} diff --git a/internal/pkg/model/bot_brokerage_setting.go b/internal/pkg/model/bot_brokerage_setting.go new file mode 100644 index 0000000..3cea098 --- /dev/null +++ b/internal/pkg/model/bot_brokerage_setting.go @@ -0,0 +1,11 @@ +package models + +type BotBrokerageSetting struct { + BrokType int `xorm:"not null comment('返佣类型:0注册,1开仓,2平仓') TINYINT(1)"` + GrandpaFee string `xorm:"not null comment('爷级ID') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + ParentFee string `xorm:"not null comment('父级ID') DECIMAL(36,18)"` + PayType int `xorm:"not null comment('结算方式:0固定费用,1按比例结算') TINYINT(1)"` + Remark string `xorm:"not null comment('备注') VARCHAR(20)"` + TopFee string `xorm:"not null comment('祖级ID') DECIMAL(36,18)"` +} diff --git a/internal/pkg/model/bot_category.go b/internal/pkg/model/bot_category.go new file mode 100644 index 0000000..306c911 --- /dev/null +++ b/internal/pkg/model/bot_category.go @@ -0,0 +1,18 @@ +package models + +type BotCategory struct { + Createtime int64 `xorm:"comment('创建时间') BIGINT"` + Description string `xorm:"default '' comment('描述') VARCHAR(255)"` + Diyname string `xorm:"default '' comment('自定义名称') VARCHAR(30)"` + Flag string `xorm:"default '' SET('hot','index','recommend')"` + Id int `xorm:"not null pk autoincr index(weigh) INT"` + Image string `xorm:"default '' comment('图片') VARCHAR(100)"` + Keywords string `xorm:"default '' comment('关键字') VARCHAR(255)"` + Name string `xorm:"default '' VARCHAR(30)"` + Nickname string `xorm:"default '' VARCHAR(50)"` + Pid int `xorm:"not null default 0 comment('父ID') index INT"` + Status string `xorm:"default '' comment('状态') VARCHAR(30)"` + Type string `xorm:"default '' comment('栏目类型') VARCHAR(30)"` + Updatetime int64 `xorm:"comment('更新时间') BIGINT"` + Weigh int `xorm:"not null default 0 comment('权重') index(weigh) INT"` +} diff --git a/internal/pkg/model/bot_config.go b/internal/pkg/model/bot_config.go new file mode 100644 index 0000000..ecd1cc5 --- /dev/null +++ b/internal/pkg/model/bot_config.go @@ -0,0 +1,16 @@ +package models + +type BotConfig struct { + Content string `xorm:"comment('变量字典数据') TEXT"` + Extend string `xorm:"default '' comment('扩展属性') VARCHAR(255)"` + Group string `xorm:"default '' comment('分组') VARCHAR(30)"` + Id int `xorm:"not null pk autoincr INT"` + Name string `xorm:"default '' comment('变量名') unique VARCHAR(30)"` + Rule string `xorm:"default '' comment('验证规则') VARCHAR(100)"` + Setting string `xorm:"default '' comment('配置') VARCHAR(255)"` + Tip string `xorm:"default '' comment('变量描述') VARCHAR(100)"` + Title string `xorm:"default '' comment('变量标题') VARCHAR(100)"` + Type string `xorm:"default '' comment('类型:string,text,int,bool,array,datetime,date,file') VARCHAR(30)"` + Value string `xorm:"comment('变量值') TEXT"` + Visible string `xorm:"default '' comment('可见条件') VARCHAR(255)"` +} diff --git a/internal/pkg/model/bot_contract_list.go b/internal/pkg/model/bot_contract_list.go new file mode 100644 index 0000000..e1e3e6e --- /dev/null +++ b/internal/pkg/model/bot_contract_list.go @@ -0,0 +1,22 @@ +package models + +import ( + "time" +) + +type BotContractList struct { + CompelNum string `xorm:"comment('强制平仓比例') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + FaceValue int64 `xorm:"comment('面值') BIGINT"` + Id int `xorm:"not null pk autoincr INT"` + Info string `xorm:"not null comment('数字货币简介') TEXT"` + IsOwner int `xorm:"comment('是否自发') TINYINT(1)"` + KeepDecimal int `xorm:"comment('保留小数位') INT"` + LogoLink string `xorm:"comment('logo链接') VARCHAR(255)"` + MaxPry int `xorm:"comment('最大杠杆') INT"` + MinPry int `xorm:"comment('最小杠杆') INT"` + Sort int `xorm:"not null default 0 comment('排序') INT"` + Status int `xorm:"not null comment('启用状态:0未启用,1已启用') index TINYINT(1)"` + TradeName string `xorm:"not null comment('合约交易对名称') unique VARCHAR(10)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` +} diff --git a/internal/pkg/model/bot_contract_market.go b/internal/pkg/model/bot_contract_market.go new file mode 100644 index 0000000..5e54920 --- /dev/null +++ b/internal/pkg/model/bot_contract_market.go @@ -0,0 +1,17 @@ +package models + +import ( + "time" +) + +type BotContractMarket struct { + BeginTime time.Time `xorm:"comment('开始时间') index index(trade_name) DATETIME"` + EndTime time.Time `xorm:"comment('结束时间') index(trade_name) DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + IsGet int `xorm:"not null default 1 comment('类型:1 未领取 ,2 已领取') index TINYINT(1)"` + MaxPrice string `xorm:"comment('开盘价') DECIMAL(36,18)"` + MinPrice string `xorm:"comment('落盘价') DECIMAL(36,18)"` + Step int `xorm:"comment('调价步长') INT"` + TradeName string `xorm:"comment('交易对') index(trade_name) VARCHAR(255)"` + Type int `xorm:"comment('类型:0插针,1自发合约 ,2 自发现货') TINYINT(1)"` +} diff --git a/internal/pkg/model/bot_contract_sec_trade.go b/internal/pkg/model/bot_contract_sec_trade.go new file mode 100644 index 0000000..1c2970e --- /dev/null +++ b/internal/pkg/model/bot_contract_sec_trade.go @@ -0,0 +1,40 @@ +package models + +import ( + "time" +) + +type BotContractSecTrade struct { + ClosingCost string `xorm:"comment('平仓手续费') DECIMAL(36,18)"` + ClosingPrice string `xorm:"comment('平仓价') DECIMAL(36,18)"` + ClosingTime time.Time `xorm:"comment('平仓时间') DATETIME"` + ContractId string `xorm:"not null comment('合约id') index(u_s_c) index(user_id) VARCHAR(100)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + DealPrice string `xorm:"comment('成交价') DECIMAL(36,18)"` + DealType int `xorm:"not null default 0 comment('委托方式:1限价,2市价') index(user_id) TINYINT(1)"` + EarnestMoney string `xorm:"not null comment('保证金') DECIMAL(36,18)"` + FaceValue int64 `xorm:"comment('面值') BIGINT"` + KeepDecimal int `xorm:"comment('小数点保留位数') INT"` + LimitPrice string `xorm:"comment('限价') DECIMAL(36,18)"` + MarketPrice string `xorm:"comment('市价') DECIMAL(36,18)"` + OpenTime time.Time `xorm:"comment('开仓时间') DATETIME"` + OrderId string `xorm:"not null comment('订单ID') index(order_id) index(user_id) VARCHAR(60)"` + OrderMoney string `xorm:"not null comment('订单金额') DECIMAL(36,18)"` + OrderNumber string `xorm:"not null comment('委托数量') DECIMAL(36,18)"` + OrderStatus int `xorm:"not null default 0 comment('订单盈亏状态: 0-平局,1-盈利,2-亏损') INT"` + OrderValue string `xorm:"not null comment('订单盈亏值') DECIMAL(36,18)"` + OvernightCost string `xorm:"comment('过夜手续费') DECIMAL(36,18)"` + PryNum int `xorm:"comment('杠杆') INT"` + SecondTime int `xorm:"comment('秒合约') INT"` + ServiceCost string `xorm:"not null comment('持仓手续费') DECIMAL(36,18)"` + State int `xorm:"not null default 0 comment('订单状态类型') index(order_id) index(u_s_c) index(user_id) INT"` + Status int `xorm:"not null default 0 comment('订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单') index(order_id) index(u_s_c) index(user_id) TINYINT(1)"` + StopLossPrice string `xorm:"comment('止损价') DECIMAL(36,18)"` + StopType int `xorm:"not null comment('止损止盈设置:0无设置,1止损止盈') TINYINT(1)"` + StopWinPrice string `xorm:"comment('止赢价') DECIMAL(36,18)"` + TotalMoney string `xorm:"not null comment('订单总金额(订单金额+手续费)') DECIMAL(36,18)"` + TradeId int `xorm:"not null pk autoincr comment('自增长ID') INT"` + TradeType int `xorm:"not null default 0 comment('交易类型:1买入,2卖出') index(user_id) TINYINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(u_s_c) index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_contract_setting.go b/internal/pkg/model/bot_contract_setting.go new file mode 100644 index 0000000..2630b69 --- /dev/null +++ b/internal/pkg/model/bot_contract_setting.go @@ -0,0 +1,13 @@ +package models + +import ( + "time" +) + +type BotContractSetting struct { + CreateTime time.Time `xorm:"DATETIME"` + EarningsNum string `xorm:"not null DECIMAL(10,2)"` + Id int `xorm:"not null pk autoincr INT"` + TimeStep int `xorm:"not null INT"` + UpdateTime time.Time `xorm:"DATETIME"` +} diff --git a/internal/pkg/model/bot_contract_trade.go b/internal/pkg/model/bot_contract_trade.go new file mode 100644 index 0000000..628775f --- /dev/null +++ b/internal/pkg/model/bot_contract_trade.go @@ -0,0 +1,38 @@ +package models + +import ( + "time" +) + +type BotContractTrade struct { + ClosingCost string `xorm:"comment('平仓手续费') DECIMAL(36,18)"` + ClosingPrice string `xorm:"comment('平仓价') DECIMAL(36,18)"` + ClosingTime time.Time `xorm:"comment('平仓时间') DATETIME"` + ContractId string `xorm:"not null comment('合约id') index(u_s_c) index(user_id) VARCHAR(100)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + DealPrice string `xorm:"comment('成交价') DECIMAL(36,18)"` + DealType int `xorm:"not null default 0 comment('委托方式:1限价,2市价') index(user_id) TINYINT(1)"` + EarnestMoney string `xorm:"not null comment('保证金') DECIMAL(36,18)"` + FaceValue int64 `xorm:"comment('面值') BIGINT"` + KeepDecimal int `xorm:"comment('小数点保留位数') INT"` + LimitPrice string `xorm:"comment('限价') DECIMAL(36,18)"` + MarketPrice string `xorm:"comment('市价') DECIMAL(36,18)"` + OpenTime time.Time `xorm:"comment('开仓时间') DATETIME"` + OrderId string `xorm:"not null comment('订单ID') index(order_id) index(user_id) VARCHAR(60)"` + OrderMoney string `xorm:"not null comment('订单金额') DECIMAL(36,18)"` + OrderNumber string `xorm:"not null comment('委托数量') DECIMAL(36,18)"` + OvernightCost string `xorm:"comment('过夜手续费') DECIMAL(36,18)"` + PryNum int `xorm:"comment('杠杆') INT"` + SecondTime int `xorm:"comment('秒合约') INT"` + ServiceCost string `xorm:"not null comment('持仓手续费') DECIMAL(36,18)"` + State int `xorm:"not null default 0 comment('订单状态类型') index(order_id) index(u_s_c) index(user_id) INT"` + Status int `xorm:"not null default 0 comment('订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单') index(order_id) index(u_s_c) index(user_id) TINYINT(1)"` + StopLossPrice string `xorm:"comment('止损价') DECIMAL(36,18)"` + StopType int `xorm:"not null comment('止损止盈设置:0无设置,1止损止盈') TINYINT(1)"` + StopWinPrice string `xorm:"comment('止赢价') DECIMAL(36,18)"` + TotalMoney string `xorm:"not null comment('订单总金额(订单金额+手续费)') DECIMAL(36,18)"` + TradeId int `xorm:"not null pk autoincr comment('自增长ID') INT"` + TradeType int `xorm:"not null default 0 comment('交易类型:1买入,2卖出') index(user_id) TINYINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(u_s_c) index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_country.go b/internal/pkg/model/bot_country.go new file mode 100644 index 0000000..7aad53d --- /dev/null +++ b/internal/pkg/model/bot_country.go @@ -0,0 +1,9 @@ +package models + +type BotCountry struct { + Code string `xorm:"not null default '' comment('国家码') VARCHAR(10)"` + Id int `xorm:"not null pk autoincr INT"` + NameCn string `xorm:"not null default '' comment('中文名称') VARCHAR(50)"` + NameEn string `xorm:"not null default '' comment('英文名称') VARCHAR(50)"` + Sort int `xorm:"not null default 1 comment('排序') INT"` +} diff --git a/internal/pkg/model/bot_digital_list.go b/internal/pkg/model/bot_digital_list.go new file mode 100644 index 0000000..2438eb7 --- /dev/null +++ b/internal/pkg/model/bot_digital_list.go @@ -0,0 +1,19 @@ +package models + +import ( + "time" +) + +type BotDigitalList struct { + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + ExchangeName string `xorm:"not null comment('数字币兑换对名称(默认USDT)') unique(digital_name) VARCHAR(10)"` + Id int `xorm:"not null pk autoincr INT"` + Info string `xorm:"not null comment('数字货币简介') TEXT"` + IsOwner int `xorm:"comment('是否自发') TINYINT(1)"` + KeepDecimal int `xorm:"comment('保留小数位') INT"` + LogoLink string `xorm:"comment('logo链接') VARCHAR(255)"` + Sort int `xorm:"comment('排序') INT"` + Status int `xorm:"comment('启用状态:0未启用,1已启用') index TINYINT(1)"` + TradeName string `xorm:"not null comment('数字货币名称') unique(digital_name) VARCHAR(10)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` +} diff --git a/internal/pkg/model/bot_digital_trade.go b/internal/pkg/model/bot_digital_trade.go new file mode 100644 index 0000000..44246ee --- /dev/null +++ b/internal/pkg/model/bot_digital_trade.go @@ -0,0 +1,30 @@ +package models + +import ( + "time" +) + +type BotDigitalTrade struct { + ClosingCost string `xorm:"comment('平仓手续费') DECIMAL(36,18)"` + ClosingPrice string `xorm:"comment('平仓价格') DECIMAL(36,18)"` + ClosingTime time.Time `xorm:"comment('平仓时间') DATETIME"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + DealPrice string `xorm:"comment('成交价') DECIMAL(36,18)"` + DealType int `xorm:"not null default 0 comment('委托方式:1限价,2市价') index(user_id) TINYINT(1)"` + DigitalId string `xorm:"not null comment('数字币交易对id') index(u_s_d) index(user_id) VARCHAR(100)"` + KeepDecimal int `xorm:"comment('小数点保留位数') INT"` + LimitPrice string `xorm:"comment('限价') DECIMAL(36,18)"` + MarketPrice string `xorm:"comment('市价') DECIMAL(36,18)"` + OpenTime time.Time `xorm:"comment('开仓时间') DATETIME"` + OrderId string `xorm:"not null comment('订单ID') index(order_id) index(user_id) VARCHAR(60)"` + OrderMoney string `xorm:"not null comment('订单金额') DECIMAL(36,18)"` + OrderNumber string `xorm:"not null comment('委托数量') DECIMAL(36,18)"` + OvernightCost string `xorm:"comment('过夜手续费') DECIMAL(36,18)"` + ServiceCost string `xorm:"not null comment('持仓手续费') DECIMAL(36,18)"` + Status int `xorm:"not null default 0 comment('订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单') index(order_id) index(u_s_d) index(user_id) TINYINT(1)"` + TotalMoney string `xorm:"not null comment('订单总金额(包含手续费用)') DECIMAL(36,18)"` + TradeId int `xorm:"not null pk autoincr comment('自增长ID') INT"` + TradeType int `xorm:"not null default 0 comment('交易类型:1买入,2卖出') index(user_id) TINYINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(u_s_d) index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_document.go b/internal/pkg/model/bot_document.go new file mode 100644 index 0000000..0f7dcfd --- /dev/null +++ b/internal/pkg/model/bot_document.go @@ -0,0 +1,19 @@ +package models + +import ( + "time" +) + +type BotDocument struct { + Content string `xorm:"not null TEXT"` + CreateTime time.Time `xorm:"not null DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + IsDelete int `xorm:"not null default 1 comment('1 未删除 2已删除') index SMALLINT"` + Lang int `xorm:"not null default 0 comment('语言') index INT"` + Name string `xorm:"not null default '' comment('名称') VARCHAR(255)"` + Status int `xorm:"not null default 1 comment('1 上架 2 下架') index SMALLINT"` + Title string `xorm:"not null default '' VARCHAR(150)"` + Type int `xorm:"not null default 0 comment('类型') index INT"` + UpdateTime time.Time `xorm:"not null DATETIME"` + Weight int `xorm:"not null default 0 index INT"` +} diff --git a/internal/pkg/model/bot_drawal_setting.go b/internal/pkg/model/bot_drawal_setting.go new file mode 100644 index 0000000..b81deef --- /dev/null +++ b/internal/pkg/model/bot_drawal_setting.go @@ -0,0 +1,11 @@ +package models + +type BotDrawalSetting struct { + BankDrawalFee string `xorm:"not null comment('银行提现手续费') DECIMAL(36,18)"` + BankRechargeFee string `xorm:"not null comment('银行充值手续费') DECIMAL(36,18)"` + DigitalDrawalFee string `xorm:"not null comment('数字币提现手续费') DECIMAL(36,18)"` + DigitalRechargeFee string `xorm:"not null comment('数字币充值手续费') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + MinDrawal string `xorm:"not null comment('最小提现金额') DECIMAL(36,18)"` + MinRecharge string `xorm:"not null comment('最小充值金额') DECIMAL(36,18)"` +} diff --git a/internal/pkg/model/bot_faq.go b/internal/pkg/model/bot_faq.go new file mode 100644 index 0000000..af017a2 --- /dev/null +++ b/internal/pkg/model/bot_faq.go @@ -0,0 +1,18 @@ +package models + +import ( + "time" +) + +type BotFaq struct { + Content string `xorm:"not null TEXT"` + CreateTime time.Time `xorm:"not null DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + IsDelete int `xorm:"not null default 1 comment('1未删除 2已删除') index SMALLINT"` + Lang int `xorm:"not null default 0 comment('语言') index INT"` + Name string `xorm:"not null default '' comment('文档内容标识') index VARCHAR(255)"` + Status int `xorm:"not null default 2 comment('1 上架 2下架') SMALLINT"` + Title string `xorm:"not null default '' VARCHAR(255)"` + UpdateTime time.Time `xorm:"not null DATETIME"` + Weight float64 `xorm:"not null default 0 comment('权重') index DOUBLE"` +} diff --git a/internal/pkg/model/bot_fee_setting.go b/internal/pkg/model/bot_fee_setting.go new file mode 100644 index 0000000..9b28a5d --- /dev/null +++ b/internal/pkg/model/bot_fee_setting.go @@ -0,0 +1,14 @@ +package models + +type BotFeeSetting struct { + BuyFee string `xorm:"not null comment('买入手续费') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + MarketType int `xorm:"not null comment('市场类型:1现货,2合约,3美股') TINYINT(1)"` + MaxEntrustNum int `xorm:"comment('最大挂单数量') INT"` + MaxHoldNum int `xorm:"comment('最大持仓数量') INT"` + MinBuyNum int `xorm:"comment('买入最小下单金额') INT"` + MinSaleNum int `xorm:"comment('卖出最小下单金额') INT"` + PayType int `xorm:"not null comment('结算方式:0固定费用,1按比例结算 , 2按张结算') TINYINT(1)"` + PurchaseFee string `xorm:"not null default 0.000000000000000000 comment('新股申购手续费') DECIMAL(36,18)"` + SaleFee string `xorm:"not null comment('卖出手续费') DECIMAL(36,18)"` +} diff --git a/internal/pkg/model/bot_file.go b/internal/pkg/model/bot_file.go new file mode 100644 index 0000000..f015bf7 --- /dev/null +++ b/internal/pkg/model/bot_file.go @@ -0,0 +1,12 @@ +package models + +import ( + "time" +) + +type BotFile struct { + CreateTime time.Time `xorm:"not null DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + Path string `xorm:"not null default '' comment('路径') VARCHAR(255)"` + Type int `xorm:"not null default 1 comment('资源类型 1 图片') SMALLINT"` +} diff --git a/internal/pkg/model/bot_forex_list.go b/internal/pkg/model/bot_forex_list.go new file mode 100644 index 0000000..0daff68 --- /dev/null +++ b/internal/pkg/model/bot_forex_list.go @@ -0,0 +1,22 @@ +package models + +import ( + "time" +) + +type BotForexList struct { + CompelNum string `xorm:"comment('强制平仓比例') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + FaceValue int64 `xorm:"comment('面值') BIGINT"` + Id int `xorm:"not null pk autoincr INT"` + Info string `xorm:"not null comment('数字货币简介') TEXT"` + IsOwner int `xorm:"comment('是否自发') TINYINT(1)"` + KeepDecimal int `xorm:"comment('保留小数位') INT"` + LogoLink string `xorm:"comment('logo链接') VARCHAR(255)"` + MaxPry int `xorm:"comment('最大杠杆') INT"` + MinPry int `xorm:"comment('最小杠杆') INT"` + Sort int `xorm:"not null default 0 comment('排序') INT"` + Status int `xorm:"not null comment('启用状态:0未启用,1已启用') index TINYINT(1)"` + TradeName string `xorm:"not null comment('合约交易对名称') unique VARCHAR(10)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` +} diff --git a/internal/pkg/model/bot_forex_trade.go b/internal/pkg/model/bot_forex_trade.go new file mode 100644 index 0000000..5486335 --- /dev/null +++ b/internal/pkg/model/bot_forex_trade.go @@ -0,0 +1,38 @@ +package models + +import ( + "time" +) + +type BotForexTrade struct { + ClosingCost string `xorm:"comment('平仓手续费') DECIMAL(36,18)"` + ClosingPrice string `xorm:"comment('平仓价') DECIMAL(36,18)"` + ClosingTime time.Time `xorm:"comment('平仓时间') DATETIME"` + ContractId string `xorm:"not null comment('合约id') index(u_s_c) index(user_id) VARCHAR(100)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + DealPrice string `xorm:"comment('成交价') DECIMAL(36,18)"` + DealType int `xorm:"not null default 0 comment('委托方式:1限价,2市价') index(user_id) TINYINT(1)"` + EarnestMoney string `xorm:"not null comment('保证金') DECIMAL(36,18)"` + FaceValue int64 `xorm:"comment('面值') BIGINT"` + KeepDecimal int `xorm:"comment('小数点保留位数') INT"` + LimitPrice string `xorm:"comment('限价') DECIMAL(36,18)"` + MarketPrice string `xorm:"comment('市价') DECIMAL(36,18)"` + OpenTime time.Time `xorm:"comment('开仓时间') DATETIME"` + OrderId string `xorm:"not null comment('订单ID') index(order_id) index(user_id) VARCHAR(60)"` + OrderMoney string `xorm:"not null comment('订单金额') DECIMAL(36,18)"` + OrderNumber string `xorm:"not null comment('委托数量') DECIMAL(36,18)"` + OvernightCost string `xorm:"comment('过夜手续费') DECIMAL(36,18)"` + PryNum int `xorm:"comment('杠杆') INT"` + SecondTime int `xorm:"comment('秒合约') INT"` + ServiceCost string `xorm:"not null comment('持仓手续费') DECIMAL(36,18)"` + State int `xorm:"not null default 0 comment('订单状态类型') index(order_id) index(u_s_c) index(user_id) INT"` + Status int `xorm:"not null default 0 comment('订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单') index(order_id) index(u_s_c) index(user_id) TINYINT(1)"` + StopLossPrice string `xorm:"comment('止损价') DECIMAL(36,18)"` + StopType int `xorm:"not null comment('止损止盈设置:0无设置,1止损止盈') TINYINT(1)"` + StopWinPrice string `xorm:"comment('止赢价') DECIMAL(36,18)"` + TotalMoney string `xorm:"not null comment('订单总金额(订单金额+手续费)') DECIMAL(36,18)"` + TradeId int `xorm:"not null pk autoincr comment('自增长ID') INT"` + TradeType int `xorm:"not null default 0 comment('交易类型:1买入,2卖出') index(user_id) TINYINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(u_s_c) index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_history_fund_stock.go b/internal/pkg/model/bot_history_fund_stock.go new file mode 100644 index 0000000..8e3555f --- /dev/null +++ b/internal/pkg/model/bot_history_fund_stock.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotHistoryFundStock struct { + EndDate time.Time `xorm:"comment('结束日期') DATE"` + EndPoint string `xorm:"comment('结束值 单位%') DECIMAL(8,2)"` + HistoryInfo string `xorm:"comment('历史走势(json存储)') JSON"` + Id int `xorm:"not null pk autoincr INT"` + StartDate time.Time `xorm:"comment('起始日期') DATE"` + StartPoint string `xorm:"comment('起始值 单位%') DECIMAL(8,2)"` + StockCode string `xorm:"not null default '' comment('基金代码') unique VARCHAR(30)"` +} diff --git a/internal/pkg/model/bot_language_setting.go b/internal/pkg/model/bot_language_setting.go new file mode 100644 index 0000000..dfb9d46 --- /dev/null +++ b/internal/pkg/model/bot_language_setting.go @@ -0,0 +1,8 @@ +package models + +type BotLanguageSetting struct { + ChinaName string `xorm:"VARCHAR(20)"` + Id int `xorm:"not null pk autoincr INT"` + LanguageCode string `xorm:"not null VARCHAR(20)"` + LanguageName string `xorm:"not null VARCHAR(20)"` +} diff --git a/internal/pkg/model/bot_money_trade.go b/internal/pkg/model/bot_money_trade.go new file mode 100644 index 0000000..f57c5d5 --- /dev/null +++ b/internal/pkg/model/bot_money_trade.go @@ -0,0 +1,37 @@ +package models + +import ( + "time" +) + +type BotMoneyTrade struct { + ClosingCost string `xorm:"comment('平仓手续费') DECIMAL(36,18)"` + ClosingPrice string `xorm:"comment('平仓价格') DECIMAL(36,18)"` + ClosingTime time.Time `xorm:"comment('平仓时间') DATETIME"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + DealPrice string `xorm:"comment('成交价') DECIMAL(36,18)"` + DealType int `xorm:"not null default 0 comment('委托方式:1限价,2市价') index(user_id) TINYINT(1)"` + FaceValue int `xorm:"comment('面值') INT"` + KeepDecimal int `xorm:"comment('股票保留小数位') INT"` + LimitPrice string `xorm:"comment('限价') DECIMAL(36,18)"` + MarketMoney string `xorm:"not null comment('市值金额') DECIMAL(36,18)"` + MarketPrice string `xorm:"comment('市价') DECIMAL(36,18)"` + OpenTime time.Time `xorm:"comment('成交时间') DATETIME"` + OrderId string `xorm:"not null comment('订单ID') index(order_id) index(user_id) VARCHAR(60)"` + OrderMoney string `xorm:"not null comment('订单总金额') DECIMAL(36,18)"` + OrderNumber string `xorm:"not null comment('委托数量') DECIMAL(36,18)"` + OvernightCost string `xorm:"comment('过夜手续费') DECIMAL(36,18)"` + PryNum int `xorm:"comment('杠杆') INT"` + ServiceCost string `xorm:"not null comment('持仓手续费') DECIMAL(36,18)"` + Status int `xorm:"not null default 0 comment('订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单') index(order_id) index(u_s_s) index(user_id) TINYINT(1)"` + StockId string `xorm:"not null comment('股票id') index(u_s_s) index(user_id) VARCHAR(100)"` + StockName string `xorm:"comment('股票名称') VARCHAR(255)"` + StopLossPrice string `xorm:"comment('止损价') DECIMAL(36,18)"` + StopType int `xorm:"not null comment('止损止盈设置:0无设置,1止损止盈') TINYINT(1)"` + StopWinPrice string `xorm:"comment('止赢价') DECIMAL(36,18)"` + TradeId int `xorm:"not null pk autoincr comment('自增长ID') INT"` + TradeType int `xorm:"not null default 0 comment('交易类型:1买入,2卖出') index(user_id) TINYINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(u_s_s) index(user_id) INT"` + MarketType int `xorm:"not null comment('交易市场') TINYINT(1)"` +} diff --git a/internal/pkg/model/bot_payment_list.go b/internal/pkg/model/bot_payment_list.go new file mode 100644 index 0000000..d46a8dc --- /dev/null +++ b/internal/pkg/model/bot_payment_list.go @@ -0,0 +1,24 @@ +package models + +type BotPaymentList struct { + AccountType string `xorm:"comment('account_type') VARCHAR(100)"` + BankAccount string `xorm:"comment('银行账号') VARCHAR(100)"` + BankBranch string `xorm:"comment('支行名称') VARCHAR(100)"` + BankName string `xorm:"comment('银行名称') VARCHAR(100)"` + BankUser string `xorm:"comment('账户名称') VARCHAR(100)"` + Channel string `xorm:"not null comment('渠道名称') VARCHAR(255)"` + ChannelType string `xorm:"comment('渠道类型') VARCHAR(50)"` + Country string `xorm:"not null comment('国家') VARCHAR(255)"` + ExchangeRate string `xorm:"comment('对美元汇率') DECIMAL(36,4)"` + Id int `xorm:"not null pk autoincr INT"` + Ifsc string `xorm:"comment('ifsc') VARCHAR(255)"` + IsOnline int `xorm:"comment('是否是在线充值:1是,0否') TINYINT(1)"` + IsRecharge int `xorm:"comment('是否是充值渠道:1是') TINYINT(1)"` + IsWithdrawal int `xorm:"comment('是否是代付渠道:1是') TINYINT(1)"` + PayType int `xorm:"not null comment('结算方式:0固定金额,1按比例结算') TINYINT(1)"` + ServiceRate string `xorm:"not null comment('手续费比例') DECIMAL(36,4)"` + Status int `xorm:"not null comment('状态') TINYINT(1)"` + Type int `xorm:"not null default 1 SMALLINT"` + Unit string `xorm:"comment('单位代码') VARCHAR(10)"` + WalletAddress string `xorm:"comment('钱包地址') VARCHAR(100)"` +} diff --git a/internal/pkg/model/bot_pre_brl_stock.go b/internal/pkg/model/bot_pre_brl_stock.go new file mode 100644 index 0000000..ac6387e --- /dev/null +++ b/internal/pkg/model/bot_pre_brl_stock.go @@ -0,0 +1,38 @@ +package models + +import ( + "time" +) + +type BotPreBrlStock struct { + CompanyInfo string `xorm:"not null comment('公司简介') TEXT"` + CompanyOpenTime time.Time `xorm:"comment('公司上市时间') DATETIME"` + CompanyRegAmount string `xorm:"not null default '' comment('公司注册资本') VARCHAR(255)"` + CreateTime time.Time `xorm:"DATETIME"` + EndTime time.Time `xorm:"comment('认购结束时间') DATETIME"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + HadGetNum int `xorm:"not null default 0 comment('已经认购数量') INT"` + HqStatus int `xorm:"comment('通知行情状态 1 成功 2 失败') SMALLINT(1)"` + Id int `xorm:"not null pk autoincr INT"` + IsDelete int `xorm:"not null default 1 comment('是否删除 1 未删除 2已删除') SMALLINT"` + IsPostPay int `xorm:"not null default 1 comment('是否后支付 1不后支付 2可后支付 ') SMALLINT"` + LimitGetNum int `xorm:"not null default 1 comment('单个账户申购次数') INT"` + Logo string `xorm:"not null default '' comment('基金 logo') VARCHAR(255)"` + Max int `xorm:"not null default 0 comment('最大申购数量') INT"` + Min int `xorm:"not null default 0 comment('最小申购数量') INT"` + OpenStatus int `xorm:"not null default 0 comment('上市状态 见配置') SMALLINT"` + OpenTime time.Time `xorm:"comment('上市时间') DATETIME"` + PayDeadlineTime time.Time `xorm:"comment('预支付截止时间') DATETIME"` + Price string `xorm:"not null default 0.000000000000000000 comment('单股价格') DECIMAL(36,18)"` + Rate string `xorm:"not null comment('10 为 10%') DECIMAL(5,2)"` + SignStatus int `xorm:"not null default 2 comment('1 已签名 2 未签名') SMALLINT"` + StartTime time.Time `xorm:"comment('开始认购时间') DATETIME"` + Status int `xorm:"not null default 2 comment('发布状态 1 已发布 2 未发布') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码 唯一') unique VARCHAR(255)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(255)"` + StockType int `xorm:"not null default 1 comment('股票类型') SMALLINT"` + Tape int `xorm:"not null default 0 comment('交易所类型') SMALLINT"` + Total int `xorm:"not null default 0 comment('发行总数') INT"` + TradeStatus int `xorm:"comment('通知交易状态 1 成功 2 失败') SMALLINT(1)"` + UpdateTime time.Time `xorm:"DATETIME"` +} diff --git a/internal/pkg/model/bot_pre_eur_stock.go b/internal/pkg/model/bot_pre_eur_stock.go new file mode 100644 index 0000000..99058e9 --- /dev/null +++ b/internal/pkg/model/bot_pre_eur_stock.go @@ -0,0 +1,38 @@ +package models + +import ( + "time" +) + +type BotPreEurStock struct { + CompanyInfo string `xorm:"not null comment('公司简介') TEXT"` + CompanyOpenTime time.Time `xorm:"comment('公司上市时间') DATETIME"` + CompanyRegAmount string `xorm:"not null default '' comment('公司注册资本') VARCHAR(255)"` + CreateTime time.Time `xorm:"DATETIME"` + EndTime time.Time `xorm:"comment('认购结束时间') DATETIME"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + HadGetNum int `xorm:"not null default 0 comment('已经认购数量') INT"` + HqStatus int `xorm:"comment('通知行情状态 1 成功 2 失败') SMALLINT(1)"` + Id int `xorm:"not null pk autoincr INT"` + IsDelete int `xorm:"not null default 1 comment('是否删除 1 未删除 2已删除') SMALLINT"` + IsPostPay int `xorm:"not null default 1 comment('是否后支付 1不后支付 2可后支付 ') SMALLINT"` + LimitGetNum int `xorm:"not null default 1 comment('单个账户申购次数') INT"` + Logo string `xorm:"not null default '' comment('基金 logo') VARCHAR(255)"` + Max int `xorm:"not null default 0 comment('最大申购数量') INT"` + Min int `xorm:"not null default 0 comment('最小申购数量') INT"` + OpenStatus int `xorm:"not null default 0 comment('上市状态 见配置') SMALLINT"` + OpenTime time.Time `xorm:"comment('上市时间') DATETIME"` + PayDeadlineTime time.Time `xorm:"comment('预支付截止时间') DATETIME"` + Price string `xorm:"not null default 0.000000000000000000 comment('单股价格') DECIMAL(36,18)"` + Rate string `xorm:"not null comment('10 为 10%') DECIMAL(5,2)"` + SignStatus int `xorm:"not null default 2 comment('1 已签名 2 未签名') SMALLINT"` + StartTime time.Time `xorm:"comment('开始认购时间') DATETIME"` + Status int `xorm:"not null default 2 comment('发布状态 1 已发布 2 未发布') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码 唯一') unique VARCHAR(255)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(255)"` + StockType int `xorm:"not null default 1 comment('股票类型') SMALLINT"` + Tape int `xorm:"not null default 0 comment('交易所类型') SMALLINT"` + Total int `xorm:"not null default 0 comment('发行总数') INT"` + TradeStatus int `xorm:"comment('通知交易状态 1 成功 2 失败') SMALLINT(1)"` + UpdateTime time.Time `xorm:"DATETIME"` +} diff --git a/internal/pkg/model/bot_pre_fund_stock.go b/internal/pkg/model/bot_pre_fund_stock.go new file mode 100644 index 0000000..e2a6b26 --- /dev/null +++ b/internal/pkg/model/bot_pre_fund_stock.go @@ -0,0 +1,38 @@ +package models + +import ( + "time" +) + +type BotPreFundStock struct { + CloseTime time.Time `xorm:"comment('退市时间') DATETIME"` + CreateTime time.Time `xorm:"DATETIME"` + CurrentManager string `xorm:"comment('现任经理(json存储)') JSON"` + Cycle int `xorm:"not null default 1 comment('周期,单位天 30 为 30天') INT"` + CycleType int `xorm:"not null default 1 comment('周期单位 1:天 2:月 3:年') TINYINT"` + EndTime time.Time `xorm:"comment('认购结束时间') DATETIME"` + HadGetPrice string `xorm:"not null default 0.000000000000000000 comment('已经购买金额') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + InterestType int `xorm:"not null default 1 comment('返利类型 1一次性本息 2.等额本息') TINYINT"` + IsDelete int `xorm:"not null default 1 comment('是否删除 1 未删除 2已删除') TINYINT"` + Logo string `xorm:"not null default '' comment('基金logo') VARCHAR(255)"` + MinPrice string `xorm:"not null default 0.000000000000000000 comment('最低购买金额') DECIMAL(36,18)"` + OpenStatus int `xorm:"not null default 0 comment('上市状态 1未上市 2已上市 3退市') TINYINT"` + OpenTime time.Time `xorm:"comment('上市时间') DATETIME"` + PhaseCount int `xorm:"not null default 1 comment('总共几期返利') INT"` + ProductFile string `xorm:"comment('产品档案(json存储)') JSON"` + Rate string `xorm:"not null comment('收益率 10 为 10%') DECIMAL(5,2)"` + Remark string `xorm:"comment('备注') VARCHAR(255)"` + ShowInterest string `xorm:"not null default 0.000000000000000000 comment('显示收益') DECIMAL(36,18)"` + SignStatus int `xorm:"not null default 2 comment('1 已签名 2 未签名') TINYINT"` + Sort int `xorm:"not null default 0 comment('排序字段,越小越靠前') INT"` + StartTime time.Time `xorm:"comment('开始认购时间') DATETIME"` + Status int `xorm:"not null default 2 comment('发布状态 1 已发布 2 未发布') TINYINT"` + StockCode string `xorm:"not null default '' comment('基金代码 唯一') unique VARCHAR(255)"` + StockInfo string `xorm:"not null comment('基金简介') TEXT"` + StockName string `xorm:"not null default '' comment('基金名称') VARCHAR(255)"` + StockType int `xorm:"not null default 1 comment('基金类型 1固定收益 ') TINYINT"` + Tag string `xorm:"not null comment('基金标签 英文逗号隔开') VARCHAR(255)"` + Tape int `xorm:"not null default 0 comment('交易所类型') TINYINT"` + UpdateTime time.Time `xorm:"DATETIME"` +} diff --git a/internal/pkg/model/bot_pre_fund_stock_refer.go b/internal/pkg/model/bot_pre_fund_stock_refer.go new file mode 100644 index 0000000..5d41610 --- /dev/null +++ b/internal/pkg/model/bot_pre_fund_stock_refer.go @@ -0,0 +1,8 @@ +package models + +type BotPreFundStockRefer struct { + Id int `xorm:"not null pk autoincr INT"` + Name string `xorm:"not null comment('基金名称') VARCHAR(255)"` + Rate string `xorm:"not null comment('收益率 10 为 10%') DECIMAL(5,2)"` + Year int `xorm:"not null comment('年份') SMALLINT"` +} diff --git a/internal/pkg/model/bot_pre_fur_stock.go b/internal/pkg/model/bot_pre_fur_stock.go new file mode 100644 index 0000000..adf96b8 --- /dev/null +++ b/internal/pkg/model/bot_pre_fur_stock.go @@ -0,0 +1,38 @@ +package models + +import ( + "time" +) + +type BotPreFurStock struct { + CompanyInfo string `xorm:"not null comment('公司简介') TEXT"` + CompanyOpenTime time.Time `xorm:"comment('公司上市时间') DATETIME"` + CompanyRegAmount string `xorm:"not null default '' comment('公司注册资本') VARCHAR(255)"` + CreateTime time.Time `xorm:"DATETIME"` + EndTime time.Time `xorm:"comment('认购结束时间') DATETIME"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + HadGetNum int `xorm:"not null default 0 comment('已经认购数量') INT"` + HqStatus int `xorm:"comment('通知行情状态 1 成功 2 失败') SMALLINT(1)"` + Id int `xorm:"not null pk autoincr INT"` + IsDelete int `xorm:"not null default 1 comment('是否删除 1 未删除 2已删除') SMALLINT"` + IsPostPay int `xorm:"not null default 1 comment('是否后支付 1不后支付 2可后支付 ') SMALLINT"` + LimitGetNum int `xorm:"not null default 1 comment('单个账户申购次数') INT"` + Logo string `xorm:"not null default '' comment('基金 logo') VARCHAR(255)"` + Max int `xorm:"not null default 0 comment('最大申购数量') INT"` + Min int `xorm:"not null default 0 comment('最小申购数量') INT"` + OpenStatus int `xorm:"not null default 0 comment('上市状态 见配置') SMALLINT"` + OpenTime time.Time `xorm:"comment('上市时间') DATETIME"` + PayDeadlineTime time.Time `xorm:"comment('预支付截止时间') DATETIME"` + Price string `xorm:"not null default 0.000000000000000000 comment('单股价格') DECIMAL(36,18)"` + Rate string `xorm:"not null comment('10 为 10%') DECIMAL(5,2)"` + SignStatus int `xorm:"not null default 2 comment('1 已签名 2 未签名') SMALLINT"` + StartTime time.Time `xorm:"comment('开始认购时间') DATETIME"` + Status int `xorm:"not null default 2 comment('发布状态 1 已发布 2 未发布') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码 唯一') unique VARCHAR(255)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(255)"` + StockType int `xorm:"not null default 1 comment('股票类型') SMALLINT"` + Tape int `xorm:"not null default 0 comment('交易所类型') SMALLINT"` + Total int `xorm:"not null default 0 comment('发行总数') INT"` + TradeStatus int `xorm:"comment('通知交易状态 1 成功 2 失败') SMALLINT(1)"` + UpdateTime time.Time `xorm:"DATETIME"` +} diff --git a/internal/pkg/model/bot_pre_hkd_stock.go b/internal/pkg/model/bot_pre_hkd_stock.go new file mode 100644 index 0000000..5f8e73e --- /dev/null +++ b/internal/pkg/model/bot_pre_hkd_stock.go @@ -0,0 +1,38 @@ +package models + +import ( + "time" +) + +type BotPreHkdStock struct { + CompanyInfo string `xorm:"not null comment('公司简介') TEXT"` + CompanyOpenTime time.Time `xorm:"comment('公司上市时间') DATETIME"` + CompanyRegAmount string `xorm:"not null default '' comment('公司注册资本') VARCHAR(255)"` + CreateTime time.Time `xorm:"DATETIME"` + EndTime time.Time `xorm:"comment('认购结束时间') DATETIME"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + HadGetNum int `xorm:"not null default 0 comment('已经认购数量') INT"` + HqStatus int `xorm:"comment('通知行情状态 1 成功 2 失败') SMALLINT(1)"` + Id int `xorm:"not null pk autoincr INT"` + IsDelete int `xorm:"not null default 1 comment('是否删除 1 未删除 2已删除') SMALLINT"` + IsPostPay int `xorm:"not null default 1 comment('是否后支付 1不后支付 2可后支付 ') SMALLINT"` + LimitGetNum int `xorm:"not null default 1 comment('单个账户申购次数') INT"` + Logo string `xorm:"not null default '' comment('股票logo') VARCHAR(255)"` + Max int `xorm:"not null default 0 comment('最大申购数量') INT"` + Min int `xorm:"not null default 0 comment('最小申购数量') INT"` + OpenStatus int `xorm:"not null default 0 comment('上市状态 见配置') SMALLINT"` + OpenTime time.Time `xorm:"comment('上市时间') DATETIME"` + PayDeadlineTime time.Time `xorm:"comment('后支付截止时间') DATETIME"` + Price string `xorm:"not null default 0.000000000000000000 comment('单股价格') DECIMAL(36,18)"` + Rate string `xorm:"not null comment('10 为 10%') DECIMAL(5,2)"` + SignStatus int `xorm:"not null default 2 comment('1 已签名 2 未签名') SMALLINT"` + StartTime time.Time `xorm:"comment('开始认购时间') DATETIME"` + Status int `xorm:"not null default 2 comment('发布状态 1 已发布 2 未发布') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码 唯一') unique VARCHAR(255)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(255)"` + StockType int `xorm:"not null default 1 comment('股票类型') SMALLINT"` + Tape int `xorm:"not null default 0 comment('交易所类型') SMALLINT"` + Total int `xorm:"not null default 0 comment('发行总数') INT"` + TradeStatus int `xorm:"comment('通知交易状态 1 成功 2 失败') SMALLINT(1)"` + UpdateTime time.Time `xorm:"DATETIME"` +} diff --git a/internal/pkg/model/bot_pre_idn_stock.go b/internal/pkg/model/bot_pre_idn_stock.go new file mode 100644 index 0000000..c5e0d78 --- /dev/null +++ b/internal/pkg/model/bot_pre_idn_stock.go @@ -0,0 +1,38 @@ +package models + +import ( + "time" +) + +type BotPreIdnStock struct { + CompanyInfo string `xorm:"not null comment('公司简介') TEXT"` + CompanyOpenTime time.Time `xorm:"comment('公司上市时间') DATETIME"` + CompanyRegAmount string `xorm:"not null default '' comment('公司注册资本') VARCHAR(255)"` + CreateTime time.Time `xorm:"DATETIME"` + EndTime time.Time `xorm:"comment('认购结束时间') DATETIME"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + HadGetNum int `xorm:"not null default 0 comment('已经认购数量') INT"` + HqStatus int `xorm:"comment('通知行情状态 1 成功 2 失败') SMALLINT"` + Id int `xorm:"not null pk autoincr INT"` + IsDelete int `xorm:"not null default 1 comment('是否删除 1 未删除 2已删除') SMALLINT"` + IsPostPay int `xorm:"not null default 1 comment('是否后支付 1不后支付 2可后支付 ') SMALLINT"` + LimitGetNum int `xorm:"not null default 1 comment('单个账户申购次数') INT"` + Logo string `xorm:"not null default '' comment('股票logo') VARCHAR(255)"` + Max int `xorm:"not null default 0 comment('最大申购数量') INT"` + Min int `xorm:"not null default 0 comment('最小申购数量') INT"` + OpenStatus int `xorm:"not null default 0 comment('上市状态 见配置') SMALLINT"` + OpenTime time.Time `xorm:"comment('上市时间') DATETIME"` + PayDeadlineTime time.Time `xorm:"comment('后支付截止时间') DATETIME"` + Price string `xorm:"not null default 0.000000000000000000 comment('单股价格') DECIMAL(36,18)"` + Rate string `xorm:"not null comment('10 为 10%') DECIMAL(5,2)"` + SignStatus int `xorm:"not null default 2 comment('1 已签名 2 未签名') SMALLINT"` + StartTime time.Time `xorm:"comment('开始认购时间') DATETIME"` + Status int `xorm:"not null default 2 comment('发布状态 1 已发布 2 未发布') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码 唯一') unique VARCHAR(255)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(255)"` + StockType int `xorm:"not null default 1 comment('股票类型') SMALLINT"` + Tape int `xorm:"not null default 0 comment('交易所类型') SMALLINT"` + Total int `xorm:"not null default 0 comment('发行总数') INT"` + TradeStatus int `xorm:"comment('通知交易状态 1 成功 2 失败') SMALLINT(1)"` + UpdateTime time.Time `xorm:"DATETIME"` +} diff --git a/internal/pkg/model/bot_pre_in_stock.go b/internal/pkg/model/bot_pre_in_stock.go new file mode 100644 index 0000000..0cc3787 --- /dev/null +++ b/internal/pkg/model/bot_pre_in_stock.go @@ -0,0 +1,38 @@ +package models + +import ( + "time" +) + +type BotPreInStock struct { + CompanyInfo string `xorm:"comment('公司简介') TEXT"` + CompanyOpenTime time.Time `xorm:"comment('公司上市时间') DATETIME"` + CompanyRegAmount string `xorm:"not null default '' comment('公司注册资本') VARCHAR(255)"` + CreateTime time.Time `xorm:"DATETIME"` + EndTime time.Time `xorm:"comment('认购结束时间') DATETIME"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + HadGetNum int `xorm:"not null default 0 comment('已经认购数量') INT"` + HqStatus int `xorm:"comment('通知行情状态 1 成功 2 失败') SMALLINT(1)"` + Id int `xorm:"not null pk autoincr INT"` + IsDelete int `xorm:"not null default 1 comment('是否删除 1 未删除 2已删除') SMALLINT"` + IsPostPay int `xorm:"not null default 1 comment('是否后支付 1不后支付 2可后支付 ') SMALLINT"` + LimitGetNum int `xorm:"not null default 1 comment('单个账户申购次数') INT"` + Logo string `xorm:"not null default '' comment('股票logo') VARCHAR(255)"` + Max int `xorm:"not null default 0 comment('最大申购数量') INT"` + Min int `xorm:"not null default 0 comment('最小申购数量') INT"` + OpenStatus int `xorm:"not null default 0 comment('上市状态 见配置') SMALLINT"` + OpenTime time.Time `xorm:"comment('上市时间') DATETIME"` + PayDeadlineTime time.Time `xorm:"comment('后支付截止时间') DATETIME"` + Price string `xorm:"not null default 0.000000000000000000 comment('单股价格') DECIMAL(36,18)"` + Rate string `xorm:"not null default 0.00 comment('10 为 10%') DECIMAL(5,2)"` + SignStatus int `xorm:"not null default 2 comment('1 已签名 2 未签名') SMALLINT"` + StartTime time.Time `xorm:"comment('开始认购时间') DATETIME"` + Status int `xorm:"not null default 2 comment('发布状态 1 已发布 2 未发布') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码 唯一') unique VARCHAR(255)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(255)"` + StockType int `xorm:"not null default 1 comment('股票类型') SMALLINT"` + Tape int `xorm:"not null default 0 comment('交易所类型') SMALLINT"` + Total int `xorm:"not null default 0 comment('发行总数') INT"` + TradeStatus int `xorm:"comment('通知交易状态 1 成功 2 失败') SMALLINT(1)"` + UpdateTime time.Time `xorm:"DATETIME"` +} diff --git a/internal/pkg/model/bot_pre_jp_stock.go b/internal/pkg/model/bot_pre_jp_stock.go new file mode 100644 index 0000000..fd4cac7 --- /dev/null +++ b/internal/pkg/model/bot_pre_jp_stock.go @@ -0,0 +1,38 @@ +package models + +import ( + "time" +) + +type BotPreJpStock struct { + CompanyInfo string `xorm:"not null comment('公司简介') TEXT"` + CompanyOpenTime time.Time `xorm:"comment('公司上市时间') DATETIME"` + CompanyRegAmount string `xorm:"not null default '' comment('公司注册资本') VARCHAR(255)"` + CreateTime time.Time `xorm:"DATETIME"` + EndTime time.Time `xorm:"comment('认购结束时间') DATETIME"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + HadGetNum int `xorm:"not null default 0 comment('已经认购数量') INT"` + HqStatus int `xorm:"comment('通知行情状态 1 成功 2 失败') SMALLINT(1)"` + Id int `xorm:"not null pk autoincr INT"` + IsDelete int `xorm:"not null default 1 comment('是否删除 1 未删除 2已删除') SMALLINT"` + IsPostPay int `xorm:"not null default 1 comment('是否后支付 1不后支付 2可后支付 ') SMALLINT"` + LimitGetNum int `xorm:"not null default 1 comment('单个账户申购次数') INT"` + Logo string `xorm:"not null default '' comment('基金 logo') VARCHAR(255)"` + Max int `xorm:"not null default 0 comment('最大申购数量') INT"` + Min int `xorm:"not null default 0 comment('最小申购数量') INT"` + OpenStatus int `xorm:"not null default 0 comment('上市状态 见配置') SMALLINT"` + OpenTime time.Time `xorm:"comment('上市时间') DATETIME"` + PayDeadlineTime time.Time `xorm:"comment('预支付截止时间') DATETIME"` + Price string `xorm:"not null default 0.000000000000000000 comment('单股价格') DECIMAL(36,18)"` + Rate string `xorm:"not null comment('10 为 10%') DECIMAL(5,2)"` + SignStatus int `xorm:"not null default 2 comment('1 已签名 2 未签名') SMALLINT"` + StartTime time.Time `xorm:"comment('开始认购时间') DATETIME"` + Status int `xorm:"not null default 2 comment('发布状态 1 已发布 2 未发布') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码 唯一') unique VARCHAR(255)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(255)"` + StockType int `xorm:"not null default 1 comment('股票类型') SMALLINT"` + Tape int `xorm:"not null default 0 comment('交易所类型') SMALLINT"` + Total int `xorm:"not null default 0 comment('发行总数') INT"` + TradeStatus int `xorm:"comment('通知交易状态 1 成功 2 失败') SMALLINT(1)"` + UpdateTime time.Time `xorm:"DATETIME"` +} diff --git a/internal/pkg/model/bot_pre_mys_stock.go b/internal/pkg/model/bot_pre_mys_stock.go new file mode 100644 index 0000000..8981e69 --- /dev/null +++ b/internal/pkg/model/bot_pre_mys_stock.go @@ -0,0 +1,38 @@ +package models + +import ( + "time" +) + +type BotPreMysStock struct { + CompanyInfo string `xorm:"not null comment('公司简介') TEXT"` + CompanyOpenTime time.Time `xorm:"comment('公司上市时间') DATETIME"` + CompanyRegAmount string `xorm:"not null default '' comment('公司注册资本') VARCHAR(255)"` + CreateTime time.Time `xorm:"DATETIME"` + EndTime time.Time `xorm:"comment('认购结束时间') DATETIME"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + HadGetNum int `xorm:"not null default 0 comment('已经认购数量') INT"` + HqStatus int `xorm:"comment('通知行情状态 1 成功 2 失败') SMALLINT(1)"` + Id int `xorm:"not null pk autoincr INT"` + IsDelete int `xorm:"not null default 1 comment('是否删除 1 未删除 2已删除') SMALLINT"` + IsPostPay int `xorm:"not null default 1 comment('是否后支付 1不后支付 2可后支付 ') SMALLINT"` + LimitGetNum int `xorm:"not null default 1 comment('单个账户申购次数') INT"` + Logo string `xorm:"not null default '' comment('股票logo') VARCHAR(255)"` + Max int `xorm:"not null default 0 comment('最大申购数量') INT"` + Min int `xorm:"not null default 0 comment('最小申购数量') INT"` + OpenStatus int `xorm:"not null default 0 comment('上市状态 见配置') SMALLINT"` + OpenTime time.Time `xorm:"comment('上市时间') DATETIME"` + PayDeadlineTime time.Time `xorm:"comment('预支付截止时间') DATETIME"` + Price string `xorm:"not null default 0.000000000000000000 comment('单股价格') DECIMAL(36,18)"` + Rate string `xorm:"not null comment('10 为 10%') DECIMAL(5,2)"` + SignStatus int `xorm:"not null default 2 comment('1 已签名 2 未签名') SMALLINT"` + StartTime time.Time `xorm:"comment('开始认购时间') DATETIME"` + Status int `xorm:"not null default 2 comment('发布状态 1 已发布 2 未发布') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码 唯一') unique VARCHAR(255)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(255)"` + StockType int `xorm:"not null default 1 comment('股票类型') SMALLINT"` + Tape int `xorm:"not null default 0 comment('交易所类型') SMALLINT"` + Total int `xorm:"not null default 0 comment('发行总数') INT"` + TradeStatus int `xorm:"comment('通知交易状态 1 成功 2 失败') SMALLINT(1)"` + UpdateTime time.Time `xorm:"DATETIME"` +} diff --git a/internal/pkg/model/bot_pre_sgd_stock.go b/internal/pkg/model/bot_pre_sgd_stock.go new file mode 100644 index 0000000..97db818 --- /dev/null +++ b/internal/pkg/model/bot_pre_sgd_stock.go @@ -0,0 +1,38 @@ +package models + +import ( + "time" +) + +type BotPreSgdStock struct { + CompanyInfo string `xorm:"not null comment('公司简介') TEXT"` + CompanyOpenTime time.Time `xorm:"comment('公司上市时间') DATETIME"` + CompanyRegAmount string `xorm:"not null default '' comment('公司注册资本') VARCHAR(255)"` + CreateTime time.Time `xorm:"DATETIME"` + EndTime time.Time `xorm:"comment('认购结束时间') DATETIME"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + HadGetNum int `xorm:"not null default 0 comment('已经认购数量') INT"` + HqStatus int `xorm:"comment('通知行情状态 1 成功 2 失败') SMALLINT(1)"` + Id int `xorm:"not null pk autoincr INT"` + IsDelete int `xorm:"not null default 1 comment('是否删除 1 未删除 2已删除') SMALLINT"` + IsPostPay int `xorm:"not null default 1 comment('是否后支付 1不后支付 2可后支付 ') SMALLINT"` + LimitGetNum int `xorm:"not null default 1 comment('单个账户申购次数') INT"` + Logo string `xorm:"not null default '' comment('基金 logo') VARCHAR(255)"` + Max int `xorm:"not null default 0 comment('最大申购数量') INT"` + Min int `xorm:"not null default 0 comment('最小申购数量') INT"` + OpenStatus int `xorm:"not null default 0 comment('上市状态 见配置') SMALLINT"` + OpenTime time.Time `xorm:"comment('上市时间') DATETIME"` + PayDeadlineTime time.Time `xorm:"comment('预支付截止时间') DATETIME"` + Price string `xorm:"not null default 0.000000000000000000 comment('单股价格') DECIMAL(36,18)"` + Rate string `xorm:"not null comment('10 为 10%') DECIMAL(5,2)"` + SignStatus int `xorm:"not null default 2 comment('1 已签名 2 未签名') SMALLINT"` + StartTime time.Time `xorm:"comment('开始认购时间') DATETIME"` + Status int `xorm:"not null default 2 comment('发布状态 1 已发布 2 未发布') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码 唯一') unique VARCHAR(255)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(255)"` + StockType int `xorm:"not null default 1 comment('股票类型') SMALLINT"` + Tape int `xorm:"not null default 0 comment('交易所类型') SMALLINT"` + Total int `xorm:"not null default 0 comment('发行总数') INT"` + TradeStatus int `xorm:"comment('通知交易状态 1 成功 2 失败') SMALLINT(1)"` + UpdateTime time.Time `xorm:"DATETIME"` +} diff --git a/internal/pkg/model/bot_pre_tha_stock.go b/internal/pkg/model/bot_pre_tha_stock.go new file mode 100644 index 0000000..a0cb536 --- /dev/null +++ b/internal/pkg/model/bot_pre_tha_stock.go @@ -0,0 +1,38 @@ +package models + +import ( + "time" +) + +type BotPreThaStock struct { + CompanyInfo string `xorm:"not null comment('公司简介') TEXT"` + CompanyOpenTime time.Time `xorm:"comment('公司上市时间') DATETIME"` + CompanyRegAmount string `xorm:"not null default '' comment('公司注册资本') VARCHAR(255)"` + CreateTime time.Time `xorm:"DATETIME"` + EndTime time.Time `xorm:"comment('认购结束时间') DATETIME"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + HadGetNum int `xorm:"not null default 0 comment('已经认购数量') INT"` + HqStatus int `xorm:"comment('通知交易状态 1 成功 2 失败') SMALLINT(5)"` + Id int `xorm:"not null pk autoincr INT"` + IsDelete int `xorm:"not null default 1 comment('是否删除 1 未删除 2已删除') SMALLINT"` + IsPostPay int `xorm:"not null default 1 comment('是否后支付 1不后支付 2可后支付 ') SMALLINT"` + LimitGetNum int `xorm:"not null default 1 comment('单个账户申购次数') INT"` + Logo string `xorm:"not null default '' comment('股票logo') VARCHAR(255)"` + Max int `xorm:"not null default 0 comment('最大申购数量') INT"` + Min int `xorm:"not null default 0 comment('最小申购数量') INT"` + OpenStatus int `xorm:"not null default 0 comment('上市状态 见配置') SMALLINT"` + OpenTime time.Time `xorm:"comment('上市时间') DATETIME"` + PayDeadlineTime time.Time `xorm:"comment('预支付截止时间') DATETIME"` + Price string `xorm:"not null default 0.000000000000000000 comment('单股价格') DECIMAL(36,18)"` + Rate string `xorm:"not null comment('10 为 10%') DECIMAL(5,2)"` + SignStatus int `xorm:"not null default 2 comment('1 已签名 2 未签名') SMALLINT"` + StartTime time.Time `xorm:"comment('开始认购时间') DATETIME"` + Status int `xorm:"not null default 2 comment('发布状态 1 已发布 2 未发布') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码 唯一') unique VARCHAR(255)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(255)"` + StockType int `xorm:"not null default 1 comment('股票类型') SMALLINT"` + Tape int `xorm:"not null default 0 comment('交易所类型') SMALLINT"` + Total int `xorm:"not null default 0 comment('发行总数') INT"` + TradeStatus int `xorm:"comment('通知交易状态 1 成功 2 失败') SMALLINT(5)"` + UpdateTime time.Time `xorm:"DATETIME"` +} diff --git a/internal/pkg/model/bot_pre_us_stock.go b/internal/pkg/model/bot_pre_us_stock.go new file mode 100644 index 0000000..91745a2 --- /dev/null +++ b/internal/pkg/model/bot_pre_us_stock.go @@ -0,0 +1,38 @@ +package models + +import ( + "time" +) + +type BotPreUsStock struct { + CompanyInfo string `xorm:"not null comment('公司简介') TEXT"` + CompanyOpenTime time.Time `xorm:"comment('公司上市时间') DATETIME"` + CompanyRegAmount string `xorm:"not null default '' comment('公司注册资本') VARCHAR(255)"` + CreateTime time.Time `xorm:"DATETIME"` + EndTime time.Time `xorm:"comment('认购结束时间') DATETIME"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + HadGetNum int `xorm:"not null default 0 comment('已经认购数量') INT"` + HqStatus int `xorm:"comment('通知行情状态 1 成功 2 失败') SMALLINT(1)"` + Id int `xorm:"not null pk autoincr INT"` + IsDelete int `xorm:"not null default 1 comment('是否删除 1 未删除 2已删除') SMALLINT"` + IsPostPay int `xorm:"not null default 1 comment('是否后支付 1不后支付 2可后支付 ') SMALLINT"` + LimitGetNum int `xorm:"not null default 1 comment('单个账户申购次数') INT"` + Logo string `xorm:"not null default '' comment('股票logo') VARCHAR(255)"` + Max int `xorm:"not null default 0 comment('最大申购数量') INT"` + Min int `xorm:"not null default 0 comment('最小申购数量') INT"` + OpenStatus int `xorm:"not null default 0 comment('上市状态 见配置') SMALLINT"` + OpenTime time.Time `xorm:"comment('上市时间') DATETIME"` + PayDeadlineTime time.Time `xorm:"comment('后支付截止时间') DATETIME"` + Price string `xorm:"not null default 0.000000000000000000 comment('单股价格') DECIMAL(36,18)"` + Rate string `xorm:"not null comment('10 为 10%') DECIMAL(5,2)"` + SignStatus int `xorm:"not null default 2 comment('1 已签名 2 未签名') SMALLINT"` + StartTime time.Time `xorm:"comment('开始认购时间') DATETIME"` + Status int `xorm:"not null default 2 comment('发布状态 1 已发布 2 未发布') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码 唯一') unique VARCHAR(255)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(255)"` + StockType int `xorm:"not null default 1 comment('股票类型') SMALLINT"` + Tape int `xorm:"not null default 0 comment('交易所类型') SMALLINT"` + Total int `xorm:"not null default 0 comment('发行总数') INT"` + TradeStatus int `xorm:"comment('通知交易状态 1 成功 2 失败') SMALLINT(1)"` + UpdateTime time.Time `xorm:"DATETIME"` +} diff --git a/internal/pkg/model/bot_recharge_apply.go b/internal/pkg/model/bot_recharge_apply.go new file mode 100644 index 0000000..eb39407 --- /dev/null +++ b/internal/pkg/model/bot_recharge_apply.go @@ -0,0 +1,29 @@ +package models + +import ( + "time" +) + +type BotRechargeApply struct { + AccountType int `xorm:"not null comment('充值账号类型:1现货,2合约,3美股') index(user_id) TINYINT(1)"` + Country string `xorm:"comment('国家') VARCHAR(50)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + CurrencyRate string `xorm:"comment('汇率') DECIMAL(36,5)"` + DealTime time.Time `xorm:"comment('充值完成时间') DATETIME"` + FileId int `xorm:"comment('文件ID') INT"` + Id int `xorm:"not null pk autoincr INT"` + IsCheck int `xorm:"comment('是否审核:1批准, 2拒绝') TINYINT(1)"` + IsOnline int `xorm:"comment('是否在线充值:1是,0否') index TINYINT(1)"` + MarketAmount string `xorm:"comment('换算的市场金额') DECIMAL(36,18)"` + OrderIdx string `xorm:"comment('第三方订单号') VARCHAR(100)"` + OrderNo string `xorm:"not null comment('充值订单号') VARCHAR(30)"` + PayUrl string `xorm:"comment('支付链接') VARCHAR(255)"` + RechargeChannel string `xorm:"comment('充值渠道') VARCHAR(30)"` + RechargeNum string `xorm:"not null comment('充值金额(美元)') DECIMAL(36,18)"` + RechargeType int `xorm:"not null comment('充值方式:1数字币,2银行卡') TINYINT(1)"` + ServiceFee string `xorm:"comment('手续费用') DECIMAL(36,2)"` + Status int `xorm:"not null comment('充值状态:0充值中,1充值已完成') index index(user_id) TINYINT(1)"` + TotalAmount string `xorm:"comment('总支付金额(渠道货币)') DECIMAL(36,5)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_service_setting.go b/internal/pkg/model/bot_service_setting.go new file mode 100644 index 0000000..c342ebf --- /dev/null +++ b/internal/pkg/model/bot_service_setting.go @@ -0,0 +1,9 @@ +package models + +type BotServiceSetting struct { + HeaderPhoto string `xorm:"comment('头像图片') VARCHAR(255)"` + Id int `xorm:"not null pk autoincr INT"` + ServerLink string `xorm:"comment('内容') VARCHAR(255)"` + ServerName string `xorm:"comment('客服名称') VARCHAR(255)"` + Type int `xorm:"not null default 1 comment('1:邮箱 2:跳转地址') TINYINT"` +} diff --git a/internal/pkg/model/bot_stock_block_list.go b/internal/pkg/model/bot_stock_block_list.go new file mode 100644 index 0000000..03ad33c --- /dev/null +++ b/internal/pkg/model/bot_stock_block_list.go @@ -0,0 +1,27 @@ +package models + +import ( + "time" +) + +type BotStockBlockList struct { + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + DownLimit string `xorm:"not null default 0.00 comment('跌停限制 30 表示 30%') DECIMAL(10,2)"` + EndTime time.Time `xorm:"comment('购买结束时间') DATETIME"` + ForcedClosure string `xorm:"not null default 0.00 comment('强制平仓阈值 30 表示 30%') DECIMAL(10,2)"` + Id int `xorm:"not null pk autoincr INT"` + Info string `xorm:"comment('股票简介') TEXT"` + IsDelete int `xorm:"not null default 1 comment('是否删除 1 未删除 2已删除') SMALLINT"` + KeepDecimal int `xorm:"not null default 4 comment('保留小数位') INT"` + Min int `xorm:"not null default 0 comment('最小购买股数') INT"` + Price string `xorm:"comment('单股价格') DECIMAL(36,18)"` + StartTime time.Time `xorm:"comment('开始购买时间') DATETIME"` + Status int `xorm:"not null default 0 comment('启用状态:0未启用,1已启用') TINYINT(1)"` + StockCode string `xorm:"not null default '' comment('股票代码') unique VARCHAR(100)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(100)"` + Tape int `xorm:"not null default 0 comment('交易所类型 0 未选择 详细见配置') SMALLINT"` + TodayAdd int `xorm:"not null default 3 comment('T+n可卖') SMALLINT"` + Type int `xorm:"comment('市场类型:3美股、4印尼股、5马股、6泰股、7印度股、9新加坡股、12港股') index INT"` + UpLimit string `xorm:"not null default 0.00 comment('涨停限制 30 表示 30%') DECIMAL(10,2)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` +} diff --git a/internal/pkg/model/bot_stock_block_trade.go b/internal/pkg/model/bot_stock_block_trade.go new file mode 100644 index 0000000..f861e98 --- /dev/null +++ b/internal/pkg/model/bot_stock_block_trade.go @@ -0,0 +1,37 @@ +package models + +import ( + "time" +) + +type BotStockBlockTrade struct { + ClosingCost string `xorm:"comment('平仓手续费') DECIMAL(36,18)"` + ClosingPrice string `xorm:"comment('平仓价格') DECIMAL(36,18)"` + ClosingTime time.Time `xorm:"comment('平仓时间') DATETIME"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + DealPrice string `xorm:"comment('成交价') DECIMAL(36,18)"` + DealType int `xorm:"not null default 0 comment('委托方式:1限价,2市价') index(user_id) TINYINT(1)"` + FaceValue int `xorm:"comment('面值') INT"` + KeepDecimal int `xorm:"comment('股票保留小数位') INT"` + LimitPrice string `xorm:"comment('限价') DECIMAL(36,18)"` + MarketMoney string `xorm:"not null comment('市值金额') DECIMAL(36,18)"` + MarketPrice string `xorm:"comment('市价') DECIMAL(36,18)"` + OpenTime time.Time `xorm:"comment('成交时间') DATETIME"` + OrderId string `xorm:"not null comment('订单ID') index(order_id) index(user_id) VARCHAR(60)"` + OrderMoney string `xorm:"not null comment('订单总金额') DECIMAL(36,18)"` + OrderNumber string `xorm:"not null comment('委托数量') DECIMAL(36,18)"` + OvernightCost string `xorm:"comment('过夜手续费') DECIMAL(36,18)"` + PryNum int `xorm:"comment('杠杆') INT"` + ServiceCost string `xorm:"not null comment('持仓手续费') DECIMAL(36,18)"` + Status int `xorm:"not null default 0 comment('订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单') index(order_id) index(u_s_s) index(user_id) TINYINT(1)"` + StockId string `xorm:"not null comment('股票id') index(u_s_s) index(user_id) VARCHAR(100)"` + StockName string `xorm:"comment('股票名称') VARCHAR(255)"` + StopLossPrice string `xorm:"comment('止损价') DECIMAL(36,18)"` + StopType int `xorm:"not null comment('止损止盈设置:0无设置,1止损止盈') TINYINT(1)"` + StopWinPrice string `xorm:"comment('止赢价') DECIMAL(36,18)"` + TradeId int `xorm:"not null pk autoincr comment('自增长ID') INT"` + TradeType int `xorm:"not null default 0 comment('交易类型:1买入,2卖出') index(user_id) TINYINT(1)"` + Type int `xorm:"comment('市场类型:3美股、4印尼股、5马股、6泰股、7印度股、9新加坡股、12港股') INT"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(u_s_s) index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_stock_brl_list.go b/internal/pkg/model/bot_stock_brl_list.go new file mode 100644 index 0000000..e4ee3fa --- /dev/null +++ b/internal/pkg/model/bot_stock_brl_list.go @@ -0,0 +1,21 @@ +package models + +import ( + "time" +) + +type BotStockBrlList struct { + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + DownLimit string `xorm:"not null default 0.00 comment('跌停限制 30 表示 30%') DECIMAL(10,2)"` + ForcedClosure string `xorm:"not null default 0.00 comment('强制平仓阈值 30 表示 30%') DECIMAL(10,2)"` + Id int `xorm:"not null pk autoincr INT"` + Info string `xorm:"comment('股票简介') TEXT"` + KeepDecimal int `xorm:"not null default 0 comment('保留小数位') INT"` + Status int `xorm:"not null default 0 comment('启用状态:0未启用,1已启用') index TINYINT(1)"` + StockCode string `xorm:"not null default '' comment('股票代码') unique VARCHAR(100)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(100)"` + Tape int `xorm:"not null default 0 comment('交易所类型 0 未选择 详细见配置') index SMALLINT"` + UpLimit string `xorm:"not null default 0.00 comment('涨停限制 30 表示 30%') DECIMAL(10,2)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + YesterdayClose string `xorm:"not null default 0.000000000000000000 comment('昨日收盘价(新股初始价)') DECIMAL(36,18)"` +} diff --git a/internal/pkg/model/bot_stock_brl_trade.go b/internal/pkg/model/bot_stock_brl_trade.go new file mode 100644 index 0000000..ead058d --- /dev/null +++ b/internal/pkg/model/bot_stock_brl_trade.go @@ -0,0 +1,36 @@ +package models + +import ( + "time" +) + +type BotStockBrlTrade struct { + ClosingCost string `xorm:"comment('平仓手续费') DECIMAL(36,18)"` + ClosingPrice string `xorm:"comment('平仓价格') DECIMAL(36,18)"` + ClosingTime time.Time `xorm:"comment('平仓时间') DATETIME"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + DealPrice string `xorm:"comment('成交价') DECIMAL(36,18)"` + DealType int `xorm:"not null default 0 comment('委托方式:1限价,2市价') index(user_id) TINYINT(1)"` + FaceValue int `xorm:"comment('面值') INT"` + KeepDecimal int `xorm:"comment('股票保留小数位') INT"` + LimitPrice string `xorm:"comment('限价') DECIMAL(36,18)"` + MarketMoney string `xorm:"not null comment('市值金额') DECIMAL(36,18)"` + MarketPrice string `xorm:"comment('市价') DECIMAL(36,18)"` + OpenTime time.Time `xorm:"comment('成交时间') DATETIME"` + OrderId string `xorm:"not null comment('订单ID') index(order_id) index(user_id) VARCHAR(60)"` + OrderMoney string `xorm:"not null comment('订单总金额') DECIMAL(36,18)"` + OrderNumber string `xorm:"not null comment('委托数量') DECIMAL(36,18)"` + OvernightCost string `xorm:"comment('过夜手续费') DECIMAL(36,18)"` + PryNum int `xorm:"comment('杠杆') INT"` + ServiceCost string `xorm:"not null comment('持仓手续费') DECIMAL(36,18)"` + Status int `xorm:"not null default 0 comment('订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单') index(order_id) index(u_s_s) index(user_id) TINYINT(1)"` + StockId string `xorm:"not null comment('股票id') index(u_s_s) index(user_id) VARCHAR(100)"` + StockName string `xorm:"comment('股票名称') VARCHAR(255)"` + StopLossPrice string `xorm:"comment('止损价') DECIMAL(36,18)"` + StopType int `xorm:"not null comment('止损止盈设置:0无设置,1止损止盈') TINYINT(1)"` + StopWinPrice string `xorm:"comment('止赢价') DECIMAL(36,18)"` + TradeId int `xorm:"not null pk autoincr comment('自增长ID') INT"` + TradeType int `xorm:"not null default 0 comment('交易类型:1买入,2卖出') index(user_id) TINYINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(u_s_s) index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_stock_eur_list.go b/internal/pkg/model/bot_stock_eur_list.go new file mode 100644 index 0000000..d456a43 --- /dev/null +++ b/internal/pkg/model/bot_stock_eur_list.go @@ -0,0 +1,21 @@ +package models + +import ( + "time" +) + +type BotStockEurList struct { + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + DownLimit string `xorm:"not null default 0.00 comment('跌停限制 30 表示 30%') DECIMAL(10,2)"` + ForcedClosure string `xorm:"not null default 0.00 comment('强制平仓阈值 30 表示 30%') DECIMAL(10,2)"` + Id int `xorm:"not null pk autoincr INT"` + Info string `xorm:"comment('股票简介') TEXT"` + KeepDecimal int `xorm:"not null default 0 comment('保留小数位') INT"` + Status int `xorm:"not null default 0 comment('启用状态:0未启用,1已启用') index TINYINT(1)"` + StockCode string `xorm:"not null default '' comment('股票代码') unique VARCHAR(100)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(100)"` + Tape int `xorm:"not null default 0 comment('交易所类型 0 未选择 详细见配置') index SMALLINT"` + UpLimit string `xorm:"not null default 0.00 comment('涨停限制 30 表示 30%') DECIMAL(10,2)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + YesterdayClose string `xorm:"not null default 0.000000000000000000 comment('昨日收盘价(新股初始价)') DECIMAL(36,18)"` +} diff --git a/internal/pkg/model/bot_stock_eur_trade.go b/internal/pkg/model/bot_stock_eur_trade.go new file mode 100644 index 0000000..8418fd2 --- /dev/null +++ b/internal/pkg/model/bot_stock_eur_trade.go @@ -0,0 +1,36 @@ +package models + +import ( + "time" +) + +type BotStockEurTrade struct { + ClosingCost string `xorm:"comment('平仓手续费') DECIMAL(36,18)"` + ClosingPrice string `xorm:"comment('平仓价格') DECIMAL(36,18)"` + ClosingTime time.Time `xorm:"comment('平仓时间') DATETIME"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + DealPrice string `xorm:"comment('成交价') DECIMAL(36,18)"` + DealType int `xorm:"not null default 0 comment('委托方式:1限价,2市价') index(user_id) TINYINT(1)"` + FaceValue int `xorm:"comment('面值') INT"` + KeepDecimal int `xorm:"comment('股票保留小数位') INT"` + LimitPrice string `xorm:"comment('限价') DECIMAL(36,18)"` + MarketMoney string `xorm:"not null comment('市值金额') DECIMAL(36,18)"` + MarketPrice string `xorm:"comment('市价') DECIMAL(36,18)"` + OpenTime time.Time `xorm:"comment('成交时间') DATETIME"` + OrderId string `xorm:"not null comment('订单ID') index(order_id) index(user_id) VARCHAR(60)"` + OrderMoney string `xorm:"not null comment('订单总金额') DECIMAL(36,18)"` + OrderNumber string `xorm:"not null comment('委托数量') DECIMAL(36,18)"` + OvernightCost string `xorm:"comment('过夜手续费') DECIMAL(36,18)"` + PryNum int `xorm:"comment('杠杆') INT"` + ServiceCost string `xorm:"not null comment('持仓手续费') DECIMAL(36,18)"` + Status int `xorm:"not null default 0 comment('订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单') index(order_id) index(u_s_s) index(user_id) TINYINT(1)"` + StockId string `xorm:"not null comment('股票id') index(u_s_s) index(user_id) VARCHAR(100)"` + StockName string `xorm:"comment('股票名称') VARCHAR(255)"` + StopLossPrice string `xorm:"comment('止损价') DECIMAL(36,18)"` + StopType int `xorm:"not null comment('止损止盈设置:0无设置,1止损止盈') TINYINT(1)"` + StopWinPrice string `xorm:"comment('止赢价') DECIMAL(36,18)"` + TradeId int `xorm:"not null pk autoincr comment('自增长ID') INT"` + TradeType int `xorm:"not null default 0 comment('交易类型:1买入,2卖出') index(user_id) TINYINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(u_s_s) index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_stock_fur_list.go b/internal/pkg/model/bot_stock_fur_list.go new file mode 100644 index 0000000..0bfa4a3 --- /dev/null +++ b/internal/pkg/model/bot_stock_fur_list.go @@ -0,0 +1,21 @@ +package models + +import ( + "time" +) + +type BotStockFurList struct { + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + DownLimit string `xorm:"not null default 0.00 comment('跌停限制 30 表示 30%') DECIMAL(10,2)"` + ForcedClosure string `xorm:"not null default 0.00 comment('强制平仓阈值 30 表示 30%') DECIMAL(10,2)"` + Id int `xorm:"not null pk autoincr INT"` + Info string `xorm:"comment('股票简介') TEXT"` + KeepDecimal int `xorm:"not null default 0 comment('保留小数位') INT"` + Status int `xorm:"not null default 0 comment('启用状态:0未启用,1已启用') index TINYINT(1)"` + StockCode string `xorm:"not null default '' comment('股票代码') unique VARCHAR(100)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(100)"` + Tape int `xorm:"not null default 0 comment('交易所类型 0 未选择 详细见配置') index SMALLINT"` + UpLimit string `xorm:"not null default 0.00 comment('涨停限制 30 表示 30%') DECIMAL(10,2)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + YesterdayClose string `xorm:"not null default 0.000000000000000000 comment('昨日收盘价(新股初始价)') DECIMAL(36,18)"` +} diff --git a/internal/pkg/model/bot_stock_fur_trade.go b/internal/pkg/model/bot_stock_fur_trade.go new file mode 100644 index 0000000..f0dea69 --- /dev/null +++ b/internal/pkg/model/bot_stock_fur_trade.go @@ -0,0 +1,36 @@ +package models + +import ( + "time" +) + +type BotStockFurTrade struct { + ClosingCost string `xorm:"comment('平仓手续费') DECIMAL(36,18)"` + ClosingPrice string `xorm:"comment('平仓价格') DECIMAL(36,18)"` + ClosingTime time.Time `xorm:"comment('平仓时间') DATETIME"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + DealPrice string `xorm:"comment('成交价') DECIMAL(36,18)"` + DealType int `xorm:"not null default 0 comment('委托方式:1限价,2市价') index(user_id) TINYINT(1)"` + FaceValue int `xorm:"comment('面值') INT"` + KeepDecimal int `xorm:"comment('股票保留小数位') INT"` + LimitPrice string `xorm:"comment('限价') DECIMAL(36,18)"` + MarketMoney string `xorm:"not null comment('市值金额') DECIMAL(36,18)"` + MarketPrice string `xorm:"comment('市价') DECIMAL(36,18)"` + OpenTime time.Time `xorm:"comment('成交时间') DATETIME"` + OrderId string `xorm:"not null comment('订单ID') index(order_id) index(user_id) VARCHAR(60)"` + OrderMoney string `xorm:"not null comment('订单总金额') DECIMAL(36,18)"` + OrderNumber string `xorm:"not null comment('委托数量') DECIMAL(36,18)"` + OvernightCost string `xorm:"comment('过夜手续费') DECIMAL(36,18)"` + PryNum int `xorm:"comment('杠杆') INT"` + ServiceCost string `xorm:"not null comment('持仓手续费') DECIMAL(36,18)"` + Status int `xorm:"not null default 0 comment('订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单') index(order_id) index(u_s_s) index(user_id) TINYINT(1)"` + StockId string `xorm:"not null comment('股票id') index(u_s_s) index(user_id) VARCHAR(100)"` + StockName string `xorm:"comment('股票名称') VARCHAR(255)"` + StopLossPrice string `xorm:"comment('止损价') DECIMAL(36,18)"` + StopType int `xorm:"not null comment('止损止盈设置:0无设置,1止损止盈') TINYINT(1)"` + StopWinPrice string `xorm:"comment('止赢价') DECIMAL(36,18)"` + TradeId int `xorm:"not null pk autoincr comment('自增长ID') INT"` + TradeType int `xorm:"not null default 0 comment('交易类型:1买入,2卖出') index(user_id) TINYINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(u_s_s) index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_stock_gbx_list.go b/internal/pkg/model/bot_stock_gbx_list.go new file mode 100644 index 0000000..1cf9e40 --- /dev/null +++ b/internal/pkg/model/bot_stock_gbx_list.go @@ -0,0 +1,22 @@ +package models + +import ( + "time" +) + +type BotStockGbxList struct { + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + DownLimit string `xorm:"not null default 0.00 comment('跌停限制 30 表示 30%') DECIMAL(10,2)"` + ForcedClosure string `xorm:"not null default 0.00 comment('强制平仓阈值 30 表示 30%') DECIMAL(10,2)"` + Id int `xorm:"not null pk autoincr INT"` + Info string `xorm:"comment('股票简介') TEXT"` + KeepDecimal int `xorm:"not null default 0 comment('保留小数位') INT"` + Source int `xorm:"not null default 1 SMALLINT"` + Status int `xorm:"not null default 0 comment('启用状态:0未启用,1已启用') index TINYINT(1)"` + StockCode string `xorm:"not null default '' comment('股票代码') unique VARCHAR(100)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(100)"` + Tape int `xorm:"not null default 0 comment('交易所类型 0 未选择 详细见配置') index SMALLINT"` + UpLimit string `xorm:"not null default 0.00 comment('涨停限制 30 表示 30%') DECIMAL(10,2)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + YesterdayClose string `xorm:"not null default 0.000000000000000000 comment('昨日收盘价(新股初始价)') DECIMAL(36,18)"` +} diff --git a/internal/pkg/model/bot_stock_gbx_trade.go b/internal/pkg/model/bot_stock_gbx_trade.go new file mode 100644 index 0000000..1386131 --- /dev/null +++ b/internal/pkg/model/bot_stock_gbx_trade.go @@ -0,0 +1,36 @@ +package models + +import ( + "time" +) + +type BotStockGbxTrade struct { + ClosingCost string `xorm:"comment('平仓手续费') DECIMAL(36,18)"` + ClosingPrice string `xorm:"comment('平仓价格') DECIMAL(36,18)"` + ClosingTime time.Time `xorm:"comment('平仓时间') DATETIME"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + DealPrice string `xorm:"comment('成交价') DECIMAL(36,18)"` + DealType int `xorm:"not null default 0 comment('委托方式:1限价,2市价') index(user_id) TINYINT(1)"` + FaceValue int `xorm:"comment('面值') INT"` + KeepDecimal int `xorm:"comment('股票保留小数位') INT"` + LimitPrice string `xorm:"comment('限价') DECIMAL(36,18)"` + MarketMoney string `xorm:"not null comment('市值金额') DECIMAL(36,18)"` + MarketPrice string `xorm:"comment('市价') DECIMAL(36,18)"` + OpenTime time.Time `xorm:"comment('成交时间') DATETIME"` + OrderId string `xorm:"not null comment('订单ID') index(order_id) index(user_id) VARCHAR(60)"` + OrderMoney string `xorm:"not null comment('订单总金额') DECIMAL(36,18)"` + OrderNumber string `xorm:"not null comment('委托数量') DECIMAL(36,18)"` + OvernightCost string `xorm:"comment('过夜手续费') DECIMAL(36,18)"` + PryNum int `xorm:"comment('杠杆') INT"` + ServiceCost string `xorm:"not null comment('持仓手续费') DECIMAL(36,18)"` + Status int `xorm:"not null default 0 comment('订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单') index(order_id) index(u_s_s) index(user_id) TINYINT(1)"` + StockId string `xorm:"not null comment('股票id') index(u_s_s) index(user_id) VARCHAR(100)"` + StockName string `xorm:"comment('股票名称') VARCHAR(255)"` + StopLossPrice string `xorm:"comment('止损价') DECIMAL(36,18)"` + StopType int `xorm:"not null comment('止损止盈设置:0无设置,1止损止盈') TINYINT(1)"` + StopWinPrice string `xorm:"comment('止赢价') DECIMAL(36,18)"` + TradeId int `xorm:"not null pk autoincr comment('自增长ID') INT"` + TradeType int `xorm:"not null default 0 comment('交易类型:1买入,2卖出') index(user_id) TINYINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(u_s_s) index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_stock_hkd_list.go b/internal/pkg/model/bot_stock_hkd_list.go new file mode 100644 index 0000000..5cd74cd --- /dev/null +++ b/internal/pkg/model/bot_stock_hkd_list.go @@ -0,0 +1,21 @@ +package models + +import ( + "time" +) + +type BotStockHkdList struct { + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + DownLimit string `xorm:"not null default 0.00 comment('跌停限制 30 表示 30%') DECIMAL(10,2)"` + ForcedClosure string `xorm:"not null default 0.00 comment('强制平仓阈值 30 表示 30%') DECIMAL(10,2)"` + Id int `xorm:"not null pk autoincr INT"` + Info string `xorm:"comment('股票简介') TEXT"` + KeepDecimal int `xorm:"not null default 0 comment('保留小数位') INT"` + Status int `xorm:"not null default 0 comment('启用状态:0未启用,1已启用') index TINYINT(1)"` + StockCode string `xorm:"not null default '' comment('股票代码') unique VARCHAR(100)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(100)"` + Tape int `xorm:"not null default 0 comment('交易所类型 0 未选择 详细见配置') index SMALLINT"` + UpLimit string `xorm:"not null default 0.00 comment('涨停限制 30 表示 30%') DECIMAL(10,2)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + YesterdayClose string `xorm:"not null default 0.000000000000000000 comment('昨日收盘价(新股初始价)') DECIMAL(36,18)"` +} diff --git a/internal/pkg/model/bot_stock_hkd_trade.go b/internal/pkg/model/bot_stock_hkd_trade.go new file mode 100644 index 0000000..8049ff8 --- /dev/null +++ b/internal/pkg/model/bot_stock_hkd_trade.go @@ -0,0 +1,36 @@ +package models + +import ( + "time" +) + +type BotStockHkdTrade struct { + ClosingCost string `xorm:"comment('平仓手续费') DECIMAL(36,18)"` + ClosingPrice string `xorm:"comment('平仓价格') DECIMAL(36,18)"` + ClosingTime time.Time `xorm:"comment('平仓时间') DATETIME"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + DealPrice string `xorm:"comment('成交价') DECIMAL(36,18)"` + DealType int `xorm:"not null default 0 comment('委托方式:1限价,2市价') index(user_id) TINYINT(1)"` + FaceValue int `xorm:"comment('面值') INT"` + KeepDecimal int `xorm:"comment('股票保留小数位') INT"` + LimitPrice string `xorm:"comment('限价') DECIMAL(36,18)"` + MarketMoney string `xorm:"not null comment('市值金额') DECIMAL(36,18)"` + MarketPrice string `xorm:"comment('市价') DECIMAL(36,18)"` + OpenTime time.Time `xorm:"comment('成交时间') DATETIME"` + OrderId string `xorm:"not null comment('订单ID') index(order_id) index(user_id) VARCHAR(60)"` + OrderMoney string `xorm:"not null comment('订单总金额') DECIMAL(36,18)"` + OrderNumber string `xorm:"not null comment('委托数量') DECIMAL(36,18)"` + OvernightCost string `xorm:"comment('过夜手续费') DECIMAL(36,18)"` + PryNum int `xorm:"comment('杠杆') INT"` + ServiceCost string `xorm:"not null comment('持仓手续费') DECIMAL(36,18)"` + Status int `xorm:"not null default 0 comment('订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单') index(order_id) index(u_s_s) index(user_id) TINYINT(1)"` + StockId string `xorm:"not null comment('股票id') index(u_s_s) index(user_id) VARCHAR(100)"` + StockName string `xorm:"comment('股票名称') VARCHAR(255)"` + StopLossPrice string `xorm:"comment('止损价') DECIMAL(36,18)"` + StopType int `xorm:"not null comment('止损止盈设置:0无设置,1止损止盈') TINYINT(1)"` + StopWinPrice string `xorm:"comment('止赢价') DECIMAL(36,18)"` + TradeId int `xorm:"not null pk autoincr comment('自增长ID') INT"` + TradeType int `xorm:"not null default 0 comment('交易类型:1买入,2卖出') index(user_id) TINYINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(u_s_s) index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_stock_idn_list.go b/internal/pkg/model/bot_stock_idn_list.go new file mode 100644 index 0000000..060a2d2 --- /dev/null +++ b/internal/pkg/model/bot_stock_idn_list.go @@ -0,0 +1,20 @@ +package models + +import ( + "time" +) + +type BotStockIdnList struct { + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + DownLimit string `xorm:"not null default 0.00 comment('跌停限制 30 表示 30%') DECIMAL(10,2)"` + ForcedClosure string `xorm:"not null default 0.00 comment('强制平仓阈值 30 表示 30%') DECIMAL(10,2)"` + Id int `xorm:"not null pk autoincr INT"` + Info string `xorm:"comment('股票简介') TEXT"` + KeepDecimal int `xorm:"not null default 0 comment('保留小数位') INT"` + Status int `xorm:"not null default 0 comment('启用状态:0未启用,1已启用') index TINYINT(1)"` + StockCode string `xorm:"not null default '' comment('股票代码') unique VARCHAR(100)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(100)"` + Tape int `xorm:"not null default 0 comment('交易所类型 0 未选择 详细见配置') index SMALLINT"` + UpLimit string `xorm:"not null default 0.00 comment('涨停限制 30 表示 30%') DECIMAL(10,2)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` +} diff --git a/internal/pkg/model/bot_stock_idn_trade.go b/internal/pkg/model/bot_stock_idn_trade.go new file mode 100644 index 0000000..18d11cf --- /dev/null +++ b/internal/pkg/model/bot_stock_idn_trade.go @@ -0,0 +1,36 @@ +package models + +import ( + "time" +) + +type BotStockIdnTrade struct { + ClosingCost string `xorm:"comment('平仓手续费') DECIMAL(36,18)"` + ClosingPrice string `xorm:"comment('平仓价格') DECIMAL(36,18)"` + ClosingTime time.Time `xorm:"comment('平仓时间') DATETIME"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + DealPrice string `xorm:"comment('成交价') DECIMAL(36,18)"` + DealType int `xorm:"not null default 0 comment('委托方式:1限价,2市价') index(user_id) TINYINT(1)"` + FaceValue int `xorm:"comment('面值') INT"` + KeepDecimal int `xorm:"comment('股票保留小数位') INT"` + LimitPrice string `xorm:"comment('限价') DECIMAL(36,18)"` + MarketMoney string `xorm:"not null comment('市值金额') DECIMAL(36,18)"` + MarketPrice string `xorm:"comment('市价') DECIMAL(36,18)"` + OpenTime time.Time `xorm:"comment('成交时间') DATETIME"` + OrderId string `xorm:"not null comment('订单ID') index(order_id) index(user_id) VARCHAR(60)"` + OrderMoney string `xorm:"not null comment('订单总金额') DECIMAL(36,18)"` + OrderNumber string `xorm:"not null comment('委托数量') DECIMAL(36,18)"` + OvernightCost string `xorm:"comment('过夜手续费') DECIMAL(36,18)"` + PryNum int `xorm:"comment('杠杆') INT"` + ServiceCost string `xorm:"not null comment('持仓手续费') DECIMAL(36,18)"` + Status int `xorm:"not null default 0 comment('订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单') index(order_id) index(u_s_s) index(user_id) TINYINT(1)"` + StockId string `xorm:"not null comment('股票id') index(u_s_s) index(user_id) VARCHAR(100)"` + StockName string `xorm:"comment('股票名称') VARCHAR(255)"` + StopLossPrice string `xorm:"comment('止损价') DECIMAL(36,18)"` + StopType int `xorm:"not null comment('止损止盈设置:0无设置,1止损止盈') TINYINT(1)"` + StopWinPrice string `xorm:"comment('止赢价') DECIMAL(36,18)"` + TradeId int `xorm:"not null pk autoincr comment('自增长ID') INT"` + TradeType int `xorm:"not null default 0 comment('交易类型:1买入,2卖出') index(user_id) TINYINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(u_s_s) index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_stock_in_list.go b/internal/pkg/model/bot_stock_in_list.go new file mode 100644 index 0000000..0162d37 --- /dev/null +++ b/internal/pkg/model/bot_stock_in_list.go @@ -0,0 +1,22 @@ +package models + +import ( + "time" +) + +type BotStockInList struct { + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + DownLimit string `xorm:"not null default 0.00 comment('跌停限制 30 表示 30%') DECIMAL(10,2)"` + ForcedClosure string `xorm:"not null default 0.00 comment('强制平仓阈值 30 表示 30%') DECIMAL(10,2)"` + Id int `xorm:"not null pk autoincr INT"` + Info string `xorm:"comment('股票简介') TEXT"` + KeepDecimal int `xorm:"not null default 0 comment('保留小数位') INT"` + Source int `xorm:"not null default 1 SMALLINT"` + Status int `xorm:"not null default 0 comment('启用状态:0未启用,1已启用') index TINYINT(1)"` + StockCode string `xorm:"not null default '' comment('股票代码') unique VARCHAR(100)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(100)"` + Tape int `xorm:"not null default 0 comment('交易所类型 0 未选择 详细见配置') index SMALLINT"` + UpLimit string `xorm:"not null default 0.00 comment('涨停限制 30 表示 30%') DECIMAL(10,2)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + YesterdayClose string `xorm:"not null default 0.000000000000000000 comment('昨日收盘价(新股初始价)') DECIMAL(36,18)"` +} diff --git a/internal/pkg/model/bot_stock_in_trade.go b/internal/pkg/model/bot_stock_in_trade.go new file mode 100644 index 0000000..b157345 --- /dev/null +++ b/internal/pkg/model/bot_stock_in_trade.go @@ -0,0 +1,36 @@ +package models + +import ( + "time" +) + +type BotStockInTrade struct { + ClosingCost string `xorm:"comment('平仓手续费') DECIMAL(36,18)"` + ClosingPrice string `xorm:"comment('平仓价格') DECIMAL(36,18)"` + ClosingTime time.Time `xorm:"comment('平仓时间') DATETIME"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + DealPrice string `xorm:"comment('成交价') DECIMAL(36,18)"` + DealType int `xorm:"not null default 0 comment('委托方式:1限价,2市价') index(user_id) TINYINT(1)"` + FaceValue int `xorm:"comment('面值') INT"` + KeepDecimal int `xorm:"comment('股票保留小数位') INT"` + LimitPrice string `xorm:"comment('限价') DECIMAL(36,18)"` + MarketMoney string `xorm:"not null comment('市值金额') DECIMAL(36,18)"` + MarketPrice string `xorm:"comment('市价') DECIMAL(36,18)"` + OpenTime time.Time `xorm:"comment('成交时间') DATETIME"` + OrderId string `xorm:"not null comment('订单ID') index(order_id) index(user_id) VARCHAR(60)"` + OrderMoney string `xorm:"not null comment('订单总金额') DECIMAL(36,18)"` + OrderNumber string `xorm:"not null comment('委托数量') DECIMAL(36,18)"` + OvernightCost string `xorm:"comment('过夜手续费') DECIMAL(36,18)"` + PryNum int `xorm:"comment('杠杆') INT"` + ServiceCost string `xorm:"not null comment('持仓手续费') DECIMAL(36,18)"` + Status int `xorm:"not null default 0 comment('订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单') index(order_id) index(u_s_s) index(user_id) TINYINT(1)"` + StockId string `xorm:"not null comment('股票id') index(u_s_s) index(user_id) VARCHAR(100)"` + StockName string `xorm:"comment('股票名称') VARCHAR(255)"` + StopLossPrice string `xorm:"comment('止损价') DECIMAL(36,18)"` + StopType int `xorm:"not null comment('止损止盈设置:0无设置,1止损止盈') TINYINT(1)"` + StopWinPrice string `xorm:"comment('止赢价') DECIMAL(36,18)"` + TradeId int `xorm:"not null pk autoincr comment('自增长ID') INT"` + TradeType int `xorm:"not null default 0 comment('交易类型:1买入,2卖出') index(user_id) TINYINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(u_s_s) index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_stock_index.go b/internal/pkg/model/bot_stock_index.go new file mode 100644 index 0000000..5d9267f --- /dev/null +++ b/internal/pkg/model/bot_stock_index.go @@ -0,0 +1,18 @@ +package models + +import ( + "time" +) + +type BotStockIndex struct { + Code string `xorm:"not null default '' comment('code') VARCHAR(255)"` + Country string `xorm:"not null default '' comment('国家') VARCHAR(255)"` + Currency string `xorm:"not null default '' comment('货币') VARCHAR(255)"` + Exchange string `xorm:"not null comment('交易所') VARCHAR(255)"` + Id int `xorm:"not null pk INT"` + Intro string `xorm:"not null comment('介绍') TEXT"` + Name string `xorm:"not null default '' comment('名称') VARCHAR(255)"` + Sort int `xorm:"not null default 0 comment('排序') INT"` + Status int `xorm:"not null default 1 comment('1 开启 2 关闭') SMALLINT"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` +} diff --git a/internal/pkg/model/bot_stock_jp_list.go b/internal/pkg/model/bot_stock_jp_list.go new file mode 100644 index 0000000..60ed497 --- /dev/null +++ b/internal/pkg/model/bot_stock_jp_list.go @@ -0,0 +1,21 @@ +package models + +import ( + "time" +) + +type BotStockJpList struct { + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + DownLimit string `xorm:"not null default 0.00 comment('跌停限制 30 表示 30%') DECIMAL(10,2)"` + ForcedClosure string `xorm:"not null default 0.00 comment('强制平仓阈值 30 表示 30%') DECIMAL(10,2)"` + Id int `xorm:"not null pk autoincr INT"` + Info string `xorm:"comment('股票简介') TEXT"` + KeepDecimal int `xorm:"not null default 0 comment('保留小数位') INT"` + Status int `xorm:"not null default 0 comment('启用状态:0未启用,1已启用') index TINYINT(1)"` + StockCode string `xorm:"not null default '' comment('股票代码') unique VARCHAR(100)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(100)"` + Tape int `xorm:"not null default 0 comment('交易所类型 0 未选择 详细见配置') index SMALLINT"` + UpLimit string `xorm:"not null default 0.00 comment('涨停限制 30 表示 30%') DECIMAL(10,2)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + YesterdayClose string `xorm:"not null default 0.000000000000000000 comment('昨日收盘价(新股初始价)') DECIMAL(36,18)"` +} diff --git a/internal/pkg/model/bot_stock_jp_trade.go b/internal/pkg/model/bot_stock_jp_trade.go new file mode 100644 index 0000000..93b74a8 --- /dev/null +++ b/internal/pkg/model/bot_stock_jp_trade.go @@ -0,0 +1,36 @@ +package models + +import ( + "time" +) + +type BotStockJpTrade struct { + ClosingCost string `xorm:"comment('平仓手续费') DECIMAL(36,18)"` + ClosingPrice string `xorm:"comment('平仓价格') DECIMAL(36,18)"` + ClosingTime time.Time `xorm:"comment('平仓时间') DATETIME"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + DealPrice string `xorm:"comment('成交价') DECIMAL(36,18)"` + DealType int `xorm:"not null default 0 comment('委托方式:1限价,2市价') index(user_id) TINYINT(1)"` + FaceValue int `xorm:"comment('面值') INT"` + KeepDecimal int `xorm:"comment('股票保留小数位') INT"` + LimitPrice string `xorm:"comment('限价') DECIMAL(36,18)"` + MarketMoney string `xorm:"not null comment('市值金额') DECIMAL(36,18)"` + MarketPrice string `xorm:"comment('市价') DECIMAL(36,18)"` + OpenTime time.Time `xorm:"comment('成交时间') DATETIME"` + OrderId string `xorm:"not null comment('订单ID') index(order_id) index(user_id) VARCHAR(60)"` + OrderMoney string `xorm:"not null comment('订单总金额') DECIMAL(36,18)"` + OrderNumber string `xorm:"not null comment('委托数量') DECIMAL(36,18)"` + OvernightCost string `xorm:"comment('过夜手续费') DECIMAL(36,18)"` + PryNum int `xorm:"comment('杠杆') INT"` + ServiceCost string `xorm:"not null comment('持仓手续费') DECIMAL(36,18)"` + Status int `xorm:"not null default 0 comment('订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单') index(order_id) index(u_s_s) index(user_id) TINYINT(1)"` + StockId string `xorm:"not null comment('股票id') index(u_s_s) index(user_id) VARCHAR(100)"` + StockName string `xorm:"comment('股票名称') VARCHAR(255)"` + StopLossPrice string `xorm:"comment('止损价') DECIMAL(36,18)"` + StopType int `xorm:"not null comment('止损止盈设置:0无设置,1止损止盈') TINYINT(1)"` + StopWinPrice string `xorm:"comment('止赢价') DECIMAL(36,18)"` + TradeId int `xorm:"not null pk autoincr comment('自增长ID') INT"` + TradeType int `xorm:"not null default 0 comment('交易类型:1买入,2卖出') index(user_id) TINYINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(u_s_s) index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_stock_list.go b/internal/pkg/model/bot_stock_list.go new file mode 100644 index 0000000..58587a1 --- /dev/null +++ b/internal/pkg/model/bot_stock_list.go @@ -0,0 +1,20 @@ +package models + +import ( + "time" +) + +type BotStockList struct { + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + DownLimit string `xorm:"not null default 0.00 comment('跌停限制 30 表示 30%') DECIMAL(10,2)"` + ForcedClosure string `xorm:"not null default 0.00 comment('强制平仓阈值 30 表示 30%') DECIMAL(10,2)"` + Id int `xorm:"not null pk autoincr INT"` + Info string `xorm:"comment('股票简介') TEXT"` + KeepDecimal int `xorm:"not null default 0 comment('保留小数位') INT"` + Status int `xorm:"not null default 0 comment('启用状态:0未启用,1已启用') index TINYINT(1)"` + StockCode string `xorm:"not null default '' comment('股票代码') unique VARCHAR(100)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(500)"` + Tape int `xorm:"not null default 0 comment('交易所类型 0 未选择 详细见配置') index SMALLINT"` + UpLimit string `xorm:"not null default 0.00 comment('涨停限制 30 表示 30%') DECIMAL(10,2)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` +} diff --git a/internal/pkg/model/bot_stock_market.go b/internal/pkg/model/bot_stock_market.go new file mode 100644 index 0000000..84f8a09 --- /dev/null +++ b/internal/pkg/model/bot_stock_market.go @@ -0,0 +1,25 @@ +package models + +import ( + "time" +) + +type BotStockMarket struct { + AmCloseTime string `xorm:"not null default '00:00' comment('上午盘闭盘时间') VARCHAR(50)"` + AmOpenTime string `xorm:"not null default '00:00' comment('上午盘开盘时间') VARCHAR(50)"` + CreateTime time.Time `xorm:"not null DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + LeverMax int `xorm:"not null default 1 comment('最大杠杆') INT"` + LeverMin int `xorm:"not null default 1 comment('最小杠杆') INT"` + LeverStatus int `xorm:"not null default 1 comment('杠杆状态 1 开启 2关闭') SMALLINT"` + PmCloseTime string `xorm:"not null default '00:00' comment('下午盘闭盘时间') VARCHAR(50)"` + PmOpenTime string `xorm:"not null default '00:00' comment('下午盘开盘时间') VARCHAR(50)"` + Rate string `xorm:"not null default '' comment('兑换汇率 支持小数') VARCHAR(255)"` + Status int `xorm:"not null default 1 comment('状态 1 启用 2 禁用') SMALLINT"` + StockMarketType int `xorm:"not null default 1 comment('股票市场类型 见配置') index SMALLINT"` + StockMin int `xorm:"not null default 1 comment('最小股数量可以使用杠杆') INT"` + Symbol string `xorm:"not null default '' comment('货币符号') VARCHAR(10)"` + TradeDayType int `xorm:"not null default 1 comment('交易日限制 见配置') SMALLINT"` + Unit string `xorm:"not null default '' comment('货币单位') VARCHAR(10)"` + UpdateTime time.Time `xorm:"not null DATETIME"` +} diff --git a/internal/pkg/model/bot_stock_mys_list.go b/internal/pkg/model/bot_stock_mys_list.go new file mode 100644 index 0000000..7f1a67f --- /dev/null +++ b/internal/pkg/model/bot_stock_mys_list.go @@ -0,0 +1,21 @@ +package models + +import ( + "time" +) + +type BotStockMysList struct { + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + DownLimit string `xorm:"not null default 0.00 comment('跌停限制 30 表示 30%') DECIMAL(10,2)"` + ForcedClosure string `xorm:"not null default 0.00 comment('强制平仓阈值 30 表示 30%') DECIMAL(10,2)"` + Id int `xorm:"not null pk autoincr INT"` + Info string `xorm:"comment('股票简介') TEXT"` + KeepDecimal int `xorm:"not null default 0 comment('保留小数位') INT"` + NumericCode string `xorm:"not null default '' comment('数字code') VARCHAR(15)"` + Status int `xorm:"not null default 0 comment('启用状态:0未启用,1已启用') index TINYINT(1)"` + StockCode string `xorm:"not null default '' comment('股票代码') unique VARCHAR(100)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(100)"` + Tape int `xorm:"not null default 0 comment('交易所类型 0 未选择 详细见配置') index SMALLINT"` + UpLimit string `xorm:"not null default 0.00 comment('涨停限制 30 表示 30%') DECIMAL(10,2)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` +} diff --git a/internal/pkg/model/bot_stock_mys_list_p_two.go b/internal/pkg/model/bot_stock_mys_list_p_two.go new file mode 100644 index 0000000..2d4454f --- /dev/null +++ b/internal/pkg/model/bot_stock_mys_list_p_two.go @@ -0,0 +1,22 @@ +package models + +import ( + "time" +) + +type BotStockMysListPTwo struct { + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + DownLimit string `xorm:"not null default 0.00 comment('跌停限制 30 表示 30%') DECIMAL(10,2)"` + ForcedClosure string `xorm:"not null default 0.00 comment('强制平仓阈值 30 表示 30%') DECIMAL(10,2)"` + Id int `xorm:"not null pk autoincr INT"` + Info string `xorm:"comment('股票简介') TEXT"` + KeepDecimal int `xorm:"not null default 0 comment('保留小数位') INT"` + NumericCode string `xorm:"not null default '' comment('数字code') VARCHAR(15)"` + Status int `xorm:"not null default 0 comment('启用状态:0未启用,1已启用') index TINYINT(1)"` + StockCode string `xorm:"not null default '' comment('股票代码') unique VARCHAR(100)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(100)"` + Tape int `xorm:"not null default 0 comment('交易所类型 0 未选择 详细见配置') index SMALLINT"` + UpLimit string `xorm:"not null default 0.00 comment('涨停限制 30 表示 30%') DECIMAL(10,2)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + YesterdayClose string `xorm:"not null default 0.000000000000000000 comment('昨日收盘价(新股初始价)') DECIMAL(36,18)"` +} diff --git a/internal/pkg/model/bot_stock_mys_trade.go b/internal/pkg/model/bot_stock_mys_trade.go new file mode 100644 index 0000000..7d47c78 --- /dev/null +++ b/internal/pkg/model/bot_stock_mys_trade.go @@ -0,0 +1,37 @@ +package models + +import ( + "time" +) + +type BotStockMysTrade struct { + ClosingCost string `xorm:"comment('平仓手续费') DECIMAL(36,18)"` + ClosingPrice string `xorm:"comment('平仓价格') DECIMAL(36,18)"` + ClosingTime time.Time `xorm:"comment('平仓时间') DATETIME"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + DealPrice string `xorm:"comment('成交价') DECIMAL(36,18)"` + DealType int `xorm:"not null default 0 comment('委托方式:1限价,2市价') index(user_id) TINYINT(1)"` + FaceValue int `xorm:"comment('面值') INT"` + KeepDecimal int `xorm:"comment('股票保留小数位') INT"` + LimitPrice string `xorm:"comment('限价') DECIMAL(36,18)"` + MarketMoney string `xorm:"not null comment('市值金额') DECIMAL(36,18)"` + MarketPrice string `xorm:"comment('市价') DECIMAL(36,18)"` + NumericCode string `xorm:"comment('股票数字code') VARCHAR(100)"` + OpenTime time.Time `xorm:"comment('成交时间') DATETIME"` + OrderId string `xorm:"not null comment('订单ID') index(order_id) index(user_id) VARCHAR(60)"` + OrderMoney string `xorm:"not null comment('订单总金额') DECIMAL(36,18)"` + OrderNumber string `xorm:"not null comment('委托数量') DECIMAL(36,18)"` + OvernightCost string `xorm:"comment('过夜手续费') DECIMAL(36,18)"` + PryNum int `xorm:"comment('杠杆') INT"` + ServiceCost string `xorm:"not null comment('持仓手续费') DECIMAL(36,18)"` + Status int `xorm:"not null default 0 comment('订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单') index(order_id) index(u_s_s) index(user_id) TINYINT(1)"` + StockId string `xorm:"not null comment('股票id') index(u_s_s) index(user_id) VARCHAR(100)"` + StockName string `xorm:"comment('股票名称') VARCHAR(255)"` + StopLossPrice string `xorm:"comment('止损价') DECIMAL(36,18)"` + StopType int `xorm:"not null comment('止损止盈设置:0无设置,1止损止盈') TINYINT(1)"` + StopWinPrice string `xorm:"comment('止赢价') DECIMAL(36,18)"` + TradeId int `xorm:"not null pk autoincr comment('自增长ID') INT"` + TradeType int `xorm:"not null default 0 comment('交易类型:1买入,2卖出') index(user_id) TINYINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(u_s_s) index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_stock_option_inr_list.go b/internal/pkg/model/bot_stock_option_inr_list.go new file mode 100644 index 0000000..d26c75b --- /dev/null +++ b/internal/pkg/model/bot_stock_option_inr_list.go @@ -0,0 +1,21 @@ +package models + +import ( + "time" +) + +type BotStockOptionInrList struct { + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + DownLimit string `xorm:"not null default 0.00 comment('跌停限制 30 表示 30%') DECIMAL(10,2)"` + ForcedClosure string `xorm:"not null default 0.00 comment('强制平仓阈值 30 表示 30%') DECIMAL(10,2)"` + Id int `xorm:"not null pk autoincr INT"` + Info string `xorm:"comment('股票简介') TEXT"` + KeepDecimal int `xorm:"not null default 0 comment('保留小数位') INT"` + Rate string `xorm:"not null default 30.00 comment('保证金比例') DECIMAL(10,2)"` + Status int `xorm:"not null default 0 comment('启用状态:0未启用,1已启用') index TINYINT(1)"` + StockCode string `xorm:"not null default '' comment('股票代码') unique VARCHAR(100)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(100)"` + Tape int `xorm:"not null default 0 comment('交易所类型 0 未选择 详细见配置') index SMALLINT"` + UpLimit string `xorm:"not null default 0.00 comment('涨停限制 30 表示 30%') DECIMAL(10,2)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` +} diff --git a/internal/pkg/model/bot_stock_option_inr_trade.go b/internal/pkg/model/bot_stock_option_inr_trade.go new file mode 100644 index 0000000..8530e93 --- /dev/null +++ b/internal/pkg/model/bot_stock_option_inr_trade.go @@ -0,0 +1,45 @@ +package models + +import ( + "time" +) + +type BotStockOptionInrTrade struct { + Ask string `xorm:"comment('卖一价') DECIMAL(36,18)"` + Bid string `xorm:"comment('买一价') DECIMAL(36,18)"` + ClosingCost string `xorm:"comment('平仓手续费') DECIMAL(36,18)"` + ClosingPrice string `xorm:"comment('平仓价格') DECIMAL(36,18)"` + ClosingTime time.Time `xorm:"comment('平仓时间') DATETIME"` + CostPrice string `xorm:"comment('成本价') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + DealPrice string `xorm:"comment('成交价') DECIMAL(36,18)"` + DealType int `xorm:"not null default 0 comment('委托方式:1限价,2市价') index(user_id) TINYINT(1)"` + FaceValue int `xorm:"comment('面值') INT"` + KeepDecimal int `xorm:"comment('股票保留小数位') INT"` + LimitPrice string `xorm:"comment('限价') DECIMAL(36,18)"` + MarketMoney string `xorm:"not null comment('市值金额') DECIMAL(36,18)"` + MarketPrice string `xorm:"comment('市价') DECIMAL(36,18)"` + Multiplier int `xorm:"not null comment('期权乘数') INT"` + OpenTime time.Time `xorm:"comment('成交时间') DATETIME"` + OrderId string `xorm:"not null comment('订单ID') index(order_id) index(user_id) VARCHAR(60)"` + OrderMoney string `xorm:"not null comment('订单总金额') DECIMAL(36,18)"` + OrderNumber string `xorm:"not null comment('委托数量') DECIMAL(36,18)"` + OvernightCost string `xorm:"comment('过夜手续费') DECIMAL(36,18)"` + PryNum int `xorm:"comment('杠杆') INT"` + Ratio int `xorm:"not null comment('保证金比例') INT"` + ServiceCost string `xorm:"not null comment('持仓手续费') DECIMAL(36,18)"` + Status int `xorm:"not null default 0 comment('订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单') index(order_id) index(u_s_s) index(user_id) TINYINT(1)"` + StockCode string `xorm:"not null comment('期权订单标识(stock_id+到期时间+行权价+(CE|PE))') VARCHAR(255)"` + StockId string `xorm:"not null comment('股票id') index(u_s_s) index(user_id) VARCHAR(100)"` + StockName string `xorm:"comment('股票名称') VARCHAR(255)"` + StopLossPrice string `xorm:"comment('止损价') DECIMAL(36,18)"` + StopTime string `xorm:"comment('设置到期时间') VARCHAR(255)"` + StopType int `xorm:"not null comment('止损止盈设置:0无设置,1止损止盈') TINYINT(1)"` + StopWinPrice string `xorm:"comment('止赢价') DECIMAL(36,18)"` + StrikePrice string `xorm:"comment('行权价') DECIMAL(36,18)"` + TradeId int `xorm:"not null pk autoincr comment('自增长ID') INT"` + TradeType int `xorm:"not null default 0 comment('交易类型:1看涨(calls-CE),2看跌(puts-PE)') index(user_id) TINYINT(1)"` + TradingType int `xorm:"not null comment('交易方式:1买入(buy),2卖出(sell)') TINYINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(u_s_s) index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_stock_prices_setting.go b/internal/pkg/model/bot_stock_prices_setting.go new file mode 100644 index 0000000..f65a7da --- /dev/null +++ b/internal/pkg/model/bot_stock_prices_setting.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotStockPricesSetting struct { + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + MarketType int `xorm:"not null comment('股票市场 见配置') index SMALLINT"` + Price string `xorm:"not null default 0.000000000000000000 comment('多个价格英文逗号分隔') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('盘前状态 1 开启 2 关闭') SMALLINT"` + StockId int `xorm:"not null comment('股票主键') index INT"` + UpdateTime time.Time `xorm:"comment('修改时间') DATETIME"` +} diff --git a/internal/pkg/model/bot_stock_sgd_list.go b/internal/pkg/model/bot_stock_sgd_list.go new file mode 100644 index 0000000..40ec0fb --- /dev/null +++ b/internal/pkg/model/bot_stock_sgd_list.go @@ -0,0 +1,21 @@ +package models + +import ( + "time" +) + +type BotStockSgdList struct { + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + DownLimit string `xorm:"not null default 0.00 comment('跌停限制 30 表示 30%') DECIMAL(10,2)"` + ForcedClosure string `xorm:"not null default 0.00 comment('强制平仓阈值 30 表示 30%') DECIMAL(10,2)"` + Id int `xorm:"not null pk autoincr INT"` + Info string `xorm:"comment('股票简介') TEXT"` + KeepDecimal int `xorm:"not null default 0 comment('保留小数位') INT"` + Status int `xorm:"not null default 0 comment('启用状态:0未启用,1已启用') index TINYINT(1)"` + StockCode string `xorm:"not null default '' comment('股票代码') unique VARCHAR(100)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(100)"` + Tape int `xorm:"not null default 0 comment('交易所类型 0 未选择 详细见配置') index SMALLINT"` + UpLimit string `xorm:"not null default 0.00 comment('涨停限制 30 表示 30%') DECIMAL(10,2)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + YesterdayClose string `xorm:"not null default 0.000000000000000000 comment('昨日收盘价(新股初始价)') DECIMAL(36,18)"` +} diff --git a/internal/pkg/model/bot_stock_sgd_trade.go b/internal/pkg/model/bot_stock_sgd_trade.go new file mode 100644 index 0000000..d2cb72c --- /dev/null +++ b/internal/pkg/model/bot_stock_sgd_trade.go @@ -0,0 +1,36 @@ +package models + +import ( + "time" +) + +type BotStockSgdTrade struct { + ClosingCost string `xorm:"comment('平仓手续费') DECIMAL(36,18)"` + ClosingPrice string `xorm:"comment('平仓价格') DECIMAL(36,18)"` + ClosingTime time.Time `xorm:"comment('平仓时间') DATETIME"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + DealPrice string `xorm:"comment('成交价') DECIMAL(36,18)"` + DealType int `xorm:"not null default 0 comment('委托方式:1限价,2市价') index(user_id) TINYINT(1)"` + FaceValue int `xorm:"comment('面值') INT"` + KeepDecimal int `xorm:"comment('股票保留小数位') INT"` + LimitPrice string `xorm:"comment('限价') DECIMAL(36,18)"` + MarketMoney string `xorm:"not null comment('市值金额') DECIMAL(36,18)"` + MarketPrice string `xorm:"comment('市价') DECIMAL(36,18)"` + OpenTime time.Time `xorm:"comment('成交时间') DATETIME"` + OrderId string `xorm:"not null comment('订单ID') index(order_id) index(user_id) VARCHAR(60)"` + OrderMoney string `xorm:"not null comment('订单总金额') DECIMAL(36,18)"` + OrderNumber string `xorm:"not null comment('委托数量') DECIMAL(36,18)"` + OvernightCost string `xorm:"comment('过夜手续费') DECIMAL(36,18)"` + PryNum int `xorm:"comment('杠杆') INT"` + ServiceCost string `xorm:"not null comment('持仓手续费') DECIMAL(36,18)"` + Status int `xorm:"not null default 0 comment('订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单') index(order_id) index(u_s_s) index(user_id) TINYINT(1)"` + StockId string `xorm:"not null comment('股票id') index(u_s_s) index(user_id) VARCHAR(100)"` + StockName string `xorm:"comment('股票名称') VARCHAR(255)"` + StopLossPrice string `xorm:"comment('止损价') DECIMAL(36,18)"` + StopType int `xorm:"not null comment('止损止盈设置:0无设置,1止损止盈') TINYINT(1)"` + StopWinPrice string `xorm:"comment('止赢价') DECIMAL(36,18)"` + TradeId int `xorm:"not null pk autoincr comment('自增长ID') INT"` + TradeType int `xorm:"not null default 0 comment('交易类型:1买入,2卖出') index(user_id) TINYINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(u_s_s) index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_stock_tha_list.go b/internal/pkg/model/bot_stock_tha_list.go new file mode 100644 index 0000000..fddc6d7 --- /dev/null +++ b/internal/pkg/model/bot_stock_tha_list.go @@ -0,0 +1,20 @@ +package models + +import ( + "time" +) + +type BotStockThaList struct { + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + DownLimit string `xorm:"not null default 0.00 comment('跌停限制 30 表示 30%') DECIMAL(10,2)"` + ForcedClosure string `xorm:"not null default 0.00 comment('强制平仓阈值 30 表示 30%') DECIMAL(10,2)"` + Id int `xorm:"not null pk autoincr INT"` + Info string `xorm:"comment('股票简介') TEXT"` + KeepDecimal int `xorm:"not null default 0 comment('保留小数位') INT"` + Status int `xorm:"not null default 0 comment('启用状态:0未启用,1已启用') index TINYINT(1)"` + StockCode string `xorm:"not null default '' comment('股票代码') unique VARCHAR(100)"` + StockName string `xorm:"not null default '' comment('股票名称') VARCHAR(100)"` + Tape int `xorm:"not null default 0 comment('交易所类型 0 未选择 详细见配置') index SMALLINT"` + UpLimit string `xorm:"not null default 0.00 comment('涨停限制 30 表示 30%') DECIMAL(10,2)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` +} diff --git a/internal/pkg/model/bot_stock_tha_trade.go b/internal/pkg/model/bot_stock_tha_trade.go new file mode 100644 index 0000000..876b574 --- /dev/null +++ b/internal/pkg/model/bot_stock_tha_trade.go @@ -0,0 +1,36 @@ +package models + +import ( + "time" +) + +type BotStockThaTrade struct { + ClosingCost string `xorm:"comment('平仓手续费') DECIMAL(36,18)"` + ClosingPrice string `xorm:"comment('平仓价格') DECIMAL(36,18)"` + ClosingTime time.Time `xorm:"comment('平仓时间') DATETIME"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + DealPrice string `xorm:"comment('成交价') DECIMAL(36,18)"` + DealType int `xorm:"not null default 0 comment('委托方式:1限价,2市价') index(user_id) TINYINT(1)"` + FaceValue int `xorm:"comment('面值') INT"` + KeepDecimal int `xorm:"comment('股票保留小数位') INT"` + LimitPrice string `xorm:"comment('限价') DECIMAL(36,18)"` + MarketMoney string `xorm:"not null comment('市值金额') DECIMAL(36,18)"` + MarketPrice string `xorm:"comment('市价') DECIMAL(36,18)"` + OpenTime time.Time `xorm:"comment('成交时间') DATETIME"` + OrderId string `xorm:"not null comment('订单ID') index(order_id) index(user_id) VARCHAR(60)"` + OrderMoney string `xorm:"not null comment('订单总金额') DECIMAL(36,18)"` + OrderNumber string `xorm:"not null comment('委托数量') DECIMAL(36,18)"` + OvernightCost string `xorm:"comment('过夜手续费') DECIMAL(36,18)"` + PryNum int `xorm:"comment('杠杆') INT"` + ServiceCost string `xorm:"not null comment('持仓手续费') DECIMAL(36,18)"` + Status int `xorm:"not null default 0 comment('订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单') index(order_id) index(u_s_s) index(user_id) TINYINT(1)"` + StockId string `xorm:"not null comment('股票id') index(u_s_s) index(user_id) VARCHAR(100)"` + StockName string `xorm:"comment('股票名称') VARCHAR(255)"` + StopLossPrice string `xorm:"comment('止损价') DECIMAL(36,18)"` + StopType int `xorm:"not null comment('止损止盈设置:0无设置,1止损止盈') TINYINT(1)"` + StopWinPrice string `xorm:"comment('止赢价') DECIMAL(36,18)"` + TradeId int `xorm:"not null pk autoincr comment('自增长ID') INT"` + TradeType int `xorm:"not null default 0 comment('交易类型:1买入,2卖出') index(user_id) TINYINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(u_s_s) index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_stock_trade.go b/internal/pkg/model/bot_stock_trade.go new file mode 100644 index 0000000..44d0cc5 --- /dev/null +++ b/internal/pkg/model/bot_stock_trade.go @@ -0,0 +1,36 @@ +package models + +import ( + "time" +) + +type BotStockTrade struct { + ClosingCost string `xorm:"comment('平仓手续费') DECIMAL(36,18)"` + ClosingPrice string `xorm:"comment('平仓价格') DECIMAL(36,18)"` + ClosingTime time.Time `xorm:"comment('平仓时间') DATETIME"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + DealPrice string `xorm:"comment('成交价') DECIMAL(36,18)"` + DealType int `xorm:"not null default 0 comment('委托方式:1限价,2市价') index(user_id) TINYINT(1)"` + FaceValue int `xorm:"comment('面值') INT"` + KeepDecimal int `xorm:"comment('股票保留小数位') INT"` + LimitPrice string `xorm:"comment('限价') DECIMAL(36,18)"` + MarketMoney string `xorm:"not null comment('市值金额') DECIMAL(36,18)"` + MarketPrice string `xorm:"comment('市价') DECIMAL(36,18)"` + OpenTime time.Time `xorm:"comment('成交时间') DATETIME"` + OrderId string `xorm:"not null comment('订单ID') index(order_id) index(user_id) VARCHAR(60)"` + OrderMoney string `xorm:"not null comment('订单总金额') DECIMAL(36,18)"` + OrderNumber string `xorm:"not null comment('委托数量') DECIMAL(36,18)"` + OvernightCost string `xorm:"comment('过夜手续费') DECIMAL(36,18)"` + PryNum int `xorm:"comment('杠杆') INT"` + ServiceCost string `xorm:"not null comment('持仓手续费') DECIMAL(36,18)"` + Status int `xorm:"not null default 0 comment('订单状态:0-挂单(委托),1-持仓订单,2-已撤单,3-完成订单') index(order_id) index(u_s_s) index(user_id) TINYINT(1)"` + StockId string `xorm:"not null comment('股票id') index(u_s_s) index(user_id) VARCHAR(100)"` + StockName string `xorm:"comment('股票名称') VARCHAR(255)"` + StopLossPrice string `xorm:"comment('止损价') DECIMAL(36,18)"` + StopType int `xorm:"not null comment('止损止盈设置:0无设置,1止损止盈') TINYINT(1)"` + StopWinPrice string `xorm:"comment('止赢价') DECIMAL(36,18)"` + TradeId int `xorm:"not null pk autoincr comment('自增长ID') INT"` + TradeType int `xorm:"not null default 0 comment('交易类型:1买入,2卖出') index(user_id) TINYINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(u_s_s) index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_trade_fee.go b/internal/pkg/model/bot_trade_fee.go new file mode 100644 index 0000000..d5f574a --- /dev/null +++ b/internal/pkg/model/bot_trade_fee.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotTradeFee struct { + AccountType int `xorm:"not null comment('账户类型:1现货,2合约,3美股') index(user_id) TINYINT(1)"` + CreateTime time.Time `xorm:"not null comment('时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + ServiceFee string `xorm:"not null comment('交易手续费用') DECIMAL(36,18)"` + TradeNo string `xorm:"not null comment('交易单号') VARCHAR(60)"` + TradeType int `xorm:"not null comment('交易类型:1买入,2卖出') index(user_id) TINYINT(1)"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_arrears.go b/internal/pkg/model/bot_user_arrears.go new file mode 100644 index 0000000..5e9c518 --- /dev/null +++ b/internal/pkg/model/bot_user_arrears.go @@ -0,0 +1,16 @@ +package models + +import ( + "time" +) + +type BotUserArrears struct { + AccountType int `xorm:"comment('账户类型') SMALLINT"` + CreateTime time.Time `xorm:"DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + Num string `xorm:"comment('欠款数量') DECIMAL(36,18)"` + OrderNo string `xorm:"comment('订单号') index VARCHAR(50)"` + Status int `xorm:"comment('欠款状态:1已还,0未还') SMALLINT"` + UpdateTime time.Time `xorm:"DATETIME"` + UserId int `xorm:"comment('用户ID') index INT"` +} diff --git a/internal/pkg/model/bot_user_balance_change_log.go b/internal/pkg/model/bot_user_balance_change_log.go new file mode 100644 index 0000000..238a06e --- /dev/null +++ b/internal/pkg/model/bot_user_balance_change_log.go @@ -0,0 +1,16 @@ +package models + +import ( + "time" +) + +type BotUserBalanceChangeLog struct { + AdminId int `xorm:"comment('操作人员id') TINYINT(1)"` + BeforeNum string `xorm:"not null comment('变更前') DECIMAL(36,18)"` + ChangeNum string `xorm:"not null comment('变更金额(美元)') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + CurrencyRate string `xorm:"not null comment('汇率') VARCHAR(255)"` + Id int `xorm:"not null pk autoincr INT"` + Type int `xorm:"not null comment('充值账号类型:1现货,2合约,3美股,4IDR,5MYR,6THB,7INR,8秒合约') TINYINT(1)"` + UserId int `xorm:"not null comment('用户ID') index INT"` +} diff --git a/internal/pkg/model/bot_user_bank.go b/internal/pkg/model/bot_user_bank.go new file mode 100644 index 0000000..dc4e0ae --- /dev/null +++ b/internal/pkg/model/bot_user_bank.go @@ -0,0 +1,24 @@ +package models + +import ( + "time" +) + +type BotUserBank struct { + BankAddress string `xorm:"VARCHAR(255)"` + BankCard string `xorm:"not null comment('银行卡账号') VARCHAR(30)"` + BankCode string `xorm:"comment('银行代码') VARCHAR(60)"` + BankCountry string `xorm:"comment('国家') VARCHAR(30)"` + BankEmail string `xorm:"comment('邮箱') VARCHAR(50)"` + BankName string `xorm:"not null comment('银行名称') VARCHAR(100)"` + BankPhone string `xorm:"comment('手机号') VARCHAR(30)"` + CreateTime time.Time `xorm:"not null comment('添加时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + IdentityCard string `xorm:"comment('身份证ID') VARCHAR(50)"` + Ifsc string `xorm:"comment('ifsc') VARCHAR(100)"` + IsDefault int `xorm:"not null default 0 comment('是否默认:0不默认,1默认') TINYINT(1)"` + TrueName string `xorm:"not null comment('开账名称') VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('修改时间') DATETIME"` + UserAddress string `xorm:"VARCHAR(255)"` + UserId int `xorm:"not null comment('用户ID') index INT"` +} diff --git a/internal/pkg/model/bot_user_brl_give_stock_order.go b/internal/pkg/model/bot_user_brl_give_stock_order.go new file mode 100644 index 0000000..324d786 --- /dev/null +++ b/internal/pkg/model/bot_user_brl_give_stock_order.go @@ -0,0 +1,20 @@ +package models + +import ( + "time" +) + +type BotUserBrlGiveStockOrder struct { + Amount string `xorm:"not null comment('金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('费率') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + Price string `xorm:"not null default 0.000000000000000000 comment('价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码') index VARCHAR(255)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_brl_pre_stock_order.go b/internal/pkg/model/bot_user_brl_pre_stock_order.go new file mode 100644 index 0000000..9b69ec4 --- /dev/null +++ b/internal/pkg/model/bot_user_brl_pre_stock_order.go @@ -0,0 +1,26 @@ +package models + +import ( + "time" +) + +type BotUserBrlPreStockOrder struct { + Amount string `xorm:"not null comment('申购金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间(申购时间)') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('申购手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('手续费率') DECIMAL(36,18)"` + GetAmount string `xorm:"not null default 0.000000000000000000 DECIMAL(36,18)"` + GetFee string `xorm:"not null comment('中签后实际收取手续费') DECIMAL(36,18)"` + GetNum int `xorm:"not null default 0 comment('中签数量') INT"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('申购数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + PayType int `xorm:"not null default 1 comment('支付类型: 1正常支付 2后支付') SMALLINT"` + PreStockId int `xorm:"not null default 0 comment('新股数据表主键') index INT"` + Price string `xorm:"not null default 0.000000000000000000 comment('申购价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + TradeStatus int `xorm:"comment('持仓状态: 1已持仓 0未持仓') SMALLINT(5)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_brokerage.go b/internal/pkg/model/bot_user_brokerage.go new file mode 100644 index 0000000..890a275 --- /dev/null +++ b/internal/pkg/model/bot_user_brokerage.go @@ -0,0 +1,16 @@ +package models + +import ( + "time" +) + +type BotUserBrokerage struct { + BackType int `xorm:"not null comment('返佣类型:0注册,1现货,2合约,3美股') TINYINT(1)"` + BrokerageNum string `xorm:"not null comment('佣金金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"not null comment('时间') index(u_l_c) DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + LevelType int `xorm:"not null comment('返佣级别:1子级,2孙级,3曾孙级') index(u_l_c) TINYINT(1)"` + OrderId string `xorm:"comment('订单号') VARCHAR(60)"` + ServiceFee string `xorm:"not null comment('手续费') DECIMAL(36,18)"` + UserId int `xorm:"not null comment('用户ID') index(u_l_c) INT"` +} diff --git a/internal/pkg/model/bot_user_contract.go b/internal/pkg/model/bot_user_contract.go new file mode 100644 index 0000000..1a30a4d --- /dev/null +++ b/internal/pkg/model/bot_user_contract.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotUserContract struct { + ContractId string `xorm:"not null comment('合约交易对ID ,usdt ,其他表示对应的合约ID') unique(user_id) VARCHAR(15)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + FrozenNum string `xorm:"not null comment('资产冻结数量') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UsableNum string `xorm:"not null comment('可用数量') DECIMAL(36,18)"` + UserId int `xorm:"not null comment('用户ID') unique(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_contract_log.go b/internal/pkg/model/bot_user_contract_log.go new file mode 100644 index 0000000..b90a27d --- /dev/null +++ b/internal/pkg/model/bot_user_contract_log.go @@ -0,0 +1,17 @@ +package models + +import ( + "time" +) + +type BotUserContractLog struct { + BeforeNum string `xorm:"not null comment('变动前余额') DECIMAL(36,18)"` + ChangeNum string `xorm:"not null comment('变动资产数量') DECIMAL(36,18)"` + ChangeType int `xorm:"not null default 0 comment('变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7账户转出,8账户转入') index(user_id) TINYINT(1)"` + ContractId string `xorm:"not null comment('合约交易对ID') index(user_id) VARCHAR(15)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + OrderId string `xorm:"comment('订单号') VARCHAR(60)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_contract_sec.go b/internal/pkg/model/bot_user_contract_sec.go new file mode 100644 index 0000000..a922aa4 --- /dev/null +++ b/internal/pkg/model/bot_user_contract_sec.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotUserContractSec struct { + ContractId string `xorm:"not null comment('合约交易对ID ,usdt ,其他表示对应的合约ID') unique(user_id) VARCHAR(15)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + FrozenNum string `xorm:"not null comment('资产冻结数量') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UsableNum string `xorm:"not null comment('可用数量') DECIMAL(36,18)"` + UserId int `xorm:"not null comment('用户ID') unique(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_contract_sec_log.go b/internal/pkg/model/bot_user_contract_sec_log.go new file mode 100644 index 0000000..9d5efbd --- /dev/null +++ b/internal/pkg/model/bot_user_contract_sec_log.go @@ -0,0 +1,17 @@ +package models + +import ( + "time" +) + +type BotUserContractSecLog struct { + BeforeNum string `xorm:"not null comment('变动前余额') DECIMAL(36,18)"` + ChangeNum string `xorm:"not null comment('变动资产数量') DECIMAL(36,18)"` + ChangeType int `xorm:"not null default 0 comment('变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7账户转出,8账户转入') index(user_id) TINYINT(1)"` + ContractId string `xorm:"not null comment('合约交易对ID') index(user_id) VARCHAR(15)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + OrderId string `xorm:"comment('订单号') VARCHAR(60)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_digital.go b/internal/pkg/model/bot_user_digital.go new file mode 100644 index 0000000..aa21367 --- /dev/null +++ b/internal/pkg/model/bot_user_digital.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotUserDigital struct { + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + DigitalId string `xorm:"not null comment('数字币ID') unique(user_id) VARCHAR(100)"` + FrozenNum string `xorm:"not null comment('资产冻结数量') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UsableNum string `xorm:"not null comment('可用资产数量') DECIMAL(36,18)"` + UserId int `xorm:"not null comment('用户ID') unique(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_digital_log.go b/internal/pkg/model/bot_user_digital_log.go new file mode 100644 index 0000000..4fbd681 --- /dev/null +++ b/internal/pkg/model/bot_user_digital_log.go @@ -0,0 +1,17 @@ +package models + +import ( + "time" +) + +type BotUserDigitalLog struct { + BeforeNum string `xorm:"comment('变动前余额') DECIMAL(36,18)"` + ChangeNum string `xorm:"not null comment('变动资产数量') DECIMAL(36,18)"` + ChangeType int `xorm:"not null default 0 comment('变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-注册返佣,8-开仓返佣,9-平仓返佣') index(user_id) TINYINT(1)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + DigitalId string `xorm:"not null comment('数字币代码') index(user_id) VARCHAR(100)"` + Id int `xorm:"not null pk autoincr INT"` + OrderId string `xorm:"comment('订单号') VARCHAR(60)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_eur_give_stock_order.go b/internal/pkg/model/bot_user_eur_give_stock_order.go new file mode 100644 index 0000000..35ed0e9 --- /dev/null +++ b/internal/pkg/model/bot_user_eur_give_stock_order.go @@ -0,0 +1,20 @@ +package models + +import ( + "time" +) + +type BotUserEurGiveStockOrder struct { + Amount string `xorm:"not null comment('金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('费率') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + Price string `xorm:"not null default 0.000000000000000000 comment('价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码') index VARCHAR(255)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_eur_pre_stock_order.go b/internal/pkg/model/bot_user_eur_pre_stock_order.go new file mode 100644 index 0000000..da2f636 --- /dev/null +++ b/internal/pkg/model/bot_user_eur_pre_stock_order.go @@ -0,0 +1,26 @@ +package models + +import ( + "time" +) + +type BotUserEurPreStockOrder struct { + Amount string `xorm:"not null comment('申购金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间(申购时间)') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('申购手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('手续费率') DECIMAL(36,18)"` + GetAmount string `xorm:"not null default 0.000000000000000000 DECIMAL(36,18)"` + GetFee string `xorm:"not null comment('中签后实际收取手续费') DECIMAL(36,18)"` + GetNum int `xorm:"not null default 0 comment('中签数量') INT"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('申购数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + PayType int `xorm:"not null default 1 comment('支付类型: 1正常支付 2后支付') SMALLINT"` + PreStockId int `xorm:"not null default 0 comment('新股数据表主键') index INT"` + Price string `xorm:"not null default 0.000000000000000000 comment('申购价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + TradeStatus int `xorm:"comment('持仓状态: 1已持仓 0未持仓') SMALLINT(5)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_forex.go b/internal/pkg/model/bot_user_forex.go new file mode 100644 index 0000000..a6019cf --- /dev/null +++ b/internal/pkg/model/bot_user_forex.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotUserForex struct { + ContractId string `xorm:"not null comment('合约交易对ID ,usdt ,其他表示对应的合约ID') unique(user_id) VARCHAR(15)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + FrozenNum string `xorm:"not null comment('资产冻结数量') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UsableNum string `xorm:"not null comment('可用数量') DECIMAL(36,18)"` + UserId int `xorm:"not null comment('用户ID') unique(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_forex_log.go b/internal/pkg/model/bot_user_forex_log.go new file mode 100644 index 0000000..7c0ff51 --- /dev/null +++ b/internal/pkg/model/bot_user_forex_log.go @@ -0,0 +1,17 @@ +package models + +import ( + "time" +) + +type BotUserForexLog struct { + BeforeNum string `xorm:"not null comment('变动前余额') DECIMAL(36,18)"` + ChangeNum string `xorm:"not null comment('变动资产数量') DECIMAL(36,18)"` + ChangeType int `xorm:"not null default 0 comment('变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7账户转出,8账户转入') index(user_id) TINYINT(1)"` + ContractId string `xorm:"not null comment('合约交易对ID') index(user_id) VARCHAR(15)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + OrderId string `xorm:"comment('订单号') VARCHAR(60)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_fund_pre_stock_order.go b/internal/pkg/model/bot_user_fund_pre_stock_order.go new file mode 100644 index 0000000..360417c --- /dev/null +++ b/internal/pkg/model/bot_user_fund_pre_stock_order.go @@ -0,0 +1,23 @@ +package models + +import ( + "time" +) + +type BotUserFundPreStockOrder struct { + Amount string `xorm:"not null comment('订单金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('订单手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('手续费率') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + InterestType int `xorm:"not null default 1 comment('返利类型 1一次性本息 2.等额本息') TINYINT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + PhaseCount int `xorm:"not null default 1 comment('总共几期返利') INT"` + PreStockId int `xorm:"not null comment('基金ID') index INT"` + Status int `xorm:"not null default 1 comment('状态 见配置') TINYINT"` + StockCycle int `xorm:"not null default 1 comment('周期,单位天 30 为 30天') INT"` + StockCycleType int `xorm:"not null default 1 comment('周期单位 1:天 2:月 3:年') TINYINT"` + StockRate string `xorm:"not null comment('收益率,单位% 10 为 10%') DECIMAL(5,2)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') INT"` +} diff --git a/internal/pkg/model/bot_user_fur_give_stock_order.go b/internal/pkg/model/bot_user_fur_give_stock_order.go new file mode 100644 index 0000000..caf642a --- /dev/null +++ b/internal/pkg/model/bot_user_fur_give_stock_order.go @@ -0,0 +1,20 @@ +package models + +import ( + "time" +) + +type BotUserFurGiveStockOrder struct { + Amount string `xorm:"not null comment('金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('费率') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + Price string `xorm:"not null default 0.000000000000000000 comment('价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码') index VARCHAR(255)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_fur_pre_stock_order.go b/internal/pkg/model/bot_user_fur_pre_stock_order.go new file mode 100644 index 0000000..e214c43 --- /dev/null +++ b/internal/pkg/model/bot_user_fur_pre_stock_order.go @@ -0,0 +1,26 @@ +package models + +import ( + "time" +) + +type BotUserFurPreStockOrder struct { + Amount string `xorm:"not null comment('申购金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间(申购时间)') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('申购手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('手续费率') DECIMAL(36,18)"` + GetAmount string `xorm:"not null default 0.000000000000000000 DECIMAL(36,18)"` + GetFee string `xorm:"not null comment('中签后实际收取手续费') DECIMAL(36,18)"` + GetNum int `xorm:"not null default 0 comment('中签数量') INT"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('申购数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + PayType int `xorm:"not null default 1 comment('支付类型: 1正常支付 2后支付') SMALLINT"` + PreStockId int `xorm:"not null default 0 comment('新股数据表主键') index INT"` + Price string `xorm:"not null default 0.000000000000000000 comment('申购价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + TradeStatus int `xorm:"comment('持仓状态: 1已持仓 0未持仓') SMALLINT(5)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_gbx_give_stock_order.go b/internal/pkg/model/bot_user_gbx_give_stock_order.go new file mode 100644 index 0000000..a9fe97e --- /dev/null +++ b/internal/pkg/model/bot_user_gbx_give_stock_order.go @@ -0,0 +1,20 @@ +package models + +import ( + "time" +) + +type BotUserGbxGiveStockOrder struct { + Amount string `xorm:"not null comment('金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('费率') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + Price string `xorm:"not null default 0.000000000000000000 comment('价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码') index VARCHAR(255)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_gbx_pre_stock_order.go b/internal/pkg/model/bot_user_gbx_pre_stock_order.go new file mode 100644 index 0000000..8e574cb --- /dev/null +++ b/internal/pkg/model/bot_user_gbx_pre_stock_order.go @@ -0,0 +1,26 @@ +package models + +import ( + "time" +) + +type BotUserGbxPreStockOrder struct { + Amount string `xorm:"not null comment('申购金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间(申购时间)') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('申购手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('手续费率') DECIMAL(36,18)"` + GetAmount string `xorm:"not null default 0.000000000000000000 DECIMAL(36,18)"` + GetFee string `xorm:"not null comment('中签后实际收取手续费') DECIMAL(36,18)"` + GetNum int `xorm:"not null default 0 comment('中签数量') INT"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('申购数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + PayType int `xorm:"not null default 1 comment('支付类型: 1正常支付 2后支付') SMALLINT"` + PreStockId int `xorm:"not null default 0 comment('新股数据表主键') index INT"` + Price string `xorm:"not null default 0.000000000000000000 comment('申购价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + TradeStatus int `xorm:"comment('持仓状态: 1已持仓 0未持仓') SMALLINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_hkd_give_stock_order.go b/internal/pkg/model/bot_user_hkd_give_stock_order.go new file mode 100644 index 0000000..8b78aa8 --- /dev/null +++ b/internal/pkg/model/bot_user_hkd_give_stock_order.go @@ -0,0 +1,20 @@ +package models + +import ( + "time" +) + +type BotUserHkdGiveStockOrder struct { + Amount string `xorm:"not null comment('金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('费率') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + Price string `xorm:"not null default 0.000000000000000000 comment('价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码') index VARCHAR(255)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_hkd_pre_stock_order.go b/internal/pkg/model/bot_user_hkd_pre_stock_order.go new file mode 100644 index 0000000..3882f75 --- /dev/null +++ b/internal/pkg/model/bot_user_hkd_pre_stock_order.go @@ -0,0 +1,26 @@ +package models + +import ( + "time" +) + +type BotUserHkdPreStockOrder struct { + Amount string `xorm:"not null comment('申购金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间(申购时间)') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('申购手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('手续费率') DECIMAL(36,18)"` + GetAmount string `xorm:"not null default 0.000000000000000000 DECIMAL(36,18)"` + GetFee string `xorm:"not null comment('中签后实际收取手续费') DECIMAL(36,18)"` + GetNum int `xorm:"not null default 0 comment('中签数量') INT"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('申购数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + PayType int `xorm:"not null default 1 comment('支付类型: 1正常支付 2后支付') SMALLINT"` + PreStockId int `xorm:"not null default 0 comment('新股数据表主键') index INT"` + Price string `xorm:"not null default 0.000000000000000000 comment('申购价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + TradeStatus int `xorm:"comment('持仓状态: 1已持仓 0未持仓') SMALLINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_idn_give_stock_order.go b/internal/pkg/model/bot_user_idn_give_stock_order.go new file mode 100644 index 0000000..c85c27c --- /dev/null +++ b/internal/pkg/model/bot_user_idn_give_stock_order.go @@ -0,0 +1,20 @@ +package models + +import ( + "time" +) + +type BotUserIdnGiveStockOrder struct { + Amount string `xorm:"not null comment('金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('费率') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + Price string `xorm:"not null default 0.000000000000000000 comment('价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码') index VARCHAR(255)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_idn_pre_stock_order.go b/internal/pkg/model/bot_user_idn_pre_stock_order.go new file mode 100644 index 0000000..ba840be --- /dev/null +++ b/internal/pkg/model/bot_user_idn_pre_stock_order.go @@ -0,0 +1,26 @@ +package models + +import ( + "time" +) + +type BotUserIdnPreStockOrder struct { + Amount string `xorm:"not null comment('申购金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间(申购时间)') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('申购手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('手续费率') DECIMAL(36,18)"` + GetAmount string `xorm:"not null default 0.000000000000000000 DECIMAL(36,18)"` + GetFee string `xorm:"not null comment('中签后实际收取手续费') DECIMAL(36,18)"` + GetNum int `xorm:"not null default 0 comment('中签数量') INT"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('申购数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + PayType int `xorm:"not null default 1 comment('支付类型: 1正常支付 2后支付') SMALLINT"` + PreStockId int `xorm:"not null default 0 comment('新股数据表主键') index INT"` + Price string `xorm:"not null default 0.000000000000000000 comment('申购价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + TradeStatus int `xorm:"comment('持仓状态: 1已持仓 0未持仓') SMALLINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_in_give_stock_order.go b/internal/pkg/model/bot_user_in_give_stock_order.go new file mode 100644 index 0000000..dbbf64c --- /dev/null +++ b/internal/pkg/model/bot_user_in_give_stock_order.go @@ -0,0 +1,20 @@ +package models + +import ( + "time" +) + +type BotUserInGiveStockOrder struct { + Amount string `xorm:"not null comment('金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('费率') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + Price string `xorm:"not null default 0.000000000000000000 comment('价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码') index VARCHAR(255)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_in_pre_stock_order.go b/internal/pkg/model/bot_user_in_pre_stock_order.go new file mode 100644 index 0000000..eb8a6e7 --- /dev/null +++ b/internal/pkg/model/bot_user_in_pre_stock_order.go @@ -0,0 +1,26 @@ +package models + +import ( + "time" +) + +type BotUserInPreStockOrder struct { + Amount string `xorm:"not null comment('申购金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间(申购时间)') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('申购手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('手续费率') DECIMAL(36,18)"` + GetAmount string `xorm:"not null default 0.000000000000000000 DECIMAL(36,18)"` + GetFee string `xorm:"not null comment('中签后实际收取手续费') DECIMAL(36,18)"` + GetNum int `xorm:"not null default 0 comment('中签数量') INT"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('申购数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + PayType int `xorm:"not null default 1 comment('支付类型: 1正常支付 2后支付') SMALLINT"` + PreStockId int `xorm:"not null default 0 comment('新股数据表主键') index INT"` + Price string `xorm:"not null default 0.000000000000000000 comment('申购价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + TradeStatus int `xorm:"comment('持仓状态: 1已持仓 0未持仓') SMALLINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_jp_give_stock_order.go b/internal/pkg/model/bot_user_jp_give_stock_order.go new file mode 100644 index 0000000..fbfcd03 --- /dev/null +++ b/internal/pkg/model/bot_user_jp_give_stock_order.go @@ -0,0 +1,20 @@ +package models + +import ( + "time" +) + +type BotUserJpGiveStockOrder struct { + Amount string `xorm:"not null comment('金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('费率') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + Price string `xorm:"not null default 0.000000000000000000 comment('价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码') index VARCHAR(255)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_jp_pre_stock_order.go b/internal/pkg/model/bot_user_jp_pre_stock_order.go new file mode 100644 index 0000000..e12136b --- /dev/null +++ b/internal/pkg/model/bot_user_jp_pre_stock_order.go @@ -0,0 +1,26 @@ +package models + +import ( + "time" +) + +type BotUserJpPreStockOrder struct { + Amount string `xorm:"not null comment('申购金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间(申购时间)') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('申购手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('手续费率') DECIMAL(36,18)"` + GetAmount string `xorm:"not null default 0.000000000000000000 DECIMAL(36,18)"` + GetFee string `xorm:"not null comment('中签后实际收取手续费') DECIMAL(36,18)"` + GetNum int `xorm:"not null default 0 comment('中签数量') INT"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('申购数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + PayType int `xorm:"not null default 1 comment('支付类型: 1正常支付 2后支付') SMALLINT"` + PreStockId int `xorm:"not null default 0 comment('新股数据表主键') index INT"` + Price string `xorm:"not null default 0.000000000000000000 comment('申购价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + TradeStatus int `xorm:"comment('持仓状态: 1已持仓 0未持仓') SMALLINT(5)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_level.go b/internal/pkg/model/bot_user_level.go new file mode 100644 index 0000000..222da51 --- /dev/null +++ b/internal/pkg/model/bot_user_level.go @@ -0,0 +1,8 @@ +package models + +type BotUserLevel struct { + GrandpaId int `xorm:"not null comment('爷级ID') index INT"` + ParentId int `xorm:"not null comment('父级ID') index INT"` + TopId int `xorm:"not null comment('祖级ID') index INT"` + UserId int `xorm:"not null pk comment('用户ID') INT"` +} diff --git a/internal/pkg/model/bot_user_login_log.go b/internal/pkg/model/bot_user_login_log.go new file mode 100644 index 0000000..b2c8b4d --- /dev/null +++ b/internal/pkg/model/bot_user_login_log.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotUserLoginLog struct { + City string `xorm:"not null default '' comment('登陆城市') VARCHAR(255)"` + Country string `xorm:"not null default '' comment('登陆国家') VARCHAR(255)"` + Device string `xorm:"not null default '' comment('登陆设备') VARCHAR(255)"` + Id int64 `xorm:"pk autoincr comment('主键') BIGINT"` + Ip string `xorm:"not null default '' comment('登陆ip') VARCHAR(255)"` + LoginDate time.Time `xorm:"not null comment('登陆时间') DATETIME"` + UserId int64 `xorm:"not null default 0 comment('用户id') index BIGINT"` +} diff --git a/internal/pkg/model/bot_user_market.go b/internal/pkg/model/bot_user_market.go new file mode 100644 index 0000000..c80fdb3 --- /dev/null +++ b/internal/pkg/model/bot_user_market.go @@ -0,0 +1,14 @@ +package models + +import ( + "time" +) + +type BotUserMarket struct { + CreateTime time.Time `xorm:"not null comment('时间') index(user_id) DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + MarketName string `xorm:"not null comment('交易对名称') VARCHAR(30)"` + MarketType int `xorm:"not null comment('市场类型:1现货,2合约,3美股') index(user_id) TINYINT(1)"` + TradeName string `xorm:"not null comment('交易对') VARCHAR(30)"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_money.go b/internal/pkg/model/bot_user_money.go new file mode 100644 index 0000000..9958e0c --- /dev/null +++ b/internal/pkg/model/bot_user_money.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotUserMoney struct { + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + FrozenNum string `xorm:"not null comment('资产冻结数量') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + StockId string `xorm:"not null comment('股票类型ID:USD代表美金,其他代表股票代码') unique(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UsableNum string `xorm:"not null comment('可用资产数量') DECIMAL(36,18)"` + UserId int `xorm:"not null comment('用户ID') unique(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_money_log.go b/internal/pkg/model/bot_user_money_log.go new file mode 100644 index 0000000..abf0ebc --- /dev/null +++ b/internal/pkg/model/bot_user_money_log.go @@ -0,0 +1,17 @@ +package models + +import ( + "time" +) + +type BotUserMoneyLog struct { + BeforeNum string `xorm:"not null comment('变动前余额') DECIMAL(36,18)"` + ChangeNum string `xorm:"not null comment('变动资产数量') DECIMAL(36,18)"` + ChangeType int `xorm:"not null default 0 comment('变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-注册返佣,8-开仓返佣,9-平仓返佣') index(user_id) TINYINT(1)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + OrderId string `xorm:"comment('订单号') VARCHAR(60)"` + StockId string `xorm:"not null comment('股票类型ID:USD代表美金,其他代表股票代码') index(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_mys_give_stock_order.go b/internal/pkg/model/bot_user_mys_give_stock_order.go new file mode 100644 index 0000000..be23c6d --- /dev/null +++ b/internal/pkg/model/bot_user_mys_give_stock_order.go @@ -0,0 +1,20 @@ +package models + +import ( + "time" +) + +type BotUserMysGiveStockOrder struct { + Amount string `xorm:"not null comment('金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('费率') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + Price string `xorm:"not null default 0.000000000000000000 comment('价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码') index VARCHAR(255)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_mys_pre_stock_order.go b/internal/pkg/model/bot_user_mys_pre_stock_order.go new file mode 100644 index 0000000..ef1f1ee --- /dev/null +++ b/internal/pkg/model/bot_user_mys_pre_stock_order.go @@ -0,0 +1,26 @@ +package models + +import ( + "time" +) + +type BotUserMysPreStockOrder struct { + Amount string `xorm:"not null comment('申购金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间(申购时间)') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('申购手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('手续费率') DECIMAL(36,18)"` + GetAmount string `xorm:"not null default 0.000000000000000000 DECIMAL(36,18)"` + GetFee string `xorm:"not null comment('中签后实际收取手续费') DECIMAL(36,18)"` + GetNum int `xorm:"not null default 0 comment('中签数量') INT"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('申购数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + PayType int `xorm:"not null default 1 comment('支付类型: 1正常支付 2后支付') SMALLINT"` + PreStockId int `xorm:"not null default 0 comment('新股数据表主键') index INT"` + Price string `xorm:"not null default 0.000000000000000000 comment('申购价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + TradeStatus int `xorm:"comment('持仓状态: 1已持仓 0未持仓') SMALLINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_sgd_give_stock_order.go b/internal/pkg/model/bot_user_sgd_give_stock_order.go new file mode 100644 index 0000000..1a4802f --- /dev/null +++ b/internal/pkg/model/bot_user_sgd_give_stock_order.go @@ -0,0 +1,20 @@ +package models + +import ( + "time" +) + +type BotUserSgdGiveStockOrder struct { + Amount string `xorm:"not null comment('金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('费率') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + Price string `xorm:"not null default 0.000000000000000000 comment('价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码') index VARCHAR(255)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_sgd_pre_stock_order.go b/internal/pkg/model/bot_user_sgd_pre_stock_order.go new file mode 100644 index 0000000..93f27c6 --- /dev/null +++ b/internal/pkg/model/bot_user_sgd_pre_stock_order.go @@ -0,0 +1,26 @@ +package models + +import ( + "time" +) + +type BotUserSgdPreStockOrder struct { + Amount string `xorm:"not null comment('申购金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间(申购时间)') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('申购手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('手续费率') DECIMAL(36,18)"` + GetAmount string `xorm:"not null default 0.000000000000000000 DECIMAL(36,18)"` + GetFee string `xorm:"not null comment('中签后实际收取手续费') DECIMAL(36,18)"` + GetNum int `xorm:"not null default 0 comment('中签数量') INT"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('申购数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + PayType int `xorm:"not null default 1 comment('支付类型: 1正常支付 2后支付') SMALLINT"` + PreStockId int `xorm:"not null default 0 comment('新股数据表主键') index INT"` + Price string `xorm:"not null default 0.000000000000000000 comment('申购价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + TradeStatus int `xorm:"comment('持仓状态: 1已持仓 0未持仓') SMALLINT(5)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_stock.go b/internal/pkg/model/bot_user_stock.go new file mode 100644 index 0000000..b7e945a --- /dev/null +++ b/internal/pkg/model/bot_user_stock.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotUserStock struct { + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + FrozenNum string `xorm:"not null comment('资产冻结数量') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + StockId string `xorm:"not null comment('股票类型ID:USD代表美金,其他代表股票代码') unique(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UsableNum string `xorm:"not null comment('可用资产数量') DECIMAL(36,18)"` + UserId int `xorm:"not null comment('用户ID') unique(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_block_log.go b/internal/pkg/model/bot_user_stock_block_log.go new file mode 100644 index 0000000..6d96295 --- /dev/null +++ b/internal/pkg/model/bot_user_stock_block_log.go @@ -0,0 +1,18 @@ +package models + +import ( + "time" +) + +type BotUserStockBlockLog struct { + BeforeNum string `xorm:"not null comment('变动前余额') DECIMAL(36,18)"` + ChangeNum string `xorm:"not null comment('变动资产数量') DECIMAL(36,18)"` + ChangeType int `xorm:"not null default 0 comment('变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-注册返佣,8-开仓返佣,9-平仓返佣') index(user_id) TINYINT(1)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + OrderId string `xorm:"comment('订单号') VARCHAR(60)"` + StockId string `xorm:"not null comment('股票代码') index(user_id) VARCHAR(100)"` + Type int `xorm:"comment('市场类型:3美股、4印尼股、5马股、6泰股、7印度股、9新加坡股、12港股') INT"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_brl.go b/internal/pkg/model/bot_user_stock_brl.go new file mode 100644 index 0000000..ba20643 --- /dev/null +++ b/internal/pkg/model/bot_user_stock_brl.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotUserStockBrl struct { + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + FrozenNum string `xorm:"not null comment('资产冻结数量') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + StockId string `xorm:"not null comment('股票类型ID:SGD代表新币,其他代表股票代码') unique(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UsableNum string `xorm:"not null comment('可用资产数量') DECIMAL(36,18)"` + UserId int `xorm:"not null comment('用户ID') unique(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_brl_log.go b/internal/pkg/model/bot_user_stock_brl_log.go new file mode 100644 index 0000000..ae1aba5 --- /dev/null +++ b/internal/pkg/model/bot_user_stock_brl_log.go @@ -0,0 +1,17 @@ +package models + +import ( + "time" +) + +type BotUserStockBrlLog struct { + BeforeNum string `xorm:"not null comment('变动前余额') DECIMAL(36,18)"` + ChangeNum string `xorm:"not null comment('变动资产数量') DECIMAL(36,18)"` + ChangeType int `xorm:"not null default 0 comment('变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-注册返佣,8-开仓返佣,9-平仓返佣') index(user_id) TINYINT(1)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + OrderId string `xorm:"comment('订单号') VARCHAR(60)"` + StockId string `xorm:"not null comment('股票类型ID:SGD代表新币,其他代表股票代码') index(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_eur.go b/internal/pkg/model/bot_user_stock_eur.go new file mode 100644 index 0000000..689b199 --- /dev/null +++ b/internal/pkg/model/bot_user_stock_eur.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotUserStockEur struct { + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + FrozenNum string `xorm:"not null comment('资产冻结数量') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + StockId string `xorm:"not null comment('股票类型ID:SGD代表新币,其他代表股票代码') unique(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UsableNum string `xorm:"not null comment('可用资产数量') DECIMAL(36,18)"` + UserId int `xorm:"not null comment('用户ID') unique(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_eur_log.go b/internal/pkg/model/bot_user_stock_eur_log.go new file mode 100644 index 0000000..d200b62 --- /dev/null +++ b/internal/pkg/model/bot_user_stock_eur_log.go @@ -0,0 +1,17 @@ +package models + +import ( + "time" +) + +type BotUserStockEurLog struct { + BeforeNum string `xorm:"not null comment('变动前余额') DECIMAL(36,18)"` + ChangeNum string `xorm:"not null comment('变动资产数量') DECIMAL(36,18)"` + ChangeType int `xorm:"not null default 0 comment('变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-注册返佣,8-开仓返佣,9-平仓返佣') index(user_id) TINYINT(1)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + OrderId string `xorm:"comment('订单号') VARCHAR(60)"` + StockId string `xorm:"not null comment('股票类型ID:SGD代表新币,其他代表股票代码') index(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_fund.go b/internal/pkg/model/bot_user_stock_fund.go new file mode 100644 index 0000000..ab0235f --- /dev/null +++ b/internal/pkg/model/bot_user_stock_fund.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotUserStockFund struct { + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + FrozenNum string `xorm:"not null comment('资产冻结数量') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + StockId string `xorm:"not null comment('货币单位') unique(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UsableNum string `xorm:"not null comment('可用资产数量') DECIMAL(36,18)"` + UserId int `xorm:"not null comment('用户ID') unique(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_fund_interest_receipt.go b/internal/pkg/model/bot_user_stock_fund_interest_receipt.go new file mode 100644 index 0000000..f877b93 --- /dev/null +++ b/internal/pkg/model/bot_user_stock_fund_interest_receipt.go @@ -0,0 +1,21 @@ +package models + +import ( + "time" +) + +type BotUserStockFundInterestReceipt struct { + Capital string `xorm:"not null comment('本金') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + Interest string `xorm:"not null comment('利息') DECIMAL(36,18)"` + OrderId int `xorm:"not null comment('订单ID') index(user_id) INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + PhaseTime int `xorm:"not null comment('第几期') INT"` + PreStockId int `xorm:"not null comment('基金ID') index(user_id) INT"` + ReturnDate time.Time `xorm:"comment('返款日期') index DATE"` + Status int `xorm:"not null default 1 comment('1.待返息 2.已完成') TINYINT"` + Unit string `xorm:"not null comment('货币单位') VARCHAR(10)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_fund_log.go b/internal/pkg/model/bot_user_stock_fund_log.go new file mode 100644 index 0000000..740e1b0 --- /dev/null +++ b/internal/pkg/model/bot_user_stock_fund_log.go @@ -0,0 +1,17 @@ +package models + +import ( + "time" +) + +type BotUserStockFundLog struct { + BeforeNum string `xorm:"not null comment('变动前余额') DECIMAL(36,18)"` + ChangeNum string `xorm:"not null comment('变动资产数量') DECIMAL(36,18)"` + ChangeType int `xorm:"not null default 0 comment('变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-注册返佣,8-开仓返佣,9-平仓返佣') index(user_id) TINYINT"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + OrderId string `xorm:"comment('订单号') VARCHAR(60)"` + StockId string `xorm:"not null comment('货币单位') VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_fur.go b/internal/pkg/model/bot_user_stock_fur.go new file mode 100644 index 0000000..9eb4d65 --- /dev/null +++ b/internal/pkg/model/bot_user_stock_fur.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotUserStockFur struct { + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + FrozenNum string `xorm:"not null comment('资产冻结数量') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + StockId string `xorm:"not null comment('股票类型ID:SGD代表新币,其他代表股票代码') unique(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UsableNum string `xorm:"not null comment('可用资产数量') DECIMAL(36,18)"` + UserId int `xorm:"not null comment('用户ID') unique(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_fur_log.go b/internal/pkg/model/bot_user_stock_fur_log.go new file mode 100644 index 0000000..1c4a23f --- /dev/null +++ b/internal/pkg/model/bot_user_stock_fur_log.go @@ -0,0 +1,17 @@ +package models + +import ( + "time" +) + +type BotUserStockFurLog struct { + BeforeNum string `xorm:"not null comment('变动前余额') DECIMAL(36,18)"` + ChangeNum string `xorm:"not null comment('变动资产数量') DECIMAL(36,18)"` + ChangeType int `xorm:"not null default 0 comment('变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-注册返佣,8-开仓返佣,9-平仓返佣') index(user_id) TINYINT(1)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + OrderId string `xorm:"comment('订单号') VARCHAR(60)"` + StockId string `xorm:"not null comment('股票类型ID:SGD代表新币,其他代表股票代码') index(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_gbx.go b/internal/pkg/model/bot_user_stock_gbx.go new file mode 100644 index 0000000..708e865 --- /dev/null +++ b/internal/pkg/model/bot_user_stock_gbx.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotUserStockGbx struct { + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + FrozenNum string `xorm:"not null comment('资产冻结数量') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + StockId string `xorm:"not null comment('股票类型ID:INR代表卢比,其他代表股票代码') unique(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UsableNum string `xorm:"not null comment('可用资产数量') DECIMAL(36,18)"` + UserId int `xorm:"not null comment('用户ID') unique(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_gbx_log.go b/internal/pkg/model/bot_user_stock_gbx_log.go new file mode 100644 index 0000000..f27d9d0 --- /dev/null +++ b/internal/pkg/model/bot_user_stock_gbx_log.go @@ -0,0 +1,17 @@ +package models + +import ( + "time" +) + +type BotUserStockGbxLog struct { + BeforeNum string `xorm:"not null comment('变动前余额') DECIMAL(36,18)"` + ChangeNum string `xorm:"not null comment('变动资产数量') DECIMAL(36,18)"` + ChangeType int `xorm:"not null default 0 comment('变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-注册返佣,8-开仓返佣,9-平仓返佣') index(user_id) TINYINT(1)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + OrderId string `xorm:"comment('订单号') VARCHAR(60)"` + StockId string `xorm:"not null comment('股票类型ID:INR代表卢比,其他代表股票代码') index(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_hkd.go b/internal/pkg/model/bot_user_stock_hkd.go new file mode 100644 index 0000000..f3727a3 --- /dev/null +++ b/internal/pkg/model/bot_user_stock_hkd.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotUserStockHkd struct { + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + FrozenNum string `xorm:"not null comment('资产冻结数量') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + StockId string `xorm:"not null comment('股票类型ID:HKD代表港元,其他代表股票代码') unique(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UsableNum string `xorm:"not null comment('可用资产数量') DECIMAL(36,18)"` + UserId int `xorm:"not null comment('用户ID') unique(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_hkd_log.go b/internal/pkg/model/bot_user_stock_hkd_log.go new file mode 100644 index 0000000..a6fd468 --- /dev/null +++ b/internal/pkg/model/bot_user_stock_hkd_log.go @@ -0,0 +1,17 @@ +package models + +import ( + "time" +) + +type BotUserStockHkdLog struct { + BeforeNum string `xorm:"not null comment('变动前余额') DECIMAL(36,18)"` + ChangeNum string `xorm:"not null comment('变动资产数量') DECIMAL(36,18)"` + ChangeType int `xorm:"not null default 0 comment('变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-注册返佣,8-开仓返佣,9-平仓返佣') index(user_id) TINYINT(1)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + OrderId string `xorm:"comment('订单号') VARCHAR(60)"` + StockId string `xorm:"not null comment('股票类型ID:HKD代表港元,其他代表股票代码') index(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_idn.go b/internal/pkg/model/bot_user_stock_idn.go new file mode 100644 index 0000000..0e47072 --- /dev/null +++ b/internal/pkg/model/bot_user_stock_idn.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotUserStockIdn struct { + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + FrozenNum string `xorm:"not null comment('资产冻结数量') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + StockId string `xorm:"not null comment('股票类型ID:IDR代表印尼,其他代表股票代码') unique(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UsableNum string `xorm:"not null comment('可用资产数量') DECIMAL(36,18)"` + UserId int `xorm:"not null comment('用户ID') unique(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_idn_log.go b/internal/pkg/model/bot_user_stock_idn_log.go new file mode 100644 index 0000000..c2ca903 --- /dev/null +++ b/internal/pkg/model/bot_user_stock_idn_log.go @@ -0,0 +1,17 @@ +package models + +import ( + "time" +) + +type BotUserStockIdnLog struct { + BeforeNum string `xorm:"not null comment('变动前余额') DECIMAL(36,18)"` + ChangeNum string `xorm:"not null comment('变动资产数量') DECIMAL(36,18)"` + ChangeType int `xorm:"not null default 0 comment('变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-注册返佣,8-开仓返佣,9-平仓返佣') index(user_id) TINYINT(1)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + OrderId string `xorm:"comment('订单号') VARCHAR(60)"` + StockId string `xorm:"not null comment('股票类型ID:IDR代表印尼,其他代表股票代码') index(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_in.go b/internal/pkg/model/bot_user_stock_in.go new file mode 100644 index 0000000..e69942a --- /dev/null +++ b/internal/pkg/model/bot_user_stock_in.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotUserStockIn struct { + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + FrozenNum string `xorm:"not null comment('资产冻结数量') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + StockId string `xorm:"not null comment('股票类型ID:INR代表卢比,其他代表股票代码') unique(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UsableNum string `xorm:"not null comment('可用资产数量') DECIMAL(36,18)"` + UserId int `xorm:"not null comment('用户ID') unique(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_in_log.go b/internal/pkg/model/bot_user_stock_in_log.go new file mode 100644 index 0000000..44c93a7 --- /dev/null +++ b/internal/pkg/model/bot_user_stock_in_log.go @@ -0,0 +1,17 @@ +package models + +import ( + "time" +) + +type BotUserStockInLog struct { + BeforeNum string `xorm:"not null comment('变动前余额') DECIMAL(36,18)"` + ChangeNum string `xorm:"not null comment('变动资产数量') DECIMAL(36,18)"` + ChangeType int `xorm:"not null default 0 comment('变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-注册返佣,8-开仓返佣,9-平仓返佣') index(user_id) TINYINT(1)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + OrderId string `xorm:"comment('订单号') VARCHAR(60)"` + StockId string `xorm:"not null comment('股票类型ID:INR代表卢比,其他代表股票代码') index(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_jp.go b/internal/pkg/model/bot_user_stock_jp.go new file mode 100644 index 0000000..a08fadd --- /dev/null +++ b/internal/pkg/model/bot_user_stock_jp.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotUserStockJp struct { + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + FrozenNum string `xorm:"not null comment('资产冻结数量') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + StockId string `xorm:"not null comment('股票类型ID:SGD代表新币,其他代表股票代码') unique(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UsableNum string `xorm:"not null comment('可用资产数量') DECIMAL(36,18)"` + UserId int `xorm:"not null comment('用户ID') unique(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_jp_log.go b/internal/pkg/model/bot_user_stock_jp_log.go new file mode 100644 index 0000000..e1e92bd --- /dev/null +++ b/internal/pkg/model/bot_user_stock_jp_log.go @@ -0,0 +1,17 @@ +package models + +import ( + "time" +) + +type BotUserStockJpLog struct { + BeforeNum string `xorm:"not null comment('变动前余额') DECIMAL(36,18)"` + ChangeNum string `xorm:"not null comment('变动资产数量') DECIMAL(36,18)"` + ChangeType int `xorm:"not null default 0 comment('变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-注册返佣,8-开仓返佣,9-平仓返佣') index(user_id) TINYINT(1)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + OrderId string `xorm:"comment('订单号') VARCHAR(60)"` + StockId string `xorm:"not null comment('股票类型ID:SGD代表新币,其他代表股票代码') index(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_log.go b/internal/pkg/model/bot_user_stock_log.go new file mode 100644 index 0000000..47192fe --- /dev/null +++ b/internal/pkg/model/bot_user_stock_log.go @@ -0,0 +1,17 @@ +package models + +import ( + "time" +) + +type BotUserStockLog struct { + BeforeNum string `xorm:"not null comment('变动前余额') DECIMAL(36,18)"` + ChangeNum string `xorm:"not null comment('变动资产数量') DECIMAL(36,18)"` + ChangeType int `xorm:"not null default 0 comment('变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-注册返佣,8-开仓返佣,9-平仓返佣') index(user_id) TINYINT(1)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + OrderId string `xorm:"comment('订单号') VARCHAR(60)"` + StockId string `xorm:"not null comment('股票类型ID:USD代表美金,其他代表股票代码') index(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_mys.go b/internal/pkg/model/bot_user_stock_mys.go new file mode 100644 index 0000000..84b8fd3 --- /dev/null +++ b/internal/pkg/model/bot_user_stock_mys.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotUserStockMys struct { + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + FrozenNum string `xorm:"not null comment('资产冻结数量') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + StockId string `xorm:"not null comment('股票类型ID:MYR代表马股,其他代表股票代码') unique(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UsableNum string `xorm:"not null comment('可用资产数量') DECIMAL(36,18)"` + UserId int `xorm:"not null comment('用户ID') unique(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_mys_log.go b/internal/pkg/model/bot_user_stock_mys_log.go new file mode 100644 index 0000000..0307e5c --- /dev/null +++ b/internal/pkg/model/bot_user_stock_mys_log.go @@ -0,0 +1,17 @@ +package models + +import ( + "time" +) + +type BotUserStockMysLog struct { + BeforeNum string `xorm:"not null comment('变动前余额') DECIMAL(36,18)"` + ChangeNum string `xorm:"not null comment('变动资产数量') DECIMAL(36,18)"` + ChangeType int `xorm:"not null default 0 comment('变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-注册返佣,8-开仓返佣,9-平仓返佣') index(user_id) TINYINT(1)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + OrderId string `xorm:"comment('订单号') VARCHAR(60)"` + StockId string `xorm:"not null comment('股票类型ID:MYR代表马股,其他代表股票代码') index(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_option_inr.go b/internal/pkg/model/bot_user_stock_option_inr.go new file mode 100644 index 0000000..665cf71 --- /dev/null +++ b/internal/pkg/model/bot_user_stock_option_inr.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotUserStockOptionInr struct { + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + FrozenNum string `xorm:"not null comment('资产冻结数量') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + StockId string `xorm:"not null comment('股票类型ID:OINR代表印度期权股,其他代表股票代码') unique(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UsableNum string `xorm:"not null comment('可用资产数量') DECIMAL(36,18)"` + UserId int `xorm:"not null comment('用户ID') unique(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_option_inr_log.go b/internal/pkg/model/bot_user_stock_option_inr_log.go new file mode 100644 index 0000000..b50c511 --- /dev/null +++ b/internal/pkg/model/bot_user_stock_option_inr_log.go @@ -0,0 +1,17 @@ +package models + +import ( + "time" +) + +type BotUserStockOptionInrLog struct { + BeforeNum string `xorm:"not null comment('变动前余额') DECIMAL(36,18)"` + ChangeNum string `xorm:"not null comment('变动资产数量') DECIMAL(36,18)"` + ChangeType int `xorm:"not null default 0 comment('变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-注册返佣,8-开仓返佣,9-平仓返佣') index(user_id) TINYINT(1)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + OrderId string `xorm:"comment('订单号') VARCHAR(60)"` + StockId string `xorm:"not null comment('股票代码') index(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_sgd.go b/internal/pkg/model/bot_user_stock_sgd.go new file mode 100644 index 0000000..5e37f60 --- /dev/null +++ b/internal/pkg/model/bot_user_stock_sgd.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotUserStockSgd struct { + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + FrozenNum string `xorm:"not null comment('资产冻结数量') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + StockId string `xorm:"not null comment('股票类型ID:SGD代表新币,其他代表股票代码') unique(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UsableNum string `xorm:"not null comment('可用资产数量') DECIMAL(36,18)"` + UserId int `xorm:"not null comment('用户ID') unique(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_sgd_log.go b/internal/pkg/model/bot_user_stock_sgd_log.go new file mode 100644 index 0000000..532dc8b --- /dev/null +++ b/internal/pkg/model/bot_user_stock_sgd_log.go @@ -0,0 +1,17 @@ +package models + +import ( + "time" +) + +type BotUserStockSgdLog struct { + BeforeNum string `xorm:"not null comment('变动前余额') DECIMAL(36,18)"` + ChangeNum string `xorm:"not null comment('变动资产数量') DECIMAL(36,18)"` + ChangeType int `xorm:"not null default 0 comment('变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-注册返佣,8-开仓返佣,9-平仓返佣') index(user_id) TINYINT(1)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + OrderId string `xorm:"comment('订单号') VARCHAR(60)"` + StockId string `xorm:"not null comment('股票类型ID:SGD代表新币,其他代表股票代码') index(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_tha.go b/internal/pkg/model/bot_user_stock_tha.go new file mode 100644 index 0000000..7be8c60 --- /dev/null +++ b/internal/pkg/model/bot_user_stock_tha.go @@ -0,0 +1,15 @@ +package models + +import ( + "time" +) + +type BotUserStockTha struct { + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + FrozenNum string `xorm:"not null comment('资产冻结数量') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + StockId string `xorm:"not null comment('股票类型ID:THB代表泰股,其他代表股票代码') unique(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UsableNum string `xorm:"not null comment('可用资产数量') DECIMAL(36,18)"` + UserId int `xorm:"not null comment('用户ID') unique(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_stock_tha_log.go b/internal/pkg/model/bot_user_stock_tha_log.go new file mode 100644 index 0000000..42aa625 --- /dev/null +++ b/internal/pkg/model/bot_user_stock_tha_log.go @@ -0,0 +1,17 @@ +package models + +import ( + "time" +) + +type BotUserStockThaLog struct { + BeforeNum string `xorm:"not null comment('变动前余额') DECIMAL(36,18)"` + ChangeNum string `xorm:"not null comment('变动资产数量') DECIMAL(36,18)"` + ChangeType int `xorm:"not null default 0 comment('变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-注册返佣,8-开仓返佣,9-平仓返佣') index(user_id) TINYINT(1)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + OrderId string `xorm:"comment('订单号') VARCHAR(60)"` + StockId string `xorm:"not null comment('股票类型ID:THB代表泰股,其他代表股票代码') index(user_id) VARCHAR(100)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` +} diff --git a/internal/pkg/model/bot_user_tha_give_stock_order.go b/internal/pkg/model/bot_user_tha_give_stock_order.go new file mode 100644 index 0000000..3a63d64 --- /dev/null +++ b/internal/pkg/model/bot_user_tha_give_stock_order.go @@ -0,0 +1,20 @@ +package models + +import ( + "time" +) + +type BotUserThaGiveStockOrder struct { + Amount string `xorm:"not null comment('金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('费率') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + Price string `xorm:"not null default 0.000000000000000000 comment('价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码') index VARCHAR(255)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_tha_pre_stock_order.go b/internal/pkg/model/bot_user_tha_pre_stock_order.go new file mode 100644 index 0000000..7800bdd --- /dev/null +++ b/internal/pkg/model/bot_user_tha_pre_stock_order.go @@ -0,0 +1,26 @@ +package models + +import ( + "time" +) + +type BotUserThaPreStockOrder struct { + Amount string `xorm:"not null comment('申购金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间(申购时间)') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('申购手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('手续费率') DECIMAL(36,18)"` + GetAmount string `xorm:"not null default 0.000000000000000000 DECIMAL(36,18)"` + GetFee string `xorm:"not null comment('中签后实际收取手续费') DECIMAL(36,18)"` + GetNum int `xorm:"not null default 0 comment('中签数量') INT"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('申购数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + PayType int `xorm:"not null default 1 comment('支付类型: 1正常支付 2后支付') SMALLINT"` + PreStockId int `xorm:"not null default 0 comment('新股数据表主键') index INT"` + Price string `xorm:"not null default 0.000000000000000000 comment('申购价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + TradeStatus int `xorm:"comment('持仓状态: 1已持仓 0未持仓') SMALLINT(1)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_transfer.go b/internal/pkg/model/bot_user_transfer.go new file mode 100644 index 0000000..71ee480 --- /dev/null +++ b/internal/pkg/model/bot_user_transfer.go @@ -0,0 +1,20 @@ +package models + +import ( + "time" +) + +type BotUserTransfer struct { + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + FromAccount int `xorm:"not null default 0 comment('转出资金账号') TINYINT(1)"` + FromAccountRate string `xorm:"not null default '1' comment('转入账户对美元') VARCHAR(255)"` + FromNum string `xorm:"not null default '0' comment('转入金额') VARCHAR(255)"` + OrderSn string `xorm:"not null default '' comment('订单号') VARCHAR(20)"` + Status int `xorm:"not null default 1 comment('状态:1成功,0处理中') TINYINT(1)"` + ToAccount int `xorm:"not null default 0 comment('转入资金账号') TINYINT(1)"` + ToAccountRate string `xorm:"not null default '1' comment('美元对转出账户') VARCHAR(255)"` + ToNum string `xorm:"not null default '0' comment('转入数量') VARCHAR(255)"` + TranId int `xorm:"not null pk autoincr INT"` + UpdateTime time.Time `xorm:"not null comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 index INT"` +} diff --git a/internal/pkg/model/bot_user_us_give_stock_order.go b/internal/pkg/model/bot_user_us_give_stock_order.go new file mode 100644 index 0000000..a1394e2 --- /dev/null +++ b/internal/pkg/model/bot_user_us_give_stock_order.go @@ -0,0 +1,20 @@ +package models + +import ( + "time" +) + +type BotUserUsGiveStockOrder struct { + Amount string `xorm:"not null comment('金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('费率') DECIMAL(36,18)"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + Price string `xorm:"not null default 0.000000000000000000 comment('价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + StockCode string `xorm:"not null default '' comment('股票代码') index VARCHAR(255)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_us_pre_stock_order.go b/internal/pkg/model/bot_user_us_pre_stock_order.go new file mode 100644 index 0000000..51789de --- /dev/null +++ b/internal/pkg/model/bot_user_us_pre_stock_order.go @@ -0,0 +1,26 @@ +package models + +import ( + "time" +) + +type BotUserUsPreStockOrder struct { + Amount string `xorm:"not null comment('申购金额') DECIMAL(36,18)"` + CreateTime time.Time `xorm:"comment('创建时间(申购时间)') DATETIME"` + Fee string `xorm:"not null default 0.000000000000000000 comment('申购手续费') DECIMAL(36,18)"` + FeeRate string `xorm:"not null default 0.000000000000000000 comment('手续费率') DECIMAL(36,18)"` + GetAmount string `xorm:"not null default 0.000000000000000000 DECIMAL(36,18)"` + GetFee string `xorm:"not null comment('中签后实际收取手续费') DECIMAL(36,18)"` + GetNum int `xorm:"not null default 0 comment('中签数量') INT"` + GetTime time.Time `xorm:"comment('中签时间') DATETIME"` + Id int `xorm:"not null pk autoincr INT"` + Num int `xorm:"not null default 0 comment('申购数量') INT"` + OrderNo string `xorm:"not null default '' comment('订单号') VARCHAR(50)"` + PayType int `xorm:"not null default 1 comment('支付类型: 1正常支付 2后支付') SMALLINT"` + PreStockId int `xorm:"not null default 0 comment('新股数据表主键') index INT"` + Price string `xorm:"not null default 0.000000000000000000 comment('申购价格') DECIMAL(36,18)"` + Status int `xorm:"not null default 1 comment('状态 见配置') SMALLINT"` + TradeStatus int `xorm:"comment('持仓状态: 1已持仓 0未持仓') SMALLINT"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户主键') INT"` +} diff --git a/internal/pkg/model/bot_user_verify_log.go b/internal/pkg/model/bot_user_verify_log.go new file mode 100644 index 0000000..9c2abcb --- /dev/null +++ b/internal/pkg/model/bot_user_verify_log.go @@ -0,0 +1,19 @@ +package models + +import ( + "time" +) + +type BotUserVerifyLog struct { + BackImg int `xorm:"not null default 0 comment('身份证照片') INT"` + Code string `xorm:"not null default '' comment('身份证号') VARCHAR(255)"` + Country int `xorm:"not null default 0 comment('国家') INT"` + CreateTime time.Time `xorm:"comment('创建时间') DATETIME"` + FrontImg int `xorm:"not null default 0 comment('身份证照片') INT"` + Id int `xorm:"not null pk autoincr INT"` + LockPassword string `xorm:"not null default '' VARCHAR(200)"` + Name string `xorm:"not null default '' comment('名称') VARCHAR(255)"` + Status int `xorm:"not null default 1 comment('1 待审核 2 审核通过 3 审核失败') SMALLINT"` + UpdateTime time.Time `xorm:"comment('修改时间') DATETIME"` + UserId int `xorm:"not null default 0 comment('用户id') index INT"` +} diff --git a/internal/pkg/model/bot_user_walletaddress.go b/internal/pkg/model/bot_user_walletaddress.go new file mode 100644 index 0000000..5859545 --- /dev/null +++ b/internal/pkg/model/bot_user_walletaddress.go @@ -0,0 +1,16 @@ +package models + +import ( + "time" +) + +type BotUserWalletaddress struct { + AdrId int `xorm:"not null pk autoincr INT"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + IsDefault int `xorm:"not null default 0 comment('是否默认:0不默认,1默认') TINYINT(1)"` + Remark string `xorm:"not null comment('备注') VARCHAR(30)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index(user_id) INT"` + WalletAddress string `xorm:"not null comment('钱包地址') VARCHAR(100)"` + WalletType string `xorm:"not null comment('钱包类型') index(user_id) VARCHAR(20)"` +} diff --git a/internal/pkg/model/bot_user_withdrawal.go b/internal/pkg/model/bot_user_withdrawal.go new file mode 100644 index 0000000..fac2bf0 --- /dev/null +++ b/internal/pkg/model/bot_user_withdrawal.go @@ -0,0 +1,29 @@ +package models + +import ( + "time" +) + +type BotUserWithdrawal struct { + AccountType int `xorm:"not null comment('提现账户类型:1现货,2合约,3美股') TINYINT(1)"` + ApplyNum string `xorm:"not null comment('申请提现金额(美元)') DECIMAL(36,18)"` + ApplyType string `xorm:"not null comment('提现方式(数字币、银行卡)') VARCHAR(20)"` + Beizhu string `xorm:"comment('备注') VARCHAR(100)"` + ChannelId int `xorm:"comment('渠道ID') INT"` + Country string `xorm:"comment('国家') VARCHAR(100)"` + CreateTime time.Time `xorm:"not null comment('创建时间') DATETIME"` + CurrencyRate string `xorm:"comment('汇率') DECIMAL(36,18)"` + DealAdminId int `xorm:"default 0 comment('处理提现管理员ID') INT"` + DealTime time.Time `xorm:"comment('处理完成时间') DATETIME"` + DrawalType int `xorm:"comment('提现类型:1数字币,2银行卡') TINYINT(1)"` + Id int `xorm:"not null pk autoincr INT"` + MarketAmount string `xorm:"comment('换算的市场金额') DECIMAL(36,18)"` + OrderIdx string `xorm:"comment('第三方订单号') VARCHAR(100)"` + OrderNo string `xorm:"not null comment('订单号') index VARCHAR(20)"` + PayInfo string `xorm:"not null comment('提现到钱包数据') JSON"` + ServiceFee string `xorm:"not null comment('提现手续费用') DECIMAL(36,18)"` + Status int `xorm:"not null comment('订单状态:0处理中,1已审核,2已完成') TINYINT(1)"` + TotalAmount string `xorm:"comment('总支付金额(渠道货币)') DECIMAL(36,18)"` + UpdateTime time.Time `xorm:"comment('更新时间') DATETIME"` + UserId int `xorm:"not null comment('用户ID') index INT"` +} diff --git a/internal/pkg/model/bot_users.go b/internal/pkg/model/bot_users.go new file mode 100644 index 0000000..6feee73 --- /dev/null +++ b/internal/pkg/model/bot_users.go @@ -0,0 +1,36 @@ +package models + +import ( + "time" +) + +type BotUsers struct { + AgentId int `xorm:"not null default 0 comment('代理id只有parent_id 为0 的用户才有可能分配代理') INT"` + CountryCode string `xorm:"not null default '' comment('国家代码') VARCHAR(20)"` + CountryId int `xorm:"not null default 0 comment('国家id') INT"` + CreateTime time.Time `xorm:"not null comment('注册时间') DATETIME"` + Email string `xorm:"not null default '' comment('电子邮箱') index VARCHAR(50)"` + FirstName string `xorm:"not null default '' comment('姓氏') VARCHAR(100)"` + Gender int `xorm:"not null default 0 comment('性别:0保密,1男,2女') TINYINT"` + HeadImgId int `xorm:"not null default 0 comment('头像图片地址') index INT"` + InviteCode string `xorm:"not null default '' comment('邀请码') unique VARCHAR(20)"` + IsReal int `xorm:"not null default 0 comment('是否实名认证,0:未实名,1实名') SMALLINT"` + IsTestUser int `xorm:"not null default 1 comment('是否测试用户: 1正式用户 2测试用户') TINYINT"` + LastLoginTime string `xorm:"not null default '' comment('最后一次登录时间') VARCHAR(20)"` + LastName string `xorm:"not null default '' comment('名字') VARCHAR(100)"` + LeverStatus int `xorm:"not null default 1 comment('用户申请杠杆状态 1 未申请 2 申请中 3 审核通过 4 审核拒绝') index SMALLINT"` + LoginPassword string `xorm:"not null default '' comment('登录密码') VARCHAR(200)"` + NickName string `xorm:"not null default '' comment('用户名称-注册时需随机生成') VARCHAR(100)"` + OriginUserId int64 `xorm:"not null default 0 comment('祖先用户id 邀请链条的第一个') index BIGINT"` + ParentId int64 `xorm:"not null default 0 comment('上级ID') BIGINT"` + ParentIds string `xorm:"not null default '' comment('用户邀请连') VARCHAR(255)"` + PhoneNumber string `xorm:"not null default '' comment('手机号码') index VARCHAR(50)"` + RealStatus int `xorm:"not null default 1 comment('实名认证状态 1 未认证 2 待审核 3 已认证 4 审核失败') SMALLINT"` + RegIp string `xorm:"not null default '' comment('注册IP') VARCHAR(200)"` + Salt string `xorm:"not null default '' comment('盐 密码使用') VARCHAR(255)"` + Status int `xorm:"not null default 1 comment('账号状态:1 启用 2禁用 3 黑名单') index SMALLINT"` + TradePassword string `xorm:"not null default '' comment('交易密码') VARCHAR(200)"` + UpdateTime time.Time `xorm:"not null comment('更新时间') DATETIME"` + UserId int64 `xorm:"not null pk autoincr comment('用户ID') BIGINT"` + UserNo string `xorm:"not null default '' comment('用于前端显示的用户ID号') unique VARCHAR(50)"` +} diff --git a/internal/pkg/pprof/cpu.prof b/internal/pkg/pprof/cpu.prof new file mode 100644 index 0000000000000000000000000000000000000000..bc1ffb9f207e196db7e0fa70b39576f950f5e141 GIT binary patch literal 4487 zcmV;25qRz&iwFP!00004|EyPgbQ@KAuWZS_mJ-cpSysL%aXgtk7|Zc!G?Hw~gh1># z50W@eoNNed2(mO$g!N)1=fUnd)oE$VtKt2~DR4p(9xYHxc%&^US=e;Rwy-R)ERRk0 zWD6~9Qz(TN!k(VebMMSZBS#ee=wD;s@BMwh?{}|OpL^r@W9M%9@0Vsd?ZgHRPCID? z`{?z*J^GRTa`yLCLPY< zp^JBl2dUJ7zkY{G9qe88jh`djHluBpf zmv_@#-0-oTCEdIC<;3iEIt-yzNxI0E=$d8yza9(YmD!vmez$@Ai~G>=w1v7buY z;AeWIHkgm|d0u>|!P90o(b?j3HP4vo=Ac#JhzB41gih28KXb9!JH;a|fg^4B z>IYQX4u7prr5zUF0^TWp)FN=ii+8+5r4D$FfX%}}1C-x8(c*0Kw0Y@}IMR+k*{{R& zoC9ng56p-1t54i-bCPy*k{!f{hn}Uq^}$)Y;2^W$eL7GV+@{yygN3+|_lW;&54gxI zScHpskN6vh$72@M;ypMBZzMqli1$?Hjf)-LHVX% zW}S{%sCQ#Fo;K>e&&d=F;5lZqg51Q9Up>EAu#?&F`)p3LK}3=75;=h*bMU(7IKe^u z@UXrdeh6TI?-oC45;!s!uQy`fPGfVX>n8u4xq9#p+{gN$SMKqE6Ur~W9dx#ISn8XH zAMT@2n**=V`dnlVEWstbSA2|A2fxxo&4VBYd8hau4YdGIJWi#Z@SZO1 z1Q})CDc(h;3-POCv==j0N$U3*zya-J3bDlbyH1IJs7EkVWuV6C3X$h+&K$5Fcu?^r)xX z=#dnZLjp$>{Mg9;&ug<+jO@es%R{syi%qwS;X=HS_loyWBuDUpXQ=c7IHcqJ0$7Sm zd9V1F%>qZF_{T@}*&d;!0A_2N!;z=~^j^I4ChEWmXKPoX*X(Z}{`60&hNy3`i->R$ zUc`IFJ1DsN@fl+W-fm`9?M3^X{@&1sA2>Uu#h^dSz?Va z*Fp!`fXA7JahJEik-E8U(5v*3Q9Svy4y9vNC|UY9O8Y7J$VR;RN%}@u0*4v|2kC)3 zb-r5y%W*kBC?0GGxJVBS;Sj$NHC1Uyhps1-aun`-5Dwk z!i&ueKtWiED|wIjJms*>c;eSoD#P=-REAZ!iuZ`mQRx=^;uK|@5PYG(!9uVaSMzJc z&*+W&J^cH3sZ@c7snkgnxD+qt*N7Vhj%>x-PEuhQo})q+3By`k%dZpfpr)7M;YVpR zBJj3eT?E$SdcIqHl@_!O?|g$Tnxi@YaYu>!&ds{Et#+t>E%kjWL8f7uu z(^Nx;mscqG`}l$J?0by@x%wLUzW#LUAmex|qp2voPM4+^enme{_*eZJioytv@Lus% zN=&`50XOho@jWXh#!dVgZ>T0u8^fRVveb#`3jDKw*YE6U$y~v%Xp6;cX5k}O;*S~3 zYVlQl;$B&K;#v+zDu)6`w&PE%n_O+ccD(^Uauwds*q{$?qHO47%pY)(J{ZMO-Xq>f zSvZad57FmlKOC6JaMTYQaU+NP;GqRTJKr{oOYl7NDR88Kj~KLkwDzVi&~30-T%@zGk6eRavT!xOjV+4Tn65Sa(CEapm!LMS z6C=#Ra(7%g?d~Yzn?{n;F1R91Qs77le{6ZuS*Ba+?=)1Vuv~v9r}UlV$S!=qh%&7e zyXdXyahs1GN0zztk=^(LE3gaB(IwWOQWo6orgj2H_TVwY@wD4^kKt%9o;6xp|F+$$ z_nsry;vX5F9;%(zwbYYk2x}M}3LN&zBmbdiV{65kEq5os~%qjX6HMyw#p3+>5XA2p%s5lb&sa#2EOcbURS1z8*7u7^Q zmnBC`qZj;xqNLacxq|=S$L#sazsd&nlZrP$g zJe^bKRu2YK>*Lzw*1R^UYRtW&;Q2{qQwi$2&9p1-Etb@5u@p~CRm((#Wu_2e)t5gt>((=2DnRG&} zS0oeA1iG^EQetN|KAFy?dh`wk)47tW<>HxOVKNmg6tw&fX?ZfKtXMG+%=Q$tJnclV zs3n5m$yWEUy`&Zyew6QIBn_%LnwB<6BezoHbS@={fx#|Go63zS^Qv7nguw~Zgx1w& zoa!c-_*5>jv)a>?rtZz_6Rk|Sn26_$v&tOfnwpERN$!y{q3U5Fo>JH3lIorfJE|zo zs@ZIQm#WOK=4A{kXoxBsR{?rf%_cJ1NPe{%FO23{*NX~Y*FhqqRqQRhl*!~1sYG3f zF&XVdyOD=PaXpwW6{VcIr&RS~?B9rWXO>0)U)bstjZm=03ba|5Oo?=?cjZ`vf) z0GK_A-aSXQbBe$KB+QWrPFYwV@whQ6s+sx zg)S+R&rePjtT3rj4H_F8s5vzpq%-Q^R63JXwJs^1Ob(51SrISA>rI9&N3fvfOL>~1 z*(v>;axnG9)>HdG%xThAb7?nSXo?CpF7}@?%gD4c#xb?Dd2gYPU}augo=j@hKGzI> zWxQBYyrwe>g_WABveOC~i2+7BT~c96*I#7lSE(Uh%4gFFNepaB=SpFvi!nsteC#q* zQ!ddBf~CC$wMdIyY`B!fKq8-`a8q+7TJu;bUMhA;nwnALMYSFzD94wWlM2kl0Hf_L ziNSuX5VzbXwK4;@m20e4YVAQbq2@|jJk!OfwB9{xYS4N*s`Z%1T~Z>R*r~E?EWORL zQ(EDUbS6``K&C;xS_@={U6qk3^DPnSb=D;%)4S41b#U)+M$L|;uT`rM5Ceuve&TAz zT~!tm16i6OZM!;{-_s?f)KaxQsRVsImasCu zc6igs@Vc-ftys5C8U9v{>4B6!Ne+jUzF5o>Ncd(qgUiQ;SwXA5gU<9|k%$zDg(Grr z#1gF2>S&wMxOkzkQ_U1uq!r($a9)@`sW%i0_w|2k^Ww=}@j^PRusC&_SEDgKkP?xU zkSs?-Rv^r?rfW_qTilhoFS~iUiZQ309=2|RrGl->@UL_O`DT*b?d}~8Y01R!~ zHoBRCjpBOcx2wpC(j!NEL$kG0OYpA+Qx;vfAW?4CPm$WLbtwtG$ zM5Smn60PNdx=T8h&`J~WqROJw#aWF;ZJ_Xg9FxMaNKA=Y0bO@CyNk+p1I~4EW|5!Q zu#hB&BjHHDbvZ?A<4qV%B(%MS(x{fsrc3EvYLQj7{yS?JJKs+i%BeAGbQ(;|5Y*|0LVu(el3yG?DdK2ZS6pqHik={PO ZTke--erRm-{{{d6|Nmv3$5A^Y0025OwF>|M literal 0 HcmV?d00001 diff --git a/internal/pkg/pprof/pprof_test.go b/internal/pkg/pprof/pprof_test.go new file mode 100644 index 0000000..5a8cf3e --- /dev/null +++ b/internal/pkg/pprof/pprof_test.go @@ -0,0 +1,31 @@ +package pprof + +import ( + "testing" +) + +var datas []string + +const url = "https://github.com/EDDYCJY" + +func TestAdd(t *testing.T) { + s := Add(url) + if s == "" { + t.Errorf("Test.Add error!") + } +} + +func Add(str string) string { + data := []byte(str) + sData := string(data) + datas = append(datas, sData) + + return sData +} + +func BenchmarkAdd(b *testing.B) { + + for i := 0; i < b.N; i++ { + Add(url) + } +} diff --git a/internal/pkg/setting/block.go b/internal/pkg/setting/block.go new file mode 100644 index 0000000..696b974 --- /dev/null +++ b/internal/pkg/setting/block.go @@ -0,0 +1,28 @@ +package setting + +var ( + MarketShareBlkUs = "subscribe:shareBlk:market_share_us" // 股票-大宗交易-美股缓存列表 + MarketShareBlkTha = "subscribe:shareBlk:market_share_tha" // 股票-大宗交易-泰股缓存列表 + MarketShareBlkMys = "subscribe:shareBlk:market_share_mys" // 股票-大宗交易-马股缓存列表 + MarketShareBlkIdn = "subscribe:shareBlk:market_share_idn" // 股票-大宗交易-印尼股缓存列表 + MarketShareBlkInr = "subscribe:shareBlk:market_share_inr" // 股票-大宗交易-印度股缓存列表 + MarketShareBlkGbx = "subscribe:shareBlk:market_share_gbx" // 股票-大宗交易-英股缓存列表 + MarketShareBlkSgd = "subscribe:shareBlk:market_share_sgd" // 股票-大宗交易-新加坡股缓存列表 + MarketShareBlkEur = "subscribe:shareBlk:market_share_eur" // 股票-大宗交易-德股缓存列表 + MarketShareBlkFur = "subscribe:shareBlk:market_share_fur" // 股票-大宗交易-法股缓存列表 + MarketShareBlkHkd = "subscribe:shareBlk:market_share_hkd" // 股票-大宗交易-港股缓存列表 + MarketShareBlkBrl = "subscribe:shareBlk:market_share_brl" // 股票-大宗交易-巴西股缓存列表 + MarketShareBlkJpy = "subscribe:shareBlk:market_share_jpy" // 股票-大宗交易-日本股缓存列表 + + MarketShareBlkEntrust = "subscribe:shareBlk:order:entrust" // 股票-大宗交易股挂单缓存列表 + MarketShareBlkPosition = "subscribe:shareBlk:order:position" // 股票-大宗交易股持仓缓存列表 + + ShareBlkSubscribe = "subscribe:shareBlk:user:shareBlkSubscribe" // 股票-用户大宗交易股订单列表 + AdminShareBlkSubscribe = "subscribe:shareBlk:admin:adminShareBlkSubscribe" // 股票-管理员大宗交易股订单列表 + + SubscribeShareBlk = "shareBlkSubscribe" // 股票-用户大宗交易股订单订阅类型 + SubscribeAdminShareBlk = "adminShareBlkSubscribe" // 股票-管理员大宗交易股订单订阅类型 + AdminShareBlkSumSubscribe = "adminShareBlkSumSubscribe" // 股票-管理员大宗交易股持仓订单浮动盈亏订阅类型 + + AdminShareUserSumSubscribe = "adminShareUserSumSubscribe" // 股票-管理员用户(美股|马股|泰股|印尼股|印度股|新加坡股|港股|德股|法股|英股|日股|期权股|大宗股)持仓总浮动盈亏订阅 +) diff --git a/internal/pkg/setting/forex.go b/internal/pkg/setting/forex.go new file mode 100644 index 0000000..205c457 --- /dev/null +++ b/internal/pkg/setting/forex.go @@ -0,0 +1,11 @@ +package setting + +var ( + MarketForex = "market_forex" // 外汇交易对缓存列表 + MarketForexEntrust = "forex.entrust" // 外汇挂单缓存列表 + MarketForexPosition = "forex.position" // 外汇持仓缓存列表 + ForexSubscribe = "forexSubscribe" // 用户外汇订单订阅列表 + AdminForexSubscribe = "adminForexSubscribe" // 管理员外汇订单订阅列表 + AdminForexSumSubscribe = "adminForexSumSubscribe" // 管理员外汇持仓订单浮动盈亏订阅 + ShareForexMarketSubscribe = "shareForexMarketSubscribe" // 外汇市场订阅统计 +) diff --git a/internal/pkg/setting/hongkong.go b/internal/pkg/setting/hongkong.go new file mode 100644 index 0000000..3bc1a40 --- /dev/null +++ b/internal/pkg/setting/hongkong.go @@ -0,0 +1,16 @@ +package setting + +var ( + MarketShareHkd = "subscribe:shareHkd:market_share_hkd" // 股票-港股交易对缓存列表 + + MarketShareHkdEntrust = "subscribe:shareHkd:order:entrust" // 股票-港股挂单缓存列表 + MarketShareHkdPosition = "subscribe:shareHkd:order:position" // 股票-港股持仓缓存列表 + + ShareHkdSubscribe = "subscribe:shareHkd:user:shareHkdSubscribe" // 股票-用户港股订单列表 + AdminShareHkdSubscribe = "subscribe:shareHkd:admin:adminShareHkdSubscribe" // 股票-管理员港股订单列表 + + SubscribeShareHkd = "shareHkdSubscribe" // 股票-用户港股订单订阅类型 + ShareHkdMarketSubscribe = "shareHkdMarketSubscribe" // 股票-英股市场订阅统计 + SubscribeAdminShareHkd = "adminShareHkdSubscribe" // 股票-管理员港股订单订阅类型 + AdminShareHkdSumSubscribe = "adminShareHkdSumSubscribe" // 股票-管理员港股持仓订单浮动盈亏订阅类型 +) diff --git a/internal/pkg/setting/money.go b/internal/pkg/setting/money.go new file mode 100644 index 0000000..a863148 --- /dev/null +++ b/internal/pkg/setting/money.go @@ -0,0 +1,11 @@ +package setting + +var ( + MarketMoneyEntrust = "money.entrust" // 综合(现货|合约|外汇)挂单缓存列表 + MarketMoneyPosition = "money.position" // 综合(现货|合约|外汇)持仓缓存列表 + MarketMoneyClose = "money.close" // 综合(现货|合约|外汇)平仓缓存列表 + MoneySubscribe = "moneySubscribe" // 用户综合(现货|合约|外汇)订单订阅列表 + AdminMoneySubscribe = "adminMoneySubscribe" // 管理员综合(现货|合约|外汇)订单订阅列表 + AdminMoneySumSubscribe = "adminMoneySumSubscribe" // 管理员综合(现货|合约|外汇)持仓订单浮动盈亏订阅 + ShareMoneyMarketSubscribe = "shareMoneyMarketSubscribe" // 综合(现货|合约|外汇)市场订阅统计 +) diff --git a/internal/pkg/setting/option.go b/internal/pkg/setting/option.go new file mode 100644 index 0000000..aa298f3 --- /dev/null +++ b/internal/pkg/setting/option.go @@ -0,0 +1,16 @@ +package setting + +var ( + MarketOptionInr = "subscribe:optionInr:market_option_inr" // 期权-印度交易对缓存列表 + + MarketOptionInrEntrust = "subscribe:optionInr:order:entrust" // 期权-印度挂单缓存列表 + MarketOptionInrPosition = "subscribe:optionInr:order:position" // 期权-印度持仓缓存列表 + + OptionInrSubscribe = "subscribe:optionInr:user:optionInrSubscribe" // 期权-用户印度订单列表 + AdminOptionInrSubscribe = "subscribe:optionInr:admin:adminOptionInrSubscribe" // 期权-管理员印度订单列表 + + SubscribeOptionInr = "optionInrSubscribe" // 期权-用户期权股订阅类型 + SubscribeSumOptionInr = "optionInrSumSubscribe" // 期权-用户期权股总浮动盈亏订阅类型 + SubscribeAdminOptionInr = "adminOptionInrSubscribe" // 期权-管理员印度订单订阅类型 + AdminOptionInrSumSubscribe = "adminOptionInrSumSubscribe" // 期权-管理员印度持仓订单浮动盈亏订阅类型 +) diff --git a/internal/pkg/setting/share.go b/internal/pkg/setting/share.go new file mode 100644 index 0000000..15a749d --- /dev/null +++ b/internal/pkg/setting/share.go @@ -0,0 +1,91 @@ +package setting + +var ( + MarketShareUs = "market_share_us" // 股票-美股交易对缓存列表 + MarketShareUsEntrust = "shareUs.entrust" // 股票-美股挂单缓存列表 + MarketShareUsPosition = "shareUs.position" // 股票-美股持仓缓存列表 + ShareUsSubscribe = "shareUsSubscribe" // 股票-用户美股订单订阅列表 + AdminShareUsSubscribe = "adminShareUsSubscribe" // 股票-管理员美股订单订阅列表 + AdminShareUsSumSubscribe = "adminShareUsSumSubscribe" // 股票-管理员美股持仓订单浮动盈亏订阅 + ShareUsMarketSubscribe = "shareUsMarketSubscribe" // 股票-美股市场订阅统计 + + MarketShareMys = "market_share_mys" // 股票-马股交易对缓存列表 + MarketShareMysEntrust = "shareMys.entrust" // 股票-马股挂单缓存列表 + MarketShareMysPosition = "shareMys.position" // 股票-马股持仓缓存列表 + ShareMysSubscribe = "shareMysSubscribe" // 股票-用户马股订单订阅列表 + AdminShareMysSubscribe = "adminShareMysSubscribe" // 股票-管理员马股订单订阅列表 + AdminShareMysSumSubscribe = "adminShareMysSumSubscribe" // 股票-管理员马股持仓订单浮动盈亏订阅 + ShareMysMarketSubscribe = "shareMysMarketSubscribe" // 股票-马股市场订阅统计 + + MarketShareTha = "market_share_tha" // 股票-泰股交易对缓存列表 + MarketShareThaEntrust = "shareTha.entrust" // 股票-泰股挂单缓存列表 + MarketShareThaPosition = "shareTha.position" // 股票-泰股持仓缓存列表 + ShareThaSubscribe = "shareThaSubscribe" // 股票-用户泰股订单订阅列表 + AdminShareThaSubscribe = "adminShareThaSubscribe" // 股票-管理员泰股订单订阅列表 + AdminShareThaSumSubscribe = "adminShareThaSumSubscribe" // 股票-管理员泰股持仓订单浮动盈亏订阅 + ShareThaMarketSubscribe = "shareThaMarketSubscribe" // 股票-泰股市场订阅统计 + + MarketShareIdn = "market_share_idn" // 股票-印尼股交易对缓存列表 + MarketShareIdnEntrust = "shareIdn.entrust" // 股票-印尼股挂单缓存列表 + MarketShareIdnPosition = "shareIdn.position" // 股票-印尼股持仓缓存列表 + ShareIdnSubscribe = "shareIdnSubscribe" // 股票-用户印尼股订单订阅列表 + AdminShareIdnSubscribe = "adminShareIdnSubscribe" // 股票-管理员印尼股订单订阅列表 + AdminShareIdnSumSubscribe = "adminShareIdnSumSubscribe" // 股票-管理员印尼股持仓订单浮动盈亏订阅 + ShareIdnMarketSubscribe = "shareIdnMarketSubscribe" // 股票-印尼股市场订阅统计 + + MarketShareInr = "market_share_inr" // 股票-印度股交易对缓存列表 + MarketShareInrEntrust = "shareInr.entrust" // 股票-印度股挂单缓存列表 + MarketShareInrPosition = "shareInr.position" // 股票-印度股持仓缓存列表 + ShareInrSubscribe = "shareInrSubscribe" // 股票-用户印度股订单订阅列表 + AdminShareInrSubscribe = "adminShareInrSubscribe" // 股票-管理员印度股订单订阅列表 + AdminShareInrSumSubscribe = "adminShareInrSumSubscribe" // 股票-管理员印度股持仓订单浮动盈亏订阅 + ShareInrMarketSubscribe = "shareInrMarketSubscribe" // 股票-印度股市场订阅统计 + + MarketShareSgd = "market_share_sgd" // 股票-新加坡股交易对缓存列表 + MarketShareSgdEntrust = "shareSgd.entrust" // 股票-新加坡股挂单缓存列表 + MarketShareSgdPosition = "shareSgd.position" // 股票-新加坡股持仓缓存列表 + ShareSgdSubscribe = "shareSgdSubscribe" // 股票-用户新加坡股订单订阅列表 + AdminShareSgdSubscribe = "adminShareSgdSubscribe" // 股票-管理员新加坡股订单订阅列表 + AdminShareSgdSumSubscribe = "adminShareSgdSumSubscribe" // 股票-管理员新加坡股持仓订单浮动盈亏订阅 + ShareSgdMarketSubscribe = "shareSgdMarketSubscribe" // 股票-新加坡股市场订阅统计 + + MarketShareGbx = "market_share_gbx" // 股票-英股交易对缓存列表 + MarketShareGbxEntrust = "shareGbx.entrust" // 股票-英股挂单缓存列表 + MarketShareGbxPosition = "shareGbx.position" // 股票-英股持仓缓存列表 + ShareGbxSubscribe = "shareGbxSubscribe" // 股票-用户英股订单订阅列表 + AdminShareGbxSubscribe = "adminShareGbxSubscribe" // 股票-管理员英股订单订阅列表 + AdminShareGbxSumSubscribe = "adminShareGbxSumSubscribe" // 股票-管理员英股持仓订单浮动盈亏订阅 + ShareGbxMarketSubscribe = "shareGbxMarketSubscribe" // 股票-英股市场订阅统计 + + MarketShareEur = "market_share_eur" // 股票-德股交易对缓存列表 + MarketShareEurEntrust = "shareEur.entrust" // 股票-德股挂单缓存列表 + MarketShareEurPosition = "shareEur.position" // 股票-德股持仓缓存列表 + ShareEurSubscribe = "shareEurSubscribe" // 股票-用户德股订单订阅列表 + AdminShareEurSubscribe = "adminShareEurSubscribe" // 股票-管理员德股订单订阅列表 + AdminShareEurSumSubscribe = "adminShareEurSumSubscribe" // 股票-管理员德股持仓订单浮动盈亏订阅 + ShareEurMarketSubscribe = "shareEurMarketSubscribe" // 股票-德股市场订阅统计 + + MarketShareFur = "market_share_fur" // 股票-法股交易对缓存列表 + MarketShareFurEntrust = "shareFur.entrust" // 股票-法股挂单缓存列表 + MarketShareFurPosition = "shareFur.position" // 股票-法股持仓缓存列表 + ShareFurSubscribe = "shareFurSubscribe" // 股票-用户法股订单订阅列表 + AdminShareFurSubscribe = "adminShareFurSubscribe" // 股票-管理员法股订单订阅列表 + AdminShareFurSumSubscribe = "adminShareFurSumSubscribe" // 股票-管理员法股持仓订单浮动盈亏订阅 + ShareFurMarketSubscribe = "shareFurMarketSubscribe" // 股票-法股市场订阅统计 + + MarketShareJpy = "market_share_jpy" // 股票-日股交易对缓存列表 + MarketShareJpyEntrust = "shareJpy.entrust" // 股票-日股挂单缓存列表 + MarketShareJpyPosition = "shareJpy.position" // 股票-日股持仓缓存列表 + ShareJpySubscribe = "shareJpySubscribe" // 股票-用户日股订单订阅列表 + AdminShareJpySubscribe = "adminShareJpySubscribe" // 股票-管理员日股订单订阅列表 + AdminShareJpySumSubscribe = "adminShareJpySumSubscribe" // 股票-管理员日股持仓订单浮动盈亏订阅 + ShareJpyMarketSubscribe = "shareJpyMarketSubscribe" // 股票-日股市场订阅统计 + + MarketShareBrl = "market_share_brl" // 股票-巴西股交易对缓存列表 + MarketShareBrlEntrust = "shareBrl.entrust" // 股票-巴西股挂单缓存列表 + MarketShareBrlPosition = "shareBrl.position" // 股票-巴西股持仓缓存列表 + ShareBrlSubscribe = "shareBrlSubscribe" // 股票-用户巴西股订单订阅列表 + AdminShareBrlSubscribe = "adminShareBrlSubscribe" // 股票-管理员巴西股订单订阅列表 + AdminShareBrlSumSubscribe = "adminShareBrlSumSubscribe" // 股票-管理员巴西股持仓订单浮动盈亏订阅 + ShareBrlMarketSubscribe = "shareBrlMarketSubscribe" // 股票-巴西股市场订阅统计 +) diff --git a/internal/pkg/setting/virtual.go b/internal/pkg/setting/virtual.go new file mode 100644 index 0000000..c7ac7ef --- /dev/null +++ b/internal/pkg/setting/virtual.go @@ -0,0 +1,21 @@ +package setting + +var ( + MarketSpots = "market_spots" // 虚拟币-现货交易对缓存列表 + MarketSpotsEntrust = "stops.entrust" // 虚拟币-现货挂单缓存列表 + SpotsSubscribe = "spotsSubscribe" // 虚拟币-用户现货订单订阅列表 + SpotsMarketSubscribe = "spotsMarketSubscribe" // 虚拟币-现货市场订阅统计 + + MarketContract = "market_contract" // 虚拟币-合约交易对缓存列表 + MarketContractEntrust = "contract.entrust" // 虚拟币-合约挂单缓存列表 + MarketContractPosition = "contract.position" // 虚拟币-合约持仓缓存列表 + ContractSubscribe = "contractSubscribe" // 虚拟币-用户合约订单订阅列表 + AdminContractSubscribe = "adminContractSubscribe" // 虚拟币-管理员合约订单订阅列表 + AdminContractSumSubscribe = "adminContractSumSubscribe" // 虚拟币-管理员合约持仓订单浮动盈亏订阅 + ContractMarketSubscribe = "contractMarketSubscribe" // 虚拟币-合约市场订阅统计 + + MarketSecondPosition = "second.position" // 虚拟币-秒合约持仓缓存列表 + SecondSubscribe = "secondSubscribe" // 虚拟币-用户秒合约订单订阅列表 + AdminSecondSubscribe = "adminSecondSubscribe" // 虚拟币-管理员秒合约订单订阅列表 + SecondMarketSubscribe = "secondMarketSubscribe" // 虚拟币-秒合约市场订阅统计 +) diff --git a/internal/pkg/utils/utils.go b/internal/pkg/utils/utils.go new file mode 100644 index 0000000..f1f9a7e --- /dev/null +++ b/internal/pkg/utils/utils.go @@ -0,0 +1,694 @@ +package utils + +import ( + "bytes" + "compress/gzip" + "encoding/json" + "fmt" + "github.com/shopspring/decimal" + "io" + "io/ioutil" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "math/rand" + "net/http" + "regexp" + "strconv" + "strings" + "time" + "unicode" +) + +// HttpGet +// +// @Description: +// @param url +// @return string +// @return error +func HttpGet(url string) (string, error) { + resp, err := http.Get(url) + if err != nil { + return flags.SetNull, err + } + defer resp.Body.Close() + result, err := ioutil.ReadAll(resp.Body) + if err != nil { + return flags.SetNull, err + } + + return string(result), err +} + +// HttpGetDoKey +// +// @Description: +// @param url +// @return string +// @return error +func HttpGetDoKey(url string) (string, error) { + req, err := http.NewRequest("GET", url, nil) + if err != nil { + return flags.SetNull, err + } + req.Header.Add("X-RapidAPI-Key", flags.SetNull) + req.Header.Add("X-RapidAPI-Host", flags.SetNull) + + res, err := http.DefaultClient.Do(req) + if err != nil { + return flags.SetNull, err + } + defer res.Body.Close() + + body, err := io.ReadAll(res.Body) + if err != nil { + return flags.SetNull, err + } + + return string(body), nil +} + +// HttpGetApi +// +// @Description: +// @param url +// @return map[string]interface{} +// @return error +func HttpGetApi(url string) (map[string]interface{}, error) { + resp, err := http.Get(url) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + var status map[string]interface{} + if err := json.NewDecoder(resp.Body).Decode(&status); err != nil { + return nil, err + } + + return status, err +} + +// HttpGetDoKeyMap +// +// @Description: +// @param url +// @return map[string]interface{} +// @return error +func HttpGetDoKeyMap(url string) (map[string]interface{}, error) { + req, err := http.NewRequest("GET", url, nil) + if err != nil { + return nil, err + } + + req.Header.Add("X-RapidAPI-Key", flags.SetNull) + req.Header.Add("X-RapidAPI-Host", flags.SetNull) + + res, err := http.DefaultClient.Do(req) + if err != nil { + return nil, err + } + defer res.Body.Close() + + var status map[string]interface{} + if err := json.NewDecoder(res.Body).Decode(&status); err != nil { + return nil, err + } + + return status, nil +} + +// HttpPost +// +// @Description: +// @param url +// @param body +// @return string +// @return error +func HttpPost(url string, body string) (string, error) { + resp, err := http.Post(url, "application/json", strings.NewReader(body)) + if err != nil { + return flags.SetNull, err + } + defer resp.Body.Close() + result, err := ioutil.ReadAll(resp.Body) + if err != nil { + return flags.SetNull, err + } + + return string(result), err +} + +// ReplaceStr +// +// @Description: 字符串替换空字符串 +// @param value +// @return string +func ReplaceStr(value string) string { + return strings.Replace(value, " ", flags.SetNull, 1) +} + +// ReplaceStrByValue +// +// @Description: 字符串替换 value替换为"-" +// @param str +// @param value +// @return string +func ReplaceStrByValue(str, value string) string { + return strings.Replace(str, value, "-", 1) +} + +// IntegerInit +// +// @Description: +// @param value +// @return int +func IntegerInit(value string) int { + in, err := strconv.Atoi(value) + if err != nil { + return 0 + } + return in +} + +// TimeMaoSendToString +// +// @Description: int64 - string +// @param i +// @return string +func TimeMaoSendToString(i int64) string { + t := time.Unix(0, i*int64(time.Microsecond)) + + return t.Format(flags.TimeLayout) +} + +// TimeDateToMaoSend +// +// @Description: time - int64 +// @param t +// @return int64 +func TimeDateToMaoSend(t time.Time) int64 { + now := time.Now() + fmt.Println(now) + return now.UnixMicro() +} + +// TimeStringToTime +// +// @Description: string - time +// @param t +// @return time.Time +func TimeStringToTime(t string) time.Time { + loc, err := time.LoadLocation("Local") + if err != nil { + return time.Time{} + } + theTime, err := time.ParseInLocation(flags.LayoutTime, t, loc) + if err != nil { + return time.Time{} + } + + return theTime +} + +// TimeStringToIn64 +// +// @Description: string - int64 +// @param t +// @return int64 +func TimeStringToIn64(t string) int64 { + loc, err := time.LoadLocation("Local") + if err != nil { + return int64(0) + } + theTime, err := time.ParseInLocation(flags.LayoutTime, t, loc) + if err != nil { + return int64(0) + } + + return theTime.UnixMicro() +} + +// DealPrice +// +// @Description: +// @param types +// @param limitPrice +// @param marketPrice +// @return decimal.Decimal +func DealPrice(types int, limitPrice, marketPrice string) decimal.Decimal { + switch types { + case 1: + return decimal.RequireFromString(limitPrice) + case 2: + return decimal.RequireFromString(marketPrice) + default: + return decimal.Zero + } +} + +// GZipDecompress +// +// @Description: +// @param input +// @return string +// @return error +func GZipDecompress(input []byte) (string, error) { + buf := bytes.NewBuffer(input) + reader, gzipErr := gzip.NewReader(buf) + if gzipErr != nil { + return flags.SetNull, gzipErr + } + defer reader.Close() + + result, readErr := ioutil.ReadAll(reader) + if readErr != nil { + return flags.SetNull, readErr + } + + return string(result), nil +} + +// Difference +// +// @Description: [生成指定范围的随机小数.注:很不智能,需要限制min和max前面的数字必须相同例如min:0.0001 max:0.0005] +// @return decimal.Decimal +func Difference() decimal.Decimal { + rad := RandFloat64(flags.MinDifference, flags.MaxDifference) + + return decimal.NewFromFloat(rad) +} + +// RandFloat64 +// +// @Description: +// @param min +// @param max +// @return float64 +func RandFloat64(min, max float64) float64 { + my_min := strconv.FormatFloat(min, 'f', -1, 64) + my_max := strconv.FormatFloat(max, 'f', -1, 64) + + if len(my_min) != len(my_max) { + return 0 + } else { + prefix := flags.SetNull + suffix := flags.SetNull + suffix1 := flags.SetNull + sw := 0 + for i := 0; i < len(my_min); i++ { + str1 := string(my_min[i]) + str2 := string(my_max[i]) + if sw == 0 { + if my_min[i] == my_max[i] { + prefix = prefix + str1 + } else { + sw = 1 + suffix = suffix + str1 + suffix1 = suffix1 + str2 + } + } else { + suffix = suffix + str1 + suffix1 = suffix1 + str2 + } + } + //前缀字符串转整数 + prefix1, err := strconv.ParseInt(suffix, 10, 64) + if err != nil { + applogger.Error("prefix1 ParseInt err: %v", err) + return min + } + prefix2, err := strconv.ParseInt(suffix1, 10, 64) + if err != nil { + applogger.Error("prefix2 ParseInt err: %v", err) + return min + } + //生成随机整数 + sjz := RandInt64(prefix1, prefix2) + //随机整数转字符串 + sjz_str := strconv.FormatInt(sjz, 10) + //前缀拼接随机字符串 + all_str := prefix + sjz_str + //全字符串转浮点数 + result, _ := strconv.ParseFloat(all_str, 64) + + return result + } +} + +// RandInt64 +// +// @Description: +// @param min +// @param max +// @return int64 +func RandInt64(min, max int64) int64 { + if min >= max || min == 0 || max == 0 { + return max + } + rand.Seed(time.Now().UnixNano()) + + return rand.Int63n(max-min) + min +} + +// RandInt +// +// @Description: 随机[1,2]整数 +// @return decimal.Decimal +func RandInt() decimal.Decimal { + rand.Seed(time.Now().UnixNano()) + randomInt := rand.Intn(2) + 1 + + return decimal.RequireFromString(strconv.Itoa(randomInt)) +} + +// CheckTime +// +// @Description: 判断当前时间是否在区间内["09:00"~"09:05"] +// @param start +// @param end +// @return bool +func CheckTime(start, end string) bool { + current, _ := time.Parse("15:04", time.Now().Format("15:04")) + startTime, _ := time.Parse("15:04", start) + endTime, _ := time.Parse("15:04", end) + + if current.After(startTime) && current.Before(endTime) || current.Equal(startTime) || current.Equal(endTime) { + return true + } else { + return false + } +} + +// CheckInPlateTime +// +// @Description: 判定股票市场是否盘中 +// @param openTime +// @param closeTime +// @return bool +func CheckInPlateTime(timeValue flags.TimeValue) bool { + var checkBool bool + dateTime, _ := time.Parse(flags.LayoutOne, time.Now().Format(flags.LayoutOne)) + // 判定上午盘 + checkAmTime := dateTime.Equal(timeValue.AmOpenTime) || dateTime.Equal(timeValue.AmCloseTime) + if timeValue.AmOpenTime.Before(timeValue.AmCloseTime) { + // 同一天 + if dateTime.After(timeValue.AmOpenTime) && dateTime.Before(timeValue.AmCloseTime) || checkAmTime { + checkBool = true + } + } else { + // 跨天 + if dateTime.After(timeValue.AmOpenTime) || dateTime.Before(timeValue.AmCloseTime) || checkAmTime { + checkBool = true + } + } + // 判定下午盘 + checkPmTime := dateTime.Equal(timeValue.PmOpenTime) || dateTime.Equal(timeValue.PmCloseTime) + if timeValue.PmOpenTime.Before(timeValue.PmCloseTime) { + // 同一天 + if dateTime.After(timeValue.PmOpenTime) && dateTime.Before(timeValue.PmCloseTime) || checkPmTime { + checkBool = true + } + } else { + // 跨天 + if dateTime.After(timeValue.PmOpenTime) || dateTime.Before(timeValue.PmCloseTime) || checkPmTime { + checkBool = true + } + } + + return checkBool +} + +// CheckTimeUTC +// +// @Description: 判断时间是否在区间内 +// @param start +// @param end +// @return bool +func CheckTimeUTC(start, end string) bool { + current, _ := time.Parse(flags.LayoutTime, time.Now().Format(flags.LayoutTime)) + startTime, _ := time.Parse(flags.LayoutTime, start) + endTime, _ := time.Parse(flags.LayoutTime, end) + + if current.After(startTime) && current.Before(endTime) || current.Equal(startTime) || current.Equal(endTime) { + return true + } else { + return false + } +} + +// GetTime +// +// @Description: 获取时间格式["09:00"] +// @return string +func GetTime() string { + // 获取当前时间 + currentTime := time.Now() + + // 获取当前时间的小时和分钟 + hour := currentTime.Hour() + minute := currentTime.Minute() + + // 打印小时和分钟 + return fmt.Sprintf("%02d:%02d", hour, minute) +} + +// GetAddTime +// +// @Description: 新增时间 +// @param st +// @param t +// @return string +func GetAddTime(st string, t string) string { + startTime, _ := time.Parse("15:04", st) + + duration, _ := time.ParseDuration(t) + + endTime := startTime.Add(duration) + + return endTime.Format("15:04") +} + +// StrReplace +// +// @Description: 替换空字符串 +// @param str +// @return string +func StrReplace(str string) string { + return strings.Replace(string(str), " ", flags.SetNull, -1) +} + +// IsNumber +// +// @Description: 正则判定是否为整数或者小数 +// @param input +// @return bool +func IsNumber(input string) bool { + numberRegex := regexp.MustCompile(`^(-)?[0-9]+(\.[0-9]+)?$`) + + return numberRegex.MatchString(input) +} + +// IsNumberInt +// +// @Description: 正则判定是否正整数 +// @param input +// @return bool +func IsNumberInt(input string) bool { + numberRegex := regexp.MustCompile(`^[1-9]\d*$`) + + return numberRegex.MatchString(input) +} + +// DecimalsPrice +// +// @Description: 处理小数 +// @param price +// @return string +func DecimalsPrice(price string) string { + if len(price) == 0 { + return flags.SetNull + } + num, err := strconv.ParseFloat(price, 64) + if err != nil { + applogger.Error("DecimalsPrice err:%", err) + return flags.SetNull + } + + return strconv.FormatFloat(num, 'f', -1, 64) +} + +// DecimlsStrInt +// +// @Description: 定义下单判定比例 +// @return decimal.Decimal +func DecimalsStrInt() decimal.Decimal { + return decimal.RequireFromString(flags.OrderCheck) +} + +// TimeAddDay +// +// @Description: 时间+天+时分秒 +// @param day +// @return time.Time +func TimeAddDay(day string) (time.Time, error) { + dayInt, err := strconv.Atoi(day) + if err != nil { + return time.Time{}, err + } + // 获取当前时间 + currentTime := time.Now() + // 创建一个表示指定天数的 Duration (24小时 * 天数) + duration := time.Duration(dayInt) * 24 * time.Hour + // 把 Duration 添加到当前时间上 + return currentTime.Add(duration), nil +} + +// TimeAddDayZero +// +// @Description: 时间+天 +// @param day +// @return time.Time +// @return error +func TimeAddDayZero(dayInt int) time.Time { + // 获取当前时间 + currentTime := time.Now() + // 创建一个表示指定天数的 Duration (24小时 * 天数) + duration := time.Duration(dayInt) * 24 * time.Hour + // 把 Duration 添加到当前时间上 + timeFormat := currentTime.Add(duration).Format(flags.LayoutZero) + // string-time + parsedTime, err := time.Parse(flags.LayoutZero, timeFormat) + if err != nil { + return time.Time{} + } + + return parsedTime +} + +// TimeAddDaySend +// +// @Description: 时间+天 +// @param day +// @return time.Time +// @return error +func TimeAddDaySend(day string) (time.Time, error) { + dayInt, err := strconv.Atoi(day) + if err != nil { + return time.Time{}, err + } + dayS := dayInt - 1 + + // 当前时间 + currentTime := time.Now() + // 创建一个表示指定天数的 Duration (24小时 * 天数) + duration := time.Duration(dayS) * 24 * time.Hour + // time-string + timeFormat := currentTime.Add(duration).Format(flags.LayoutZero) + // string-time + parsedTime, err := time.Parse(flags.LayoutZero, timeFormat) + if err != nil { + return time.Time{}, err + } + + return parsedTime, nil +} + +// TimeStopTime +// +// @Description: 处理期权到期时间 +// @param day +// @return time.Time +// @return error +func TimeStopTime(day string) (time.Time, error) { + dayStr := fmt.Sprintf("%v 00:00:00", day) + parsedTime, err := time.Parse(flags.LayoutZero, dayStr) + if err != nil { + return time.Time{}, err + } + + return parsedTime, nil +} + +// TimeYYYMMDD +// +// @Description: 期权到期时间和当前时间判定是否相同-相同不容许下单 +// @param day +// @return time.Time +// @return error +func TimeYYYMMDD(day string) bool { + timeNow := time.Now().Format(flags.TimeFormat) + if timeNow == day { + return false + } + return true +} + +// TimeComparison +// +// @Description: 时间校对(时间到期平仓) +// @param stopTime +// @return bool +func TimeComparison(stopTime time.Time) bool { + time1 := time.Now() + time2 := stopTime.Add(time.Hour * 17) + + // 判断 time1 是否在 time2 之前 + if time1.Before(time2) { + return false + } + + // 判断两个时间是否相同 + if time1.Equal(time2) { + return true + } + + // 判断 time1 是否在 time2 之后 + if time1.After(time2) { + return true + } + + return false +} + +// MapToString +// +// @Description: map[string]string 转 string +// @param m +// @return string +// @return error +func MapToString(m map[string]string) (string, error) { + jsonBytes, err := json.Marshal(m) + if err != nil { + return "", err + } + buffer := bytes.NewBuffer(jsonBytes) + return buffer.String(), nil +} + +// StringToInt +// +// @Description: String -> To +// @param str +// @return int +func StringToInt(str string) int { + checkInt, err := strconv.Atoi(str) + if err != nil { + return 0 + } + + return checkInt +} + +// ExtractSubstringBeforeFirstDigit +// +// @Description: takes a string and returns the substring before the first digit. +// @param s +// @return string +func ExtractSubstringBeforeFirstDigit(s string) string { + for i, c := range s { + if unicode.IsDigit(c) { + return s[:i] + } + } + return s // 如果没有找到数字,返回原字符串 +} diff --git a/internal/pkg/utils/utils_test.go b/internal/pkg/utils/utils_test.go new file mode 100644 index 0000000..fc07c1e --- /dev/null +++ b/internal/pkg/utils/utils_test.go @@ -0,0 +1,741 @@ +package utils + +import ( + "github.com/shopspring/decimal" + "reflect" + "testing" + "time" +) + +func TestCheckTime(t *testing.T) { + type args struct { + start string + end string + } + tests := []struct { + name string + args args + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CheckTime(tt.args.start, tt.args.end); got != tt.want { + t.Errorf("CheckTime() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCheckTimeUTC(t *testing.T) { + type args struct { + start string + end string + } + tests := []struct { + name string + args args + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CheckTimeUTC(tt.args.start, tt.args.end); got != tt.want { + t.Errorf("CheckTimeUTC() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestDealPrice(t *testing.T) { + type args struct { + types int + limitPrice string + marketPrice string + } + tests := []struct { + name string + args args + want decimal.Decimal + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := DealPrice(tt.args.types, tt.args.limitPrice, tt.args.marketPrice); !reflect.DeepEqual(got, tt.want) { + t.Errorf("DealPrice() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestDecimalsPrice(t *testing.T) { + type args struct { + price string + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := DecimalsPrice(tt.args.price); got != tt.want { + t.Errorf("DecimalsPrice() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestDecimalsStrInt(t *testing.T) { + tests := []struct { + name string + want decimal.Decimal + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := DecimalsStrInt(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("DecimalsStrInt() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestDifference(t *testing.T) { + tests := []struct { + name string + want decimal.Decimal + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := Difference(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("Difference() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGZipDecompress(t *testing.T) { + type args struct { + input []byte + } + tests := []struct { + name string + args args + want string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := GZipDecompress(tt.args.input) + if (err != nil) != tt.wantErr { + t.Errorf("GZipDecompress() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("GZipDecompress() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetAddTime(t *testing.T) { + type args struct { + st string + t string + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := GetAddTime(tt.args.st, tt.args.t); got != tt.want { + t.Errorf("GetAddTime() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetTime(t *testing.T) { + tests := []struct { + name string + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := GetTime(); got != tt.want { + t.Errorf("GetTime() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestHttpGet(t *testing.T) { + type args struct { + url string + } + tests := []struct { + name string + args args + want string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := HttpGet(tt.args.url) + if (err != nil) != tt.wantErr { + t.Errorf("HttpGet() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("HttpGet() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestHttpGetApi(t *testing.T) { + type args struct { + url string + } + tests := []struct { + name string + args args + want map[string]interface{} + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := HttpGetApi(tt.args.url) + if (err != nil) != tt.wantErr { + t.Errorf("HttpGetApi() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("HttpGetApi() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestHttpGetDoKey(t *testing.T) { + type args struct { + url string + } + tests := []struct { + name string + args args + want string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := HttpGetDoKey(tt.args.url) + if (err != nil) != tt.wantErr { + t.Errorf("HttpGetDoKey() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("HttpGetDoKey() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestHttpGetDoKeyMap(t *testing.T) { + type args struct { + url string + } + tests := []struct { + name string + args args + want map[string]interface{} + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := HttpGetDoKeyMap(tt.args.url) + if (err != nil) != tt.wantErr { + t.Errorf("HttpGetDoKeyMap() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("HttpGetDoKeyMap() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestHttpPost(t *testing.T) { + type args struct { + url string + body string + } + tests := []struct { + name string + args args + want string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := HttpPost(tt.args.url, tt.args.body) + if (err != nil) != tt.wantErr { + t.Errorf("HttpPost() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("HttpPost() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestIntegerInit(t *testing.T) { + type args struct { + value string + } + tests := []struct { + name string + args args + want int + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := IntegerInit(tt.args.value); got != tt.want { + t.Errorf("IntegerInit() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestIsNumber(t *testing.T) { + type args struct { + input string + } + tests := []struct { + name string + args args + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := IsNumber(tt.args.input); got != tt.want { + t.Errorf("IsNumber() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestIsNumberInt(t *testing.T) { + type args struct { + input string + } + tests := []struct { + name string + args args + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := IsNumberInt(tt.args.input); got != tt.want { + t.Errorf("IsNumberInt() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMapToString(t *testing.T) { + type args struct { + m map[string]string + } + tests := []struct { + name string + args args + want string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := MapToString(tt.args.m) + if (err != nil) != tt.wantErr { + t.Errorf("MapToString() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("MapToString() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestRandFloat64(t *testing.T) { + type args struct { + min float64 + max float64 + } + tests := []struct { + name string + args args + want float64 + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := RandFloat64(tt.args.min, tt.args.max); got != tt.want { + t.Errorf("RandFloat64() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestRandInt(t *testing.T) { + tests := []struct { + name string + want decimal.Decimal + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := RandInt(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("RandInt() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestRandInt64(t *testing.T) { + type args struct { + min int64 + max int64 + } + tests := []struct { + name string + args args + want int64 + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := RandInt64(tt.args.min, tt.args.max); got != tt.want { + t.Errorf("RandInt64() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestReplaceStr(t *testing.T) { + type args struct { + value string + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := ReplaceStr(tt.args.value); got != tt.want { + t.Errorf("ReplaceStr() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestReplaceStrByValue(t *testing.T) { + type args struct { + str string + value string + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := ReplaceStrByValue(tt.args.str, tt.args.value); got != tt.want { + t.Errorf("ReplaceStrByValue() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestStrReplace(t *testing.T) { + type args struct { + str string + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := StrReplace(tt.args.str); got != tt.want { + t.Errorf("StrReplace() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestStringToInt(t *testing.T) { + type args struct { + str string + } + tests := []struct { + name string + args args + want int + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := StringToInt(tt.args.str); got != tt.want { + t.Errorf("StringToInt() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestTimeAddDay(t *testing.T) { + type args struct { + day string + } + tests := []struct { + name string + args args + want time.Time + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := TimeAddDay(tt.args.day) + if (err != nil) != tt.wantErr { + t.Errorf("TimeAddDay() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("TimeAddDay() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestTimeAddDaySend(t *testing.T) { + type args struct { + day string + } + tests := []struct { + name string + args args + want time.Time + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := TimeAddDaySend(tt.args.day) + if (err != nil) != tt.wantErr { + t.Errorf("TimeAddDaySend() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("TimeAddDaySend() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestTimeAddDayZero(t *testing.T) { + type args struct { + dayInt int + } + tests := []struct { + name string + args args + want time.Time + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := TimeAddDayZero(tt.args.dayInt); !reflect.DeepEqual(got, tt.want) { + t.Errorf("TimeAddDayZero() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestTimeComparison(t *testing.T) { + type args struct { + stopTime time.Time + } + tests := []struct { + name string + args args + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := TimeComparison(tt.args.stopTime); got != tt.want { + t.Errorf("TimeComparison() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestTimeDateToMaoSend(t *testing.T) { + type args struct { + t time.Time + } + tests := []struct { + name string + args args + want int64 + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := TimeDateToMaoSend(tt.args.t); got != tt.want { + t.Errorf("TimeDateToMaoSend() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestTimeMaoSendToString(t *testing.T) { + type args struct { + i int64 + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := TimeMaoSendToString(tt.args.i); got != tt.want { + t.Errorf("TimeMaoSendToString() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestTimeStopTime(t *testing.T) { + type args struct { + day string + } + tests := []struct { + name string + args args + want time.Time + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := TimeStopTime(tt.args.day) + if (err != nil) != tt.wantErr { + t.Errorf("TimeStopTime() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("TimeStopTime() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestTimeStringToIn64(t *testing.T) { + type args struct { + t string + } + tests := []struct { + name string + args args + want int64 + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := TimeStringToIn64(tt.args.t); got != tt.want { + t.Errorf("TimeStringToIn64() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestTimeStringToTime(t *testing.T) { + type args struct { + t string + } + tests := []struct { + name string + args args + want time.Time + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := TimeStringToTime(tt.args.t); !reflect.DeepEqual(got, tt.want) { + t.Errorf("TimeStringToTime() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/server/grpc.go b/internal/server/grpc.go new file mode 100644 index 0000000..83e733f --- /dev/null +++ b/internal/server/grpc.go @@ -0,0 +1,64 @@ +package server + +import ( + "github.com/go-kratos/kratos/v2/log" + "github.com/go-kratos/kratos/v2/middleware/recovery" + "github.com/go-kratos/kratos/v2/transport/grpc" + "matchmaking-system/internal/conf" + "matchmaking-system/internal/service" + + backend "matchmaking-system/api/matchmaking/v1/backend" + block "matchmaking-system/api/matchmaking/v1/block" + forex "matchmaking-system/api/matchmaking/v1/forex" + money "matchmaking-system/api/matchmaking/v1/money" + option "matchmaking-system/api/matchmaking/v1/option" + order "matchmaking-system/api/matchmaking/v1/order" + share "matchmaking-system/api/matchmaking/v1/share" + virtually "matchmaking-system/api/matchmaking/v1/virtually" +) + +// NewGRPCServer +// +// @Description: +// @param c +// @param s +// @param logger +// @return *grpc.Server +func NewGRPCServer(c *conf.Server, s *service.ConduitService, logger log.Logger) *grpc.Server { + var opts = []grpc.ServerOption{ + grpc.Middleware( + recovery.Recovery(), + ), + } + if c.Grpc.Network != "" { + opts = append(opts, grpc.Network(c.Grpc.Network)) + } + if c.Grpc.Addr != "" { + opts = append(opts, grpc.Address(c.Grpc.Addr)) + } + + srv := grpc.NewServer(opts...) + order.RegisterOrderServer(srv, s) // Order pre + virtually.RegisterSpotsServer(srv, s) // Spot + virtually.RegisterSecondServer(srv, s) // Second + virtually.RegisterContractServer(srv, s) // Contract + forex.RegisterForexServer(srv, s) // Forex + money.RegisterMoneyServer(srv, s) // Money + backend.RegisterBackendServer(srv, s) // Backend + share.RegisterShareUsServer(srv, s) // Us + share.RegisterShareThaServer(srv, s) // Tha + share.RegisterShareIdnServer(srv, s) // Idn + share.RegisterShareInrServer(srv, s) // Inr + share.RegisterShareMysServer(srv, s) // Mys + share.RegisterShareSgdServer(srv, s) // Sgd + share.RegisterShareGbxServer(srv, s) // Gbx + share.RegisterShareHkdServer(srv, s) // Hkd + share.RegisterShareEurServer(srv, s) // Eur + share.RegisterShareFurServer(srv, s) // Fur + share.RegisterShareJpyServer(srv, s) // Jpy + share.RegisterShareBrlServer(srv, s) // Brl + block.RegisterBlockTradeServer(srv, s) // Block stock + option.RegisterOptionInrServer(srv, s) // Option inr + + return srv +} diff --git a/internal/server/http.go b/internal/server/http.go new file mode 100644 index 0000000..629b498 --- /dev/null +++ b/internal/server/http.go @@ -0,0 +1,132 @@ +package server + +import ( + "fmt" + "github.com/go-kratos/kratos/v2/log" + "github.com/go-kratos/kratos/v2/middleware/logging" + "github.com/go-kratos/kratos/v2/middleware/recovery" + "github.com/go-kratos/kratos/v2/transport/http" + "github.com/gorilla/handlers" + "github.com/gorilla/mux" + "matchmaking-system/internal/conf" + "matchmaking-system/internal/data/socket" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/pkg/logging/applogger" + "matchmaking-system/internal/service" + + backend "matchmaking-system/api/matchmaking/v1/backend" + block "matchmaking-system/api/matchmaking/v1/block" + forex "matchmaking-system/api/matchmaking/v1/forex" + money "matchmaking-system/api/matchmaking/v1/money" + option "matchmaking-system/api/matchmaking/v1/option" + order "matchmaking-system/api/matchmaking/v1/order" + share "matchmaking-system/api/matchmaking/v1/share" + virtually "matchmaking-system/api/matchmaking/v1/virtually" +) + +// NewHTTPServer +// +// @Description: +// @param c +// @param s +// @param logger +// @return *http.Server +func NewHTTPServer(c *conf.Server, s *service.ConduitService, logger log.Logger) *http.Server { + var opts = []http.ServerOption{ + http.Middleware( + recovery.Recovery(), + logging.Server(logger), + ), + http.Filter(handlers.CORS( + handlers.AllowedHeaders([]string{"X-Requested-With", "Content-Type", "Authorization", "token", "Language"}), + handlers.AllowedMethods([]string{"GET", "POST", "PUT", "HEAD", "OPTIONS"}), + handlers.AllowedOrigins([]string{"*"}), + handlers.AllowCredentials(), + )), + } + if c.Http.Network != "" { + opts = append(opts, http.Network(c.Http.Network)) + } + if c.Http.Addr != "" { + opts = append(opts, http.Address(c.Http.Addr)) + } + + // wss 订单订阅行情 + var wss string + routerQuotes := mux.NewRouter() + switch flags.CheckEnvironment { + case flags.CheckSport: // Spots Wss + wss = fmt.Sprintf("/%v", flags.SpotsWss) + case flags.CheckContract: // Contract Wss + wss = fmt.Sprintf("/%v", flags.ContractWss) + case flags.CheckSecond: // Second Wss + wss = fmt.Sprintf("/%v", flags.SecondWss) + case flags.CheckForex: // Forex Wss + wss = fmt.Sprintf("/%v", flags.ForexWss) + case flags.CheckMoney: // Money Wss + wss = fmt.Sprintf("/%v", flags.MoneyWss) + case flags.CheckShareUs: // Share Us Wss + wss = fmt.Sprintf("/%v", flags.ShareUsWss) + case flags.CheckShareMys: // Share Mys Wss + wss = fmt.Sprintf("/%v", flags.ShareMysWss) + case flags.CheckShareTha: // Share Tha Wss + wss = fmt.Sprintf("/%v", flags.ShareThaWss) + case flags.CheckShareIdn: // Share Idn Wss + wss = fmt.Sprintf("/%v", flags.ShareIdnWss) + case flags.CheckShareInr: // Share Inr Wss + wss = fmt.Sprintf("/%v", flags.ShareInrWss) + case flags.CheckShareSgd: // Share Sgd Wss + wss = fmt.Sprintf("/%v", flags.ShareSgdWss) + case flags.CheckShareGbx: // Share Gbx Wss + wss = fmt.Sprintf("/%v", flags.ShareGbxWss) + case flags.CheckShareHkd: // Share Hkd Wss + wss = fmt.Sprintf("/%v", flags.ShareHkdWss) + case flags.CheckShareEur: // Share Eur Wss + wss = fmt.Sprintf("/%v", flags.ShareEurWss) + case flags.CheckShareFur: // Share Fur Wss + wss = fmt.Sprintf("/%v", flags.ShareFurWss) + case flags.CheckShareJpy: // Share Jpy Wss + wss = fmt.Sprintf("/%v", flags.ShareJpyWss) + case flags.CheckShareBrl: // Share Brl Wss + wss = fmt.Sprintf("/%v", flags.ShareBrlWss) + case flags.CheckShareBlk: // Share Blk Wss + wss = fmt.Sprintf("/%v", flags.ShareBlkWss) + case flags.CheckOptionInr: // Option Inr Wss + wss = fmt.Sprintf("/%v", flags.OptionInrWss) + case flags.CheckAdmin: // Admin Wss + wss = fmt.Sprintf("/%v", flags.AdminWss) + case flags.CheckAdminBlk: // admin Blk Wss + wss = fmt.Sprintf("/%v", flags.AdminBlkWss) + default: + applogger.Error(flags.ErrOrderSeven.Error()) + } + routerQuotes.HandleFunc(wss, socket.WsHandlerOrder) + + // http 订单静态服务 + srv := http.NewServer(opts...) + order.RegisterOrderHTTPServer(srv, s) // OrderPre + virtually.RegisterSecondHTTPServer(srv, s) // Second + virtually.RegisterSpotsHTTPServer(srv, s) // Spots + virtually.RegisterContractHTTPServer(srv, s) // Contract + forex.RegisterForexHTTPServer(srv, s) // Forex + money.RegisterMoneyHTTPServer(srv, s) // Money + backend.RegisterBackendHTTPServer(srv, s) // Backend + share.RegisterShareUsHTTPServer(srv, s) // Us + share.RegisterShareThaHTTPServer(srv, s) // Tha + share.RegisterShareIdnHTTPServer(srv, s) // Idn + share.RegisterShareInrHTTPServer(srv, s) // Inr + share.RegisterShareMysHTTPServer(srv, s) // Mys + share.RegisterShareSgdHTTPServer(srv, s) // Sgd + share.RegisterShareGbxHTTPServer(srv, s) // Gbx + share.RegisterShareHkdHTTPServer(srv, s) // Hkd + share.RegisterShareEurHTTPServer(srv, s) // Eur + share.RegisterShareFurHTTPServer(srv, s) // Fur + share.RegisterShareJpyHTTPServer(srv, s) // Jpy + share.RegisterShareBrlHTTPServer(srv, s) // Brl + block.RegisterBlockTradeHTTPServer(srv, s) // Block stock + option.RegisterOptionInrHTTPServer(srv, s) // OptionInr + + srv.HandlePrefix("/", routerQuotes) + + return srv +} diff --git a/internal/server/server.go b/internal/server/server.go new file mode 100644 index 0000000..4d267a7 --- /dev/null +++ b/internal/server/server.go @@ -0,0 +1,8 @@ +package server + +import ( + "github.com/google/wire" +) + +// ProviderSet is server providers. +var ProviderSet = wire.NewSet(NewHTTPServer, NewGRPCServer) diff --git a/internal/service/README.md b/internal/service/README.md new file mode 100644 index 0000000..e0abb29 --- /dev/null +++ b/internal/service/README.md @@ -0,0 +1,17 @@ +# 一、Service 模块功能 +### 功能块: [数字币(合约|现货|秒合约)、股票(美股|泰股|马股|印尼股|印度股|新加坡股|港股)、新股申购(美股|泰股|马股|印尼股|印度股|新加坡股|港股)、大宗交易(美股|泰股|马股|印尼股|印度股|新加坡股|港股)、期权(印度)] +``` + 1、自动监控服务功能 + 1>初始化代码列表 + 2>监控代码价格(行情|设置)缓存 + 3>监控挂单 + 4>监控持仓 + 2、调用服务功能(详细逻辑-->见相关功能设计文档) + 1>下单 + 2>止盈止损 + 3>撤单 + 4>平仓 + 5>一键平仓 + 6>新股申购 + 3、相关调用文档(http://g.jd66.cc:3001/project/56/interface/api) +``` \ No newline at end of file diff --git a/internal/service/backend.go b/internal/service/backend.go new file mode 100644 index 0000000..edb3d63 --- /dev/null +++ b/internal/service/backend.go @@ -0,0 +1,30 @@ +package service + +import ( + "context" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/backend" + + v1 "matchmaking-system/api/matchmaking/v1/backend" +) + +// SharePreTrade +// +// @Description: 新股申购下单-开盘服务(美股|泰股|印尼股|马股|印度股|新加坡|港股) +// @receiver s +// @param ctx +// @param req +// @return *v1.BotUsersNullRequest +// @return error +func (s *ConduitService) UpdateBotUsersByIsReal(ctx context.Context, req *v1.BotUsersNullRequest) (*v1.BotUsersReply, error) { + if !backend.VerificationRequest(req) { + return backend.BotUsersReply(false, flags.ErrIsParameter.Error()), nil + } + + err := s.ba.UpdateBotUsersByIsReal(ctx) + if err != nil { + return backend.BotUsersReply(false, err.Error()), nil + } + + return backend.BotUsersReply(true, flags.SetNull), nil +} diff --git a/internal/service/backend/backend.go b/internal/service/backend/backend.go new file mode 100644 index 0000000..cd42512 --- /dev/null +++ b/internal/service/backend/backend.go @@ -0,0 +1,73 @@ +package backend + +import ( + v1 "matchmaking-system/api/matchmaking/v1/backend" + "matchmaking-system/internal/pkg/flags" + "net/http" +) + +// VerificationRequest +// +// @Description: +// @param req +// @return bool +func VerificationRequest(req *v1.BotUsersNullRequest) bool { + + return true +} + +// BotUsersReply +// +// @Description: +// @param check +// @param err +// @return *v1.BotUsersReply +func BotUsersReply(check bool, err string) *v1.BotUsersReply { + code, replyStr := ResultCodeSrr(check, err) + + return &v1.BotUsersReply{ + Code: code, + Data: "", + Message: replyStr, + } +} + +// ResultCodeSrr +// +// @Description: +// @param check +// @param err +// @return int64 +// @return string +func ResultCodeSrr(check bool, err string) (int64, string) { + var code int + var replyStr string + if !check { + code, replyStr = ResultTokenError(err) + } else { + code = http.StatusOK + replyStr = "successful" + } + return int64(code), replyStr +} + +// ResultTokenError +// +// @Description: +// @param err +// @return int +// @return string +func ResultTokenError(err string) (int, string) { + switch err { + case flags.ErrTokenError.Error(): + return http.StatusUnauthorized, flags.ErrTokenMessage.Error() + case flags.ErrTokenMessage.Error(): + return http.StatusUnauthorized, err + case flags.ErrIsReal.Error(): + return http.StatusMethodNotAllowed, err + case flags.ErrIsParameter.Error(): + return http.StatusBadRequest, err + default: + return http.StatusBadRequest, err + } +} diff --git a/internal/service/block/share_blk.go b/internal/service/block/share_blk.go new file mode 100644 index 0000000..dc95838 --- /dev/null +++ b/internal/service/block/share_blk.go @@ -0,0 +1,305 @@ +package block + +import ( + "google.golang.org/protobuf/types/known/timestamppb" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/service/order" + "strconv" + + v1 "matchmaking-system/api/matchmaking/v1/block" + models "matchmaking-system/internal/pkg/model" +) + +// ShareBlockCancelReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.OrderBlockReply +func ShareBlockCancelReply(check bool, err string, req *v1.CancelBlockOrderRequest) *v1.OrderBlockReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.OrderBlockReply{ + Code: code, + Data: ResultBlockOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationShareBlockCancel +// +// @Description: +// @param req +// @return bool +func VerificationShareBlockCancel(req *v1.CancelBlockOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + if req.GetType() <= 0 { + return false + } + + return true +} + +// ShareBlockPositionOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.OrderBlockReply +func ShareBlockPositionOrderReply(check bool, err string, req *v1.CancelBlockOrderRequest) *v1.OrderBlockReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.OrderBlockReply{ + Code: code, + Data: ResultBlockOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationShareBlockPosition +// +// @Description: +// @param req +// @return bool +func VerificationShareBlockPosition(req *v1.CancelBlockOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + return true +} + +// StopOrderBlockQuery +// +// @Description: +// @param request +// @return structure.StopOrder +func StopOrderBlockQuery(request *v1.UpdateBlockOrderRequest) structure.StopOrder { + return structure.StopOrder{ + OrderId: request.OrderId, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + } +} + +// ShareBlockUpdateOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.OrderBlockReply +func ShareBlockUpdateOrderReply(check bool, err string, req *v1.UpdateBlockOrderRequest) *v1.OrderBlockReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.OrderBlockReply{ + Code: code, + Data: ResultBlockOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationStopOrderBlockQuery +// +// @Description: +// @param request +// @return bool +func VerificationStopOrderBlockQuery(request *v1.UpdateBlockOrderRequest) bool { + if len(request.GetOrderId()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + case 0: + //if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + // return false + //} + return true + default: + return false + } + + return true +} + +// ShareBlockOrderQuery +// +// @Description: +// @param request +// @return structure.ShareOrder +func ShareBlockOrderQuery(request *v1.OrderBlockRequest) structure.ShareOrder { + return structure.ShareOrder{ + StockId: request.StockId, + TradeType: request.TradeType, + DealType: request.DealType, + LimitPrice: request.LimitPrice, + MarketPrice: request.MarketPrice, + MarketMoney: request.MarketMoney, + OrderNumber: request.OrderNumber, + ServiceCost: request.ServiceCost, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + PryNum: request.PryNum, + Type: request.Type, + } +} + +// ShareBlockPlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param orderId +// @return *v1.OrderBlockReply +func ShareBlockPlaceOrderReply(check bool, err string, orderId string) *v1.OrderBlockReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.OrderBlockReply{ + Code: code, + Data: ResultBlockOrderMessage(orderId), + Message: replyStr, + } +} + +// ResultBlockOrderMessage +// +// @Description: +// @param orderId +// @return *v1.OrderBlockResult +func ResultBlockOrderMessage(orderId string) *v1.OrderBlockResult { + return &v1.OrderBlockResult{ + OrderId: orderId, + } +} + +// VerificationShareBlockOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationShareBlockOrderQuery(request *v1.OrderBlockRequest) bool { + if len(request.GetStockId()) <= 0 { + return false + } + switch request.DealType { + case 1: // 限价 + if len(request.GetLimitPrice()) <= 0 { + return false + } + case 2: // 市价 + if len(request.GetMarketPrice()) <= 0 { + return false + } + default: + return false + } + if request.Type <= 0 { + return false + } + if len(request.GetMarketMoney()) <= 0 { + return false + } + if len(request.GetOrderNumber()) <= 0 { + return false + } + if len(request.GetServiceCost()) <= 0 { + return false + } + switch request.TradeType { + case 1: + case 2: + default: + return false + } + + return true +} + +// VerificationBotStockBlockTrade +// +// @Description: +// @param req +// @return bool +func VerificationBotStockBlockTrade(req *v1.GetBotStockBlockTradeRequest) bool { + if req.GetPageSize() < 0 { + return false + } + if req.GetStatus() < 0 { + return false + } + if req.GetPageCount() < 0 { + return false + } + if req.GetType() <= 0 { + return false + } + + return true +} + +// BotStockBlockTradeReply +// +// @Description: +// @param check +// @param err +// @param req +// @param data +// @param totalCount +// @return *v1.GetBotStockBlockTradeReply +func BotStockBlockTradeReply(check bool, err string, req *v1.GetBotStockBlockTradeRequest, data []*models.BotStockBlockTrade, totalCount int64) *v1.GetBotStockBlockTradeReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.GetBotStockBlockTradeReply{ + Code: code, + Data: &v1.BotStockBlockTradeData{ + PageSize: req.PageSize, + PageCount: req.PageCount, + Data: BotStockBlockTradeMessage(data), + TotalCount: totalCount, + }, + Message: replyStr, + } +} + +// BotStockBlockTradeMessage +// +// @Description: +// @param stockList +// @return stockTrade +func BotStockBlockTradeMessage(stockList []*models.BotStockBlockTrade) (stockTrade []*v1.BotOrderBlockTrade) { + for _, value := range stockList { + stockTrade = append(stockTrade, &v1.BotOrderBlockTrade{ + OrderId: value.OrderId, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + DealPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + OrderNumber: value.OrderNumber, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + ServiceCost: value.ServiceCost, + MarketMoney: value.MarketMoney, + OrderMoney: value.OrderMoney, + ClosingCost: value.ClosingCost, + Status: int64(value.Status), + CreateTime: timestamppb.New(value.CreateTime), + UpdateTime: timestamppb.New(value.UpdateTime), + OpenTime: timestamppb.New(value.OpenTime), + ClosingTime: timestamppb.New(value.ClosingTime), + KeepDecimal: strconv.Itoa(value.KeepDecimal), + StockName: value.StockName, + PryNum: strconv.Itoa(value.PryNum), + Type: int64(value.Type), + }) + } + return +} diff --git a/internal/service/forex.go b/internal/service/forex.go new file mode 100644 index 0000000..ef6fe53 --- /dev/null +++ b/internal/service/forex.go @@ -0,0 +1,129 @@ +package service + +import ( + "context" + v1 "matchmaking-system/api/matchmaking/v1/forex" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/forex" +) + +// GetBotForexTrade +// +// @Description: 外汇订单列表 +// @receiver s +// @param ctx +// @param req +// @return *v1.GetBotForexTradeReply +// @return error +func (s *ConduitService) GetBotForexTrade(ctx context.Context, req *v1.GetBotForexTradeRequest) (*v1.GetBotForexTradeReply, error) { + if !forex.VerificationBotForexTrade(req) { + return forex.BotForexTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil + } + + contractTradeList, totalCount, err := s.fr.BotForexTradeList(ctx, req.PageSize, req.PageCount, req.Status) + if err != nil { + return forex.BotForexTradeReply(false, err.Error(), req, nil, 0), nil + } + + return forex.BotForexTradeReply(true, flags.SetNull, req, contractTradeList, totalCount), nil +} + +// ForexPlaceOrder +// +// @Description: 外汇下单 +// @receiver s +// @param ctx +// @param req +// @return *v1.ForexReply +// @return error +func (s *ConduitService) ForexPlaceOrder(ctx context.Context, req *v1.ForexRequest) (*v1.ForexReply, error) { + if !forex.VerificationForexPlaceOrder(req) { + return forex.ForexPlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil + } + + orderId, err := s.fr.ForexPlaceOrder(ctx, forex.ForexOrderQuery(req)) + if err != nil { + return forex.ForexPlaceOrderReply(false, err.Error(), flags.SetNull), nil + } + + return forex.ForexPlaceOrderReply(true, flags.SetNull, orderId), nil +} + +// ForexUpdatePlaceOrder +// +// @Description: 外汇设置止盈止损 +// @receiver s +// @param ctx +// @param req +// @return *v1.ForexReply +// @return error +func (s *ConduitService) ForexUpdatePlaceOrder(ctx context.Context, req *v1.UpdateForexRequest) (*v1.ForexReply, error) { + if !forex.VerificationForexUpdatePlaceOrder(req) { + return forex.ForexUpdatePlaceOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.fr.ForexUpdatePlaceOrder(ctx, forex.ForexStopQuery(req)) + if err != nil { + return forex.ForexUpdatePlaceOrderReply(false, err.Error(), req), nil + } + + return forex.ForexUpdatePlaceOrderReply(true, flags.SetNull, req), nil +} + +// ForexPosition +// +// @Description: 外汇平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.ForexReply +// @return error +func (s *ConduitService) ForexPosition(ctx context.Context, req *v1.CancelForexRequest) (*v1.ForexReply, error) { + if !forex.VerificationForexPosition(req) { + return forex.ForexPositionOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.fr.ForexPosition(ctx, req.OrderId) + if err != nil { + return forex.ForexPositionOrderReply(false, err.Error(), req), nil + } + + return forex.ForexPositionOrderReply(true, flags.SetNull, req), nil +} + +// ForexAllPosition +// +// @Description: 外汇一键平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.AllForexReply +// @return error +func (s *ConduitService) ForexAllPosition(ctx context.Context, req *v1.AllForexRequest) (*v1.AllForexReply, error) { + if err := s.fr.ForexAllPosition(ctx); err != nil { + return forex.ForexAllPositionReply(false, err.Error()), nil + } + + return forex.ForexAllPositionReply(true, flags.SetNull), nil +} + +// ForexCancel +// +// @Description: 外汇撤单 +// @receiver s +// @param ctx +// @param req +// @return *v1.ForexReply +// @return error +func (s *ConduitService) ForexCancel(ctx context.Context, req *v1.CancelForexRequest) (*v1.ForexReply, error) { + if !forex.VerificationForexCancel(req) { + return forex.ForexCancelOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.fr.ForexCancel(ctx, req.OrderId) + if err != nil { + return forex.ForexCancelOrderReply(false, err.Error(), req), nil + } + + return forex.ForexCancelOrderReply(true, flags.SetNull, req), nil +} diff --git a/internal/service/forex/forex.go b/internal/service/forex/forex.go new file mode 100644 index 0000000..5ba1768 --- /dev/null +++ b/internal/service/forex/forex.go @@ -0,0 +1,325 @@ +package forex + +import ( + "google.golang.org/protobuf/types/known/timestamppb" + v1 "matchmaking-system/api/matchmaking/v1/forex" + "matchmaking-system/internal/biz/structure" + models "matchmaking-system/internal/pkg/model" + "matchmaking-system/internal/service/order" + "strconv" +) + +// ForexStopQuery +// +// @Description: +// @param request +// @return structure.StopOrder +func ForexStopQuery(request *v1.UpdateForexRequest) structure.StopOrder { + return structure.StopOrder{ + OrderId: request.OrderId, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + } +} + +// ForexCancelOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.OrderReply +func ForexCancelOrderReply(check bool, err string, req *v1.CancelForexRequest) *v1.ForexReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.ForexReply{ + Code: code, + Data: ResultForexMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationForexCancel +// +// @Description: +// @param req +// @return bool +func VerificationForexCancel(req *v1.CancelForexRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// ForexAllPositionReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.AllOrderReply +func ForexAllPositionReply(check bool, err string) *v1.AllForexReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.AllForexReply{ + Code: code, + Data: "", + Message: replyStr, + } +} + +// ForexPositionOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.OrderReply +func ForexPositionOrderReply(check bool, err string, req *v1.CancelForexRequest) *v1.ForexReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.ForexReply{ + Code: code, + Data: ResultForexMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationForexPosition +// +// @Description: +// @param req +// @return bool +func VerificationForexPosition(req *v1.CancelForexRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// ForexUpdatePlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.OrderReply +func ForexUpdatePlaceOrderReply(check bool, err string, req *v1.UpdateForexRequest) *v1.ForexReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.ForexReply{ + Code: code, + Data: ResultForexMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationForexUpdatePlaceOrder +// +// @Description: +// @param req +// @return bool +func VerificationForexUpdatePlaceOrder(req *v1.UpdateForexRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + switch req.StopType { + case 0: + return true + case 1: + if len(req.GetStopLossPrice()) <= 0 && len(req.GetStopWinPrice()) <= 0 { + return false + } + default: + return false + } + + return true +} + +// VerificationBotForexTrade +// +// @Description: +// @param req +// @return bool +func VerificationBotForexTrade(req *v1.GetBotForexTradeRequest) bool { + if req.GetPageSize() < 0 { + return false + } + if req.GetStatus() < 0 { + return false + } + if req.GetPageCount() < 0 { + return false + } + + return true +} + +// BotForexTradeMessage +// +// @Description: +// @param stockList +// @return contractTrade +func BotForexTradeMessage(stockList []*models.BotForexTrade) (contractTrade []*v1.BotForexTrade) { + for _, value := range stockList { + faceValue := strconv.FormatInt(value.FaceValue, 10) + contractTrade = append(contractTrade, &v1.BotForexTrade{ + OrderId: value.OrderId, + ForexId: value.ContractId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + DealPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + OrderNumber: value.OrderNumber, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + ServiceCost: value.ServiceCost, + EarnestMoney: value.EarnestMoney, + OrderMoney: value.OrderMoney, + Status: int64(value.Status), + ClosingCost: value.ClosingCost, + CreateTime: timestamppb.New(value.CreateTime), + UpdateTime: timestamppb.New(value.UpdateTime), + OpenTime: timestamppb.New(value.OpenTime), + ClosingTime: timestamppb.New(value.ClosingTime), + FaceValue: faceValue, + OvernightCost: value.OvernightCost, + KeepDecimal: strconv.Itoa(value.KeepDecimal), + PryNum: strconv.Itoa(value.PryNum), + SecondTime: strconv.Itoa(value.SecondTime), + State: int64(value.State), + }) + } + return +} + +// BotForexTradeReply +// +// @Description: +// @param check +// @param err +// @param req +// @param data +// @param totalCount +// @return *v1.GetBotForexTradeReply +func BotForexTradeReply(check bool, err string, req *v1.GetBotForexTradeRequest, data []*models.BotForexTrade, totalCount int64) *v1.GetBotForexTradeReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.GetBotForexTradeReply{ + Code: code, + Data: &v1.BotForexTradeData{ + PageSize: req.PageSize, + PageCount: req.PageCount, + Data: BotForexTradeMessage(data), + TotalCount: totalCount, + }, + Message: replyStr, + } +} + +// VerificationForexPlaceOrder +// +// @Description: 合约下单参数判定 +// @param req +// @return bool +func VerificationForexPlaceOrder(req *v1.ForexRequest) bool { + if len(req.GetPryNum()) <= 0 { + return false + } + if len(req.GetForexId()) <= 0 { + return false + } + if len(req.GetOrderAmount()) <= 0 { + return false + } + if len(req.GetOrderNumber()) <= 0 { + return false + } + if len(req.GetEarnestMoney()) <= 0 { + return false + } + if len(req.GetServiceCost()) <= 0 { + return false + } + switch req.StopType { + case 1: + if len(req.GetStopLossPrice()) <= 0 && len(req.GetStopWinPrice()) <= 0 { + return false + } + } + + switch req.TradeType { + case 1: + case 2: + default: + return false + } + + switch req.DealType { + case 1: + if len(req.GetLimitPrice()) <= 0 { + return false + } + case 2: + if len(req.GetMarketPrice()) <= 0 { + return false + } + default: + return false + } + + return true +} + +// ForexPlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param orderId +// @return *v1.OrderReply +func ForexPlaceOrderReply(check bool, err string, orderId string) *v1.ForexReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.ForexReply{ + Code: code, + Data: ResultForexMessage(orderId), + Message: replyStr, + } +} + +// ResultForexMessage +// +// @Description: +// @param orderId +// @return *v1.Result +func ResultForexMessage(orderId string) *v1.ForexResult { + return &v1.ForexResult{ + OrderId: orderId, + } +} + +// ForexOrderQuery +// +// @Description: +// @param request +// @return structure.ForexOrder +func ForexOrderQuery(request *v1.ForexRequest) structure.ForexOrder { + return structure.ForexOrder{ + ForexId: request.ForexId, + TradeType: request.TradeType, + DealType: request.DealType, + LimitPrice: request.LimitPrice, + MarketPrice: request.MarketPrice, + OrderAmount: request.OrderAmount, + OrderNumber: request.OrderNumber, + EarnestMoney: request.EarnestMoney, + ServiceCost: request.ServiceCost, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + PryNum: request.PryNum, + } +} diff --git a/internal/service/money.go b/internal/service/money.go new file mode 100644 index 0000000..f4882a1 --- /dev/null +++ b/internal/service/money.go @@ -0,0 +1,150 @@ +package service + +import ( + "context" + v1 "matchmaking-system/api/matchmaking/v1/money" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/money" +) + +// GetBotMoneyTrade +// +// @Description: 外汇订单列表 +// @receiver s +// @param ctx +// @param req +// @return *v1.GetBotMoneyTradeReply +// @return error +func (s *ConduitService) GetBotMoneyTrade(ctx context.Context, req *v1.GetBotMoneyTradeRequest) (*v1.GetBotMoneyTradeReply, error) { + if !money.VerificationBotMoneyTrade(req) { + return money.BotMoneyTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil + } + + contractTradeList, totalCount, err := s.mo.BotMoneyTradeList(ctx, req.PageSize, req.PageCount, req.Status, req.Type) + if err != nil { + return money.BotMoneyTradeReply(false, err.Error(), req, nil, 0), nil + } + + return money.BotMoneyTradeReply(true, flags.SetNull, req, contractTradeList, totalCount), nil +} + +// MoneyPlaceOrder +// +// @Description: 外汇下单 +// @receiver s +// @param ctx +// @param req +// @return *v1.MoneyReply +// @return error +func (s *ConduitService) MoneyPlaceOrder(ctx context.Context, req *v1.MoneyRequest) (*v1.MoneyReply, error) { + if !money.VerificationMoneyPlaceOrder(req) { + return money.MoneyPlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil + } + + orderId, err := s.mo.MoneyPlaceOrder(ctx, money.MoneyOrderQuery(req)) + if err != nil { + return money.MoneyPlaceOrderReply(false, err.Error(), flags.SetNull), nil + } + + return money.MoneyPlaceOrderReply(true, flags.SetNull, orderId), nil +} + +// MoneyUpdatePlaceOrder +// +// @Description: 外汇设置止盈止损 +// @receiver s +// @param ctx +// @param req +// @return *v1.MoneyReply +// @return error +func (s *ConduitService) MoneyUpdatePlaceOrder(ctx context.Context, req *v1.UpdateMoneyRequest) (*v1.MoneyReply, error) { + if !money.VerificationMoneyUpdatePlaceOrder(req) { + return money.MoneyUpdatePlaceOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.mo.MoneyUpdatePlaceOrder(ctx, money.MoneyStopQuery(req)) + if err != nil { + return money.MoneyUpdatePlaceOrderReply(false, err.Error(), req), nil + } + + return money.MoneyUpdatePlaceOrderReply(true, flags.SetNull, req), nil +} + +// MoneyPosition +// +// @Description: 外汇平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.MoneyReply +// @return error +func (s *ConduitService) MoneyPosition(ctx context.Context, req *v1.CancelMoneyRequest) (*v1.MoneyReply, error) { + if !money.VerificationMoneyPosition(req) { + return money.MoneyPositionOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.mo.MoneyPosition(ctx, req.OrderId) + if err != nil { + return money.MoneyPositionOrderReply(false, err.Error(), req), nil + } + + return money.MoneyPositionOrderReply(true, flags.SetNull, req), nil +} + +// MoneyAllPosition +// +// @Description: 外汇一键平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.AllMoneyReply +// @return error +func (s *ConduitService) MoneyAllPosition(ctx context.Context, req *v1.AllMoneyRequest) (*v1.AllMoneyReply, error) { + if err := s.mo.MoneyAllPosition(ctx); err != nil { + return money.MoneyAllPositionReply(false, err.Error()), nil + } + + return money.MoneyAllPositionReply(true, flags.SetNull), nil +} + +// MoneyCancel +// +// @Description: 外汇撤单 +// @receiver s +// @param ctx +// @param req +// @return *v1.MoneyReply +// @return error +func (s *ConduitService) MoneyCancel(ctx context.Context, req *v1.CancelMoneyRequest) (*v1.MoneyReply, error) { + if !money.VerificationMoneyCancel(req) { + return money.MoneyCancelOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.mo.MoneyCancel(ctx, req.OrderId) + if err != nil { + return money.MoneyCancelOrderReply(false, err.Error(), req), nil + } + + return money.MoneyCancelOrderReply(true, flags.SetNull, req), nil +} + +// SpotsOneClickRedemption +// +// @Description: 现货一键兑换 +// @receiver s +// @param ctx +// @param req +// @return *v1.SpotsOrderReply +// @return error +func (s *ConduitService) MoneyOneClickRedemption(ctx context.Context, req *v1.MoneyRequest) (*v1.MoneyReply, error) { + if !money.VerificationMoneyPlaceOrder(req) { + return money.MoneyPlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil + } + + orderId, err := s.mo.MoneyOneClickRedemption(ctx, money.MoneyOrderQuery(req)) + if err != nil { + return money.SharePlaceOrderReply(false, err.Error(), flags.SetNull), nil + } + + return money.SharePlaceOrderReply(true, flags.SetNull, orderId), nil +} diff --git a/internal/service/money/money.go b/internal/service/money/money.go new file mode 100644 index 0000000..4d0d375 --- /dev/null +++ b/internal/service/money/money.go @@ -0,0 +1,346 @@ +package money + +import ( + "google.golang.org/protobuf/types/known/timestamppb" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/service/order" + "strconv" + + v1 "matchmaking-system/api/matchmaking/v1/money" + models "matchmaking-system/internal/pkg/model" +) + +// MoneyStopQuery +// +// @Description: +// @param request +// @return structure.StopOrder +func MoneyStopQuery(request *v1.UpdateMoneyRequest) structure.StopOrder { + return structure.StopOrder{ + OrderId: request.OrderId, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + } +} + +// MoneyCancelOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.OrderReply +func MoneyCancelOrderReply(check bool, err string, req *v1.CancelMoneyRequest) *v1.MoneyReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.MoneyReply{ + Code: code, + Data: ResultMoneyMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationMoneyCancel +// +// @Description: +// @param req +// @return bool +func VerificationMoneyCancel(req *v1.CancelMoneyRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// MoneyAllPositionReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.AllOrderReply +func MoneyAllPositionReply(check bool, err string) *v1.AllMoneyReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.AllMoneyReply{ + Code: code, + Data: "", + Message: replyStr, + } +} + +// MoneyPositionOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.OrderReply +func MoneyPositionOrderReply(check bool, err string, req *v1.CancelMoneyRequest) *v1.MoneyReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.MoneyReply{ + Code: code, + Data: ResultMoneyMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationMoneyPosition +// +// @Description: +// @param req +// @return bool +func VerificationMoneyPosition(req *v1.CancelMoneyRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// MoneyUpdatePlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.OrderReply +func MoneyUpdatePlaceOrderReply(check bool, err string, req *v1.UpdateMoneyRequest) *v1.MoneyReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.MoneyReply{ + Code: code, + Data: ResultMoneyMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationMoneyUpdatePlaceOrder +// +// @Description: +// @param req +// @return bool +func VerificationMoneyUpdatePlaceOrder(req *v1.UpdateMoneyRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + switch req.StopType { + case 0: + return true + case 1: + if len(req.GetStopLossPrice()) <= 0 && len(req.GetStopWinPrice()) <= 0 { + return false + } + default: + return false + } + + return true +} + +// VerificationBotMoneyTrade +// +// @Description: +// @param req +// @return bool +func VerificationBotMoneyTrade(req *v1.GetBotMoneyTradeRequest) bool { + if req.GetPageSize() < 0 { + return false + } + if req.GetStatus() < 0 { + return false + } + if req.GetPageCount() < 0 { + return false + } + if req.GetType() < 0 { + return false + } + + return true +} + +// BotMoneyTradeMessage +// +// @Description: +// @param stockList +// @return contractTrade +func BotMoneyTradeMessage(stockList []*models.BotMoneyTrade) (contractTrade []*v1.BotMoneyTrade) { + for _, value := range stockList { + contractTrade = append(contractTrade, &v1.BotMoneyTrade{ + OrderId: value.OrderId, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + DealPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + OrderNumber: value.OrderNumber, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + ServiceCost: value.ServiceCost, + EarnestMoney: value.MarketMoney, + OrderMoney: value.OrderMoney, + Status: int64(value.Status), + ClosingCost: value.ClosingCost, + CreateTime: timestamppb.New(value.CreateTime), + UpdateTime: timestamppb.New(value.UpdateTime), + OpenTime: timestamppb.New(value.OpenTime), + ClosingTime: timestamppb.New(value.ClosingTime), + OvernightCost: value.OvernightCost, + KeepDecimal: strconv.Itoa(value.KeepDecimal), + PryNum: strconv.Itoa(value.PryNum), + }) + } + return +} + +// BotMoneyTradeReply +// +// @Description: +// @param check +// @param err +// @param req +// @param data +// @param totalCount +// @return *v1.GetBotMoneyTradeReply +func BotMoneyTradeReply(check bool, err string, req *v1.GetBotMoneyTradeRequest, data []*models.BotMoneyTrade, totalCount int64) *v1.GetBotMoneyTradeReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.GetBotMoneyTradeReply{ + Code: code, + Data: &v1.BotMoneyTradeData{ + PageSize: req.PageSize, + PageCount: req.PageCount, + Data: BotMoneyTradeMessage(data), + TotalCount: totalCount, + }, + Message: replyStr, + } +} + +// VerificationMoneyPlaceOrder +// +// @Description: 合约下单参数判定 +// @param req +// @return bool +func VerificationMoneyPlaceOrder(req *v1.MoneyRequest) bool { + if len(req.GetPryNum()) <= 0 { + return false + } + if len(req.GetStockId()) <= 0 { + return false + } + if len(req.GetOrderAmount()) <= 0 { + return false + } + if len(req.GetOrderNumber()) <= 0 { + return false + } + if len(req.GetEarnestMoney()) <= 0 { + return false + } + if len(req.GetServiceCost()) <= 0 { + return false + } + switch req.StopType { + case 1: + if len(req.GetStopLossPrice()) <= 0 && len(req.GetStopWinPrice()) <= 0 { + return false + } + } + + switch req.TradeType { + case 1: + case 2: + default: + return false + } + + switch req.DealType { + case 1: + if len(req.GetLimitPrice()) <= 0 { + return false + } + case 2: + if len(req.GetMarketPrice()) <= 0 { + return false + } + default: + return false + } + + return true +} + +// MoneyPlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param orderId +// @return *v1.OrderReply +func MoneyPlaceOrderReply(check bool, err string, orderId string) *v1.MoneyReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.MoneyReply{ + Code: code, + Data: ResultMoneyMessage(orderId), + Message: replyStr, + } +} + +// ResultMoneyMessage +// +// @Description: +// @param orderId +// @return *v1.Result +func ResultMoneyMessage(orderId string) *v1.MoneyResult { + return &v1.MoneyResult{ + OrderId: orderId, + } +} + +// MoneyOrderQuery +// +// @Description: +// @param request +// @return structure.MoneyOrder +func MoneyOrderQuery(request *v1.MoneyRequest) structure.MoneyOrder { + return structure.MoneyOrder{ + StockId: request.StockId, + TradeType: request.TradeType, + DealType: request.DealType, + LimitPrice: request.LimitPrice, + MarketPrice: request.MarketPrice, + OrderAmount: request.OrderAmount, + OrderNumber: request.OrderNumber, + EarnestMoney: request.EarnestMoney, + ServiceCost: request.ServiceCost, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + PryNum: request.PryNum, + Type: request.Type, + } +} + +// VerificationSpotsPlaceOrder +// +// @Description: +// @param req +// @return bool +func SharePlaceOrderReply(check bool, err string, orderId string) *v1.MoneyReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.MoneyReply{ + Code: code, + Data: ResultMessage(orderId), + Message: replyStr, + } +} +func ResultMessage(orderId string) *v1.MoneyResult { + return &v1.MoneyResult{ + OrderId: orderId, + } +} diff --git a/internal/service/option/option_inr.go b/internal/service/option/option_inr.go new file mode 100644 index 0000000..4974dcb --- /dev/null +++ b/internal/service/option/option_inr.go @@ -0,0 +1,358 @@ +package option + +import ( + "google.golang.org/protobuf/types/known/timestamppb" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/service/order" + "strconv" + + v1 "matchmaking-system/api/matchmaking/v1/option" + models "matchmaking-system/internal/pkg/model" +) + +// OptionInrCancelReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.OptionInrOrderReply +func OptionInrCancelReply(check bool, err string, req *v1.CancelOptionInrOrderRequest) *v1.OptionInrOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.OptionInrOrderReply{ + Code: code, + Data: ResultOptionInrOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationOptionInrCancel +// +// @Description: +// @param req +// @return bool +func VerificationOptionInrCancel(req *v1.CancelOptionInrOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// OptionInrAllPositionRequest +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.AllOptionInrOrderReply +func OptionInrAllPositionRequest(check bool, err string) *v1.AllOptionInrOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.AllOptionInrOrderReply{ + Code: code, + Data: "", + Message: replyStr, + } +} + +// OptionInrPositionOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.OptionInrOrderReply +func OptionInrPositionOrderReply(check bool, err string, req *v1.CancelOptionInrOrderRequest) *v1.OptionInrOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.OptionInrOrderReply{ + Code: code, + Data: ResultOptionInrOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationOptionInrPosition +// +// @Description: +// @param req +// @return bool +func VerificationOptionInrPosition(req *v1.CancelOptionInrOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// StopOptionInrOrderQuery +// +// @Description: +// @param request +// @return structure.StopOrder +func StopOptionInrOrderQuery(request *v1.UpdateOptionInrOrderRequest) structure.StopOrder { + return structure.StopOrder{ + OrderId: request.OrderId, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + } +} + +// OptionInrUpdateOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.OptionInrOrderReply +func OptionInrUpdateOrderReply(check bool, err string, req *v1.UpdateOptionInrOrderRequest) *v1.OptionInrOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.OptionInrOrderReply{ + Code: code, + Data: ResultOptionInrOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationOptionInrStopOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationOptionInrStopOrderQuery(request *v1.UpdateOptionInrOrderRequest) bool { + if len(request.GetOrderId()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + case 0: + //if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + // return false + //} + return true + default: + return false + } + + return true +} + +// OptionInrOrderQuery +// +// @Description: +// @param request +// @return structure.ShareOrder +func OptionInrOrderQuery(request *v1.OptionInrOrderRequest) structure.ShareOrder { + return structure.ShareOrder{ + StockId: request.StockId, + TradeType: request.TradeType, + DealType: request.DealType, + LimitPrice: request.LimitPrice, + MarketPrice: request.MarketPrice, + MarketMoney: request.MarketMoney, + OrderNumber: request.OrderNumber, + ServiceCost: request.ServiceCost, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + PryNum: request.PryNum, + StrikePrice: request.StrikePrice, + StockCode: request.StockCode, + StopTime: request.StopTime, + Multiplier: request.Multiplier, + TradingType: request.TradingType, + Ask: request.Ask, + Bid: request.Bid, + } +} + +// ResultOptionInrOrderMessage +// +// @Description: +// @param orderId +// @return *v1.OptionInrOrderResult +func ResultOptionInrOrderMessage(orderId string) *v1.OptionInrOrderResult { + return &v1.OptionInrOrderResult{ + OrderId: orderId, + } +} + +// OptionInrPlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param orderId +// @return *v1.OptionInrOrderReply +func OptionInrPlaceOrderReply(check bool, err string, orderId string) *v1.OptionInrOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.OptionInrOrderReply{ + Code: code, + Data: ResultOptionInrOrderMessage(orderId), + Message: replyStr, + } +} + +// VerificationOptionInrOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationOptionInrOrderQuery(request *v1.OptionInrOrderRequest) bool { + if len(request.GetMultiplier()) <= 0 { + return false + } + if len(request.GetStockCode()) <= 0 { + return false + } + if len(request.GetStockId()) <= 0 { + return false + } + if len(request.GetMarketMoney()) <= 0 { + return false + } + if len(request.GetOrderNumber()) <= 0 { + return false + } + if len(request.GetServiceCost()) <= 0 { + return false + } + if len(request.GetStrikePrice()) <= 0 { + return false + } + if len(request.GetStopTime()) <= 0 { + return false + } + if len(request.GetAsk()) <= 0 { + return false + } + if len(request.GetBid()) <= 0 { + return false + } + + switch request.DealType { + case 1: // 限价 + if len(request.GetLimitPrice()) <= 0 { + return false + } + case 2: // 市价 + if len(request.GetMarketPrice()) <= 0 { + return false + } + default: + return false + } + switch request.StopType { + case 1: // 止盈止损 + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + } + switch request.TradeType { + case 1: // 看涨 + case 2: // 看跌 + default: + return false + } + switch request.TradingType { + case 1: // 买入 + case 2: // 卖出 + default: + return false + } + + return true +} + +// BotStockOptionInrTradeMessage +// +// @Description: +// @param stockList +// @return BotInrStockInrTrade +func BotStockOptionInrTradeMessage(stockList []*models.BotStockOptionInrTrade) (stockTrade []*v1.BotStockOptionInrTrade) { + for _, value := range stockList { + stockTrade = append(stockTrade, &v1.BotStockOptionInrTrade{ + OrderId: value.OrderId, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + DealPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + OrderNumber: value.OrderNumber, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + ServiceCost: value.ServiceCost, + MarketMoney: value.MarketMoney, + OrderMoney: value.OrderMoney, + ClosingCost: value.ClosingCost, + Status: int64(value.Status), + CreateTime: timestamppb.New(value.CreateTime), + UpdateTime: timestamppb.New(value.UpdateTime), + OpenTime: timestamppb.New(value.OpenTime), + ClosingTime: timestamppb.New(value.ClosingTime), + KeepDecimal: strconv.Itoa(value.KeepDecimal), + StockName: value.StockName, + PryNum: strconv.Itoa(value.PryNum), + StopTime: value.StopTime, + StrikePrice: value.StrikePrice, + StockCode: value.StockCode, + TradingType: int64(value.TradingType), + Multiplier: int64(value.Multiplier), + CostPrice: value.CostPrice, + Ratio: int64(value.Ratio), + Bid: value.Bid, + Ask: value.Ask, + }) + } + return +} + +// BotStockOptionInrTradeReply +// +// @Description: +// @param check +// @param err +// @param req +// @param data +// @param totalCount +// @return *v1.GetBotStockOptionInrTradeReply +func BotStockOptionInrTradeReply(check bool, err string, req *v1.GetBotStockOptionInrTradeRequest, data []*models.BotStockOptionInrTrade, totalCount int64) *v1.GetBotStockOptionInrTradeReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.GetBotStockOptionInrTradeReply{ + Code: code, + Data: &v1.BotStockOptionInrTradeData{ + PageSize: req.PageSize, + PageCount: req.PageCount, + Data: BotStockOptionInrTradeMessage(data), + TotalCount: totalCount, + }, + Message: replyStr, + } +} + +// VerificationBotStockOptionInrTrade +// +// @Description: +// @param req +// @return bool +func VerificationBotStockOptionInrTrade(req *v1.GetBotStockOptionInrTradeRequest) bool { + if req.GetPageSize() < 0 { + return false + } + if req.GetStatus() < 0 { + return false + } + if req.GetPageCount() < 0 { + return false + } + return true +} diff --git a/internal/service/option_inr.go b/internal/service/option_inr.go new file mode 100644 index 0000000..1d0cb5c --- /dev/null +++ b/internal/service/option_inr.go @@ -0,0 +1,131 @@ +package service + +import ( + "context" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/option" + "matchmaking-system/internal/service/order" + + v1 "matchmaking-system/api/matchmaking/v1/option" +) + +// GetBotStockOptionInrTrade +// +// @Description: 期权印度股订单列表 +// @receiver s +// @param ctx +// @param req +// @return *v1.GetBotStockOptionInrTradeReply +// @return error +func (s *ConduitService) GetBotStockOptionInrTrade(ctx context.Context, req *v1.GetBotStockOptionInrTradeRequest) (*v1.GetBotStockOptionInrTradeReply, error) { + if !option.VerificationBotStockOptionInrTrade(req) { + return option.BotStockOptionInrTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil + } + + stockTradeList, totalCount, err := s.oi.BotStockOptionInrTradeList(ctx, req.PageSize, req.PageCount, req.Status) + if err != nil { + return option.BotStockOptionInrTradeReply(false, err.Error(), req, nil, 0), nil + } + + return option.BotStockOptionInrTradeReply(true, flags.SetNull, req, stockTradeList, totalCount), nil +} + +// OptionInrPlaceOrder +// +// @Description: 期权印度股下单 +// @receiver s +// @param ctx +// @param req +// @return *v1.OptionInrOrderReply +// @return error +func (s *ConduitService) OptionInrPlaceOrder(ctx context.Context, req *v1.OptionInrOrderRequest) (*v1.OptionInrOrderReply, error) { + if !option.VerificationOptionInrOrderQuery(req) { + return option.OptionInrPlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil + } + + orderId, err := s.oi.OptionInrPlaceOrder(ctx, option.OptionInrOrderQuery(req)) + if err != nil { + return option.OptionInrPlaceOrderReply(false, order.CheckShareError(err), flags.SetNull), nil + } + + return option.OptionInrPlaceOrderReply(true, flags.SetNull, orderId), nil +} + +// OptionInrUpdateOrder +// +// @Description: 期权印度股止盈止损 +// @receiver s +// @param ctx +// @param req +// @return *v1.OptionInrOrderReply +// @return error +func (s *ConduitService) OptionInrUpdateOrder(ctx context.Context, req *v1.UpdateOptionInrOrderRequest) (*v1.OptionInrOrderReply, error) { + if !option.VerificationOptionInrStopOrderQuery(req) { + return option.OptionInrUpdateOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.oi.OptionInrUpdateOrder(ctx, option.StopOptionInrOrderQuery(req)) + if err != nil { + return option.OptionInrUpdateOrderReply(false, order.CheckShareError(err), req), nil + } + + return option.OptionInrUpdateOrderReply(true, flags.SetNull, req), nil +} + +// OptionInrCancel +// +// @Description: 期权印度股撤单 +// @receiver s +// @param ctx +// @param req +// @return *v1.OptionInrOrderReply +// @return error +func (s *ConduitService) OptionInrCancel(ctx context.Context, req *v1.CancelOptionInrOrderRequest) (*v1.OptionInrOrderReply, error) { + if !option.VerificationOptionInrCancel(req) { + return option.OptionInrCancelReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.oi.OptionInrCancel(ctx, req.OrderId) + if err != nil { + return option.OptionInrCancelReply(false, order.CheckShareError(err), req), nil + } + + return option.OptionInrCancelReply(true, flags.SetNull, req), nil +} + +// OptionInrPosition +// +// @Description: 期权印度股平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.InrOrderReply +// @return error +func (s *ConduitService) OptionInrPosition(ctx context.Context, req *v1.CancelOptionInrOrderRequest) (*v1.OptionInrOrderReply, error) { + if !option.VerificationOptionInrPosition(req) { + return option.OptionInrPositionOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.oi.OptionInrPosition(ctx, req.OrderId) + if err != nil { + return option.OptionInrPositionOrderReply(false, order.CheckShareError(err), req), nil + } + + return option.OptionInrPositionOrderReply(true, flags.SetNull, req), nil +} + +// OptionInrAllPosition +// +// @Description: 期权印度股一键平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.AllOptionInrOrderReply +// @return error +func (s *ConduitService) OptionInrAllPosition(ctx context.Context, req *v1.AllOptionInrOrderRequest) (*v1.AllOptionInrOrderReply, error) { + if err := s.oi.OptionInrAllPosition(ctx); err != nil { + return option.OptionInrAllPositionRequest(false, order.CheckShareError(err)), nil + } + + return option.OptionInrAllPositionRequest(true, flags.SetNull), nil +} diff --git a/internal/service/order.go b/internal/service/order.go new file mode 100644 index 0000000..7ad5b98 --- /dev/null +++ b/internal/service/order.go @@ -0,0 +1,110 @@ +package service + +import ( + "context" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + + v1 "matchmaking-system/api/matchmaking/v1/order" +) + +// SharePreTrade +// +// @Description: 新股申购下单-开盘服务(美股|泰股|印尼股|马股|印度股|新加坡|港股) +// @receiver s +// @param ctx +// @param req +// @return *v1.SharePreReply +// @return error +func (s *ConduitService) SharePreTrade(ctx context.Context, req *v1.SharePreRequest) (*v1.SharePreReply, error) { + if !order.VerificationSharePreTrade(req) { + return order.SharePreReply(false, flags.ErrIsParameter.Error()), nil + } + + err := s.uo.SharePreTrade(ctx, req.Id, req.Code, req.Stock) + if err != nil { + return order.SharePreReply(false, err.Error()), nil + } + + return order.SharePreReply(true, flags.SetNull), nil +} + +// SharePreTradeByOrderNo +// +// @Description: 新股申购下单-开盘服务(--->订单号)(美股|泰股|印尼股|马股|印度股|新加坡|港股) +// @receiver s +// @param ctx +// @param req +// @return *v1.SharePreReply +// @return error +func (s *ConduitService) SharePreTradeByOrderNo(ctx context.Context, req *v1.SharePreRequest) (*v1.SharePreReply, error) { + if !order.VerificationSharePreTrade(req) { + return order.SharePreReply(false, flags.ErrIsParameter.Error()), nil + } + + err := s.uo.SharePreTradeByOrderOn(ctx, req.Id, req.Code, req.Stock) + if err != nil { + return order.SharePreReply(false, err.Error()), nil + } + + return order.SharePreReply(true, flags.SetNull), nil +} + +// UpdateShareTradeStockId +// +// @Description: 更新股票代码(美股|泰股|印尼股|马股|印度股|新加坡|港股) +// @receiver s +// @param ctx +// @param req +// @return *v1.SharePreReply +// @return error +func (s *ConduitService) UpdateShareTradeStockId(ctx context.Context, req *v1.ShareTradeStockIdRequest) (*v1.SharePreReply, error) { + if !order.VerificationUpdateShareTrade(req) { + return order.SharePreReply(false, flags.ErrIsParameter.Error()), nil + } + + err := s.uo.UpdateShareTradeStockId(ctx, req.Code, req.CodeOld, req.Stock) + if err != nil { + return order.SharePreReply(false, err.Error()), nil + } + + return order.SharePreReply(true, flags.SetNull), nil +} + +// ShareGiveaways +// +// @Description: 股票赠送-(美股|泰股|马股|印尼股|印度股|新加坡股|港股) +// @receiver s +// @param ctx +// @param req +// @return *v1.SharePreReply +// @return error +func (s *ConduitService) ShareGiveaways(ctx context.Context, req *v1.SharePreRequest) (*v1.SharePreReply, error) { + if !order.VerificationSharePreTrade(req) { + return order.SharePreReply(false, flags.ErrIsParameter.Error()), nil + } + + err := s.uo.ShareGiveaways(ctx, req.Id, req.Code, req.Stock) + if err != nil { + return order.SharePreReply(false, err.Error()), nil + } + + return order.SharePreReply(true, flags.SetNull), nil +} + +// UpdateShareAllStockId +// +// @Description: 更新全局股票StockId-[交易所名称:股票代码(BSE:AHINDCOPPER)] +// @receiver s +// @param ctx +// @param req +// @return *v1.SharePreReply +// @return error +func (s *ConduitService) UpdateShareAllStockId(ctx context.Context, req *v1.ShareNullRequest) (*v1.SharePreReply, error) { + err := s.uo.UpdateShareTradeStockIdByList(ctx) + if err != nil { + return order.SharePreReply(false, err.Error()), nil + } + + return order.SharePreReply(true, flags.SetNull), nil +} diff --git a/internal/service/order/order.go b/internal/service/order/order.go new file mode 100644 index 0000000..e9b8c34 --- /dev/null +++ b/internal/service/order/order.go @@ -0,0 +1,134 @@ +package order + +import ( + "matchmaking-system/internal/pkg/flags" + "net/http" + + v1 "matchmaking-system/api/matchmaking/v1/order" +) + +// ResultTokenError +// +// @Description: +// @param err +// @return int +// @return string +func ResultTokenError(err string) (int, string) { + switch err { + case flags.ErrTokenError.Error(): + return http.StatusUnauthorized, flags.ErrTokenMessage.Error() + case flags.ErrTokenMessage.Error(): + return http.StatusUnauthorized, err + case flags.ErrIsReal.Error(): + return http.StatusMethodNotAllowed, err + case flags.ErrIsParameter.Error(): + return http.StatusBadRequest, err + default: + return http.StatusBadRequest, err + } +} + +// VerificationSharePreTrade +// +// @Description: +// @param req +// @return bool +func VerificationSharePreTrade(req *v1.SharePreRequest) bool { + if len(req.GetId()) <= 0 { + return false + } + if len(req.GetCode()) <= 0 { + return false + } + if req.Stock <= 0 { + return false + } + + return true +} + +// VerificationUpdateShareTrade +// +// @Description: +// @param req +// @return bool +func VerificationUpdateShareTrade(req *v1.ShareTradeStockIdRequest) bool { + if len(req.GetCode()) <= 0 { + return false + } + if len(req.GetCodeOld()) <= 0 { + return false + } + if req.Stock <= 0 { + return false + } + + return true +} + +// SharePreReply +// +// @Description: +// @param check +// @param err +// @return *v1.SharePreReply +func SharePreReply(check bool, err string) *v1.SharePreReply { + code, replyStr := ResultCodeSrr(check, err) + + return &v1.SharePreReply{ + Code: code, + Data: "", + Message: replyStr, + } +} + +// ResultCodeSrr +// +// @Description: +// @param check +// @param err +// @return int64 +// @return string +func ResultCodeSrr(check bool, err string) (int64, string) { + var code int + var replyStr string + if !check { + code, replyStr = ResultTokenError(err) + } else { + code = http.StatusOK + replyStr = "successful" + } + return int64(code), replyStr +} + +// CheckShareError +// +// @Description: +// @param err +// @return string +func CheckShareError(err error) string { + switch err.Error() { + //case flags.ErrPosition.Error(): // 报价提示 + // return err.Error() + //case flags.ErrStopTread.Error(): // 休市提示 + // return err.Error() + //case flags.ErrBuyStopWinPrice.Error(): // 限价买涨下单,止盈价格必须大于限价 + // return err.Error() + //case flags.ErrBuyStopLossPrice.Error(): // 限价买涨下单,止损价格必须小于限价 + // return err.Error() + //case flags.ErrSellStopWinPrice.Error(): // 限价买跌下单,止盈价格必须小于限价 + // return err.Error() + //case flags.ErrSellStopLossPrice.Error(): // 限价买跌下单,止损价格必须大于限价 + // return err.Error() + case flags.ErrTokenError.Error(): // token 不存在 + return flags.ErrTokenMessage.Error() + case flags.ErrTokenMessage.Error(): // token 异常 + return flags.ErrTokenMessage.Error() + case flags.ErrIsReal.Error(): // 实名认证 + return flags.ErrIsReal.Error() + //default: // 数据异常提示(数据库,缓存,code异常) + // return flags.ErrMySqlDB.Error() + default: // 数据异常提示(数据库,缓存,code异常) + return err.Error() + } +} diff --git a/internal/service/order/order_test.go b/internal/service/order/order_test.go new file mode 100644 index 0000000..21c6669 --- /dev/null +++ b/internal/service/order/order_test.go @@ -0,0 +1,119 @@ +package order + +import ( + v1 "matchmaking-system/api/matchmaking/v1/order" + "reflect" + "testing" +) + +func TestCheckShareError(t *testing.T) { + type args struct { + err error + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := CheckShareError(tt.args.err); got != tt.want { + t.Errorf("CheckShareError() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestResultCodeSrr(t *testing.T) { + type args struct { + check bool + err string + } + tests := []struct { + name string + args args + want int64 + want1 string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, got1 := ResultCodeSrr(tt.args.check, tt.args.err) + if got != tt.want { + t.Errorf("ResultCodeSrr() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("ResultCodeSrr() got1 = %v, want %v", got1, tt.want1) + } + }) + } +} + +func TestResultTokenError(t *testing.T) { + type args struct { + err string + } + tests := []struct { + name string + args args + want int + want1 string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, got1 := ResultTokenError(tt.args.err) + if got != tt.want { + t.Errorf("ResultTokenError() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("ResultTokenError() got1 = %v, want %v", got1, tt.want1) + } + }) + } +} + +func TestSharePreReply(t *testing.T) { + type args struct { + check bool + err string + } + tests := []struct { + name string + args args + want *v1.SharePreReply + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := SharePreReply(tt.args.check, tt.args.err); !reflect.DeepEqual(got, tt.want) { + t.Errorf("SharePreReply() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestVerificationSharePreTrade(t *testing.T) { + type args struct { + req *v1.SharePreRequest + } + tests := []struct { + name string + args args + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := VerificationSharePreTrade(tt.args.req); got != tt.want { + t.Errorf("VerificationSharePreTrade() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/service/service.go b/internal/service/service.go new file mode 100644 index 0000000..12f2a84 --- /dev/null +++ b/internal/service/service.go @@ -0,0 +1,127 @@ +package service + +import ( + "github.com/go-kratos/kratos/v2/log" + "github.com/google/wire" + "matchmaking-system/internal/biz" + "matchmaking-system/internal/data/sms" + + backend "matchmaking-system/api/matchmaking/v1/backend" + block "matchmaking-system/api/matchmaking/v1/block" + forex "matchmaking-system/api/matchmaking/v1/forex" + money "matchmaking-system/api/matchmaking/v1/money" + option "matchmaking-system/api/matchmaking/v1/option" + order "matchmaking-system/api/matchmaking/v1/order" + share "matchmaking-system/api/matchmaking/v1/share" + virtually "matchmaking-system/api/matchmaking/v1/virtually" +) + +// ProviderSet is service providers. +var ProviderSet = wire.NewSet(NewConduitService) + +// ConduitService +// @Description: +type ConduitService struct { + order.UnimplementedOrderServer + virtually.UnimplementedSpotsServer + virtually.UnimplementedSecondServer + virtually.UnimplementedContractServer + forex.UnimplementedForexServer + money.UnimplementedMoneyServer + share.UnimplementedShareUsServer + share.UnimplementedShareThaServer + share.UnimplementedShareIdnServer + share.UnimplementedShareInrServer + share.UnimplementedShareMysServer + share.UnimplementedShareSgdServer + share.UnimplementedShareHkdServer + share.UnimplementedShareGbxServer + share.UnimplementedShareEurServer + share.UnimplementedShareFurServer + share.UnimplementedShareJpyServer + share.UnimplementedShareBrlServer + block.UnimplementedBlockTradeServer + option.UnimplementedOptionInrServer + backend.UnimplementedBackendServer + + msg *sms.ALiYunCase + uo *biz.UserOrder + so *biz.UserSecondOrder + sp *biz.UserSpotsOrder + co *biz.UserContractOrder + fr *biz.UserForexOrder + mo *biz.UserMoneyOrder + us *biz.UserShareUsOrder + ta *biz.UserShareThaOrder + id *biz.UserShareIdnOrder + in *biz.UserShareInrOrder + my *biz.UserShareMysOrder + sg *biz.UserShareSgdOrder + hd *biz.UserShareHkdOrder + gb *biz.UserShareGbxOrder + eu *biz.UserShareEurOrder + fu *biz.UserShareFurOrder + jp *biz.UserShareJpyOrder + br *biz.UserShareBrlOrder + bl *biz.UserShareBlockOrder + oi *biz.UserOptionInrOrder + ba *biz.UserBackend + log *log.Helper +} + +// NewConduitService +// +// @Description: +// @param msg +// @param uo +// @param logger +// @return *ConduitService +func NewConduitService( + msg *sms.ALiYunCase, + uo *biz.UserOrder, + so *biz.UserSecondOrder, + sp *biz.UserSpotsOrder, + co *biz.UserContractOrder, + fr *biz.UserForexOrder, + mo *biz.UserMoneyOrder, + us *biz.UserShareUsOrder, + ta *biz.UserShareThaOrder, + id *biz.UserShareIdnOrder, + in *biz.UserShareInrOrder, + my *biz.UserShareMysOrder, + sg *biz.UserShareSgdOrder, + hd *biz.UserShareHkdOrder, + gb *biz.UserShareGbxOrder, + eu *biz.UserShareEurOrder, + fu *biz.UserShareFurOrder, + jp *biz.UserShareJpyOrder, + br *biz.UserShareBrlOrder, + bl *biz.UserShareBlockOrder, + oi *biz.UserOptionInrOrder, + ba *biz.UserBackend, + logger log.Logger) *ConduitService { + return &ConduitService{ + msg: msg, + uo: uo, + so: so, + sp: sp, + co: co, + fr: fr, + mo: mo, + us: us, + ta: ta, + id: id, + in: in, + my: my, + sg: sg, + hd: hd, + gb: gb, + eu: eu, + fu: fu, + jp: jp, + br: br, + bl: bl, + oi: oi, + ba: ba, + log: log.NewHelper(logger)} +} diff --git a/internal/service/share/share_brl.go b/internal/service/share/share_brl.go new file mode 100644 index 0000000..8ed2a4a --- /dev/null +++ b/internal/service/share/share_brl.go @@ -0,0 +1,314 @@ +package share + +import ( + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "strconv" + + v1 "matchmaking-system/api/matchmaking/v1/share" + models "matchmaking-system/internal/pkg/model" +) + +// ShareBrlCancelReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.BrlOrderReply +func ShareBrlCancelReply(check bool, err string, req *v1.CancelBrlOrderRequest) *v1.BrlOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.BrlOrderReply{ + Code: code, + Data: ResultBrlOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationBrlShareCancel +// +// @Description: +// @param req +// @return bool +func VerificationBrlShareCancel(req *v1.CancelBrlOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// ShareAllBrlPositionRequest +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.AllBrlOrderReply +func ShareAllBrlPositionRequest(check bool, err string) *v1.AllBrlOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.AllBrlOrderReply{ + Code: code, + Data: "", + Message: replyStr, + } +} + +// ShareBrlPositionOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.BrlOrderReply +func ShareBrlPositionOrderReply(check bool, err string, req *v1.CancelBrlOrderRequest) *v1.BrlOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.BrlOrderReply{ + Code: code, + Data: ResultBrlOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationBrlSharePosition +// +// @Description: +// @param req +// @return bool +func VerificationBrlSharePosition(req *v1.CancelBrlOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// StopBrlOrderQuery +// +// @Description: +// @param request +// @return structure.StopOrder +func StopBrlOrderQuery(request *v1.UpdateBrlOrderRequest) structure.StopOrder { + return structure.StopOrder{ + OrderId: request.OrderId, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + } +} + +// ShareBrlUpdateOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.SgdOrderReply +func ShareBrlUpdateOrderReply(check bool, err string, req *v1.UpdateBrlOrderRequest) *v1.BrlOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.BrlOrderReply{ + Code: code, + Data: ResultBrlOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationBrlStopOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationBrlStopOrderQuery(request *v1.UpdateBrlOrderRequest) bool { + if len(request.GetOrderId()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + case 0: + return true + default: + return false + } + + return true +} + +// ShareBrlOrderQuery +// +// @Description: +// @param request +// @return structure.ShareOrder +func ShareBrlOrderQuery(request *v1.ShareBrlOrderRequest) structure.ShareOrder { + return structure.ShareOrder{ + StockId: request.StockId, + TradeType: request.TradeType, + DealType: request.DealType, + LimitPrice: request.LimitPrice, + MarketPrice: request.MarketPrice, + MarketMoney: request.MarketMoney, + OrderNumber: request.OrderNumber, + ServiceCost: request.ServiceCost, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + PryNum: request.PryNum, + } +} + +// ResultBrlOrderMessage +// +// @Description: +// @param orderId +// @return *v1.SgdOrderResult +func ResultBrlOrderMessage(orderId string) *v1.BrlOrderResult { + return &v1.BrlOrderResult{ + OrderId: orderId, + } +} + +// ShareBrlPlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param orderId +// @return *v1.SgdOrderReply +func ShareBrlPlaceOrderReply(check bool, err string, orderId string) *v1.BrlOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.BrlOrderReply{ + Code: code, + Data: ResultBrlOrderMessage(orderId), + Message: replyStr, + } +} + +// VerificationSgdShareOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationBrlShareOrderQuery(request *v1.ShareBrlOrderRequest) bool { + if len(request.GetStockId()) <= 0 { + return false + } + switch request.DealType { + case 1: + if len(request.GetLimitPrice()) <= 0 { + return false + } + case 2: + if len(request.GetMarketPrice()) <= 0 { + return false + } + default: + return false + } + if len(request.GetMarketMoney()) <= 0 { + return false + } + if len(request.GetOrderNumber()) <= 0 { + return false + } + if len(request.GetServiceCost()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + } + switch request.TradeType { + case 1: + case 2: + default: + return false + } + + return true +} + +// VerificationBrlBotStockTrade +// +// @Description: +// @param req +// @return bool +func VerificationBrlBotStockTrade(req *v1.GetBrlBotStockTradeRequest) bool { + if req.GetPageSize() < 0 { + return false + } + if req.GetStatus() < 0 { + return false + } + if req.GetPageCount() < 0 { + return false + } + return true +} + +// BotStockBrlTradeReply +// +// @Description: +// @param check +// @param err +// @param req +// @param data +// @param totalCount +// @return *v1.GetBotStockBrlTradeReply +func BotStockBrlTradeReply(check bool, err string, req *v1.GetBrlBotStockTradeRequest, data []*models.BotStockBrlTrade, totalCount int64) *v1.GetBotStockBrlTradeReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.GetBotStockBrlTradeReply{ + Code: code, + Data: &v1.BotStockBrlTradeReply{ + PageSize: req.PageSize, + PageCount: req.PageCount, + Data: BotStockBrlTradeMessage(data), + TotalCount: totalCount, + }, + Message: replyStr, + } +} + +// BotStockBrlTradeMessage +// +// @Description: +// @param stockList +// @return BotStockBrlTrade +func BotStockBrlTradeMessage(stockList []*models.BotStockBrlTrade) (stockTrade []*v1.BotStockBrlTrade) { + for _, value := range stockList { + stockTrade = append(stockTrade, &v1.BotStockBrlTrade{ + OrderId: value.OrderId, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + DealPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + OrderNumber: value.OrderNumber, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + ServiceCost: value.ServiceCost, + MarketMoney: value.MarketMoney, + OrderMoney: value.OrderMoney, + ClosingCost: value.ClosingCost, + Status: int64(value.Status), + CreateTime: value.CreateTime.Format(flags.LayoutTime), + UpdateTime: value.UpdateTime.Format(flags.LayoutTime), + OpenTime: value.OpenTime.Format(flags.LayoutTime), + ClosingTime: value.ClosingTime.Format(flags.LayoutTime), + KeepDecimal: strconv.Itoa(value.KeepDecimal), + StockName: value.StockName, + PryNum: strconv.Itoa(value.PryNum), + }) + } + return +} diff --git a/internal/service/share/share_eur.go b/internal/service/share/share_eur.go new file mode 100644 index 0000000..31bc9e2 --- /dev/null +++ b/internal/service/share/share_eur.go @@ -0,0 +1,314 @@ +package share + +import ( + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "strconv" + + v1 "matchmaking-system/api/matchmaking/v1/share" + models "matchmaking-system/internal/pkg/model" +) + +// ShareEurCancelReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.EurOrderReply +func ShareEurCancelReply(check bool, err string, req *v1.CancelEurOrderRequest) *v1.EurOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.EurOrderReply{ + Code: code, + Data: ResultEurOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationEurShareCancel +// +// @Description: +// @param req +// @return bool +func VerificationEurShareCancel(req *v1.CancelEurOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// ShareAllEurPositionRequest +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.AllEurOrderReply +func ShareAllEurPositionRequest(check bool, err string) *v1.AllEurOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.AllEurOrderReply{ + Code: code, + Data: "", + Message: replyStr, + } +} + +// ShareEurPositionOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.EurOrderReply +func ShareEurPositionOrderReply(check bool, err string, req *v1.CancelEurOrderRequest) *v1.EurOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.EurOrderReply{ + Code: code, + Data: ResultEurOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationEurSharePosition +// +// @Description: +// @param req +// @return bool +func VerificationEurSharePosition(req *v1.CancelEurOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// StopEurOrderQuery +// +// @Description: +// @param request +// @return structure.StopOrder +func StopEurOrderQuery(request *v1.UpdateEurOrderRequest) structure.StopOrder { + return structure.StopOrder{ + OrderId: request.OrderId, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + } +} + +// ShareEurUpdateOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.SgdOrderReply +func ShareEurUpdateOrderReply(check bool, err string, req *v1.UpdateEurOrderRequest) *v1.EurOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.EurOrderReply{ + Code: code, + Data: ResultEurOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationEurStopOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationEurStopOrderQuery(request *v1.UpdateEurOrderRequest) bool { + if len(request.GetOrderId()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + case 0: + return true + default: + return false + } + + return true +} + +// ShareEurOrderQuery +// +// @Description: +// @param request +// @return structure.ShareOrder +func ShareEurOrderQuery(request *v1.ShareEurOrderRequest) structure.ShareOrder { + return structure.ShareOrder{ + StockId: request.StockId, + TradeType: request.TradeType, + DealType: request.DealType, + LimitPrice: request.LimitPrice, + MarketPrice: request.MarketPrice, + MarketMoney: request.MarketMoney, + OrderNumber: request.OrderNumber, + ServiceCost: request.ServiceCost, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + PryNum: request.PryNum, + } +} + +// ResultEurOrderMessage +// +// @Description: +// @param orderId +// @return *v1.SgdOrderResult +func ResultEurOrderMessage(orderId string) *v1.EurOrderResult { + return &v1.EurOrderResult{ + OrderId: orderId, + } +} + +// ShareEurPlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param orderId +// @return *v1.SgdOrderReply +func ShareEurPlaceOrderReply(check bool, err string, orderId string) *v1.EurOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.EurOrderReply{ + Code: code, + Data: ResultEurOrderMessage(orderId), + Message: replyStr, + } +} + +// VerificationSgdShareOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationEurShareOrderQuery(request *v1.ShareEurOrderRequest) bool { + if len(request.GetStockId()) <= 0 { + return false + } + switch request.DealType { + case 1: + if len(request.GetLimitPrice()) <= 0 { + return false + } + case 2: + if len(request.GetMarketPrice()) <= 0 { + return false + } + default: + return false + } + if len(request.GetMarketMoney()) <= 0 { + return false + } + if len(request.GetOrderNumber()) <= 0 { + return false + } + if len(request.GetServiceCost()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + } + switch request.TradeType { + case 1: + case 2: + default: + return false + } + + return true +} + +// VerificationEurBotStockTrade +// +// @Description: +// @param req +// @return bool +func VerificationEurBotStockTrade(req *v1.GetEurBotStockTradeRequest) bool { + if req.GetPageSize() < 0 { + return false + } + if req.GetStatus() < 0 { + return false + } + if req.GetPageCount() < 0 { + return false + } + return true +} + +// BotStockEurTradeReply +// +// @Description: +// @param check +// @param err +// @param req +// @param data +// @param totalCount +// @return *v1.GetBotStockEurTradeReply +func BotStockEurTradeReply(check bool, err string, req *v1.GetEurBotStockTradeRequest, data []*models.BotStockEurTrade, totalCount int64) *v1.GetBotStockEurTradeReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.GetBotStockEurTradeReply{ + Code: code, + Data: &v1.BotStockEurTradeReply{ + PageSize: req.PageSize, + PageCount: req.PageCount, + Data: BotStockEurTradeMessage(data), + TotalCount: totalCount, + }, + Message: replyStr, + } +} + +// BotStockEurTradeMessage +// +// @Description: +// @param stockList +// @return BotStockEurTrade +func BotStockEurTradeMessage(stockList []*models.BotStockEurTrade) (stockTrade []*v1.BotStockEurTrade) { + for _, value := range stockList { + stockTrade = append(stockTrade, &v1.BotStockEurTrade{ + OrderId: value.OrderId, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + DealPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + OrderNumber: value.OrderNumber, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + ServiceCost: value.ServiceCost, + MarketMoney: value.MarketMoney, + OrderMoney: value.OrderMoney, + ClosingCost: value.ClosingCost, + Status: int64(value.Status), + CreateTime: value.CreateTime.Format(flags.LayoutTime), + UpdateTime: value.UpdateTime.Format(flags.LayoutTime), + OpenTime: value.OpenTime.Format(flags.LayoutTime), + ClosingTime: value.ClosingTime.Format(flags.LayoutTime), + KeepDecimal: strconv.Itoa(value.KeepDecimal), + StockName: value.StockName, + PryNum: strconv.Itoa(value.PryNum), + }) + } + return +} diff --git a/internal/service/share/share_fur.go b/internal/service/share/share_fur.go new file mode 100644 index 0000000..a53b922 --- /dev/null +++ b/internal/service/share/share_fur.go @@ -0,0 +1,314 @@ +package share + +import ( + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "strconv" + + v1 "matchmaking-system/api/matchmaking/v1/share" + models "matchmaking-system/internal/pkg/model" +) + +// ShareFurCancelReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.EurOrderReply +func ShareFurCancelReply(check bool, err string, req *v1.CancelFurOrderRequest) *v1.FurOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.FurOrderReply{ + Code: code, + Data: ResultFurOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationFurShareCancel +// +// @Description: +// @param req +// @return bool +func VerificationFurShareCancel(req *v1.CancelFurOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// ShareAllFurPositionRequest +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.AllEurOrderReply +func ShareAllFurPositionRequest(check bool, err string) *v1.AllFurOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.AllFurOrderReply{ + Code: code, + Data: "", + Message: replyStr, + } +} + +// ShareFurPositionOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.EurOrderReply +func ShareFurPositionOrderReply(check bool, err string, req *v1.CancelFurOrderRequest) *v1.FurOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.FurOrderReply{ + Code: code, + Data: ResultFurOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationFurSharePosition +// +// @Description: +// @param req +// @return bool +func VerificationFurSharePosition(req *v1.CancelFurOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// StopEurOrderQuery +// +// @Description: +// @param request +// @return structure.StopOrder +func StopFurOrderQuery(request *v1.UpdateFurOrderRequest) structure.StopOrder { + return structure.StopOrder{ + OrderId: request.OrderId, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + } +} + +// ShareFurUpdateOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.SgdOrderReply +func ShareFurUpdateOrderReply(check bool, err string, req *v1.UpdateFurOrderRequest) *v1.FurOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.FurOrderReply{ + Code: code, + Data: ResultFurOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationFurStopOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationFurStopOrderQuery(request *v1.UpdateFurOrderRequest) bool { + if len(request.GetOrderId()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + case 0: + return true + default: + return false + } + + return true +} + +// ShareFurOrderQuery +// +// @Description: +// @param request +// @return structure.ShareOrder +func ShareFurOrderQuery(request *v1.ShareFurOrderRequest) structure.ShareOrder { + return structure.ShareOrder{ + StockId: request.StockId, + TradeType: request.TradeType, + DealType: request.DealType, + LimitPrice: request.LimitPrice, + MarketPrice: request.MarketPrice, + MarketMoney: request.MarketMoney, + OrderNumber: request.OrderNumber, + ServiceCost: request.ServiceCost, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + PryNum: request.PryNum, + } +} + +// ResultFurOrderMessage +// +// @Description: +// @param orderId +// @return *v1.FurOrderResult +func ResultFurOrderMessage(orderId string) *v1.FurOrderResult { + return &v1.FurOrderResult{ + OrderId: orderId, + } +} + +// ShareFurPlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param orderId +// @return *v1.FurOrderReply +func ShareFurPlaceOrderReply(check bool, err string, orderId string) *v1.FurOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.FurOrderReply{ + Code: code, + Data: ResultFurOrderMessage(orderId), + Message: replyStr, + } +} + +// VerificationSgdShareOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationFurShareOrderQuery(request *v1.ShareFurOrderRequest) bool { + if len(request.GetStockId()) <= 0 { + return false + } + switch request.DealType { + case 1: + if len(request.GetLimitPrice()) <= 0 { + return false + } + case 2: + if len(request.GetMarketPrice()) <= 0 { + return false + } + default: + return false + } + if len(request.GetMarketMoney()) <= 0 { + return false + } + if len(request.GetOrderNumber()) <= 0 { + return false + } + if len(request.GetServiceCost()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + } + switch request.TradeType { + case 1: + case 2: + default: + return false + } + + return true +} + +// VerificationFurBotStockTrade +// +// @Description: +// @param req +// @return bool +func VerificationFurBotStockTrade(req *v1.GetFurBotStockTradeRequest) bool { + if req.GetPageSize() < 0 { + return false + } + if req.GetStatus() < 0 { + return false + } + if req.GetPageCount() < 0 { + return false + } + return true +} + +// BotStockFurTradeReply +// +// @Description: +// @param check +// @param err +// @param req +// @param data +// @param totalCount +// @return *v1.GetBotStockEurTradeReply +func BotStockFurTradeReply(check bool, err string, req *v1.GetFurBotStockTradeRequest, data []*models.BotStockFurTrade, totalCount int64) *v1.GetBotStockFurTradeReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.GetBotStockFurTradeReply{ + Code: code, + Data: &v1.BotStockFurTradeReply{ + PageSize: req.PageSize, + PageCount: req.PageCount, + Data: BotStockFurTradeMessage(data), + TotalCount: totalCount, + }, + Message: replyStr, + } +} + +// BotStockEurTradeMessage +// +// @Description: +// @param stockList +// @return BotStockEurTrade +func BotStockFurTradeMessage(stockList []*models.BotStockFurTrade) (stockTrade []*v1.BotStockFurTrade) { + for _, value := range stockList { + stockTrade = append(stockTrade, &v1.BotStockFurTrade{ + OrderId: value.OrderId, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + DealPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + OrderNumber: value.OrderNumber, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + ServiceCost: value.ServiceCost, + MarketMoney: value.MarketMoney, + OrderMoney: value.OrderMoney, + ClosingCost: value.ClosingCost, + Status: int64(value.Status), + CreateTime: value.CreateTime.Format(flags.LayoutTime), + UpdateTime: value.UpdateTime.Format(flags.LayoutTime), + OpenTime: value.OpenTime.Format(flags.LayoutTime), + ClosingTime: value.ClosingTime.Format(flags.LayoutTime), + KeepDecimal: strconv.Itoa(value.KeepDecimal), + StockName: value.StockName, + PryNum: strconv.Itoa(value.PryNum), + }) + } + return +} diff --git a/internal/service/share/share_gbx.go b/internal/service/share/share_gbx.go new file mode 100644 index 0000000..6f2b165 --- /dev/null +++ b/internal/service/share/share_gbx.go @@ -0,0 +1,316 @@ +package share + +import ( + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "strconv" + + v1 "matchmaking-system/api/matchmaking/v1/share" + models "matchmaking-system/internal/pkg/model" +) + +// ShareGbxCancelReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.OrderGbxReply +func ShareGbxCancelReply(check bool, err string, req *v1.CancelGbxOrderRequest) *v1.OrderGbxReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.OrderGbxReply{ + Code: code, + Data: ResultGbxOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationGbxShareCancel +// +// @Description: +// @param req +// @return bool +func VerificationGbxShareCancel(req *v1.CancelGbxOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// ShareAllGbxPositionRequest +// +// @Description: +// @param check +// @param err +// @return *v1.AllGbxOrderReply +func ShareAllGbxPositionRequest(check bool, err string) *v1.AllGbxOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.AllGbxOrderReply{ + Code: code, + Data: "", + Message: replyStr, + } +} + +// ShareGbxPositionOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.OrderGbxReply +func ShareGbxPositionOrderReply(check bool, err string, req *v1.CancelGbxOrderRequest) *v1.OrderGbxReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.OrderGbxReply{ + Code: code, + Data: ResultGbxOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationGbxSharePosition +// +// @Description: +// @param req +// @return bool +func VerificationGbxSharePosition(req *v1.CancelGbxOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// StopGbxOrderQuery +// +// @Description: +// @param request +// @return structure.StopOrder +func StopGbxOrderQuery(request *v1.UpdateGbxOrderRequest) structure.StopOrder { + return structure.StopOrder{ + OrderId: request.OrderId, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + } +} + +// ShareGbxUpdateOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.OrderGbxReply +func ShareGbxUpdateOrderReply(check bool, err string, req *v1.UpdateGbxOrderRequest) *v1.OrderGbxReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.OrderGbxReply{ + Code: code, + Data: ResultGbxOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationGbxStopOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationGbxStopOrderQuery(request *v1.UpdateGbxOrderRequest) bool { + if len(request.GetOrderId()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + case 0: + //if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + // return false + //} + return true + default: + return false + } + + return true +} + +// ShareGbxOrderQuery +// +// @Description: +// @param request +// @return structure.ShareOrder +func ShareGbxOrderQuery(request *v1.OrderGbxRequest) structure.ShareOrder { + return structure.ShareOrder{ + StockId: request.StockId, + TradeType: request.TradeType, + DealType: request.DealType, + LimitPrice: request.LimitPrice, + MarketPrice: request.MarketPrice, + MarketMoney: request.MarketMoney, + OrderNumber: request.OrderNumber, + ServiceCost: request.ServiceCost, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + PryNum: request.PryNum, + } +} + +// ResultGbxOrderMessage +// +// @Description: +// @param orderId +// @return *v1.OrderGbxResult +func ResultGbxOrderMessage(orderId string) *v1.OrderGbxResult { + return &v1.OrderGbxResult{ + OrderId: orderId, + } +} + +// ShareGbxPlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param orderId +// @return *v1.OrderGbxReply +func ShareGbxPlaceOrderReply(check bool, err string, orderId string) *v1.OrderGbxReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.OrderGbxReply{ + Code: code, + Data: ResultGbxOrderMessage(orderId), + Message: replyStr, + } +} + +// VerificationGbxShareOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationGbxShareOrderQuery(request *v1.OrderGbxRequest) bool { + if len(request.GetStockId()) <= 0 { + return false + } + switch request.DealType { + case 1: + if len(request.GetLimitPrice()) <= 0 { + return false + } + case 2: + if len(request.GetMarketPrice()) <= 0 { + return false + } + default: + return false + } + if len(request.GetMarketMoney()) <= 0 { + return false + } + if len(request.GetOrderNumber()) <= 0 { + return false + } + if len(request.GetServiceCost()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + } + switch request.TradeType { + case 1: + case 2: + default: + return false + } + + return true +} + +// VerificationGbxBotStockTrade +// +// @Description: +// @param req +// @return bool +func VerificationGbxBotStockTrade(req *v1.GetBotStockGbxTradeRequest) bool { + if req.GetPageSize() < 0 { + return false + } + if req.GetStatus() < 0 { + return false + } + if req.GetPageCount() < 0 { + return false + } + return true +} + +// BotStockGbxTradeReply +// +// @Description: +// @param check +// @param err +// @param req +// @param data +// @param totalCount +// @return *v1.GetBotStockGbxTradeReply +func BotStockGbxTradeReply(check bool, err string, req *v1.GetBotStockGbxTradeRequest, data []*models.BotStockGbxTrade, totalCount int64) *v1.GetBotStockGbxTradeReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.GetBotStockGbxTradeReply{ + Code: code, + Data: &v1.BotStockGbxTradeData{ + PageSize: req.PageSize, + PageCount: req.PageCount, + Data: BotStockGbxTradeMessage(data), + TotalCount: totalCount, + }, + Message: replyStr, + } +} + +// BotStockGbxTradeMessage +// +// @Description: +// @param stockList +// @return stockTrade +func BotStockGbxTradeMessage(stockList []*models.BotStockGbxTrade) (stockTrade []*v1.BotOrderGbxTrade) { + for _, value := range stockList { + stockTrade = append(stockTrade, &v1.BotOrderGbxTrade{ + OrderId: value.OrderId, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + DealPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + OrderNumber: value.OrderNumber, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + ServiceCost: value.ServiceCost, + MarketMoney: value.MarketMoney, + OrderMoney: value.OrderMoney, + ClosingCost: value.ClosingCost, + Status: int64(value.Status), + CreateTime: value.CreateTime.Format(flags.LayoutTime), + UpdateTime: value.UpdateTime.Format(flags.LayoutTime), + OpenTime: value.OpenTime.Format(flags.LayoutTime), + ClosingTime: value.ClosingTime.Format(flags.LayoutTime), + KeepDecimal: strconv.Itoa(value.KeepDecimal), + StockName: value.StockName, + PryNum: strconv.Itoa(value.PryNum), + }) + } + return +} diff --git a/internal/service/share/share_hkd.go b/internal/service/share/share_hkd.go new file mode 100644 index 0000000..a7963c1 --- /dev/null +++ b/internal/service/share/share_hkd.go @@ -0,0 +1,317 @@ +package share + +import ( + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "strconv" + + v1 "matchmaking-system/api/matchmaking/v1/share" + models "matchmaking-system/internal/pkg/model" +) + +// ShareHkdCancelReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.UsOrderReply +func ShareHkdCancelReply(check bool, err string, req *v1.CancelHkdOrderRequest) *v1.OrderHkdReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.OrderHkdReply{ + Code: code, + Data: ResultHkdOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationShareHkdCancel +// +// @Description: +// @param req +// @return bool +func VerificationShareHkdCancel(req *v1.CancelHkdOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// ShareHkdAllPositionRequest +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.AllHkdOrderReply +func ShareHkdAllPositionRequest(check bool, err string) *v1.AllHkdOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.AllHkdOrderReply{ + Code: code, + Data: "", + Message: replyStr, + } +} + +// ShareHkdPositionOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.UsOrderReply +func ShareHkdPositionOrderReply(check bool, err string, req *v1.CancelHkdOrderRequest) *v1.OrderHkdReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.OrderHkdReply{ + Code: code, + Data: ResultHkdOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationShareHkdPosition +// +// @Description: +// @param req +// @return bool +func VerificationShareHkdPosition(req *v1.CancelHkdOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// StopOrderHkdQuery +// +// @Description: +// @param request +// @return structure.StopOrder +func StopOrderHkdQuery(request *v1.UpdateHkdOrderRequest) structure.StopOrder { + return structure.StopOrder{ + OrderId: request.OrderId, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + } +} + +// ShareHkdUpdateOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.UsOrderReply +func ShareHkdUpdateOrderReply(check bool, err string, req *v1.UpdateHkdOrderRequest) *v1.OrderHkdReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.OrderHkdReply{ + Code: code, + Data: ResultHkdOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationStopOrderHkdQuery +// +// @Description: +// @param request +// @return bool +func VerificationStopOrderHkdQuery(request *v1.UpdateHkdOrderRequest) bool { + if len(request.GetOrderId()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + case 0: + //if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + // return false + //} + return true + default: + return false + } + + return true +} + +// ShareHkdOrderQuery +// +// @Description: +// @param request +// @return structure.ShareOrder +func ShareHkdOrderQuery(request *v1.OrderHkdRequest) structure.ShareOrder { + return structure.ShareOrder{ + StockId: request.StockId, + TradeType: request.TradeType, + DealType: request.DealType, + LimitPrice: request.LimitPrice, + MarketPrice: request.MarketPrice, + MarketMoney: request.MarketMoney, + OrderNumber: request.OrderNumber, + ServiceCost: request.ServiceCost, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + PryNum: request.PryNum, + } +} + +// ShareHkdPlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param orderId +// @return *v1.UsOrderReply +func ShareHkdPlaceOrderReply(check bool, err string, orderId string) *v1.OrderHkdReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.OrderHkdReply{ + Code: code, + Data: ResultHkdOrderMessage(orderId), + Message: replyStr, + } +} + +// ResultUsOrderMessage +// +// @Description: +// @param orderId +// @return *v1.UsOrderResult +func ResultHkdOrderMessage(orderId string) *v1.OrderHkdResult { + return &v1.OrderHkdResult{ + OrderId: orderId, + } +} + +// VerificationShareHkdOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationShareHkdOrderQuery(request *v1.OrderHkdRequest) bool { + if len(request.GetStockId()) <= 0 { + return false + } + switch request.DealType { + case 1: + if len(request.GetLimitPrice()) <= 0 { + return false + } + case 2: + if len(request.GetMarketPrice()) <= 0 { + return false + } + default: + return false + } + if len(request.GetMarketMoney()) <= 0 { + return false + } + if len(request.GetOrderNumber()) <= 0 { + return false + } + if len(request.GetServiceCost()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + } + switch request.TradeType { + case 1: + case 2: + default: + return false + } + + return true +} + +// VerificationBotStockHkdTrade +// +// @Description: +// @param req +// @return bool +func VerificationBotStockHkdTrade(req *v1.GetBotStockHkdTradeRequest) bool { + if req.GetPageSize() < 0 { + return false + } + if req.GetStatus() < 0 { + return false + } + if req.GetPageCount() < 0 { + return false + } + return true +} + +// BotStockHkdTradeReply +// +// @Description: +// @param check +// @param err +// @param req +// @param data +// @param totalCount +// @return *v1.GetUsBotStockTradeReply +func BotStockHkdTradeReply(check bool, err string, req *v1.GetBotStockHkdTradeRequest, data []*models.BotStockHkdTrade, totalCount int64) *v1.GetBotStockHkdTradeReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.GetBotStockHkdTradeReply{ + Code: code, + Data: &v1.BotStockHkdTradeData{ + PageSize: req.PageSize, + PageCount: req.PageCount, + Data: BotStockHkdTradeMessage(data), + TotalCount: totalCount, + }, + Message: replyStr, + } +} + +// BotStockTradeMessage +// +// @Description: +// @param stockList +// @return BotUsOrderTrade +func BotStockHkdTradeMessage(stockList []*models.BotStockHkdTrade) (stockTrade []*v1.BotOrderHkdTrade) { + for _, value := range stockList { + stockTrade = append(stockTrade, &v1.BotOrderHkdTrade{ + OrderId: value.OrderId, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + DealPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + OrderNumber: value.OrderNumber, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + ServiceCost: value.ServiceCost, + MarketMoney: value.MarketMoney, + OrderMoney: value.OrderMoney, + ClosingCost: value.ClosingCost, + Status: int64(value.Status), + CreateTime: value.CreateTime.Format(flags.LayoutTime), + UpdateTime: value.UpdateTime.Format(flags.LayoutTime), + OpenTime: value.OpenTime.Format(flags.LayoutTime), + ClosingTime: value.ClosingTime.Format(flags.LayoutTime), + KeepDecimal: strconv.Itoa(value.KeepDecimal), + StockName: value.StockName, + PryNum: strconv.Itoa(value.PryNum), + }) + } + return +} diff --git a/internal/service/share/share_idn.go b/internal/service/share/share_idn.go new file mode 100644 index 0000000..3df2ce6 --- /dev/null +++ b/internal/service/share/share_idn.go @@ -0,0 +1,317 @@ +package share + +import ( + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "strconv" + + v1 "matchmaking-system/api/matchmaking/v1/share" + models "matchmaking-system/internal/pkg/model" +) + +// ShareIdnCancelReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.IdnOrderReply +func ShareIdnCancelReply(check bool, err string, req *v1.CancelIdnOrderRequest) *v1.IdnOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.IdnOrderReply{ + Code: code, + Data: ResultIdnOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationIdnShareCancel +// +// @Description: +// @param req +// @return bool +func VerificationIdnShareCancel(req *v1.CancelIdnOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// ShareIdnAllPositionRequest +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.AllIdnOrderReply +func ShareIdnAllPositionRequest(check bool, err string) *v1.AllIdnOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.AllIdnOrderReply{ + Code: code, + Data: "", + Message: replyStr, + } +} + +// ShareIdnPositionOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.IdnOrderReply +func ShareIdnPositionOrderReply(check bool, err string, req *v1.CancelIdnOrderRequest) *v1.IdnOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.IdnOrderReply{ + Code: code, + Data: ResultIdnOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationIdnSharePosition +// +// @Description: +// @param req +// @return bool +func VerificationIdnSharePosition(req *v1.CancelIdnOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// StopIdnOrderQuery +// +// @Description: +// @param request +// @return structure.StopOrder +func StopIdnOrderQuery(request *v1.UpdateIdnOrderRequest) structure.StopOrder { + return structure.StopOrder{ + OrderId: request.OrderId, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + } +} + +// ShareIdnUpdateOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.IdnOrderReply +func ShareIdnUpdateOrderReply(check bool, err string, req *v1.UpdateIdnOrderRequest) *v1.IdnOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.IdnOrderReply{ + Code: code, + Data: ResultIdnOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationIdnStopOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationIdnStopOrderQuery(request *v1.UpdateIdnOrderRequest) bool { + if len(request.GetOrderId()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + case 0: + //if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + // return false + //} + return true + default: + return false + } + + return true +} + +// ShareIdnOrderQuery +// +// @Description: +// @param request +// @return structure.ShareOrder +func ShareIdnOrderQuery(request *v1.ShareIdnOrderRequest) structure.ShareOrder { + return structure.ShareOrder{ + StockId: request.StockId, + TradeType: request.TradeType, + DealType: request.DealType, + LimitPrice: request.LimitPrice, + MarketPrice: request.MarketPrice, + MarketMoney: request.MarketMoney, + OrderNumber: request.OrderNumber, + ServiceCost: request.ServiceCost, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + PryNum: request.PryNum, + } +} + +// ResultIdnOrderMessage +// +// @Description: +// @param orderId +// @return *v1.IdnOrderResult +func ResultIdnOrderMessage(orderId string) *v1.IdnOrderResult { + return &v1.IdnOrderResult{ + OrderId: orderId, + } +} + +// ShareIdnPlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param orderId +// @return *v1.IdnOrderReply +func ShareIdnPlaceOrderReply(check bool, err string, orderId string) *v1.IdnOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.IdnOrderReply{ + Code: code, + Data: ResultIdnOrderMessage(orderId), + Message: replyStr, + } +} + +// VerificationIdnShareOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationIdnShareOrderQuery(request *v1.ShareIdnOrderRequest) bool { + if len(request.StockId) <= 0 { + return false + } + switch request.DealType { + case 1: + if len(request.GetLimitPrice()) <= 0 { + return false + } + case 2: + if len(request.GetMarketPrice()) <= 0 { + return false + } + default: + return false + } + if len(request.GetMarketMoney()) <= 0 { + return false + } + if len(request.GetOrderNumber()) <= 0 { + return false + } + if len(request.GetServiceCost()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + } + switch request.TradeType { + case 1: + case 2: + default: + return false + } + + return true +} + +// BotStockIdnTradeMessage +// +// @Description: +// @param stockList +// @return BotIdnStockIdnTrade +func BotStockIdnTradeMessage(stockList []*models.BotStockIdnTrade) (stockTrade []*v1.BotStockIdnTrade) { + for _, value := range stockList { + stockTrade = append(stockTrade, &v1.BotStockIdnTrade{ + OrderId: value.OrderId, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + DealPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + OrderNumber: value.OrderNumber, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + ServiceCost: value.ServiceCost, + MarketMoney: value.MarketMoney, + OrderMoney: value.OrderMoney, + ClosingCost: value.ClosingCost, + Status: int64(value.Status), + CreateTime: value.CreateTime.Format(flags.LayoutTime), + UpdateTime: value.UpdateTime.Format(flags.LayoutTime), + OpenTime: value.OpenTime.Format(flags.LayoutTime), + ClosingTime: value.ClosingTime.Format(flags.LayoutTime), + KeepDecimal: strconv.Itoa(value.KeepDecimal), + StockName: value.StockName, + PryNum: strconv.Itoa(value.PryNum), + }) + } + return +} + +// VerificationIdnBotStockTrade +// +// @Description: +// @param req +// @return bool +func VerificationIdnBotStockTrade(req *v1.GetIdnBotStockTradeRequest) bool { + if req.GetPageSize() < 0 { + return false + } + if req.GetStatus() < 0 { + return false + } + if req.GetPageCount() < 0 { + return false + } + return true +} + +// BotStockIdnTradeReply +// +// @Description: +// @param check +// @param err +// @param req +// @param data +// @param totalCount +// @return *v1.GetIdnBotStockIdnTradeReply +func BotStockIdnTradeReply(check bool, err string, req *v1.GetIdnBotStockTradeRequest, data []*models.BotStockIdnTrade, totalCount int64) *v1.GetBotStockIdnTradeReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.GetBotStockIdnTradeReply{ + Code: code, + Data: &v1.BotStockIdnTradeData{ + PageSize: req.PageSize, + PageCount: req.PageCount, + Data: BotStockIdnTradeMessage(data), + TotalCount: totalCount, + }, + Message: replyStr, + } +} diff --git a/internal/service/share/share_inr.go b/internal/service/share/share_inr.go new file mode 100644 index 0000000..0bd0fc2 --- /dev/null +++ b/internal/service/share/share_inr.go @@ -0,0 +1,317 @@ +package share + +import ( + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "strconv" + + v1 "matchmaking-system/api/matchmaking/v1/share" + models "matchmaking-system/internal/pkg/model" +) + +// ShareInrCancelReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.InrOrderReply +func ShareInrCancelReply(check bool, err string, req *v1.CancelInrOrderRequest) *v1.InrOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.InrOrderReply{ + Code: code, + Data: ResultInrOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationInrShareCancel +// +// @Description: +// @param req +// @return bool +func VerificationInrShareCancel(req *v1.CancelInrOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// ShareInrAllPositionRequest +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.AllInrOrderReply +func ShareInrAllPositionRequest(check bool, err string) *v1.AllInrOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.AllInrOrderReply{ + Code: code, + Data: "", + Message: replyStr, + } +} + +// ShareInrPositionOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.InrOrderReply +func ShareInrPositionOrderReply(check bool, err string, req *v1.CancelInrOrderRequest) *v1.InrOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.InrOrderReply{ + Code: code, + Data: ResultInrOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationInrSharePosition +// +// @Description: +// @param req +// @return bool +func VerificationInrSharePosition(req *v1.CancelInrOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// StopInrOrderQuery +// +// @Description: +// @param request +// @return structure.StopOrder +func StopInrOrderQuery(request *v1.UpdateInrOrderRequest) structure.StopOrder { + return structure.StopOrder{ + OrderId: request.OrderId, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + } +} + +// ShareInrUpdateOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.InrOrderReply +func ShareInrUpdateOrderReply(check bool, err string, req *v1.UpdateInrOrderRequest) *v1.InrOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.InrOrderReply{ + Code: code, + Data: ResultInrOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationInrStopOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationInrStopOrderQuery(request *v1.UpdateInrOrderRequest) bool { + if len(request.GetOrderId()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + case 0: + //if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + // return false + //} + return true + default: + return false + } + + return true +} + +// ShareInrOrderQuery +// +// @Description: +// @param request +// @return structure.ShareOrder +func ShareInrOrderQuery(request *v1.ShareInrOrderRequest) structure.ShareOrder { + return structure.ShareOrder{ + StockId: request.StockId, + TradeType: request.TradeType, + DealType: request.DealType, + LimitPrice: request.LimitPrice, + MarketPrice: request.MarketPrice, + MarketMoney: request.MarketMoney, + OrderNumber: request.OrderNumber, + ServiceCost: request.ServiceCost, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + PryNum: request.PryNum, + } +} + +// ResultInrOrderMessage +// +// @Description: +// @param orderId +// @return *v1.InrOrderResult +func ResultInrOrderMessage(orderId string) *v1.InrOrderResult { + return &v1.InrOrderResult{ + OrderId: orderId, + } +} + +// ShareInrPlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param orderId +// @return *v1.InrOrderReply +func ShareInrPlaceOrderReply(check bool, err string, orderId string) *v1.InrOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.InrOrderReply{ + Code: code, + Data: ResultInrOrderMessage(orderId), + Message: replyStr, + } +} + +// VerificationInrShareOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationInrShareOrderQuery(request *v1.ShareInrOrderRequest) bool { + if len(request.GetStockId()) <= 0 { + return false + } + switch request.DealType { + case 1: + if len(request.GetLimitPrice()) <= 0 { + return false + } + case 2: + if len(request.GetMarketPrice()) <= 0 { + return false + } + default: + return false + } + if len(request.GetMarketMoney()) <= 0 { + return false + } + if len(request.GetOrderNumber()) <= 0 { + return false + } + if len(request.GetServiceCost()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + } + switch request.TradeType { + case 1: + case 2: + default: + return false + } + + return true +} + +// BotStockInrTradeMessage +// +// @Description: +// @param stockList +// @return BotInrStockInrTrade +func BotStockInrTradeMessage(stockList []*models.BotStockInTrade) (stockTrade []*v1.BotStockInrTrade) { + for _, value := range stockList { + stockTrade = append(stockTrade, &v1.BotStockInrTrade{ + OrderId: value.OrderId, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + DealPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + OrderNumber: value.OrderNumber, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + ServiceCost: value.ServiceCost, + MarketMoney: value.MarketMoney, + OrderMoney: value.OrderMoney, + ClosingCost: value.ClosingCost, + Status: int64(value.Status), + CreateTime: value.CreateTime.Format(flags.LayoutTime), + UpdateTime: value.UpdateTime.Format(flags.LayoutTime), + OpenTime: value.OpenTime.Format(flags.LayoutTime), + ClosingTime: value.ClosingTime.Format(flags.LayoutTime), + KeepDecimal: strconv.Itoa(value.KeepDecimal), + StockName: value.StockName, + PryNum: strconv.Itoa(value.PryNum), + }) + } + return +} + +// BotStockInrTradeReply +// +// @Description: +// @param check +// @param err +// @param req +// @param data +// @param totalCount +// @return *v1.GetInrBotStockInrTradeReply +func BotStockInrTradeReply(check bool, err string, req *v1.GetInrBotStockTradeRequest, data []*models.BotStockInTrade, totalCount int64) *v1.GetBotStockInrTradeReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.GetBotStockInrTradeReply{ + Code: code, + Data: &v1.BotStockInrTradeData{ + PageSize: req.PageSize, + PageCount: req.PageCount, + Data: BotStockInrTradeMessage(data), + TotalCount: totalCount, + }, + Message: replyStr, + } +} + +// VerificationInrBotStockTrade +// +// @Description: +// @param req +// @return bool +func VerificationInrBotStockTrade(req *v1.GetInrBotStockTradeRequest) bool { + if req.GetPageSize() < 0 { + return false + } + if req.GetStatus() < 0 { + return false + } + if req.GetPageCount() < 0 { + return false + } + return true +} diff --git a/internal/service/share/share_jpy.go b/internal/service/share/share_jpy.go new file mode 100644 index 0000000..dd218ed --- /dev/null +++ b/internal/service/share/share_jpy.go @@ -0,0 +1,314 @@ +package share + +import ( + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "strconv" + + v1 "matchmaking-system/api/matchmaking/v1/share" + models "matchmaking-system/internal/pkg/model" +) + +// ShareJpyCancelReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.EurOrderReply +func ShareJpyCancelReply(check bool, err string, req *v1.CancelJpyOrderRequest) *v1.JpyOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.JpyOrderReply{ + Code: code, + Data: ResultJpyOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationJpyShareCancel +// +// @Description: +// @param req +// @return bool +func VerificationJpyShareCancel(req *v1.CancelJpyOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// ShareAllJpyPositionRequest +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.AllEurOrderReply +func ShareAllJpyPositionRequest(check bool, err string) *v1.AllJpyOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.AllJpyOrderReply{ + Code: code, + Data: "", + Message: replyStr, + } +} + +// ShareJpyPositionOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.EurOrderReply +func ShareJpyPositionOrderReply(check bool, err string, req *v1.CancelJpyOrderRequest) *v1.JpyOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.JpyOrderReply{ + Code: code, + Data: ResultJpyOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationJpySharePosition +// +// @Description: +// @param req +// @return bool +func VerificationJpySharePosition(req *v1.CancelJpyOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// StopEurOrderQuery +// +// @Description: +// @param request +// @return structure.StopOrder +func StopJpyOrderQuery(request *v1.UpdateJpyOrderRequest) structure.StopOrder { + return structure.StopOrder{ + OrderId: request.OrderId, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + } +} + +// ShareJpyUpdateOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.SgdOrderReply +func ShareJpyUpdateOrderReply(check bool, err string, req *v1.UpdateJpyOrderRequest) *v1.JpyOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.JpyOrderReply{ + Code: code, + Data: ResultJpyOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationJpyStopOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationJpyStopOrderQuery(request *v1.UpdateJpyOrderRequest) bool { + if len(request.GetOrderId()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + case 0: + return true + default: + return false + } + + return true +} + +// ShareJpyOrderQuery +// +// @Description: +// @param request +// @return structure.ShareOrder +func ShareJpyOrderQuery(request *v1.ShareJpyOrderRequest) structure.ShareOrder { + return structure.ShareOrder{ + StockId: request.StockId, + TradeType: request.TradeType, + DealType: request.DealType, + LimitPrice: request.LimitPrice, + MarketPrice: request.MarketPrice, + MarketMoney: request.MarketMoney, + OrderNumber: request.OrderNumber, + ServiceCost: request.ServiceCost, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + PryNum: request.PryNum, + } +} + +// ResultJpyOrderMessage +// +// @Description: +// @param orderId +// @return *v1.JpyOrderResult +func ResultJpyOrderMessage(orderId string) *v1.JpyOrderResult { + return &v1.JpyOrderResult{ + OrderId: orderId, + } +} + +// ShareJpyPlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param orderId +// @return *v1.JpyOrderReply +func ShareJpyPlaceOrderReply(check bool, err string, orderId string) *v1.JpyOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.JpyOrderReply{ + Code: code, + Data: ResultJpyOrderMessage(orderId), + Message: replyStr, + } +} + +// VerificationSgdShareOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationJpyShareOrderQuery(request *v1.ShareJpyOrderRequest) bool { + if len(request.GetStockId()) <= 0 { + return false + } + switch request.DealType { + case 1: + if len(request.GetLimitPrice()) <= 0 { + return false + } + case 2: + if len(request.GetMarketPrice()) <= 0 { + return false + } + default: + return false + } + if len(request.GetMarketMoney()) <= 0 { + return false + } + if len(request.GetOrderNumber()) <= 0 { + return false + } + if len(request.GetServiceCost()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + } + switch request.TradeType { + case 1: + case 2: + default: + return false + } + + return true +} + +// VerificationJpyBotStockTrade +// +// @Description: +// @param req +// @return bool +func VerificationJpyBotStockTrade(req *v1.GetJpyBotStockTradeRequest) bool { + if req.GetPageSize() < 0 { + return false + } + if req.GetStatus() < 0 { + return false + } + if req.GetPageCount() < 0 { + return false + } + return true +} + +// BotStockJpyTradeReply +// +// @Description: +// @param check +// @param err +// @param req +// @param data +// @param totalCount +// @return *v1.GetBotStockEurTradeReply +func BotStockJpyTradeReply(check bool, err string, req *v1.GetJpyBotStockTradeRequest, data []*models.BotStockJpTrade, totalCount int64) *v1.GetBotStockJpyTradeReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.GetBotStockJpyTradeReply{ + Code: code, + Data: &v1.BotStockJpyTradeReply{ + PageSize: req.PageSize, + PageCount: req.PageCount, + Data: BotStockJpyTradeMessage(data), + TotalCount: totalCount, + }, + Message: replyStr, + } +} + +// BotStockEurTradeMessage +// +// @Description: +// @param stockList +// @return BotStockEurTrade +func BotStockJpyTradeMessage(stockList []*models.BotStockJpTrade) (stockTrade []*v1.BotStockJpyTrade) { + for _, value := range stockList { + stockTrade = append(stockTrade, &v1.BotStockJpyTrade{ + OrderId: value.OrderId, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + DealPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + OrderNumber: value.OrderNumber, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + ServiceCost: value.ServiceCost, + MarketMoney: value.MarketMoney, + OrderMoney: value.OrderMoney, + ClosingCost: value.ClosingCost, + Status: int64(value.Status), + CreateTime: value.CreateTime.Format(flags.LayoutTime), + UpdateTime: value.UpdateTime.Format(flags.LayoutTime), + OpenTime: value.OpenTime.Format(flags.LayoutTime), + ClosingTime: value.ClosingTime.Format(flags.LayoutTime), + KeepDecimal: strconv.Itoa(value.KeepDecimal), + StockName: value.StockName, + PryNum: strconv.Itoa(value.PryNum), + }) + } + return +} diff --git a/internal/service/share/share_mys.go b/internal/service/share/share_mys.go new file mode 100644 index 0000000..0d66ab2 --- /dev/null +++ b/internal/service/share/share_mys.go @@ -0,0 +1,318 @@ +package share + +import ( + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "strconv" + + v1 "matchmaking-system/api/matchmaking/v1/share" + models "matchmaking-system/internal/pkg/model" +) + +// ShareMysCancelReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.MysOrderReply +func ShareMysCancelReply(check bool, err string, req *v1.CancelMysOrderRequest) *v1.MysOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.MysOrderReply{ + Code: code, + Data: ResultMysOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationMysShareCancel +// +// @Description: +// @param req +// @return bool +func VerificationMysShareCancel(req *v1.CancelMysOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// ShareAllMysPositionRequest +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.AllMysOrderReply +func ShareAllMysPositionRequest(check bool, err string) *v1.AllMysOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.AllMysOrderReply{ + Code: code, + Data: "", + Message: replyStr, + } +} + +// ShareMysPositionOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.MysOrderReply +func ShareMysPositionOrderReply(check bool, err string, req *v1.CancelMysOrderRequest) *v1.MysOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.MysOrderReply{ + Code: code, + Data: ResultMysOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// ShareMysOrderQuery +// +// @Description: +// @param request +// @return structure.ShareOrder +func ShareMysOrderQuery(request *v1.ShareMysOrderRequest) structure.ShareOrder { + return structure.ShareOrder{ + StockId: request.StockId, + TradeType: request.TradeType, + DealType: request.DealType, + LimitPrice: request.LimitPrice, + MarketPrice: request.MarketPrice, + MarketMoney: request.MarketMoney, + OrderNumber: request.OrderNumber, + ServiceCost: request.ServiceCost, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + PryNum: request.PryNum, + } +} + +// VerificationMysSharePosition +// +// @Description: +// @param req +// @return bool +func VerificationMysSharePosition(req *v1.CancelMysOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// StopOrderMysQuery +// +// @Description: +// @param request +// @return structure.StopOrder +func StopOrderMysQuery(request *v1.UpdateMysOrderRequest) structure.StopOrder { + return structure.StopOrder{ + OrderId: request.OrderId, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + } +} + +// ShareUpdateMysOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.MysOrderReply +func ShareUpdateMysOrderReply(check bool, err string, req *v1.UpdateMysOrderRequest) *v1.MysOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.MysOrderReply{ + Code: code, + Data: ResultMysOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationMysStopOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationMysStopOrderQuery(request *v1.UpdateMysOrderRequest) bool { + if len(request.GetOrderId()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + case 0: + //if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + // return false + //} + return true + default: + return false + } + + return true +} + +// SharePlaceMysOrderReply +// +// @Description: +// @param check +// @param err +// @param orderId +// @return *v1.MysOrderReply +func SharePlaceMysOrderReply(check bool, err string, orderId string) *v1.MysOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.MysOrderReply{ + Code: code, + Data: ResultMysOrderMessage(orderId), + Message: replyStr, + } +} + +// ResultMysOrderMessage +// +// @Description: +// @param orderId +// @return *v1.ShareMysResult +func ResultMysOrderMessage(orderId string) *v1.ShareMysResult { + return &v1.ShareMysResult{ + OrderId: orderId, + } +} + +// VerificationMysShareOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationMysShareOrderQuery(request *v1.ShareMysOrderRequest) bool { + if len(request.GetStockId()) <= 0 { + return false + } + switch request.DealType { + case 1: + if len(request.GetLimitPrice()) <= 0 { + return false + } + case 2: + if len(request.GetMarketPrice()) <= 0 { + return false + } + default: + return false + } + if len(request.GetMarketMoney()) <= 0 { + return false + } + if len(request.GetOrderNumber()) <= 0 { + return false + } + if len(request.GetServiceCost()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + } + switch request.TradeType { + case 1: + case 2: + default: + return false + } + + return true +} + +// VerificationMysBotStockTrade +// +// @Description: +// @param req +// @return bool +func VerificationMysBotStockTrade(req *v1.GetMysBotStockTradeRequest) bool { + if req.GetPageSize() < 0 { + return false + } + if req.GetStatus() < 0 { + return false + } + if req.GetPageCount() < 0 { + return false + } + return true +} + +// BotStockMysTradeReply +// +// @Description: +// @param check +// @param err +// @param req +// @param data +// @param totalCount +// @return *v1.GetMysBotStockMysTradeReply +func BotStockMysTradeReply(check bool, err string, req *v1.GetMysBotStockTradeRequest, data []*models.BotStockMysTrade, totalCount int64) *v1.GetBotStockMysTradeReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.GetBotStockMysTradeReply{ + Code: code, + Data: &v1.BotStockMysTradeData{ + PageSize: req.PageSize, + PageCount: req.PageCount, + Data: BotStockMysTradeMessage(data), + TotalCount: totalCount, + }, + Message: replyStr, + } +} + +// BotStockMysTradeMessage +// +// @Description: +// @param stockList +// @return BotMysStockMysTrade +func BotStockMysTradeMessage(stockList []*models.BotStockMysTrade) (stockTrade []*v1.BotStockMysTrade) { + for _, value := range stockList { + stockTrade = append(stockTrade, &v1.BotStockMysTrade{ + OrderId: value.OrderId, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + DealPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + OrderNumber: value.OrderNumber, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + ServiceCost: value.ServiceCost, + MarketMoney: value.MarketMoney, + OrderMoney: value.OrderMoney, + ClosingCost: value.ClosingCost, + Status: int64(value.Status), + CreateTime: value.CreateTime.Format(flags.LayoutTime), + UpdateTime: value.UpdateTime.Format(flags.LayoutTime), + OpenTime: value.OpenTime.Format(flags.LayoutTime), + ClosingTime: value.ClosingTime.Format(flags.LayoutTime), + KeepDecimal: strconv.Itoa(value.KeepDecimal), + StockName: value.StockName, + PryNum: strconv.Itoa(value.PryNum), + NumericCode: value.NumericCode, + }) + } + return +} diff --git a/internal/service/share/share_sgd.go b/internal/service/share/share_sgd.go new file mode 100644 index 0000000..0b5cdf5 --- /dev/null +++ b/internal/service/share/share_sgd.go @@ -0,0 +1,317 @@ +package share + +import ( + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "strconv" + + v1 "matchmaking-system/api/matchmaking/v1/share" + models "matchmaking-system/internal/pkg/model" +) + +// ShareSgdCancelReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.SgdOrderReply +func ShareSgdCancelReply(check bool, err string, req *v1.CancelSgdOrderRequest) *v1.SgdOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.SgdOrderReply{ + Code: code, + Data: ResultSgdOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationSgdShareCancel +// +// @Description: +// @param req +// @return bool +func VerificationSgdShareCancel(req *v1.CancelSgdOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// ShareAllSgdPositionRequest +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.AllSgdOrderReply +func ShareAllSgdPositionRequest(check bool, err string) *v1.AllSgdOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.AllSgdOrderReply{ + Code: code, + Data: "", + Message: replyStr, + } +} + +// ShareSgdPositionOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.SgdOrderReply +func ShareSgdPositionOrderReply(check bool, err string, req *v1.CancelSgdOrderRequest) *v1.SgdOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.SgdOrderReply{ + Code: code, + Data: ResultSgdOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationSgdSharePosition +// +// @Description: +// @param req +// @return bool +func VerificationSgdSharePosition(req *v1.CancelSgdOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// StopSgdOrderQuery +// +// @Description: +// @param request +// @return structure.StopOrder +func StopSgdOrderQuery(request *v1.UpdateSgdOrderRequest) structure.StopOrder { + return structure.StopOrder{ + OrderId: request.OrderId, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + } +} + +// ShareSgdUpdateOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.SgdOrderReply +func ShareSgdUpdateOrderReply(check bool, err string, req *v1.UpdateSgdOrderRequest) *v1.SgdOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.SgdOrderReply{ + Code: code, + Data: ResultSgdOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationSgdStopOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationSgdStopOrderQuery(request *v1.UpdateSgdOrderRequest) bool { + if len(request.GetOrderId()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + case 0: + //if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + // return false + //} + return true + default: + return false + } + + return true +} + +// ShareSgdOrderQuery +// +// @Description: +// @param request +// @return structure.ShareOrder +func ShareSgdOrderQuery(request *v1.ShareSgdOrderRequest) structure.ShareOrder { + return structure.ShareOrder{ + StockId: request.StockId, + TradeType: request.TradeType, + DealType: request.DealType, + LimitPrice: request.LimitPrice, + MarketPrice: request.MarketPrice, + MarketMoney: request.MarketMoney, + OrderNumber: request.OrderNumber, + ServiceCost: request.ServiceCost, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + PryNum: request.PryNum, + } +} + +// ResultSgdOrderMessage +// +// @Description: +// @param orderId +// @return *v1.SgdOrderResult +func ResultSgdOrderMessage(orderId string) *v1.SgdOrderResult { + return &v1.SgdOrderResult{ + OrderId: orderId, + } +} + +// ShareSgdPlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param orderId +// @return *v1.SgdOrderReply +func ShareSgdPlaceOrderReply(check bool, err string, orderId string) *v1.SgdOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.SgdOrderReply{ + Code: code, + Data: ResultSgdOrderMessage(orderId), + Message: replyStr, + } +} + +// VerificationSgdShareOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationSgdShareOrderQuery(request *v1.ShareSgdOrderRequest) bool { + if len(request.GetStockId()) <= 0 { + return false + } + switch request.DealType { + case 1: + if len(request.GetLimitPrice()) <= 0 { + return false + } + case 2: + if len(request.GetMarketPrice()) <= 0 { + return false + } + default: + return false + } + if len(request.GetMarketMoney()) <= 0 { + return false + } + if len(request.GetOrderNumber()) <= 0 { + return false + } + if len(request.GetServiceCost()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + } + switch request.TradeType { + case 1: + case 2: + default: + return false + } + + return true +} + +// VerificationSgdBotStockTrade +// +// @Description: +// @param req +// @return bool +func VerificationSgdBotStockTrade(req *v1.GetSgdBotStockTradeRequest) bool { + if req.GetPageSize() < 0 { + return false + } + if req.GetStatus() < 0 { + return false + } + if req.GetPageCount() < 0 { + return false + } + return true +} + +// BotStockSgdTradeReply +// +// @Description: +// @param check +// @param err +// @param req +// @param data +// @param totalCount +// @return *v1.GetBotStockSgdTradeReply +func BotStockSgdTradeReply(check bool, err string, req *v1.GetSgdBotStockTradeRequest, data []*models.BotStockSgdTrade, totalCount int64) *v1.GetBotStockSgdTradeReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.GetBotStockSgdTradeReply{ + Code: code, + Data: &v1.BotStockSgdTradeReply{ + PageSize: req.PageSize, + PageCount: req.PageCount, + Data: BotStockSgdTradeMessage(data), + TotalCount: totalCount, + }, + Message: replyStr, + } +} + +// BotStockSgdTradeMessage +// +// @Description: +// @param stockList +// @return BotStockSgdTrade +func BotStockSgdTradeMessage(stockList []*models.BotStockSgdTrade) (stockTrade []*v1.BotStockSgdTrade) { + for _, value := range stockList { + stockTrade = append(stockTrade, &v1.BotStockSgdTrade{ + OrderId: value.OrderId, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + DealPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + OrderNumber: value.OrderNumber, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + ServiceCost: value.ServiceCost, + MarketMoney: value.MarketMoney, + OrderMoney: value.OrderMoney, + ClosingCost: value.ClosingCost, + Status: int64(value.Status), + CreateTime: value.CreateTime.Format(flags.LayoutTime), + UpdateTime: value.UpdateTime.Format(flags.LayoutTime), + OpenTime: value.OpenTime.Format(flags.LayoutTime), + ClosingTime: value.ClosingTime.Format(flags.LayoutTime), + KeepDecimal: strconv.Itoa(value.KeepDecimal), + StockName: value.StockName, + PryNum: strconv.Itoa(value.PryNum), + }) + } + return +} diff --git a/internal/service/share/share_tha.go b/internal/service/share/share_tha.go new file mode 100644 index 0000000..140c271 --- /dev/null +++ b/internal/service/share/share_tha.go @@ -0,0 +1,317 @@ +package share + +import ( + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "strconv" + + v1 "matchmaking-system/api/matchmaking/v1/share" + models "matchmaking-system/internal/pkg/model" +) + +// ShareThaCancelReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.ThaOrderReply +func ShareThaCancelReply(check bool, err string, req *v1.CancelThaOrderRequest) *v1.ThaOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.ThaOrderReply{ + Code: code, + Data: ResultThaOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationThaShareCancel +// +// @Description: +// @param req +// @return bool +func VerificationThaShareCancel(req *v1.CancelThaOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// ShareAllThaPositionRequest +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.AllThaOrderReply +func ShareAllThaPositionRequest(check bool, err string) *v1.AllThaOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.AllThaOrderReply{ + Code: code, + Data: "", + Message: replyStr, + } +} + +// ShareThaPositionOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.ThaOrderReply +func ShareThaPositionOrderReply(check bool, err string, req *v1.CancelThaOrderRequest) *v1.ThaOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.ThaOrderReply{ + Code: code, + Data: ResultThaOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationThaSharePosition +// +// @Description: +// @param req +// @return bool +func VerificationThaSharePosition(req *v1.CancelThaOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// StopThaOrderQuery +// +// @Description: +// @param request +// @return structure.StopOrder +func StopThaOrderQuery(request *v1.UpdateThaOrderRequest) structure.StopOrder { + return structure.StopOrder{ + OrderId: request.OrderId, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + } +} + +// ShareThaUpdateOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.ThaOrderReply +func ShareThaUpdateOrderReply(check bool, err string, req *v1.UpdateThaOrderRequest) *v1.ThaOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.ThaOrderReply{ + Code: code, + Data: ResultThaOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationThaStopOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationThaStopOrderQuery(request *v1.UpdateThaOrderRequest) bool { + if len(request.GetOrderId()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + case 0: + //if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + // return false + //} + return true + default: + return false + } + + return true +} + +// ShareThaOrderQuery +// +// @Description: +// @param request +// @return structure.ShareOrder +func ShareThaOrderQuery(request *v1.ShareThaOrderRequest) structure.ShareOrder { + return structure.ShareOrder{ + StockId: request.StockId, + TradeType: request.TradeType, + DealType: request.DealType, + LimitPrice: request.LimitPrice, + MarketPrice: request.MarketPrice, + MarketMoney: request.MarketMoney, + OrderNumber: request.OrderNumber, + ServiceCost: request.ServiceCost, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + PryNum: request.PryNum, + } +} + +// ResultThaOrderMessage +// +// @Description: +// @param orderId +// @return *v1.ThaOrderResult +func ResultThaOrderMessage(orderId string) *v1.ThaOrderResult { + return &v1.ThaOrderResult{ + OrderId: orderId, + } +} + +// ShareThaPlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param orderId +// @return *v1.ThaOrderReply +func ShareThaPlaceOrderReply(check bool, err string, orderId string) *v1.ThaOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.ThaOrderReply{ + Code: code, + Data: ResultThaOrderMessage(orderId), + Message: replyStr, + } +} + +// VerificationThaShareOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationThaShareOrderQuery(request *v1.ShareThaOrderRequest) bool { + if len(request.GetStockId()) <= 0 { + return false + } + switch request.DealType { + case 1: + if len(request.GetLimitPrice()) <= 0 { + return false + } + case 2: + if len(request.GetMarketPrice()) <= 0 { + return false + } + default: + return false + } + if len(request.GetMarketMoney()) <= 0 { + return false + } + if len(request.GetOrderNumber()) <= 0 { + return false + } + if len(request.ServiceCost) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + } + switch request.TradeType { + case 1: + case 2: + default: + return false + } + + return true +} + +// VerificationThaBotStockTrade +// +// @Description: +// @param req +// @return bool +func VerificationThaBotStockTrade(req *v1.GetThaBotStockTradeRequest) bool { + if req.GetPageSize() < 0 { + return false + } + if req.GetStatus() < 0 { + return false + } + if req.GetPageCount() < 0 { + return false + } + return true +} + +// BotStockThaTradeReply +// +// @Description: +// @param check +// @param err +// @param req +// @param data +// @param totalCount +// @return *v1.GetThaBotStockThaTradeReply +func BotStockThaTradeReply(check bool, err string, req *v1.GetThaBotStockTradeRequest, data []*models.BotStockThaTrade, totalCount int64) *v1.GetBotStockThaTradeReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.GetBotStockThaTradeReply{ + Code: code, + Data: &v1.BotStockThaTradeData{ + PageSize: req.PageSize, + PageCount: req.PageCount, + Data: BotStockThaTradeMessage(data), + TotalCount: totalCount, + }, + Message: replyStr, + } +} + +// BotStockThaTradeMessage +// +// @Description: +// @param stockList +// @return BotThaStockThaTrade +func BotStockThaTradeMessage(stockList []*models.BotStockThaTrade) (stockTrade []*v1.BotStockThaTrade) { + for _, value := range stockList { + stockTrade = append(stockTrade, &v1.BotStockThaTrade{ + OrderId: value.OrderId, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + DealPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + OrderNumber: value.OrderNumber, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + ServiceCost: value.ServiceCost, + MarketMoney: value.MarketMoney, + OrderMoney: value.OrderMoney, + ClosingCost: value.ClosingCost, + Status: int64(value.Status), + CreateTime: value.CreateTime.Format(flags.LayoutTime), + UpdateTime: value.UpdateTime.Format(flags.LayoutTime), + OpenTime: value.OpenTime.Format(flags.LayoutTime), + ClosingTime: value.ClosingTime.Format(flags.LayoutTime), + KeepDecimal: strconv.Itoa(value.KeepDecimal), + StockName: value.StockName, + PryNum: strconv.Itoa(value.PryNum), + }) + } + return +} diff --git a/internal/service/share/share_us.go b/internal/service/share/share_us.go new file mode 100644 index 0000000..436d81b --- /dev/null +++ b/internal/service/share/share_us.go @@ -0,0 +1,317 @@ +package share + +import ( + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "strconv" + + v1 "matchmaking-system/api/matchmaking/v1/share" + models "matchmaking-system/internal/pkg/model" +) + +// ShareCancelReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.UsOrderReply +func ShareCancelReply(check bool, err string, req *v1.CancelUsOrderRequest) *v1.UsOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.UsOrderReply{ + Code: code, + Data: ResultUsOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationShareCancel +// +// @Description: +// @param req +// @return bool +func VerificationShareCancel(req *v1.CancelUsOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// ShareAllPositionRequest +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.AllUsOrderReply +func ShareAllPositionRequest(check bool, err string) *v1.AllUsOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.AllUsOrderReply{ + Code: code, + Data: "", + Message: replyStr, + } +} + +// SharePositionOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.UsOrderReply +func SharePositionOrderReply(check bool, err string, req *v1.CancelUsOrderRequest) *v1.UsOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.UsOrderReply{ + Code: code, + Data: ResultUsOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationSharePosition +// +// @Description: +// @param req +// @return bool +func VerificationSharePosition(req *v1.CancelUsOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// StopOrderQuery +// +// @Description: +// @param request +// @return structure.StopOrder +func StopOrderQuery(request *v1.UpdateUsOrderRequest) structure.StopOrder { + return structure.StopOrder{ + OrderId: request.OrderId, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + } +} + +// ShareUpdateOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.UsOrderReply +func ShareUpdateOrderReply(check bool, err string, req *v1.UpdateUsOrderRequest) *v1.UsOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.UsOrderReply{ + Code: code, + Data: ResultUsOrderMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationStopOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationStopOrderQuery(request *v1.UpdateUsOrderRequest) bool { + if len(request.GetOrderId()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + case 0: + //if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + // return false + //} + return true + default: + return false + } + + return true +} + +// ShareUsOrderQuery +// +// @Description: +// @param request +// @return structure.ShareOrder +func ShareUsOrderQuery(request *v1.UsOrderRequest) structure.ShareOrder { + return structure.ShareOrder{ + StockId: request.StockId, + TradeType: request.TradeType, + DealType: request.DealType, + LimitPrice: request.LimitPrice, + MarketPrice: request.MarketPrice, + MarketMoney: request.MarketMoney, + OrderNumber: request.OrderNumber, + ServiceCost: request.ServiceCost, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + PryNum: request.PryNum, + } +} + +// ShareUsPlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param orderId +// @return *v1.UsOrderReply +func ShareUsPlaceOrderReply(check bool, err string, orderId string) *v1.UsOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.UsOrderReply{ + Code: code, + Data: ResultUsOrderMessage(orderId), + Message: replyStr, + } +} + +// ResultUsOrderMessage +// +// @Description: +// @param orderId +// @return *v1.UsOrderResult +func ResultUsOrderMessage(orderId string) *v1.UsOrderResult { + return &v1.UsOrderResult{ + OrderId: orderId, + } +} + +// VerificationShareOrderQuery +// +// @Description: +// @param request +// @return bool +func VerificationShareOrderQuery(request *v1.UsOrderRequest) bool { + if len(request.GetStockId()) <= 0 { + return false + } + switch request.DealType { + case 1: + if len(request.GetLimitPrice()) <= 0 { + return false + } + case 2: + if len(request.GetMarketPrice()) <= 0 { + return false + } + default: + return false + } + if len(request.GetMarketMoney()) <= 0 { + return false + } + if len(request.GetOrderNumber()) <= 0 { + return false + } + if len(request.GetServiceCost()) <= 0 { + return false + } + switch request.StopType { + case 1: + if len(request.GetStopLossPrice()) <= 0 && len(request.GetStopWinPrice()) <= 0 { + return false + } + } + switch request.TradeType { + case 1: + case 2: + default: + return false + } + + return true +} + +// VerificationBotStockTrade +// +// @Description: +// @param req +// @return bool +func VerificationBotStockTrade(req *v1.GetUsBotStockTradeRequest) bool { + if req.GetPageSize() < 0 { + return false + } + if req.GetStatus() < 0 { + return false + } + if req.GetPageCount() < 0 { + return false + } + return true +} + +// BotStockTradeReply +// +// @Description: +// @param check +// @param err +// @param req +// @param data +// @param totalCount +// @return *v1.GetUsBotStockTradeReply +func BotStockTradeReply(check bool, err string, req *v1.GetUsBotStockTradeRequest, data []*models.BotStockTrade, totalCount int64) *v1.GetUsBotStockTradeReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.GetUsBotStockTradeReply{ + Code: code, + Data: &v1.BotUsStockTradeData{ + PageSize: req.PageSize, + PageCount: req.PageCount, + Data: BotStockTradeMessage(data), + TotalCount: totalCount, + }, + Message: replyStr, + } +} + +// BotStockTradeMessage +// +// @Description: +// @param stockList +// @return BotUsOrderTrade +func BotStockTradeMessage(stockList []*models.BotStockTrade) (stockTrade []*v1.BotUsOrderTrade) { + for _, value := range stockList { + stockTrade = append(stockTrade, &v1.BotUsOrderTrade{ + OrderId: value.OrderId, + StockId: value.StockId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + DealPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + OrderNumber: value.OrderNumber, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + ServiceCost: value.ServiceCost, + MarketMoney: value.MarketMoney, + OrderMoney: value.OrderMoney, + ClosingCost: value.ClosingCost, + Status: int64(value.Status), + CreateTime: value.CreateTime.Format(flags.LayoutTime), + UpdateTime: value.UpdateTime.Format(flags.LayoutTime), + OpenTime: value.OpenTime.Format(flags.LayoutTime), + ClosingTime: value.ClosingTime.Format(flags.LayoutTime), + KeepDecimal: strconv.Itoa(value.KeepDecimal), + StockName: value.StockName, + PryNum: strconv.Itoa(value.PryNum), + }) + } + return +} diff --git a/internal/service/share_blk.go b/internal/service/share_blk.go new file mode 100644 index 0000000..d894e02 --- /dev/null +++ b/internal/service/share_blk.go @@ -0,0 +1,114 @@ +package service + +import ( + "context" + v1 "matchmaking-system/api/matchmaking/v1/block" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/block" + "matchmaking-system/internal/service/order" +) + +// GetBotStockBlockTrade +// +// @Description: 大宗交易订单列表 +// @receiver s +// @param ctx +// @param req +// @return *v1.GetBotStockBlockTradeReply +// @return error +func (s *ConduitService) GetBotStockBlockTrade(ctx context.Context, req *v1.GetBotStockBlockTradeRequest) (*v1.GetBotStockBlockTradeReply, error) { + if !block.VerificationBotStockBlockTrade(req) { + return block.BotStockBlockTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil + } + + stockTradeList, totalCount, err := s.bl.BotStockBlockTradeList(ctx, req.PageSize, req.PageCount, req.Type, req.Status) + if err != nil { + return block.BotStockBlockTradeReply(false, err.Error(), req, nil, 0), nil + } + + return block.BotStockBlockTradeReply(true, flags.SetNull, req, stockTradeList, totalCount), nil +} + +// ShareBlockPlaceOrder +// +// @Description: 大宗交易股下单 +// @receiver s +// @param ctx +// @param req +// @return *v1.OrderBlockReply +// @return error +func (s *ConduitService) ShareBlockPlaceOrder(ctx context.Context, req *v1.OrderBlockRequest) (*v1.OrderBlockReply, error) { + if !block.VerificationShareBlockOrderQuery(req) { + return block.ShareBlockPlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil + } + + orderId, err := s.bl.ShareBlockPlaceOrder(ctx, block.ShareBlockOrderQuery(req)) + if err != nil { + return block.ShareBlockPlaceOrderReply(false, order.CheckShareError(err), flags.SetNull), nil + } + + return block.ShareBlockPlaceOrderReply(true, flags.SetNull, orderId), nil +} + +// ShareBlockUpdateOrder +// +// @Description: 大宗交易股设置止盈止损 +// @receiver s +// @param ctx +// @param req +// @return *v1.OrderBlockReply +// @return error +func (s *ConduitService) ShareBlockUpdateOrder(ctx context.Context, req *v1.UpdateBlockOrderRequest) (*v1.OrderBlockReply, error) { + if !block.VerificationStopOrderBlockQuery(req) { + return block.ShareBlockUpdateOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.bl.ShareBlockUpdateOrder(ctx, block.StopOrderBlockQuery(req)) + if err != nil { + return block.ShareBlockUpdateOrderReply(false, order.CheckShareError(err), req), nil + } + + return block.ShareBlockUpdateOrderReply(true, flags.SetNull, req), nil +} + +// ShareBlockPosition +// +// @Description: 大宗交易股平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.OrderBlockReply +// @return error +func (s *ConduitService) ShareBlockPosition(ctx context.Context, req *v1.CancelBlockOrderRequest) (*v1.OrderBlockReply, error) { + if !block.VerificationShareBlockPosition(req) { + return block.ShareBlockPositionOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.bl.ShareBlockPosition(ctx, req.OrderId, req.Type) + if err != nil { + return block.ShareBlockPositionOrderReply(false, order.CheckShareError(err), req), nil + } + + return block.ShareBlockPositionOrderReply(true, flags.SetNull, req), nil +} + +// ShareBlockCancel +// +// @Description: 大宗交易股撤单 +// @receiver s +// @param ctx +// @param req +// @return *v1.OrderBlockReply +// @return error +func (s *ConduitService) ShareBlockCancel(ctx context.Context, req *v1.CancelBlockOrderRequest) (*v1.OrderBlockReply, error) { + if !block.VerificationShareBlockCancel(req) { + return block.ShareBlockCancelReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.bl.ShareBlockCancel(ctx, req.OrderId, req.Type) + if err != nil { + return block.ShareBlockCancelReply(false, order.CheckShareError(err), req), nil + } + + return block.ShareBlockCancelReply(true, flags.SetNull, req), nil +} diff --git a/internal/service/share_brl.go b/internal/service/share_brl.go new file mode 100644 index 0000000..c83c554 --- /dev/null +++ b/internal/service/share_brl.go @@ -0,0 +1,131 @@ +package service + +import ( + "context" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "matchmaking-system/internal/service/share" + + v1 "matchmaking-system/api/matchmaking/v1/share" +) + +// GetBotStockBrlTrade +// +// @Description: 巴西国股订单列表 +// @receiver s +// @param ctx +// @param req +// @return *v1.GetBotStockBrlTradeReply +// @return error +func (s *ConduitService) GetBotStockBrlTrade(ctx context.Context, req *v1.GetBrlBotStockTradeRequest) (*v1.GetBotStockBrlTradeReply, error) { + if !share.VerificationBrlBotStockTrade(req) { + return share.BotStockBrlTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil + } + + stockTradeList, totalCount, err := s.br.BotStockBrlTradeList(ctx, req.PageSize, req.PageCount, req.Status) + if err != nil { + return share.BotStockBrlTradeReply(false, err.Error(), req, nil, 0), nil + } + + return share.BotStockBrlTradeReply(true, flags.SetNull, req, stockTradeList, totalCount), nil +} + +// ShareBrlPlaceOrder +// +// @Description: 巴西国股下单 +// @receiver s +// @param ctx +// @param req +// @return *v1.SgdOrderReply +// @return error +func (s *ConduitService) ShareBrlPlaceOrder(ctx context.Context, req *v1.ShareBrlOrderRequest) (*v1.BrlOrderReply, error) { + if !share.VerificationBrlShareOrderQuery(req) { + return share.ShareBrlPlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil + } + + orderId, err := s.br.ShareBrlPlaceOrder(ctx, share.ShareBrlOrderQuery(req)) + if err != nil { + return share.ShareBrlPlaceOrderReply(false, order.CheckShareError(err), flags.SetNull), nil + } + + return share.ShareBrlPlaceOrderReply(true, flags.SetNull, orderId), nil +} + +// ShareBrlUpdateOrder +// +// @Description: 巴西国股设置止盈止损 +// @receiver s +// @param ctx +// @param req +// @return *v1.BrlOrderReply +// @return error +func (s *ConduitService) ShareBrlUpdateOrder(ctx context.Context, req *v1.UpdateBrlOrderRequest) (*v1.BrlOrderReply, error) { + if !share.VerificationBrlStopOrderQuery(req) { + return share.ShareBrlUpdateOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.br.ShareBrlUpdateOrder(ctx, share.StopBrlOrderQuery(req)) + if err != nil { + return share.ShareBrlUpdateOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareBrlUpdateOrderReply(true, flags.SetNull, req), nil +} + +// ShareBrlPosition +// +// @Description: 巴西国股平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.BrlOrderReply +// @return error +func (s *ConduitService) ShareBrlPosition(ctx context.Context, req *v1.CancelBrlOrderRequest) (*v1.BrlOrderReply, error) { + if !share.VerificationBrlSharePosition(req) { + return share.ShareBrlPositionOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.br.ShareBrlPosition(ctx, req.OrderId) + if err != nil { + return share.ShareBrlPositionOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareBrlPositionOrderReply(true, flags.SetNull, req), nil +} + +// ShareBrlAllPosition +// +// @Description: 巴西国股一键平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.AllBrlOrderReply +// @return error +func (s *ConduitService) ShareBrlAllPosition(ctx context.Context, req *v1.AllBrlOrderRequest) (*v1.AllBrlOrderReply, error) { + if err := s.br.ShareBrlAllPosition(ctx); err != nil { + return share.ShareAllBrlPositionRequest(false, order.CheckShareError(err)), nil + } + + return share.ShareAllBrlPositionRequest(true, flags.SetNull), nil +} + +// ShareBrlCancel +// +// @Description: 巴西国股撤单 +// @receiver s +// @param ctx +// @param req +// @return *v1.BrlOrderReply +// @return error +func (s *ConduitService) ShareBrlCancel(ctx context.Context, req *v1.CancelBrlOrderRequest) (*v1.BrlOrderReply, error) { + if !share.VerificationBrlShareCancel(req) { + return share.ShareBrlCancelReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.br.ShareBrlCancel(ctx, req.OrderId) + if err != nil { + return share.ShareBrlCancelReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareBrlCancelReply(true, flags.SetNull, req), nil +} diff --git a/internal/service/share_eur.go b/internal/service/share_eur.go new file mode 100644 index 0000000..987a297 --- /dev/null +++ b/internal/service/share_eur.go @@ -0,0 +1,131 @@ +package service + +import ( + "context" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "matchmaking-system/internal/service/share" + + v1 "matchmaking-system/api/matchmaking/v1/share" +) + +// GetBotStockEurTrade +// +// @Description: 德国股订单列表 +// @receiver s +// @param ctx +// @param req +// @return *v1.GetBotStockEurTradeReply +// @return error +func (s *ConduitService) GetBotStockEurTrade(ctx context.Context, req *v1.GetEurBotStockTradeRequest) (*v1.GetBotStockEurTradeReply, error) { + if !share.VerificationEurBotStockTrade(req) { + return share.BotStockEurTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil + } + + stockTradeList, totalCount, err := s.eu.BotStockEurTradeList(ctx, req.PageSize, req.PageCount, req.Status) + if err != nil { + return share.BotStockEurTradeReply(false, err.Error(), req, nil, 0), nil + } + + return share.BotStockEurTradeReply(true, flags.SetNull, req, stockTradeList, totalCount), nil +} + +// ShareEurPlaceOrder +// +// @Description: 德国股下单 +// @receiver s +// @param ctx +// @param req +// @return *v1.SgdOrderReply +// @return error +func (s *ConduitService) ShareEurPlaceOrder(ctx context.Context, req *v1.ShareEurOrderRequest) (*v1.EurOrderReply, error) { + if !share.VerificationEurShareOrderQuery(req) { + return share.ShareEurPlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil + } + + orderId, err := s.eu.ShareEurPlaceOrder(ctx, share.ShareEurOrderQuery(req)) + if err != nil { + return share.ShareEurPlaceOrderReply(false, order.CheckShareError(err), flags.SetNull), nil + } + + return share.ShareEurPlaceOrderReply(true, flags.SetNull, orderId), nil +} + +// ShareEurUpdateOrder +// +// @Description: 德国股设置止盈止损 +// @receiver s +// @param ctx +// @param req +// @return *v1.EurOrderReply +// @return error +func (s *ConduitService) ShareEurUpdateOrder(ctx context.Context, req *v1.UpdateEurOrderRequest) (*v1.EurOrderReply, error) { + if !share.VerificationEurStopOrderQuery(req) { + return share.ShareEurUpdateOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.eu.ShareEurUpdateOrder(ctx, share.StopEurOrderQuery(req)) + if err != nil { + return share.ShareEurUpdateOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareEurUpdateOrderReply(true, flags.SetNull, req), nil +} + +// ShareEurPosition +// +// @Description: 德国股平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.EurOrderReply +// @return error +func (s *ConduitService) ShareEurPosition(ctx context.Context, req *v1.CancelEurOrderRequest) (*v1.EurOrderReply, error) { + if !share.VerificationEurSharePosition(req) { + return share.ShareEurPositionOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.eu.ShareEurPosition(ctx, req.OrderId) + if err != nil { + return share.ShareEurPositionOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareEurPositionOrderReply(true, flags.SetNull, req), nil +} + +// ShareEurAllPosition +// +// @Description: 德国股一键平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.AllEurOrderReply +// @return error +func (s *ConduitService) ShareEurAllPosition(ctx context.Context, req *v1.AllEurOrderRequest) (*v1.AllEurOrderReply, error) { + if err := s.eu.ShareEurAllPosition(ctx); err != nil { + return share.ShareAllEurPositionRequest(false, order.CheckShareError(err)), nil + } + + return share.ShareAllEurPositionRequest(true, flags.SetNull), nil +} + +// ShareEurCancel +// +// @Description: 德国股撤单 +// @receiver s +// @param ctx +// @param req +// @return *v1.EurOrderReply +// @return error +func (s *ConduitService) ShareEurCancel(ctx context.Context, req *v1.CancelEurOrderRequest) (*v1.EurOrderReply, error) { + if !share.VerificationEurShareCancel(req) { + return share.ShareEurCancelReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.eu.ShareEurCancel(ctx, req.OrderId) + if err != nil { + return share.ShareEurCancelReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareEurCancelReply(true, flags.SetNull, req), nil +} diff --git a/internal/service/share_fur.go b/internal/service/share_fur.go new file mode 100644 index 0000000..2cde364 --- /dev/null +++ b/internal/service/share_fur.go @@ -0,0 +1,131 @@ +package service + +import ( + "context" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "matchmaking-system/internal/service/share" + + v1 "matchmaking-system/api/matchmaking/v1/share" +) + +// GetBotStockEurTrade +// +// @Description: 法国股订单列表 +// @receiver s +// @param ctx +// @param req +// @return *v1.GetBotStockEurTradeReply +// @return error +func (s *ConduitService) GetBotStockFurTrade(ctx context.Context, req *v1.GetFurBotStockTradeRequest) (*v1.GetBotStockFurTradeReply, error) { + if !share.VerificationFurBotStockTrade(req) { + return share.BotStockFurTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil + } + + stockTradeList, totalCount, err := s.fu.BotStockFurTradeList(ctx, req.PageSize, req.PageCount, req.Status) + if err != nil { + return share.BotStockFurTradeReply(false, err.Error(), req, nil, 0), nil + } + + return share.BotStockFurTradeReply(true, flags.SetNull, req, stockTradeList, totalCount), nil +} + +// ShareEurPlaceOrder +// +// @Description: 法国股下单 +// @receiver s +// @param ctx +// @param req +// @return *v1.SgdOrderReply +// @return error +func (s *ConduitService) ShareFurPlaceOrder(ctx context.Context, req *v1.ShareFurOrderRequest) (*v1.FurOrderReply, error) { + if !share.VerificationFurShareOrderQuery(req) { + return share.ShareFurPlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil + } + + orderId, err := s.fu.ShareFurPlaceOrder(ctx, share.ShareFurOrderQuery(req)) + if err != nil { + return share.ShareFurPlaceOrderReply(false, order.CheckShareError(err), flags.SetNull), nil + } + + return share.ShareFurPlaceOrderReply(true, flags.SetNull, orderId), nil +} + +// ShareEurUpdateOrder +// +// @Description: 法国股设置止盈止损 +// @receiver s +// @param ctx +// @param req +// @return *v1.EurOrderReply +// @return error +func (s *ConduitService) ShareFurUpdateOrder(ctx context.Context, req *v1.UpdateFurOrderRequest) (*v1.FurOrderReply, error) { + if !share.VerificationFurStopOrderQuery(req) { + return share.ShareFurUpdateOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.fu.ShareFurUpdateOrder(ctx, share.StopFurOrderQuery(req)) + if err != nil { + return share.ShareFurUpdateOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareFurUpdateOrderReply(true, flags.SetNull, req), nil +} + +// ShareEurPosition +// +// @Description: 法国股平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.EurOrderReply +// @return error +func (s *ConduitService) ShareFurPosition(ctx context.Context, req *v1.CancelFurOrderRequest) (*v1.FurOrderReply, error) { + if !share.VerificationFurSharePosition(req) { + return share.ShareFurPositionOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.fu.ShareFurPosition(ctx, req.OrderId) + if err != nil { + return share.ShareFurPositionOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareFurPositionOrderReply(true, flags.SetNull, req), nil +} + +// ShareEurAllPosition +// +// @Description: 法国股一键平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.AllEurOrderReply +// @return error +func (s *ConduitService) ShareFurAllPosition(ctx context.Context, req *v1.AllFurOrderRequest) (*v1.AllFurOrderReply, error) { + if err := s.fu.ShareFurAllPosition(ctx); err != nil { + return share.ShareAllFurPositionRequest(false, order.CheckShareError(err)), nil + } + + return share.ShareAllFurPositionRequest(true, flags.SetNull), nil +} + +// ShareEurCancel +// +// @Description: 法国股撤单 +// @receiver s +// @param ctx +// @param req +// @return *v1.EurOrderReply +// @return error +func (s *ConduitService) ShareFurCancel(ctx context.Context, req *v1.CancelFurOrderRequest) (*v1.FurOrderReply, error) { + if !share.VerificationFurShareCancel(req) { + return share.ShareFurCancelReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.fu.ShareFurCancel(ctx, req.OrderId) + if err != nil { + return share.ShareFurCancelReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareFurCancelReply(true, flags.SetNull, req), nil +} diff --git a/internal/service/share_gbx.go b/internal/service/share_gbx.go new file mode 100644 index 0000000..9aee989 --- /dev/null +++ b/internal/service/share_gbx.go @@ -0,0 +1,131 @@ +package service + +import ( + "context" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "matchmaking-system/internal/service/share" + + v1 "matchmaking-system/api/matchmaking/v1/share" +) + +// GetBotStockInrTrade +// +// @Description: 英股订单列表 +// @receiver s +// @param ctx +// @param req +// @return *v1.GetInrBotStockInrTradeReply +// @return error +func (s *ConduitService) GetBotStockGbxTrade(ctx context.Context, req *v1.GetBotStockGbxTradeRequest) (*v1.GetBotStockGbxTradeReply, error) { + if !share.VerificationGbxBotStockTrade(req) { + return share.BotStockGbxTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil + } + + stockTradeList, totalCount, err := s.gb.BotStockGbxTradeList(ctx, req.PageSize, req.PageCount, req.Status) + if err != nil { + return share.BotStockGbxTradeReply(false, err.Error(), req, nil, 0), nil + } + + return share.BotStockGbxTradeReply(true, flags.SetNull, req, stockTradeList, totalCount), nil +} + +// ShareInrPlaceOrder +// +// @Description: 英股下单 +// @receiver s +// @param ctx +// @param req +// @return *v1.InrOrderReply +// @return error +func (s *ConduitService) ShareGbxPlaceOrder(ctx context.Context, req *v1.OrderGbxRequest) (*v1.OrderGbxReply, error) { + if !share.VerificationGbxShareOrderQuery(req) { + return share.ShareGbxPlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil + } + + orderId, err := s.gb.ShareGbxPlaceOrder(ctx, share.ShareGbxOrderQuery(req)) + if err != nil { + return share.ShareGbxPlaceOrderReply(false, order.CheckShareError(err), flags.SetNull), nil + } + + return share.ShareGbxPlaceOrderReply(true, flags.SetNull, orderId), nil +} + +// ShareInrUpdateOrder +// +// @Description: 英股止盈止损 +// @receiver s +// @param ctx +// @param req +// @return *v1.InrOrderReply +// @return error +func (s *ConduitService) ShareGbxUpdateOrder(ctx context.Context, req *v1.UpdateGbxOrderRequest) (*v1.OrderGbxReply, error) { + if !share.VerificationGbxStopOrderQuery(req) { + return share.ShareGbxUpdateOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.gb.ShareGbxUpdateOrder(ctx, share.StopGbxOrderQuery(req)) + if err != nil { + return share.ShareGbxUpdateOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareGbxUpdateOrderReply(true, flags.SetNull, req), nil +} + +// ShareInrPosition +// +// @Description: 英股平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.InrOrderReply +// @return error +func (s *ConduitService) ShareGbxPosition(ctx context.Context, req *v1.CancelGbxOrderRequest) (*v1.OrderGbxReply, error) { + if !share.VerificationGbxSharePosition(req) { + return share.ShareGbxPositionOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.gb.ShareGbxPosition(ctx, req.OrderId) + if err != nil { + return share.ShareGbxPositionOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareGbxPositionOrderReply(true, flags.SetNull, req), nil +} + +// ShareInrAllPosition +// +// @Description: 英股一键平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.AllInrOrderReply +// @return error +func (s *ConduitService) ShareGbxAllPosition(ctx context.Context, req *v1.AllGbxOrderRequest) (*v1.AllGbxOrderReply, error) { + if err := s.gb.ShareGbxAllPosition(ctx); err != nil { + return share.ShareAllGbxPositionRequest(false, order.CheckShareError(err)), nil + } + + return share.ShareAllGbxPositionRequest(true, flags.SetNull), nil +} + +// ShareInrCancel +// +// @Description: 英股撤单 +// @receiver s +// @param ctx +// @param req +// @return *v1.InrOrderReply +// @return error +func (s *ConduitService) ShareGbxCancel(ctx context.Context, req *v1.CancelGbxOrderRequest) (*v1.OrderGbxReply, error) { + if !share.VerificationGbxShareCancel(req) { + return share.ShareGbxCancelReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.gb.ShareGbxCancel(ctx, req.OrderId) + if err != nil { + return share.ShareGbxCancelReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareGbxCancelReply(true, flags.SetNull, req), nil +} diff --git a/internal/service/share_hkd.go b/internal/service/share_hkd.go new file mode 100644 index 0000000..8e91937 --- /dev/null +++ b/internal/service/share_hkd.go @@ -0,0 +1,131 @@ +package service + +import ( + "context" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "matchmaking-system/internal/service/share" + + v1 "matchmaking-system/api/matchmaking/v1/share" +) + +// GetBotStockHkdTrade +// +// @Description: 港股订单列表 +// @receiver s +// @param ctx +// @param req +// @return *v1.GetUsBotStockTradeReply +// @return error +func (s *ConduitService) GetBotStockHkdTrade(ctx context.Context, req *v1.GetBotStockHkdTradeRequest) (*v1.GetBotStockHkdTradeReply, error) { + if !share.VerificationBotStockHkdTrade(req) { + return share.BotStockHkdTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil + } + + stockTradeList, totalCount, err := s.hd.BotStockHkdTradeList(ctx, req.PageSize, req.PageCount, req.Status) + if err != nil { + return share.BotStockHkdTradeReply(false, err.Error(), req, nil, 0), nil + } + + return share.BotStockHkdTradeReply(true, flags.SetNull, req, stockTradeList, totalCount), nil +} + +// SharePlaceOrder +// +// @Description: 港股下单 +// @receiver s +// @param ctx +// @param req +// @return *v1.UsOrderReply +// @return error +func (s *ConduitService) ShareHkdPlaceOrder(ctx context.Context, req *v1.OrderHkdRequest) (*v1.OrderHkdReply, error) { + if !share.VerificationShareHkdOrderQuery(req) { + return share.ShareHkdPlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil + } + + orderId, err := s.hd.ShareHkdPlaceOrder(ctx, share.ShareHkdOrderQuery(req)) + if err != nil { + return share.ShareHkdPlaceOrderReply(false, order.CheckShareError(err), flags.SetNull), nil + } + + return share.ShareHkdPlaceOrderReply(true, flags.SetNull, orderId), nil +} + +// ShareUpdateOrder +// +// @Description: 港股设置止盈止损 +// @receiver s +// @param ctx +// @param req +// @return *v1.UsOrderReply +// @return error +func (s *ConduitService) ShareHkdUpdateOrder(ctx context.Context, req *v1.UpdateHkdOrderRequest) (*v1.OrderHkdReply, error) { + if !share.VerificationStopOrderHkdQuery(req) { + return share.ShareHkdUpdateOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.hd.ShareHkdUpdateOrder(ctx, share.StopOrderHkdQuery(req)) + if err != nil { + return share.ShareHkdUpdateOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareHkdUpdateOrderReply(true, flags.SetNull, req), nil +} + +// SharePosition +// +// @Description: 港股平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.UsOrderReply +// @return error +func (s *ConduitService) ShareHkdPosition(ctx context.Context, req *v1.CancelHkdOrderRequest) (*v1.OrderHkdReply, error) { + if !share.VerificationShareHkdPosition(req) { + return share.ShareHkdPositionOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.hd.ShareHkdPosition(ctx, req.OrderId) + if err != nil { + return share.ShareHkdPositionOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareHkdPositionOrderReply(true, flags.SetNull, req), nil +} + +// ShareAllPosition +// +// @Description: 港股一键平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.AllHkdOrderReply +// @return error +func (s *ConduitService) ShareHkdAllPosition(ctx context.Context, req *v1.AllHkdOrderRequest) (*v1.AllHkdOrderReply, error) { + if err := s.hd.ShareHkdAllPosition(ctx); err != nil { + return share.ShareHkdAllPositionRequest(false, order.CheckShareError(err)), nil + } + + return share.ShareHkdAllPositionRequest(true, flags.SetNull), nil +} + +// ShareCancel +// +// @Description: 港股撤单 +// @receiver s +// @param ctx +// @param req +// @return *v1.UsOrderReply +// @return error +func (s *ConduitService) ShareHkdCancel(ctx context.Context, req *v1.CancelHkdOrderRequest) (*v1.OrderHkdReply, error) { + if !share.VerificationShareHkdCancel(req) { + return share.ShareHkdCancelReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.hd.ShareHkdCancel(ctx, req.OrderId) + if err != nil { + return share.ShareHkdCancelReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareHkdCancelReply(true, flags.SetNull, req), nil +} diff --git a/internal/service/share_idn.go b/internal/service/share_idn.go new file mode 100644 index 0000000..6e01686 --- /dev/null +++ b/internal/service/share_idn.go @@ -0,0 +1,131 @@ +package service + +import ( + "context" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "matchmaking-system/internal/service/share" + + v1 "matchmaking-system/api/matchmaking/v1/share" +) + +// GetBotStockIdnTrade +// +// @Description: 印尼股列表 +// @receiver s +// @param ctx +// @param req +// @return *v1.GetIdnBotStockIdnTradeReply +// @return error +func (s *ConduitService) GetBotStockIdnTrade(ctx context.Context, req *v1.GetIdnBotStockTradeRequest) (*v1.GetBotStockIdnTradeReply, error) { + if !share.VerificationIdnBotStockTrade(req) { + return share.BotStockIdnTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil + } + + stockTradeList, totalCount, err := s.id.BotStockIdnTradeList(ctx, req.PageSize, req.PageCount, req.Status) + if err != nil { + return share.BotStockIdnTradeReply(false, err.Error(), req, nil, 0), nil + } + + return share.BotStockIdnTradeReply(true, flags.SetNull, req, stockTradeList, totalCount), nil +} + +// ShareIdnPlaceOrder +// +// @Description: 印尼股下单 +// @receiver s +// @param ctx +// @param req +// @return *v1.IdnOrderReply +// @return error +func (s *ConduitService) ShareIdnPlaceOrder(ctx context.Context, req *v1.ShareIdnOrderRequest) (*v1.IdnOrderReply, error) { + if !share.VerificationIdnShareOrderQuery(req) { + return share.ShareIdnPlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil + } + + orderId, err := s.id.ShareIdnPlaceOrder(ctx, share.ShareIdnOrderQuery(req)) + if err != nil { + return share.ShareIdnPlaceOrderReply(false, order.CheckShareError(err), flags.SetNull), nil + } + + return share.ShareIdnPlaceOrderReply(true, flags.SetNull, orderId), nil +} + +// ShareIdnUpdateOrder +// +// @Description: 印尼股设置止盈止损 +// @receiver s +// @param ctx +// @param req +// @return *v1.IdnOrderReply +// @return error +func (s *ConduitService) ShareIdnUpdateOrder(ctx context.Context, req *v1.UpdateIdnOrderRequest) (*v1.IdnOrderReply, error) { + if !share.VerificationIdnStopOrderQuery(req) { + return share.ShareIdnUpdateOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.id.ShareIdnUpdateOrder(ctx, share.StopIdnOrderQuery(req)) + if err != nil { + return share.ShareIdnUpdateOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareIdnUpdateOrderReply(true, flags.SetNull, req), nil +} + +// ShareIdnPosition +// +// @Description: 印尼股平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.IdnOrderReply +// @return error +func (s *ConduitService) ShareIdnPosition(ctx context.Context, req *v1.CancelIdnOrderRequest) (*v1.IdnOrderReply, error) { + if !share.VerificationIdnSharePosition(req) { + return share.ShareIdnPositionOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.id.ShareIdnPosition(ctx, req.OrderId) + if err != nil { + return share.ShareIdnPositionOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareIdnPositionOrderReply(true, flags.SetNull, req), nil +} + +// ShareIdnAllPosition +// +// @Description: 印尼一键平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.AllIdnOrderReply +// @return error +func (s *ConduitService) ShareIdnAllPosition(ctx context.Context, req *v1.AllIdnOrderRequest) (*v1.AllIdnOrderReply, error) { + if err := s.id.ShareIdnAllPosition(ctx); err != nil { + return share.ShareIdnAllPositionRequest(false, order.CheckShareError(err)), nil + } + + return share.ShareIdnAllPositionRequest(true, flags.SetNull), nil +} + +// ShareIdnCancel +// +// @Description: 印尼股撤单 +// @receiver s +// @param ctx +// @param req +// @return *v1.IdnOrderReply +// @return error +func (s *ConduitService) ShareIdnCancel(ctx context.Context, req *v1.CancelIdnOrderRequest) (*v1.IdnOrderReply, error) { + if !share.VerificationIdnShareCancel(req) { + return share.ShareIdnCancelReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.id.ShareIdnCancel(ctx, req.OrderId) + if err != nil { + return share.ShareIdnCancelReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareIdnCancelReply(true, flags.SetNull, req), nil +} diff --git a/internal/service/share_inr.go b/internal/service/share_inr.go new file mode 100644 index 0000000..8fb1495 --- /dev/null +++ b/internal/service/share_inr.go @@ -0,0 +1,131 @@ +package service + +import ( + "context" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "matchmaking-system/internal/service/share" + + v1 "matchmaking-system/api/matchmaking/v1/share" +) + +// GetBotStockInrTrade +// +// @Description: 印度股订单列表 +// @receiver s +// @param ctx +// @param req +// @return *v1.GetInrBotStockInrTradeReply +// @return error +func (s *ConduitService) GetBotStockInrTrade(ctx context.Context, req *v1.GetInrBotStockTradeRequest) (*v1.GetBotStockInrTradeReply, error) { + if !share.VerificationInrBotStockTrade(req) { + return share.BotStockInrTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil + } + + stockTradeList, totalCount, err := s.in.BotStockInrTradeList(ctx, req.PageSize, req.PageCount, req.Status) + if err != nil { + return share.BotStockInrTradeReply(false, err.Error(), req, nil, 0), nil + } + + return share.BotStockInrTradeReply(true, flags.SetNull, req, stockTradeList, totalCount), nil +} + +// ShareInrPlaceOrder +// +// @Description: 印度股下单 +// @receiver s +// @param ctx +// @param req +// @return *v1.InrOrderReply +// @return error +func (s *ConduitService) ShareInrPlaceOrder(ctx context.Context, req *v1.ShareInrOrderRequest) (*v1.InrOrderReply, error) { + if !share.VerificationInrShareOrderQuery(req) { + return share.ShareInrPlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil + } + + orderId, err := s.in.ShareInrPlaceOrder(ctx, share.ShareInrOrderQuery(req)) + if err != nil { + return share.ShareInrPlaceOrderReply(false, order.CheckShareError(err), flags.SetNull), nil + } + + return share.ShareInrPlaceOrderReply(true, flags.SetNull, orderId), nil +} + +// ShareInrUpdateOrder +// +// @Description: 印度股止盈止损 +// @receiver s +// @param ctx +// @param req +// @return *v1.InrOrderReply +// @return error +func (s *ConduitService) ShareInrUpdateOrder(ctx context.Context, req *v1.UpdateInrOrderRequest) (*v1.InrOrderReply, error) { + if !share.VerificationInrStopOrderQuery(req) { + return share.ShareInrUpdateOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.in.ShareInrUpdateOrder(ctx, share.StopInrOrderQuery(req)) + if err != nil { + return share.ShareInrUpdateOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareInrUpdateOrderReply(true, flags.SetNull, req), nil +} + +// ShareInrPosition +// +// @Description: 印度股平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.InrOrderReply +// @return error +func (s *ConduitService) ShareInrPosition(ctx context.Context, req *v1.CancelInrOrderRequest) (*v1.InrOrderReply, error) { + if !share.VerificationInrSharePosition(req) { + return share.ShareInrPositionOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.in.ShareInrPosition(ctx, req.OrderId) + if err != nil { + return share.ShareInrPositionOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareInrPositionOrderReply(true, flags.SetNull, req), nil +} + +// ShareInrAllPosition +// +// @Description: 印度股一键平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.AllInrOrderReply +// @return error +func (s *ConduitService) ShareInrAllPosition(ctx context.Context, req *v1.AllInrOrderRequest) (*v1.AllInrOrderReply, error) { + if err := s.in.ShareInrAllPosition(ctx); err != nil { + return share.ShareInrAllPositionRequest(false, order.CheckShareError(err)), nil + } + + return share.ShareInrAllPositionRequest(true, flags.SetNull), nil +} + +// ShareInrCancel +// +// @Description: 印度股撤单 +// @receiver s +// @param ctx +// @param req +// @return *v1.InrOrderReply +// @return error +func (s *ConduitService) ShareInrCancel(ctx context.Context, req *v1.CancelInrOrderRequest) (*v1.InrOrderReply, error) { + if !share.VerificationInrShareCancel(req) { + return share.ShareInrCancelReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.in.ShareInrCancel(ctx, req.OrderId) + if err != nil { + return share.ShareInrCancelReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareInrCancelReply(true, flags.SetNull, req), nil +} diff --git a/internal/service/share_jpy.go b/internal/service/share_jpy.go new file mode 100644 index 0000000..6943cd4 --- /dev/null +++ b/internal/service/share_jpy.go @@ -0,0 +1,131 @@ +package service + +import ( + "context" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "matchmaking-system/internal/service/share" + + v1 "matchmaking-system/api/matchmaking/v1/share" +) + +// GetBotStockEurTrade +// +// @Description: 日本股订单列表 +// @receiver s +// @param ctx +// @param req +// @return *v1.GetBotStockJpyTradeReply +// @return error +func (s *ConduitService) GetBotStockJpyTrade(ctx context.Context, req *v1.GetJpyBotStockTradeRequest) (*v1.GetBotStockJpyTradeReply, error) { + if !share.VerificationJpyBotStockTrade(req) { + return share.BotStockJpyTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil + } + + stockTradeList, totalCount, err := s.jp.BotStockJpyTradeList(ctx, req.PageSize, req.PageCount, req.Status) + if err != nil { + return share.BotStockJpyTradeReply(false, err.Error(), req, nil, 0), nil + } + + return share.BotStockJpyTradeReply(true, flags.SetNull, req, stockTradeList, totalCount), nil +} + +// ShareEurPlaceOrder +// +// @Description: 日本股下单 +// @receiver s +// @param ctx +// @param req +// @return *v1.JpyOrderReply +// @return error +func (s *ConduitService) ShareJpyPlaceOrder(ctx context.Context, req *v1.ShareJpyOrderRequest) (*v1.JpyOrderReply, error) { + if !share.VerificationJpyShareOrderQuery(req) { + return share.ShareJpyPlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil + } + + orderId, err := s.jp.ShareJpyPlaceOrder(ctx, share.ShareJpyOrderQuery(req)) + if err != nil { + return share.ShareJpyPlaceOrderReply(false, order.CheckShareError(err), flags.SetNull), nil + } + + return share.ShareJpyPlaceOrderReply(true, flags.SetNull, orderId), nil +} + +// ShareEurUpdateOrder +// +// @Description: 日本股设置止盈止损 +// @receiver s +// @param ctx +// @param req +// @return *v1.JpyOrderReply +// @return error +func (s *ConduitService) ShareJpyUpdateOrder(ctx context.Context, req *v1.UpdateJpyOrderRequest) (*v1.JpyOrderReply, error) { + if !share.VerificationJpyStopOrderQuery(req) { + return share.ShareJpyUpdateOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.jp.ShareJpyUpdateOrder(ctx, share.StopJpyOrderQuery(req)) + if err != nil { + return share.ShareJpyUpdateOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareJpyUpdateOrderReply(true, flags.SetNull, req), nil +} + +// ShareEurPosition +// +// @Description: 日本股平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.JpyOrderReply +// @return error +func (s *ConduitService) ShareJpyPosition(ctx context.Context, req *v1.CancelJpyOrderRequest) (*v1.JpyOrderReply, error) { + if !share.VerificationJpySharePosition(req) { + return share.ShareJpyPositionOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.jp.ShareJpyPosition(ctx, req.OrderId) + if err != nil { + return share.ShareJpyPositionOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareJpyPositionOrderReply(true, flags.SetNull, req), nil +} + +// ShareEurAllPosition +// +// @Description: 日本股一键平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.AllJpyOrderReply +// @return error +func (s *ConduitService) ShareJpyAllPosition(ctx context.Context, req *v1.AllJpyOrderRequest) (*v1.AllJpyOrderReply, error) { + if err := s.jp.ShareJpyAllPosition(ctx); err != nil { + return share.ShareAllJpyPositionRequest(false, order.CheckShareError(err)), nil + } + + return share.ShareAllJpyPositionRequest(true, flags.SetNull), nil +} + +// ShareEurCancel +// +// @Description: 日本股撤单 +// @receiver s +// @param ctx +// @param req +// @return *v1.JpyOrderReply +// @return error +func (s *ConduitService) ShareJpyCancel(ctx context.Context, req *v1.CancelJpyOrderRequest) (*v1.JpyOrderReply, error) { + if !share.VerificationJpyShareCancel(req) { + return share.ShareJpyCancelReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.jp.ShareJpyCancel(ctx, req.OrderId) + if err != nil { + return share.ShareJpyCancelReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareJpyCancelReply(true, flags.SetNull, req), nil +} diff --git a/internal/service/share_mys.go b/internal/service/share_mys.go new file mode 100644 index 0000000..6f0818d --- /dev/null +++ b/internal/service/share_mys.go @@ -0,0 +1,131 @@ +package service + +import ( + "context" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "matchmaking-system/internal/service/share" + + v1 "matchmaking-system/api/matchmaking/v1/share" +) + +// GetBotStockMysTrade +// +// @Description: 马股订单列表 +// @receiver s +// @param ctx +// @param req +// @return *v1.GetMysBotStockMysTradeReply +// @return error +func (s *ConduitService) GetBotStockMysTrade(ctx context.Context, req *v1.GetMysBotStockTradeRequest) (*v1.GetBotStockMysTradeReply, error) { + if !share.VerificationMysBotStockTrade(req) { + return share.BotStockMysTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil + } + + stockTradeList, totalCount, err := s.my.BotStockMysTradeList(ctx, req.PageSize, req.PageCount, req.Status) + if err != nil { + return share.BotStockMysTradeReply(false, err.Error(), req, nil, 0), nil + } + + return share.BotStockMysTradeReply(true, flags.SetNull, req, stockTradeList, totalCount), nil +} + +// ShareMysPlaceOrder +// +// @Description: 马股下单 +// @receiver s +// @param ctx +// @param req +// @return *v1.MysOrderReply +// @return error +func (s *ConduitService) ShareMysPlaceOrder(ctx context.Context, req *v1.ShareMysOrderRequest) (*v1.MysOrderReply, error) { + if !share.VerificationMysShareOrderQuery(req) { + return share.SharePlaceMysOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil + } + + orderId, err := s.my.ShareMysPlaceOrder(ctx, share.ShareMysOrderQuery(req)) + if err != nil { + return share.SharePlaceMysOrderReply(false, order.CheckShareError(err), flags.SetNull), nil + } + + return share.SharePlaceMysOrderReply(true, flags.SetNull, orderId), nil +} + +// ShareMysUpdateOrder +// +// @Description: 马股设置止盈止损 +// @receiver s +// @param ctx +// @param req +// @return *v1.MysOrderReply +// @return error +func (s *ConduitService) ShareMysUpdateOrder(ctx context.Context, req *v1.UpdateMysOrderRequest) (*v1.MysOrderReply, error) { + if !share.VerificationMysStopOrderQuery(req) { + return share.ShareUpdateMysOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.my.ShareMysUpdateOrder(ctx, share.StopOrderMysQuery(req)) + if err != nil { + return share.ShareUpdateMysOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareUpdateMysOrderReply(true, flags.SetNull, req), nil +} + +// ShareMysPosition +// +// @Description: 马股平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.MysOrderReply +// @return error +func (s *ConduitService) ShareMysPosition(ctx context.Context, req *v1.CancelMysOrderRequest) (*v1.MysOrderReply, error) { + if !share.VerificationMysSharePosition(req) { + return share.ShareMysPositionOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.my.ShareMysPosition(ctx, req.OrderId) + if err != nil { + return share.ShareMysPositionOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareMysPositionOrderReply(true, flags.SetNull, req), nil +} + +// ShareMysAllPosition +// +// @Description: 马股一键平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.AllMysOrderReply +// @return error +func (s *ConduitService) ShareMysAllPosition(ctx context.Context, req *v1.AllMysOrderRequest) (*v1.AllMysOrderReply, error) { + if err := s.my.ShareMysAllPosition(ctx); err != nil { + return share.ShareAllMysPositionRequest(false, order.CheckShareError(err)), nil + } + + return share.ShareAllMysPositionRequest(true, flags.SetNull), nil +} + +// ShareMysCancel +// +// @Description: 马股撤单 +// @receiver s +// @param ctx +// @param req +// @return *v1.MysOrderReply +// @return error +func (s *ConduitService) ShareMysCancel(ctx context.Context, req *v1.CancelMysOrderRequest) (*v1.MysOrderReply, error) { + if !share.VerificationMysShareCancel(req) { + return share.ShareMysCancelReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.my.ShareMysCancel(ctx, req.OrderId) + if err != nil { + return share.ShareMysCancelReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareMysCancelReply(true, flags.SetNull, req), nil +} diff --git a/internal/service/share_sgd.go b/internal/service/share_sgd.go new file mode 100644 index 0000000..ff2d1af --- /dev/null +++ b/internal/service/share_sgd.go @@ -0,0 +1,131 @@ +package service + +import ( + "context" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "matchmaking-system/internal/service/share" + + v1 "matchmaking-system/api/matchmaking/v1/share" +) + +// GetBotStockSgdTrade +// +// @Description: 新加坡股订单列表 +// @receiver s +// @param ctx +// @param req +// @return *v1.GetBotStockSgdTradeReply +// @return error +func (s *ConduitService) GetBotStockSgdTrade(ctx context.Context, req *v1.GetSgdBotStockTradeRequest) (*v1.GetBotStockSgdTradeReply, error) { + if !share.VerificationSgdBotStockTrade(req) { + return share.BotStockSgdTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil + } + + stockTradeList, totalCount, err := s.sg.BotStockSgdTradeList(ctx, req.PageSize, req.PageCount, req.Status) + if err != nil { + return share.BotStockSgdTradeReply(false, err.Error(), req, nil, 0), nil + } + + return share.BotStockSgdTradeReply(true, flags.SetNull, req, stockTradeList, totalCount), nil +} + +// ShareSgdPlaceOrder +// +// @Description: 新加坡股下单 +// @receiver s +// @param ctx +// @param req +// @return *v1.SgdOrderReply +// @return error +func (s *ConduitService) ShareSgdPlaceOrder(ctx context.Context, req *v1.ShareSgdOrderRequest) (*v1.SgdOrderReply, error) { + if !share.VerificationSgdShareOrderQuery(req) { + return share.ShareSgdPlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil + } + + orderId, err := s.sg.ShareSgdPlaceOrder(ctx, share.ShareSgdOrderQuery(req)) + if err != nil { + return share.ShareSgdPlaceOrderReply(false, order.CheckShareError(err), flags.SetNull), nil + } + + return share.ShareSgdPlaceOrderReply(true, flags.SetNull, orderId), nil +} + +// ShareSgdUpdateOrder +// +// @Description: 新加坡股设置止盈止损 +// @receiver s +// @param ctx +// @param req +// @return *v1.SgdOrderReply +// @return error +func (s *ConduitService) ShareSgdUpdateOrder(ctx context.Context, req *v1.UpdateSgdOrderRequest) (*v1.SgdOrderReply, error) { + if !share.VerificationSgdStopOrderQuery(req) { + return share.ShareSgdUpdateOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.sg.ShareSgdUpdateOrder(ctx, share.StopSgdOrderQuery(req)) + if err != nil { + return share.ShareSgdUpdateOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareSgdUpdateOrderReply(true, flags.SetNull, req), nil +} + +// ShareSgdPosition +// +// @Description: 新加坡股平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.SgdOrderReply +// @return error +func (s *ConduitService) ShareSgdPosition(ctx context.Context, req *v1.CancelSgdOrderRequest) (*v1.SgdOrderReply, error) { + if !share.VerificationSgdSharePosition(req) { + return share.ShareSgdPositionOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.sg.ShareSgdPosition(ctx, req.OrderId) + if err != nil { + return share.ShareSgdPositionOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareSgdPositionOrderReply(true, flags.SetNull, req), nil +} + +// ShareSgdAllPosition +// +// @Description: 新加坡股一键平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.AllSgdOrderReply +// @return error +func (s *ConduitService) ShareSgdAllPosition(ctx context.Context, req *v1.AllSgdOrderRequest) (*v1.AllSgdOrderReply, error) { + if err := s.sg.ShareSgdAllPosition(ctx); err != nil { + return share.ShareAllSgdPositionRequest(false, order.CheckShareError(err)), nil + } + + return share.ShareAllSgdPositionRequest(true, flags.SetNull), nil +} + +// ShareSgdCancel +// +// @Description: 新加坡股撤单 +// @receiver s +// @param ctx +// @param req +// @return *v1.SgdOrderReply +// @return error +func (s *ConduitService) ShareSgdCancel(ctx context.Context, req *v1.CancelSgdOrderRequest) (*v1.SgdOrderReply, error) { + if !share.VerificationSgdShareCancel(req) { + return share.ShareSgdCancelReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.sg.ShareSgdCancel(ctx, req.OrderId) + if err != nil { + return share.ShareSgdCancelReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareSgdCancelReply(true, flags.SetNull, req), nil +} diff --git a/internal/service/share_tha.go b/internal/service/share_tha.go new file mode 100644 index 0000000..3e8ba00 --- /dev/null +++ b/internal/service/share_tha.go @@ -0,0 +1,131 @@ +package service + +import ( + "context" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "matchmaking-system/internal/service/share" + + v1 "matchmaking-system/api/matchmaking/v1/share" +) + +// GetBotStockThaTrade +// +// @Description: 泰股订单列表 +// @receiver s +// @param ctx +// @param req +// @return *v1.GetThaBotStockThaTradeReply +// @return error +func (s *ConduitService) GetBotStockThaTrade(ctx context.Context, req *v1.GetThaBotStockTradeRequest) (*v1.GetBotStockThaTradeReply, error) { + if !share.VerificationThaBotStockTrade(req) { + return share.BotStockThaTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil + } + + stockTradeList, totalCount, err := s.ta.BotStockThaTradeList(ctx, req.PageSize, req.PageCount, req.Status) + if err != nil { + return share.BotStockThaTradeReply(false, err.Error(), req, nil, 0), nil + } + + return share.BotStockThaTradeReply(true, flags.SetNull, req, stockTradeList, totalCount), nil +} + +// ShareThaPlaceOrder +// +// @Description: 泰股下单 +// @receiver s +// @param ctx +// @param req +// @return *v1.ThaOrderReply +// @return error +func (s *ConduitService) ShareThaPlaceOrder(ctx context.Context, req *v1.ShareThaOrderRequest) (*v1.ThaOrderReply, error) { + if !share.VerificationThaShareOrderQuery(req) { + return share.ShareThaPlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil + } + + orderId, err := s.ta.ShareThaPlaceOrder(ctx, share.ShareThaOrderQuery(req)) + if err != nil { + return share.ShareThaPlaceOrderReply(false, order.CheckShareError(err), flags.SetNull), nil + } + + return share.ShareThaPlaceOrderReply(true, flags.SetNull, orderId), nil +} + +// ShareThaUpdateOrder +// +// @Description: 泰股设置止盈止损 +// @receiver s +// @param ctx +// @param req +// @return *v1.ThaOrderReply +// @return error +func (s *ConduitService) ShareThaUpdateOrder(ctx context.Context, req *v1.UpdateThaOrderRequest) (*v1.ThaOrderReply, error) { + if !share.VerificationThaStopOrderQuery(req) { + return share.ShareThaUpdateOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.ta.ShareThaUpdateOrder(ctx, share.StopThaOrderQuery(req)) + if err != nil { + return share.ShareThaUpdateOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareThaUpdateOrderReply(true, flags.SetNull, req), nil +} + +// ShareThaPosition +// +// @Description: 泰股平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.ThaOrderReply +// @return error +func (s *ConduitService) ShareThaPosition(ctx context.Context, req *v1.CancelThaOrderRequest) (*v1.ThaOrderReply, error) { + if !share.VerificationThaSharePosition(req) { + return share.ShareThaPositionOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.ta.ShareThaPosition(ctx, req.OrderId) + if err != nil { + return share.ShareThaPositionOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareThaPositionOrderReply(true, flags.SetNull, req), nil +} + +// ShareThaAllPosition +// +// @Description: 泰股一键平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.AllThaOrderReply +// @return error +func (s *ConduitService) ShareThaAllPosition(ctx context.Context, req *v1.AllThaOrderRequest) (*v1.AllThaOrderReply, error) { + if err := s.ta.ShareThaAllPosition(ctx); err != nil { + return share.ShareAllThaPositionRequest(false, order.CheckShareError(err)), nil + } + + return share.ShareAllThaPositionRequest(true, flags.SetNull), nil +} + +// ShareThaCancel +// +// @Description: 泰股撤单 +// @receiver s +// @param ctx +// @param req +// @return *v1.ThaOrderReply +// @return error +func (s *ConduitService) ShareThaCancel(ctx context.Context, req *v1.CancelThaOrderRequest) (*v1.ThaOrderReply, error) { + if !share.VerificationThaShareCancel(req) { + return share.ShareThaCancelReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.ta.ShareThaCancel(ctx, req.OrderId) + if err != nil { + return share.ShareThaCancelReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareThaCancelReply(true, flags.SetNull, req), nil +} diff --git a/internal/service/share_us.go b/internal/service/share_us.go new file mode 100644 index 0000000..3c9a5a1 --- /dev/null +++ b/internal/service/share_us.go @@ -0,0 +1,131 @@ +package service + +import ( + "context" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "matchmaking-system/internal/service/share" + + v1 "matchmaking-system/api/matchmaking/v1/share" +) + +// GetBotStockTrade +// +// @Description: 美股订单列表 +// @receiver s +// @param ctx +// @param req +// @return *v1.GetUsBotStockTradeReply +// @return error +func (s *ConduitService) GetBotStockTrade(ctx context.Context, req *v1.GetUsBotStockTradeRequest) (*v1.GetUsBotStockTradeReply, error) { + if !share.VerificationBotStockTrade(req) { + return share.BotStockTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil + } + + stockTradeList, totalCount, err := s.us.BotStockTradeList(ctx, req.PageSize, req.PageCount, req.Status) + if err != nil { + return share.BotStockTradeReply(false, err.Error(), req, nil, 0), nil + } + + return share.BotStockTradeReply(true, flags.SetNull, req, stockTradeList, totalCount), nil +} + +// SharePlaceOrder +// +// @Description: 美股下单 +// @receiver s +// @param ctx +// @param req +// @return *v1.UsOrderReply +// @return error +func (s *ConduitService) SharePlaceOrder(ctx context.Context, req *v1.UsOrderRequest) (*v1.UsOrderReply, error) { + if !share.VerificationShareOrderQuery(req) { + return share.ShareUsPlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil + } + + orderId, err := s.us.SharePlaceOrder(ctx, share.ShareUsOrderQuery(req)) + if err != nil { + return share.ShareUsPlaceOrderReply(false, order.CheckShareError(err), flags.SetNull), nil + } + + return share.ShareUsPlaceOrderReply(true, flags.SetNull, orderId), nil +} + +// ShareUpdateOrder +// +// @Description: 美股设置止盈止损 +// @receiver s +// @param ctx +// @param req +// @return *v1.UsOrderReply +// @return error +func (s *ConduitService) ShareUpdateOrder(ctx context.Context, req *v1.UpdateUsOrderRequest) (*v1.UsOrderReply, error) { + if !share.VerificationStopOrderQuery(req) { + return share.ShareUpdateOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.us.ShareUpdateOrder(ctx, share.StopOrderQuery(req)) + if err != nil { + return share.ShareUpdateOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareUpdateOrderReply(true, flags.SetNull, req), nil +} + +// SharePosition +// +// @Description: 美股平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.UsOrderReply +// @return error +func (s *ConduitService) SharePosition(ctx context.Context, req *v1.CancelUsOrderRequest) (*v1.UsOrderReply, error) { + if !share.VerificationSharePosition(req) { + return share.SharePositionOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.us.SharePosition(ctx, req.OrderId) + if err != nil { + return share.SharePositionOrderReply(false, order.CheckShareError(err), req), nil + } + + return share.SharePositionOrderReply(true, flags.SetNull, req), nil +} + +// ShareAllPosition +// +// @Description: 美股一键平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.AllUsOrderReply +// @return error +func (s *ConduitService) ShareAllPosition(ctx context.Context, req *v1.AllUsOrderRequest) (*v1.AllUsOrderReply, error) { + if err := s.us.ShareAllPosition(ctx); err != nil { + return share.ShareAllPositionRequest(false, order.CheckShareError(err)), nil + } + + return share.ShareAllPositionRequest(true, flags.SetNull), nil +} + +// ShareCancel +// +// @Description: 美股撤单 +// @receiver s +// @param ctx +// @param req +// @return *v1.UsOrderReply +// @return error +func (s *ConduitService) ShareCancel(ctx context.Context, req *v1.CancelUsOrderRequest) (*v1.UsOrderReply, error) { + if !share.VerificationShareCancel(req) { + return share.ShareCancelReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.us.ShareCancel(ctx, req.OrderId) + if err != nil { + return share.ShareCancelReply(false, order.CheckShareError(err), req), nil + } + + return share.ShareCancelReply(true, flags.SetNull, req), nil +} diff --git a/internal/service/virtual/contract.go b/internal/service/virtual/contract.go new file mode 100644 index 0000000..5697474 --- /dev/null +++ b/internal/service/virtual/contract.go @@ -0,0 +1,326 @@ +package virtual + +import ( + "google.golang.org/protobuf/types/known/timestamppb" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/service/order" + "strconv" + + v1 "matchmaking-system/api/matchmaking/v1/virtually" + models "matchmaking-system/internal/pkg/model" +) + +// ContractStopQuery +// +// @Description: +// @param request +// @return structure.StopOrder +func ContractStopQuery(request *v1.UpdateContractRequest) structure.StopOrder { + return structure.StopOrder{ + OrderId: request.OrderId, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + } +} + +// ContractCancelOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.OrderReply +func ContractCancelOrderReply(check bool, err string, req *v1.CancelContractRequest) *v1.ContractReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.ContractReply{ + Code: code, + Data: ResultContractMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationContractCancel +// +// @Description: +// @param req +// @return bool +func VerificationContractCancel(req *v1.CancelContractRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// ContractAllPositionReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.AllOrderReply +func ContractAllPositionReply(check bool, err string) *v1.AllContractReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.AllContractReply{ + Code: code, + Data: "", + Message: replyStr, + } +} + +// ContractPositionOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.OrderReply +func ContractPositionOrderReply(check bool, err string, req *v1.CancelContractRequest) *v1.ContractReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.ContractReply{ + Code: code, + Data: ResultContractMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationContractPosition +// +// @Description: +// @param req +// @return bool +func VerificationContractPosition(req *v1.CancelContractRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// ContractUpdatePlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.OrderReply +func ContractUpdatePlaceOrderReply(check bool, err string, req *v1.UpdateContractRequest) *v1.ContractReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.ContractReply{ + Code: code, + Data: ResultContractMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationContractUpdatePlaceOrder +// +// @Description: +// @param req +// @return bool +func VerificationContractUpdatePlaceOrder(req *v1.UpdateContractRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + switch req.StopType { + case 0: + return true + case 1: + if len(req.GetStopLossPrice()) <= 0 && len(req.GetStopWinPrice()) <= 0 { + return false + } + default: + return false + } + + return true +} + +// VerificationBotContractTrade +// +// @Description: +// @param req +// @return bool +func VerificationBotContractTrade(req *v1.GetBotContractTradeRequest) bool { + if req.GetPageSize() < 0 { + return false + } + if req.GetStatus() < 0 { + return false + } + if req.GetPageCount() < 0 { + return false + } + + return true +} + +// BotContractTradeMessage +// +// @Description: +// @param stockList +// @return contractTrade +func BotContractTradeMessage(stockList []*models.BotContractTrade) (contractTrade []*v1.BotContractTrade) { + for _, value := range stockList { + faceValue := strconv.FormatInt(value.FaceValue, 10) + contractTrade = append(contractTrade, &v1.BotContractTrade{ + OrderId: value.OrderId, + ContractId: value.ContractId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + DealPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + OrderNumber: value.OrderNumber, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + ServiceCost: value.ServiceCost, + EarnestMoney: value.EarnestMoney, + OrderMoney: value.OrderMoney, + Status: int64(value.Status), + ClosingCost: value.ClosingCost, + CreateTime: timestamppb.New(value.CreateTime), + UpdateTime: timestamppb.New(value.UpdateTime), + OpenTime: timestamppb.New(value.OpenTime), + ClosingTime: timestamppb.New(value.ClosingTime), + FaceValue: faceValue, + OvernightCost: value.OvernightCost, + KeepDecimal: strconv.Itoa(value.KeepDecimal), + PryNum: strconv.Itoa(value.PryNum), + SecondTime: strconv.Itoa(value.SecondTime), + State: int64(value.State), + }) + } + return +} + +// BotContractTradeReply +// +// @Description: +// @param check +// @param err +// @param req +// @param data +// @param totalCount +// @return *v1.GetBotContractTradeReply +func BotContractTradeReply(check bool, err string, req *v1.GetBotContractTradeRequest, data []*models.BotContractTrade, totalCount int64) *v1.GetBotContractTradeReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.GetBotContractTradeReply{ + Code: code, + Data: &v1.BotContractTradeData{ + PageSize: req.PageSize, + PageCount: req.PageCount, + Data: BotContractTradeMessage(data), + TotalCount: totalCount, + }, + Message: replyStr, + } +} + +// VerificationContractPlaceOrder +// +// @Description: 合约下单参数判定 +// @param req +// @return bool +func VerificationContractPlaceOrder(req *v1.ContractRequest) bool { + if len(req.GetPryNum()) <= 0 { + return false + } + if len(req.GetContractId()) <= 0 { + return false + } + if len(req.GetOrderAmount()) <= 0 { + return false + } + if len(req.GetOrderNumber()) <= 0 { + return false + } + if len(req.GetEarnestMoney()) <= 0 { + return false + } + if len(req.GetServiceCost()) <= 0 { + return false + } + switch req.StopType { + case 1: + if len(req.GetStopLossPrice()) <= 0 && len(req.GetStopWinPrice()) <= 0 { + return false + } + } + + switch req.TradeType { + case 1: + case 2: + default: + return false + } + + switch req.DealType { + case 1: + if len(req.GetLimitPrice()) <= 0 { + return false + } + case 2: + if len(req.GetMarketPrice()) <= 0 { + return false + } + default: + return false + } + + return true +} + +// ContractPlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param orderId +// @return *v1.OrderReply +func ContractPlaceOrderReply(check bool, err string, orderId string) *v1.ContractReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.ContractReply{ + Code: code, + Data: ResultContractMessage(orderId), + Message: replyStr, + } +} + +// ResultContractMessage +// +// @Description: +// @param orderId +// @return *v1.Result +func ResultContractMessage(orderId string) *v1.ContractResult { + return &v1.ContractResult{ + OrderId: orderId, + } +} + +// ContractOrderQuery +// +// @Description: +// @param request +// @return structure.ContractOrder +func ContractOrderQuery(request *v1.ContractRequest) structure.ContractOrder { + return structure.ContractOrder{ + ContractId: request.ContractId, + TradeType: request.TradeType, + DealType: request.DealType, + LimitPrice: request.LimitPrice, + MarketPrice: request.MarketPrice, + OrderAmount: request.OrderAmount, + OrderNumber: request.OrderNumber, + EarnestMoney: request.EarnestMoney, + ServiceCost: request.ServiceCost, + StopType: request.StopType, + StopLossPrice: request.StopLossPrice, + StopWinPrice: request.StopWinPrice, + PryNum: request.PryNum, + } +} diff --git a/internal/service/virtual/second.go b/internal/service/virtual/second.go new file mode 100644 index 0000000..088a3d2 --- /dev/null +++ b/internal/service/virtual/second.go @@ -0,0 +1,194 @@ +package virtual + +import ( + "google.golang.org/protobuf/types/known/timestamppb" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/order" + "strconv" + + v1 "matchmaking-system/api/matchmaking/v1/virtually" + models "matchmaking-system/internal/pkg/model" +) + +// VerificationBotSecondTrade +// +// @Description: +// @param req +// @return bool +func VerificationBotSecondTrade(req *v1.GetBotSecondTradeRequest) bool { + if req.GetPageSize() < 0 { + return false + } + if req.GetStatus() < 0 { + return false + } + if req.GetPageCount() < 0 { + return false + } + + return true +} + +// BotSecondTradeReply +// +// @Description: +// @param check +// @param err +// @param req +// @param data +// @param totalCount +// @return *v1.GetBotContractTradeReply +func BotSecondTradeReply(check bool, err string, req *v1.GetBotSecondTradeRequest, data []*models.BotContractSecTrade, totalCount int64) *v1.GetBotSecondTradeReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.GetBotSecondTradeReply{ + Code: code, + Data: &v1.BotSecondTradeData{ + PageSize: req.PageSize, + PageCount: req.PageCount, + Data: BotSecondTradeMessage(data), + TotalCount: totalCount, + }, + Message: replyStr, + } +} + +// BotSecondTradeMessage +// +// @Description: +// @param stockList +// @return contractTrade +func BotSecondTradeMessage(stockList []*models.BotContractSecTrade) (contractTrade []*v1.BotSecondTrade) { + for _, value := range stockList { + faceValue := strconv.FormatInt(value.FaceValue, 10) + contractTrade = append(contractTrade, &v1.BotSecondTrade{ + OrderId: value.OrderId, + ContractId: value.ContractId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + DealPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + OrderNumber: value.OrderNumber, + StopType: int64(value.StopType), + StopLossPrice: value.StopLossPrice, + StopWinPrice: value.StopWinPrice, + ServiceCost: value.ServiceCost, + EarnestMoney: value.EarnestMoney, + OrderMoney: value.OrderMoney, + Status: int64(value.Status), + ClosingCost: value.ClosingCost, + CreateTime: timestamppb.New(value.CreateTime), + UpdateTime: timestamppb.New(value.UpdateTime), + OpenTime: timestamppb.New(value.OpenTime), + ClosingTime: timestamppb.New(value.ClosingTime), + FaceValue: faceValue, + OvernightCost: value.OvernightCost, + KeepDecimal: strconv.Itoa(value.KeepDecimal), + PryNum: strconv.Itoa(value.PryNum), + SecondTime: strconv.Itoa(value.SecondTime), + State: int64(value.State), + OrderStatus: int64(value.OrderStatus), + OrderValue: value.OrderValue, + }) + } + return +} + +// VerificationSecondOrder +// +// @Description: 秒合约下单参数判定 +// @param req +// @return bool +func VerificationSecondOrder(req *v1.SecondOrderRequest) bool { + if len(req.GetPryNum()) <= 0 { + req.PryNum = flags.SetOne + } + if len(req.GetContractId()) <= 0 { + return false + } + if len(req.GetOrderAmount()) <= 0 { + return false + } + if len(req.GetEarnestMoney()) <= 0 { + return false + } + if len(req.GetServiceCost()) <= 0 { + return false + } + if req.GetTime() <= 0 { + return false + } + + switch req.TradeType { + case 1: + case 2: + default: + return false + } + + switch req.DealType { + case 1: + if len(req.GetLimitPrice()) <= 0 { + return false + } + case 2: + if len(req.GetMarketPrice()) <= 0 { + return false + } + default: + return false + } + + return true +} + +// SecondPlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param orderId +// @return *v1.SecondOrderReply +func SecondPlaceOrderReply(check bool, err string, orderId string) *v1.SecondOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.SecondOrderReply{ + Code: code, + Data: SecondResultMessage(orderId), + Message: replyStr, + } +} + +// SecondResultMessage +// +// @Description: +// @param orderId +// @return *v1.SecondResult +func SecondResultMessage(orderId string) *v1.SecondResult { + return &v1.SecondResult{ + OrderId: orderId, + } +} + +// SecondQuery +// +// @Description: +// @param request +// @return structure.ContractOrder +func SecondQuery(request *v1.SecondOrderRequest) structure.ContractOrder { + return structure.ContractOrder{ + ContractId: request.ContractId, + TradeType: request.TradeType, + DealType: request.DealType, + LimitPrice: request.LimitPrice, + MarketPrice: request.MarketPrice, + OrderAmount: request.OrderAmount, + OrderNumber: request.OrderNumber, + EarnestMoney: request.EarnestMoney, + ServiceCost: request.ServiceCost, + PryNum: request.PryNum, + Time: request.Time, + } +} diff --git a/internal/service/virtual/spots.go b/internal/service/virtual/spots.go new file mode 100644 index 0000000..1802b79 --- /dev/null +++ b/internal/service/virtual/spots.go @@ -0,0 +1,216 @@ +package virtual + +import ( + "google.golang.org/protobuf/types/known/timestamppb" + "matchmaking-system/internal/biz/structure" + "matchmaking-system/internal/service/order" + "strconv" + + v1 "matchmaking-system/api/matchmaking/v1/virtually" + models "matchmaking-system/internal/pkg/model" +) + +// BotDigitalTradeMessage +// +// @Description: +// @param stockList +// @return BotDigitalTrade +func BotDigitalTradeMessage(stockList []*models.BotDigitalTrade) (stockTrade []*v1.BotDigitalTrade) { + for _, value := range stockList { + stockTrade = append(stockTrade, &v1.BotDigitalTrade{ + OrderId: value.OrderId, + DigitalId: value.DigitalId, + TradeType: int64(value.TradeType), + DealType: int64(value.DealType), + LimitPrice: value.LimitPrice, + MarketPrice: value.MarketPrice, + DealPrice: value.DealPrice, + ClosingPrice: value.ClosingPrice, + OrderNumber: value.OrderNumber, + ServiceCost: value.ServiceCost, + OrderMoney: value.OrderMoney, + TotalMoney: value.TotalMoney, + ClosingCost: value.ClosingCost, + Status: int64(value.Status), + CreateTime: timestamppb.New(value.CreateTime), + UpdateTime: timestamppb.New(value.UpdateTime), + OpenTime: timestamppb.New(value.OpenTime), + ClosingTime: timestamppb.New(value.ClosingTime), + KeepDecimal: strconv.Itoa(value.KeepDecimal), + }) + } + return +} + +// BotDigitalTradeReply +// +// @Description: +// @param check +// @param err +// @param req +// @param data +// @param totalCount +// @return *v1.GetBotDigitalTradeReply +func BotDigitalTradeReply(check bool, err string, req *v1.GetBotDigitalTradeRequest, data []*models.BotDigitalTrade, totalCount int64) *v1.GetBotDigitalTradeReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.GetBotDigitalTradeReply{ + Code: code, + Data: &v1.BotDigitalTradeData{ + PageSize: req.PageSize, + PageCount: req.PageCount, + Data: BotDigitalTradeMessage(data), + TotalCount: totalCount, + }, + Message: replyStr, + } +} + +// VerificationBotDigitalTrade +// +// @Description: +// @param req +// @return bool +func VerificationBotDigitalTrade(req *v1.GetBotDigitalTradeRequest) bool { + if req.GetPageSize() < 0 { + return false + } + if req.GetStatus() < 0 { + return false + } + if req.GetPageCount() < 0 { + return false + } + return true +} + +// SpotsPlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param orderId +// @return *v1.SpotsOrderReply +func SpotsPlaceOrderReply(check bool, err string, orderId string) *v1.SpotsOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.SpotsOrderReply{ + Code: code, + Data: ResultMessage(orderId), + Message: replyStr, + } +} + +// SpotsCancelOrderReply +// +// @Description: +// @param check +// @param err +// @param req +// @return *v1.SpotsOrderReply +func SpotsCancelOrderReply(check bool, err string, req *v1.CancelSpotsOrderRequest) *v1.SpotsOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + return &v1.SpotsOrderReply{ + Code: code, + Data: ResultMessage(req.OrderId), + Message: replyStr, + } +} + +// VerificationSpotsCancel +// +// @Description: +// @param req +// @return bool +func VerificationSpotsCancel(req *v1.CancelSpotsOrderRequest) bool { + if len(req.GetOrderId()) <= 0 { + return false + } + + return true +} + +// SpotsOrderQuery +// +// @Description: +// @param request +// @return structure.SpotsOrder +func SpotsOrderQuery(request *v1.SpotsOrderRequest) structure.SpotsOrder { + return structure.SpotsOrder{ + DigitalId: request.DigitalId, + TradeType: request.TradeType, + DealType: request.DealType, + DealPrice: request.DealPrice, + LimitPrice: request.LimitPrice, + MarketPrice: request.MarketPrice, + OrderNumber: request.OrderNumber, + OrderMoney: request.OrderMoney, + ServiceCost: request.ServiceCost, + } +} + +// ResultMessage +// +// @Description: +// @param orderId +// @return *v1.SpotsOrderResult +func ResultMessage(orderId string) *v1.SpotsOrderResult { + return &v1.SpotsOrderResult{ + OrderId: orderId, + } +} + +// SharePlaceOrderReply +// +// @Description: +// @param check +// @param err +// @param orderId +// @return *v1.SpotsOrderReply +func SharePlaceOrderReply(check bool, err string, orderId string) *v1.SpotsOrderReply { + code, replyStr := order.ResultCodeSrr(check, err) + + return &v1.SpotsOrderReply{ + Code: code, + Data: ResultMessage(orderId), + Message: replyStr, + } +} + +// VerificationSpotsPlaceOrder +// +// @Description: +// @param req +// @return bool +func VerificationSpotsPlaceOrder(req *v1.SpotsOrderRequest) bool { + if len(req.GetDigitalId()) <= 0 { + return false + } + if len(req.GetOrderNumber()) <= 0 { + return false + } + if len(req.GetOrderMoney()) <= 0 { + return false + } + if len(req.GetServiceCost()) <= 0 { + return false + } + switch req.DealType { + case 1: + if len(req.GetLimitPrice()) <= 0 { + return false + } + case 2: + if len(req.GetMarketPrice()) <= 0 { + return false + } + default: + return false + } + switch req.TradeType { + case 1: + case 2: + default: + return false + } + return true +} diff --git a/internal/service/virtual_contract.go b/internal/service/virtual_contract.go new file mode 100644 index 0000000..32a6f01 --- /dev/null +++ b/internal/service/virtual_contract.go @@ -0,0 +1,130 @@ +package service + +import ( + "context" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/virtual" + + v1 "matchmaking-system/api/matchmaking/v1/virtually" +) + +// GetBotContractTrade +// +// @Description: 合约订单列表 +// @receiver s +// @param ctx +// @param req +// @return *v1.GetBotContractTradeReply +// @return error +func (s *ConduitService) GetBotContractTrade(ctx context.Context, req *v1.GetBotContractTradeRequest) (*v1.GetBotContractTradeReply, error) { + if !virtual.VerificationBotContractTrade(req) { + return virtual.BotContractTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil + } + + contractTradeList, totalCount, err := s.co.BotContractTradeList(ctx, req.PageSize, req.PageCount, req.Status) + if err != nil { + return virtual.BotContractTradeReply(false, err.Error(), req, nil, 0), nil + } + + return virtual.BotContractTradeReply(true, flags.SetNull, req, contractTradeList, totalCount), nil +} + +// ContractPlaceOrder +// +// @Description: 合约下单 +// @receiver s +// @param ctx +// @param req +// @return *v1.ContractReply +// @return error +func (s *ConduitService) ContractPlaceOrder(ctx context.Context, req *v1.ContractRequest) (*v1.ContractReply, error) { + if !virtual.VerificationContractPlaceOrder(req) { + return virtual.ContractPlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil + } + + orderId, err := s.co.ContractPlaceOrder(ctx, virtual.ContractOrderQuery(req)) + if err != nil { + return virtual.ContractPlaceOrderReply(false, err.Error(), flags.SetNull), nil + } + + return virtual.ContractPlaceOrderReply(true, flags.SetNull, orderId), nil +} + +// ContractUpdatePlaceOrder +// +// @Description: 合约设置止盈止损 +// @receiver s +// @param ctx +// @param req +// @return *v1.ContractReply +// @return error +func (s *ConduitService) ContractUpdatePlaceOrder(ctx context.Context, req *v1.UpdateContractRequest) (*v1.ContractReply, error) { + if !virtual.VerificationContractUpdatePlaceOrder(req) { + return virtual.ContractUpdatePlaceOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.co.ContractUpdatePlaceOrder(ctx, virtual.ContractStopQuery(req)) + if err != nil { + return virtual.ContractUpdatePlaceOrderReply(false, err.Error(), req), nil + } + + return virtual.ContractUpdatePlaceOrderReply(true, flags.SetNull, req), nil +} + +// ContractPosition +// +// @Description: 合约平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.ContractReply +// @return error +func (s *ConduitService) ContractPosition(ctx context.Context, req *v1.CancelContractRequest) (*v1.ContractReply, error) { + if !virtual.VerificationContractPosition(req) { + return virtual.ContractPositionOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.co.ContractPosition(ctx, req.OrderId) + if err != nil { + return virtual.ContractPositionOrderReply(false, err.Error(), req), nil + } + + return virtual.ContractPositionOrderReply(true, flags.SetNull, req), nil +} + +// ContractAllPosition +// +// @Description: 合约一键平仓 +// @receiver s +// @param ctx +// @param req +// @return *v1.AllContractReply +// @return error +func (s *ConduitService) ContractAllPosition(ctx context.Context, req *v1.AllContractRequest) (*v1.AllContractReply, error) { + if err := s.co.ContractAllPosition(ctx); err != nil { + return virtual.ContractAllPositionReply(false, err.Error()), nil + } + + return virtual.ContractAllPositionReply(true, flags.SetNull), nil +} + +// ContractCancel +// +// @Description: 合约撤单 +// @receiver s +// @param ctx +// @param req +// @return *v1.ContractReply +// @return error +func (s *ConduitService) ContractCancel(ctx context.Context, req *v1.CancelContractRequest) (*v1.ContractReply, error) { + if !virtual.VerificationContractCancel(req) { + return virtual.ContractCancelOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.co.ContractCancel(ctx, req.OrderId) + if err != nil { + return virtual.ContractCancelOrderReply(false, err.Error(), req), nil + } + + return virtual.ContractCancelOrderReply(true, flags.SetNull, req), nil +} diff --git a/internal/service/virtual_second.go b/internal/service/virtual_second.go new file mode 100644 index 0000000..f3802ad --- /dev/null +++ b/internal/service/virtual_second.go @@ -0,0 +1,51 @@ +package service + +import ( + "context" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/virtual" + + v1 "matchmaking-system/api/matchmaking/v1/virtually" +) + +// SecondGetBotContractTrade +// +// @Description: 秒合约订单列表 +// @receiver s +// @param ctx +// @param req +// @return *v1.GetBotSecondTradeReply +// @return error +func (s *ConduitService) SecondGetBotContractTrade(ctx context.Context, req *v1.GetBotSecondTradeRequest) (*v1.GetBotSecondTradeReply, error) { + if !virtual.VerificationBotSecondTrade(req) { + return virtual.BotSecondTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil + } + + contractTradeList, totalCount, err := s.so.SecondTradeList(ctx, req.PageSize, req.PageCount, req.Status) + if err != nil { + return virtual.BotSecondTradeReply(false, err.Error(), req, nil, 0), nil + } + + return virtual.BotSecondTradeReply(true, flags.SetNull, req, contractTradeList, totalCount), nil +} + +// SecondOrder +// +// @Description: 秒合约下单 +// @receiver s +// @param ctx +// @param req +// @return *v1.SecondOrderReply +// @return error +func (s *ConduitService) SecondOrder(ctx context.Context, req *v1.SecondOrderRequest) (*v1.SecondOrderReply, error) { + if !virtual.VerificationSecondOrder(req) { + return virtual.SecondPlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil + } + + orderId, err := s.so.SecondOrder(ctx, virtual.SecondQuery(req)) + if err != nil { + return virtual.SecondPlaceOrderReply(false, err.Error(), flags.SetNull), nil + } + + return virtual.SecondPlaceOrderReply(true, flags.SetNull, orderId), nil +} diff --git a/internal/service/virtual_spots.go b/internal/service/virtual_spots.go new file mode 100644 index 0000000..e3324c3 --- /dev/null +++ b/internal/service/virtual_spots.go @@ -0,0 +1,93 @@ +package service + +import ( + "context" + "matchmaking-system/internal/pkg/flags" + "matchmaking-system/internal/service/virtual" + + v1 "matchmaking-system/api/matchmaking/v1/virtually" +) + +// GetBotDigitalTrade +// +// @Description: 现货订单列表 +// @receiver s +// @param ctx +// @param req +// @return *v1.GetBotDigitalTradeReply +// @return error +func (s *ConduitService) GetBotDigitalTrade(ctx context.Context, req *v1.GetBotDigitalTradeRequest) (*v1.GetBotDigitalTradeReply, error) { + if !virtual.VerificationBotDigitalTrade(req) { + return virtual.BotDigitalTradeReply(false, flags.ErrIsParameter.Error(), req, nil, 0), nil + } + + digitalTradeList, totalCount, err := s.sp.BotDigitalTradeList(ctx, req.PageSize, req.PageCount, req.Status) + if err != nil { + return virtual.BotDigitalTradeReply(false, err.Error(), req, nil, 0), nil + } + + return virtual.BotDigitalTradeReply(true, flags.SetNull, req, digitalTradeList, totalCount), nil +} + +// SpotsPlaceOrder +// +// @Description: 现货下单 +// @receiver s +// @param ctx +// @param req +// @return *v1.SpotsOrderReply +// @return error +func (s *ConduitService) SpotsPlaceOrder(ctx context.Context, req *v1.SpotsOrderRequest) (*v1.SpotsOrderReply, error) { + if !virtual.VerificationSpotsPlaceOrder(req) { + return virtual.SharePlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil + } + + orderId, err := s.sp.SpotsPlaceOrder(ctx, virtual.SpotsOrderQuery(req)) + if err != nil { + return virtual.SharePlaceOrderReply(false, err.Error(), flags.SetNull), nil + } + + return virtual.SpotsPlaceOrderReply(true, flags.SetNull, orderId), nil +} + +// SpotsCancel +// +// @Description: 现货撤单 +// @receiver s +// @param ctx +// @param req +// @return *v1.SpotsOrderReply +// @return error +func (s *ConduitService) SpotsCancel(ctx context.Context, req *v1.CancelSpotsOrderRequest) (*v1.SpotsOrderReply, error) { + if !virtual.VerificationSpotsCancel(req) { + return virtual.SpotsCancelOrderReply(false, flags.ErrIsParameter.Error(), req), nil + } + + _, err := s.sp.SpotsCancel(ctx, req.OrderId) + if err != nil { + return virtual.SpotsCancelOrderReply(false, err.Error(), req), nil + } + + return virtual.SpotsCancelOrderReply(true, flags.SetNull, req), nil +} + +// SpotsOneClickRedemption +// +// @Description: 现货一键兑换 +// @receiver s +// @param ctx +// @param req +// @return *v1.SpotsOrderReply +// @return error +func (s *ConduitService) SpotsOneClickRedemption(ctx context.Context, req *v1.SpotsOrderRequest) (*v1.SpotsOrderReply, error) { + if !virtual.VerificationSpotsPlaceOrder(req) { + return virtual.SharePlaceOrderReply(false, flags.ErrIsParameter.Error(), flags.SetNull), nil + } + + orderId, err := s.sp.SpotsOneClickRedemption(ctx, virtual.SpotsOrderQuery(req)) + if err != nil { + return virtual.SharePlaceOrderReply(false, err.Error(), flags.SetNull), nil + } + + return virtual.SpotsPlaceOrderReply(true, flags.SetNull, orderId), nil +} diff --git a/openapi.yaml b/openapi.yaml new file mode 100644 index 0000000..1746a92 --- /dev/null +++ b/openapi.yaml @@ -0,0 +1,5187 @@ +# Generated with protoc-gen-openapi +# https://github.com/google/gnostic/tree/master/cmd/protoc-gen-openapi + +openapi: 3.0.3 +info: + title: "" + version: 0.0.1 +paths: + /order_backend/update_is_real: + post: + tags: + - Backend + description: UpdateBotUsersByIsReal 更新用户KYC认证 + operationId: Backend_UpdateBotUsersByIsReal + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.BotUsersNullRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.BotUsersReply' + /order_contract/contract_all_position: + post: + tags: + - Contract + description: ContractAllPosition 合约一键平仓 + operationId: Contract_ContractAllPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllContractRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllContractReply' + /order_contract/contract_cancel: + post: + tags: + - Contract + description: ContractCancel 合约撤单 + operationId: Contract_ContractCancel + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelContractRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ContractReply' + /order_contract/contract_list: + post: + tags: + - Contract + description: GetBotContractTrade 合约列表查询 + operationId: Contract_GetBotContractTrade + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotContractTradeRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotContractTradeReply' + /order_contract/contract_place_order: + post: + tags: + - Contract + description: ContractPlaceOrder 合约下单 + operationId: Contract_ContractPlaceOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ContractRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ContractReply' + /order_contract/contract_position: + post: + tags: + - Contract + description: ContractPosition 合约平仓 + operationId: Contract_ContractPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelContractRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ContractReply' + /order_contract/contract_update_order: + post: + tags: + - Contract + description: ContractUpdatePlaceOrder 合约设置止盈止损 + operationId: Contract_ContractUpdatePlaceOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UpdateContractRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ContractReply' + /order_forex/forex_all_position: + post: + tags: + - Forex + description: ForexAllPosition 外汇一键平仓 + operationId: Forex_ForexAllPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllForexRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllForexReply' + /order_forex/forex_cancel: + post: + tags: + - Forex + description: ForexCancel 外汇撤单 + operationId: Forex_ForexCancel + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelForexRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ForexReply' + /order_forex/forex_list: + post: + tags: + - Forex + description: GetBotForexTrade 外汇列表查询 + operationId: Forex_GetBotForexTrade + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotForexTradeRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotForexTradeReply' + /order_forex/forex_place_order: + post: + tags: + - Forex + description: ForexPlaceOrder 外汇下单 + operationId: Forex_ForexPlaceOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ForexRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ForexReply' + /order_forex/forex_position: + post: + tags: + - Forex + description: ForexPosition 外汇平仓 + operationId: Forex_ForexPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelForexRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ForexReply' + /order_forex/forex_update_order: + post: + tags: + - Forex + description: ForexUpdatePlaceOrder 外汇设置止盈止损 + operationId: Forex_ForexUpdatePlaceOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UpdateForexRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ForexReply' + /order_money/money_all_position: + post: + tags: + - Money + description: MoneyAllPosition 综合一键平仓 + operationId: Money_MoneyAllPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllMoneyRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllMoneyReply' + /order_money/money_cancel: + post: + tags: + - Money + description: MoneyCancel 综合撤单 + operationId: Money_MoneyCancel + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelMoneyRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.MoneyReply' + /order_money/money_list: + post: + tags: + - Money + description: GetBotMoneyTrade 综合列表查询 + operationId: Money_GetBotMoneyTrade + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotMoneyTradeRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotMoneyTradeReply' + /order_money/money_one_click_redemption: + post: + tags: + - Money + description: MoneyOneClickRedemption 现货一键兑换 + operationId: Money_MoneyOneClickRedemption + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.MoneyRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.MoneyReply' + /order_money/money_place_order: + post: + tags: + - Money + description: MoneyPlaceOrder 综合下单 + operationId: Money_MoneyPlaceOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.MoneyRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.MoneyReply' + /order_money/money_position: + post: + tags: + - Money + description: MoneyPosition 综合平仓 + operationId: Money_MoneyPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelMoneyRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.MoneyReply' + /order_money/money_update_order: + post: + tags: + - Money + description: MoneyUpdatePlaceOrder 综合设置止盈止损 + operationId: Money_MoneyUpdatePlaceOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UpdateMoneyRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.MoneyReply' + /order_optioninr/share_all_position: + post: + tags: + - OptionInr + description: OptionInrAllPosition 期权-印度股一键平仓 + operationId: OptionInr_OptionInrAllPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllOptionInrOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllOptionInrOrderReply' + /order_optioninr/share_cancel: + post: + tags: + - OptionInr + description: OptionInrCancel 期权-印度股撤单 + operationId: OptionInr_OptionInrCancel + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelOptionInrOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.OptionInrOrderReply' + /order_optioninr/share_list: + post: + tags: + - OptionInr + description: GetBotStockOptionInrTrade 期权-印度股列表查询 + operationId: OptionInr_GetBotStockOptionInrTrade + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotStockOptionInrTradeRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotStockOptionInrTradeReply' + /order_optioninr/share_place_order: + post: + tags: + - OptionInr + description: OptionInrPlaceOrder 期权-印度股下单 + operationId: OptionInr_OptionInrPlaceOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.OptionInrOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.OptionInrOrderReply' + /order_optioninr/share_position: + post: + tags: + - OptionInr + description: OptionInrPosition 期权-印度股平仓 + operationId: OptionInr_OptionInrPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelOptionInrOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.OptionInrOrderReply' + /order_optioninr/share_update_order: + post: + tags: + - OptionInr + description: OptionInrUpdateOrder 期权-印度股设置止盈止损 + operationId: OptionInr_OptionInrUpdateOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UpdateOptionInrOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.OptionInrOrderReply' + /order_second/contract_second_order: + post: + tags: + - Second + description: SecondOrder 秒合约下单 + operationId: Second_SecondOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.SecondOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.SecondOrderReply' + /order_second/second_list: + post: + tags: + - Second + description: SecondGetBotContractTrade 合约列表查询 + operationId: Second_SecondGetBotContractTrade + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotSecondTradeRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotSecondTradeReply' + /order_shareblock/share_cancel: + post: + tags: + - BlockTrade + description: ShareBlockCancel 大宗交易股撤单 + operationId: BlockTrade_ShareBlockCancel + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelBlockOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.OrderBlockReply' + /order_shareblock/share_list: + post: + tags: + - BlockTrade + description: GetBotStockBlockTrade 大宗交易股列表查询 + operationId: BlockTrade_GetBotStockBlockTrade + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotStockBlockTradeRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotStockBlockTradeReply' + /order_shareblock/share_place_order: + post: + tags: + - BlockTrade + description: ShareBlockPlaceOrder 大宗交易股下单 + operationId: BlockTrade_ShareBlockPlaceOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.OrderBlockRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.OrderBlockReply' + /order_shareblock/share_position: + post: + tags: + - BlockTrade + description: ShareBlockPosition 大宗交易股平仓 + operationId: BlockTrade_ShareBlockPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelBlockOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.OrderBlockReply' + /order_shareblock/share_update_order: + post: + tags: + - BlockTrade + description: ShareBlockUpdateOrder 大宗交易股设置止盈止损 + operationId: BlockTrade_ShareBlockUpdateOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UpdateBlockOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.OrderBlockReply' + /order_sharebrl/share_all_position: + post: + tags: + - ShareBrl + description: ShareBrlAllPosition 巴西国股一键平仓 + operationId: ShareBrl_ShareBrlAllPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllBrlOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllBrlOrderReply' + /order_sharebrl/share_cancel: + post: + tags: + - ShareBrl + description: ShareBrlCancel 巴西国股撤单 + operationId: ShareBrl_ShareBrlCancel + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelBrlOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.BrlOrderReply' + /order_sharebrl/share_list: + post: + tags: + - ShareBrl + description: GetBotStockBrlTrade 巴西国股列表查询 + operationId: ShareBrl_GetBotStockBrlTrade + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBrlBotStockTradeRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotStockBrlTradeReply' + /order_sharebrl/share_place_order: + post: + tags: + - ShareBrl + description: ShareBrlPlaceOrder 巴西国股下单 + operationId: ShareBrl_ShareBrlPlaceOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ShareBrlOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.BrlOrderReply' + /order_sharebrl/share_position: + post: + tags: + - ShareBrl + description: ShareBrlPosition 巴西国股平仓 + operationId: ShareBrl_ShareBrlPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelBrlOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.BrlOrderReply' + /order_sharebrl/share_update_order: + post: + tags: + - ShareBrl + description: ShareBrlUpdateOrder 巴西国股设置止盈止损 + operationId: ShareBrl_ShareBrlUpdateOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UpdateBrlOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.BrlOrderReply' + /order_shareeur/share_all_position: + post: + tags: + - ShareEur + description: ShareEurAllPosition 德国股一键平仓 + operationId: ShareEur_ShareEurAllPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllEurOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllEurOrderReply' + /order_shareeur/share_cancel: + post: + tags: + - ShareEur + description: ShareEurCancel 德国股撤单 + operationId: ShareEur_ShareEurCancel + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelEurOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.EurOrderReply' + /order_shareeur/share_list: + post: + tags: + - ShareEur + description: GetBotStockEurTrade 德国股列表查询 + operationId: ShareEur_GetBotStockEurTrade + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetEurBotStockTradeRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotStockEurTradeReply' + /order_shareeur/share_place_order: + post: + tags: + - ShareEur + description: ShareEurPlaceOrder 德国股下单 + operationId: ShareEur_ShareEurPlaceOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ShareEurOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.EurOrderReply' + /order_shareeur/share_position: + post: + tags: + - ShareEur + description: ShareEurPosition 德国股平仓 + operationId: ShareEur_ShareEurPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelEurOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.EurOrderReply' + /order_shareeur/share_update_order: + post: + tags: + - ShareEur + description: ShareEurUpdateOrder 德国股设置止盈止损 + operationId: ShareEur_ShareEurUpdateOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UpdateEurOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.EurOrderReply' + /order_sharefur/share_all_position: + post: + tags: + - ShareFur + description: ShareFurAllPosition 法国股一键平仓 + operationId: ShareFur_ShareFurAllPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllFurOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllFurOrderReply' + /order_sharefur/share_cancel: + post: + tags: + - ShareFur + description: ShareFurCancel 法国股撤单 + operationId: ShareFur_ShareFurCancel + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelFurOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.FurOrderReply' + /order_sharefur/share_list: + post: + tags: + - ShareFur + description: GetBotStockFurTrade 法国股列表查询 + operationId: ShareFur_GetBotStockFurTrade + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetFurBotStockTradeRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotStockFurTradeReply' + /order_sharefur/share_place_order: + post: + tags: + - ShareFur + description: ShareFurPlaceOrder 法国股下单 + operationId: ShareFur_ShareFurPlaceOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ShareFurOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.FurOrderReply' + /order_sharefur/share_position: + post: + tags: + - ShareFur + description: ShareFurPosition 法国股平仓 + operationId: ShareFur_ShareFurPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelFurOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.FurOrderReply' + /order_sharefur/share_update_order: + post: + tags: + - ShareFur + description: ShareFurUpdateOrder 法国股设置止盈止损 + operationId: ShareFur_ShareFurUpdateOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UpdateFurOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.FurOrderReply' + /order_sharegbx/share_all_position: + post: + tags: + - ShareGbx + description: ShareGbxAllPosition 英股一键平仓 + operationId: ShareGbx_ShareGbxAllPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllGbxOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllGbxOrderReply' + /order_sharegbx/share_cancel: + post: + tags: + - ShareGbx + description: ShareGbxCancel 英股撤单 + operationId: ShareGbx_ShareGbxCancel + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelGbxOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.OrderGbxReply' + /order_sharegbx/share_list: + post: + tags: + - ShareGbx + description: GetBotStockGbxTrade 英股列表查询 + operationId: ShareGbx_GetBotStockGbxTrade + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotStockGbxTradeRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotStockGbxTradeReply' + /order_sharegbx/share_place_order: + post: + tags: + - ShareGbx + description: ShareGbxPlaceOrder 英股下单 + operationId: ShareGbx_ShareGbxPlaceOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.OrderGbxRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.OrderGbxReply' + /order_sharegbx/share_position: + post: + tags: + - ShareGbx + description: ShareGbxPosition 英股平仓 + operationId: ShareGbx_ShareGbxPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelGbxOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.OrderGbxReply' + /order_sharegbx/share_update_order: + post: + tags: + - ShareGbx + description: ShareGbxUpdateOrder 英股设置止盈止损 + operationId: ShareGbx_ShareGbxUpdateOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UpdateGbxOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.OrderGbxReply' + /order_sharehkd/share_all_position: + post: + tags: + - ShareHkd + description: ShareHkdAllPosition 港股一键平仓 + operationId: ShareHkd_ShareHkdAllPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllHkdOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllHkdOrderReply' + /order_sharehkd/share_cancel: + post: + tags: + - ShareHkd + description: ShareHkdCancel 港股撤单 + operationId: ShareHkd_ShareHkdCancel + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelHkdOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.OrderHkdReply' + /order_sharehkd/share_list: + post: + tags: + - ShareHkd + description: GetBotStockHkdTrade 港股列表查询 + operationId: ShareHkd_GetBotStockHkdTrade + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotStockHkdTradeRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotStockHkdTradeReply' + /order_sharehkd/share_place_order: + post: + tags: + - ShareHkd + description: ShareHkdPlaceOrder 港股下单 + operationId: ShareHkd_ShareHkdPlaceOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.OrderHkdRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.OrderHkdReply' + /order_sharehkd/share_position: + post: + tags: + - ShareHkd + description: ShareHkdPosition 港股平仓 + operationId: ShareHkd_ShareHkdPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelHkdOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.OrderHkdReply' + /order_sharehkd/share_update_order: + post: + tags: + - ShareHkd + description: ShareHkdUpdateOrder 港股设置止盈止损 + operationId: ShareHkd_ShareHkdUpdateOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UpdateHkdOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.OrderHkdReply' + /order_shareidn/share_all_position: + post: + tags: + - ShareIdn + description: ShareIdnAllPosition 印尼股一键平仓 + operationId: ShareIdn_ShareIdnAllPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllIdnOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllIdnOrderReply' + /order_shareidn/share_cancel: + post: + tags: + - ShareIdn + description: ShareIdnCancel 印尼股撤单 + operationId: ShareIdn_ShareIdnCancel + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelIdnOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.IdnOrderReply' + /order_shareidn/share_list: + post: + tags: + - ShareIdn + description: GetBotStockIdnTrade 印尼股列表查询 + operationId: ShareIdn_GetBotStockIdnTrade + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetIdnBotStockTradeRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotStockIdnTradeReply' + /order_shareidn/share_place_order: + post: + tags: + - ShareIdn + description: ShareIdnPlaceOrder 印尼股下单 + operationId: ShareIdn_ShareIdnPlaceOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ShareIdnOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.IdnOrderReply' + /order_shareidn/share_position: + post: + tags: + - ShareIdn + description: ShareIdnPosition 印尼股平仓 + operationId: ShareIdn_ShareIdnPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelIdnOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.IdnOrderReply' + /order_shareidn/share_update_order: + post: + tags: + - ShareIdn + description: ShareIdnUpdateOrder 印尼股设置止盈止损 + operationId: ShareIdn_ShareIdnUpdateOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UpdateIdnOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.IdnOrderReply' + /order_shareinr/share_all_position: + post: + tags: + - ShareInr + description: ShareInrAllPosition 印度股一键平仓 + operationId: ShareInr_ShareInrAllPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllInrOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllInrOrderReply' + /order_shareinr/share_cancel: + post: + tags: + - ShareInr + description: ShareInrCancel 印度股撤单 + operationId: ShareInr_ShareInrCancel + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelInrOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.InrOrderReply' + /order_shareinr/share_list: + post: + tags: + - ShareInr + description: GetBotStockInrTrade 印度股列表查询 + operationId: ShareInr_GetBotStockInrTrade + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetInrBotStockTradeRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotStockInrTradeReply' + /order_shareinr/share_place_order: + post: + tags: + - ShareInr + description: ShareInrPlaceOrder 印度股下单 + operationId: ShareInr_ShareInrPlaceOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ShareInrOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.InrOrderReply' + /order_shareinr/share_position: + post: + tags: + - ShareInr + description: ShareInrPosition 印度股平仓 + operationId: ShareInr_ShareInrPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelInrOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.InrOrderReply' + /order_shareinr/share_update_order: + post: + tags: + - ShareInr + description: ShareInrUpdateOrder 印度股设置止盈止损 + operationId: ShareInr_ShareInrUpdateOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UpdateInrOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.InrOrderReply' + /order_sharejpy/share_all_position: + post: + tags: + - ShareJpy + description: ShareJpyAllPosition 日本股一键平仓 + operationId: ShareJpy_ShareJpyAllPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllJpyOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllJpyOrderReply' + /order_sharejpy/share_cancel: + post: + tags: + - ShareJpy + description: ShareJpyCancel 日本股撤单 + operationId: ShareJpy_ShareJpyCancel + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelJpyOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.JpyOrderReply' + /order_sharejpy/share_list: + post: + tags: + - ShareJpy + description: GetBotStockJpyTrade 日本股列表查询 + operationId: ShareJpy_GetBotStockJpyTrade + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetJpyBotStockTradeRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotStockJpyTradeReply' + /order_sharejpy/share_place_order: + post: + tags: + - ShareJpy + description: ShareJpyPlaceOrder 日本股下单 + operationId: ShareJpy_ShareJpyPlaceOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ShareJpyOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.JpyOrderReply' + /order_sharejpy/share_position: + post: + tags: + - ShareJpy + description: ShareJpyPosition 日本股平仓 + operationId: ShareJpy_ShareJpyPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelJpyOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.JpyOrderReply' + /order_sharejpy/share_update_order: + post: + tags: + - ShareJpy + description: ShareJpyUpdateOrder 日本股设置止盈止损 + operationId: ShareJpy_ShareJpyUpdateOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UpdateJpyOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.JpyOrderReply' + /order_sharemys/share_all_position: + post: + tags: + - ShareMys + description: ShareMysAllPosition 马股一键平仓 + operationId: ShareMys_ShareMysAllPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllMysOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllMysOrderReply' + /order_sharemys/share_cancel: + post: + tags: + - ShareMys + description: ShareMysCancel 马股撤单 + operationId: ShareMys_ShareMysCancel + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelMysOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.MysOrderReply' + /order_sharemys/share_list: + post: + tags: + - ShareMys + description: GetBotStockMysTrade 马股列表查询 + operationId: ShareMys_GetBotStockMysTrade + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetMysBotStockTradeRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotStockMysTradeReply' + /order_sharemys/share_place_order: + post: + tags: + - ShareMys + description: ShareMysPlaceOrder 马股下单 + operationId: ShareMys_ShareMysPlaceOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ShareMysOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.MysOrderReply' + /order_sharemys/share_position: + post: + tags: + - ShareMys + description: ShareMysPosition 马股平仓 + operationId: ShareMys_ShareMysPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelMysOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.MysOrderReply' + /order_sharemys/share_update_order: + post: + tags: + - ShareMys + description: ShareMysUpdateOrder 马股设置止盈止损 + operationId: ShareMys_ShareMysUpdateOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UpdateMysOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.MysOrderReply' + /order_sharepre/share_giveaways: + post: + tags: + - Order + description: ShareGiveaways 股票赠送 + operationId: Order_ShareGiveaways + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.SharePreRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.SharePreReply' + /order_sharepre/share_pre_trade: + post: + tags: + - Order + description: SharePreTrade 新股申购 + operationId: Order_SharePreTrade + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.SharePreRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.SharePreReply' + /order_sharepre/share_pre_trade_by_order_no: + post: + tags: + - Order + description: SharePreTradeByOrderNo 新股申购-订单号 + operationId: Order_SharePreTradeByOrderNo + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.SharePreRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.SharePreReply' + /order_sharepre/update_all_stock_id: + post: + tags: + - Order + description: UpdateShareAllStockId 更新全局的股票StockId + operationId: Order_UpdateShareAllStockId + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ShareNullRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.SharePreReply' + /order_sharepre/update_stock_id: + post: + tags: + - Order + description: UpdateShareTradeStockId 更新股票代码stock_id + operationId: Order_UpdateShareTradeStockId + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ShareTradeStockIdRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.SharePreReply' + /order_sharesgd/share_all_position: + post: + tags: + - ShareSgd + description: ShareSgdAllPosition 新加坡股一键平仓 + operationId: ShareSgd_ShareSgdAllPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllSgdOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllSgdOrderReply' + /order_sharesgd/share_cancel: + post: + tags: + - ShareSgd + description: ShareSgdCancel 新加坡股撤单 + operationId: ShareSgd_ShareSgdCancel + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelSgdOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.SgdOrderReply' + /order_sharesgd/share_list: + post: + tags: + - ShareSgd + description: GetBotStockSgdTrade 新加坡股列表查询 + operationId: ShareSgd_GetBotStockSgdTrade + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetSgdBotStockTradeRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotStockSgdTradeReply' + /order_sharesgd/share_place_order: + post: + tags: + - ShareSgd + description: ShareSgdPlaceOrder 新加坡股下单 + operationId: ShareSgd_ShareSgdPlaceOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ShareSgdOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.SgdOrderReply' + /order_sharesgd/share_position: + post: + tags: + - ShareSgd + description: ShareSgdPosition 新加坡股平仓 + operationId: ShareSgd_ShareSgdPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelSgdOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.SgdOrderReply' + /order_sharesgd/share_update_order: + post: + tags: + - ShareSgd + description: ShareSgdUpdateOrder 新加坡股设置止盈止损 + operationId: ShareSgd_ShareSgdUpdateOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UpdateSgdOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.SgdOrderReply' + /order_sharetha/share_all_position: + post: + tags: + - ShareTha + description: ShareThaAllPosition 泰股一键平仓 + operationId: ShareTha_ShareThaAllPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllThaOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllThaOrderReply' + /order_sharetha/share_cancel: + post: + tags: + - ShareTha + description: ShareThaCancel 泰股撤单 + operationId: ShareTha_ShareThaCancel + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelThaOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ThaOrderReply' + /order_sharetha/share_list: + post: + tags: + - ShareTha + description: GetBotStockThaTrade 泰股列表查询 + operationId: ShareTha_GetBotStockThaTrade + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetThaBotStockTradeRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotStockThaTradeReply' + /order_sharetha/share_place_order: + post: + tags: + - ShareTha + description: ShareThaPlaceOrder 泰股下单 + operationId: ShareTha_ShareThaPlaceOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ShareThaOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ThaOrderReply' + /order_sharetha/share_position: + post: + tags: + - ShareTha + description: ShareThaPosition 泰股平仓 + operationId: ShareTha_ShareThaPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelThaOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ThaOrderReply' + /order_sharetha/share_update_order: + post: + tags: + - ShareTha + description: ShareThaUpdateOrder 泰股设置止盈止损 + operationId: ShareTha_ShareThaUpdateOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UpdateThaOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.ThaOrderReply' + /order_shareus/share_all_position: + post: + tags: + - ShareUs + description: ShareCancel 美股一键平仓 + operationId: ShareUs_ShareAllPosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllUsOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.AllUsOrderReply' + /order_shareus/share_cancel: + post: + tags: + - ShareUs + description: ShareCancel 美股撤单 + operationId: ShareUs_ShareCancel + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelUsOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UsOrderReply' + /order_shareus/share_list: + post: + tags: + - ShareUs + description: GetBotStockTrade 美股列表查询 + operationId: ShareUs_GetBotStockTrade + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetUsBotStockTradeRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetUsBotStockTradeReply' + /order_shareus/share_place_order: + post: + tags: + - ShareUs + description: SharePlaceOrder 美股下单 + operationId: ShareUs_SharePlaceOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UsOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UsOrderReply' + /order_shareus/share_position: + post: + tags: + - ShareUs + description: SharePosition 美股平仓 + operationId: ShareUs_SharePosition + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelUsOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UsOrderReply' + /order_shareus/share_update_order: + post: + tags: + - ShareUs + description: ShareUpdateOrder 美股设置止盈止损 + operationId: ShareUs_ShareUpdateOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UpdateUsOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.UsOrderReply' + /order_spots/spots_cancel: + post: + tags: + - Spots + description: SpotsCancel 现货撤单 + operationId: Spots_SpotsCancel + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.CancelSpotsOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.SpotsOrderReply' + /order_spots/spots_list: + post: + tags: + - Spots + description: GetBotDigitalTrade 现货列表查询 + operationId: Spots_GetBotDigitalTrade + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotDigitalTradeRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.GetBotDigitalTradeReply' + /order_spots/spots_one_click_redemption: + post: + tags: + - Spots + description: SpotsOneClickRedemption 现货一键兑换 + operationId: Spots_SpotsOneClickRedemption + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.SpotsOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.SpotsOrderReply' + /order_spots/spots_place_order: + post: + tags: + - Spots + description: SpotsPlaceOrder 现货下单 + operationId: Spots_SpotsPlaceOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.SpotsOrderRequest' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/matchmaking.v1.SpotsOrderReply' +components: + schemas: + matchmaking.v1.AllBrlOrderReply: + type: object + properties: + code: + type: string + data: + type: string + message: + type: string + matchmaking.v1.AllBrlOrderRequest: + type: object + properties: {} + matchmaking.v1.AllContractReply: + type: object + properties: + code: + type: string + data: + type: string + message: + type: string + matchmaking.v1.AllContractRequest: + type: object + properties: {} + matchmaking.v1.AllEurOrderReply: + type: object + properties: + code: + type: string + data: + type: string + message: + type: string + matchmaking.v1.AllEurOrderRequest: + type: object + properties: {} + matchmaking.v1.AllForexReply: + type: object + properties: + code: + type: string + data: + type: string + message: + type: string + matchmaking.v1.AllForexRequest: + type: object + properties: {} + matchmaking.v1.AllFurOrderReply: + type: object + properties: + code: + type: string + data: + type: string + message: + type: string + matchmaking.v1.AllFurOrderRequest: + type: object + properties: {} + matchmaking.v1.AllGbxOrderReply: + type: object + properties: + code: + type: string + data: + type: string + message: + type: string + matchmaking.v1.AllGbxOrderRequest: + type: object + properties: {} + matchmaking.v1.AllHkdOrderReply: + type: object + properties: + code: + type: string + data: + type: string + message: + type: string + matchmaking.v1.AllHkdOrderRequest: + type: object + properties: {} + matchmaking.v1.AllIdnOrderReply: + type: object + properties: + code: + type: string + data: + type: string + message: + type: string + matchmaking.v1.AllIdnOrderRequest: + type: object + properties: {} + matchmaking.v1.AllInrOrderReply: + type: object + properties: + code: + type: string + data: + type: string + message: + type: string + matchmaking.v1.AllInrOrderRequest: + type: object + properties: {} + matchmaking.v1.AllJpyOrderReply: + type: object + properties: + code: + type: string + data: + type: string + message: + type: string + matchmaking.v1.AllJpyOrderRequest: + type: object + properties: {} + matchmaking.v1.AllMoneyReply: + type: object + properties: + code: + type: string + data: + type: string + message: + type: string + matchmaking.v1.AllMoneyRequest: + type: object + properties: {} + matchmaking.v1.AllMysOrderReply: + type: object + properties: + code: + type: string + data: + type: string + message: + type: string + matchmaking.v1.AllMysOrderRequest: + type: object + properties: {} + matchmaking.v1.AllOptionInrOrderReply: + type: object + properties: + code: + type: string + data: + type: string + message: + type: string + matchmaking.v1.AllOptionInrOrderRequest: + type: object + properties: {} + matchmaking.v1.AllSgdOrderReply: + type: object + properties: + code: + type: string + data: + type: string + message: + type: string + matchmaking.v1.AllSgdOrderRequest: + type: object + properties: {} + matchmaking.v1.AllThaOrderReply: + type: object + properties: + code: + type: string + data: + type: string + message: + type: string + matchmaking.v1.AllThaOrderRequest: + type: object + properties: {} + matchmaking.v1.AllUsOrderReply: + type: object + properties: + code: + type: string + data: + type: string + message: + type: string + matchmaking.v1.AllUsOrderRequest: + type: object + properties: {} + matchmaking.v1.BotContractTrade: + type: object + properties: + orderId: + type: string + contractId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + dealPrice: + type: string + closingPrice: + type: string + orderNumber: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + serviceCost: + type: string + earnestMoney: + type: string + orderMoney: + type: string + status: + type: string + createTime: + type: string + format: date-time + updateTime: + type: string + format: date-time + openTime: + type: string + format: date-time + closingTime: + type: string + format: date-time + closingCost: + type: string + faceValue: + type: string + overnightCost: + type: string + pryNum: + type: string + keepDecimal: + type: string + secondTime: + type: string + state: + type: string + matchmaking.v1.BotContractTradeData: + type: object + properties: + pageSize: + type: string + pageCount: + type: string + data: + type: array + items: + $ref: '#/components/schemas/matchmaking.v1.BotContractTrade' + totalCount: + type: string + matchmaking.v1.BotDigitalTrade: + type: object + properties: + orderId: + type: string + digitalId: + type: string + tradeType: + type: string + dealType: + type: string + dealPrice: + type: string + closingPrice: + type: string + limitPrice: + type: string + marketPrice: + type: string + orderNumber: + type: string + serviceCost: + type: string + orderMoney: + type: string + totalMoney: + type: string + status: + type: string + createTime: + type: string + format: date-time + updateTime: + type: string + format: date-time + openTime: + type: string + format: date-time + closingTime: + type: string + format: date-time + closingCost: + type: string + keepDecimal: + type: string + matchmaking.v1.BotDigitalTradeData: + type: object + properties: + pageSize: + type: string + pageCount: + type: string + data: + type: array + items: + $ref: '#/components/schemas/matchmaking.v1.BotDigitalTrade' + totalCount: + type: string + matchmaking.v1.BotForexTrade: + type: object + properties: + orderId: + type: string + forexId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + dealPrice: + type: string + closingPrice: + type: string + orderNumber: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + serviceCost: + type: string + earnestMoney: + type: string + orderMoney: + type: string + status: + type: string + createTime: + type: string + format: date-time + updateTime: + type: string + format: date-time + openTime: + type: string + format: date-time + closingTime: + type: string + format: date-time + closingCost: + type: string + faceValue: + type: string + overnightCost: + type: string + pryNum: + type: string + keepDecimal: + type: string + secondTime: + type: string + state: + type: string + matchmaking.v1.BotForexTradeData: + type: object + properties: + pageSize: + type: string + pageCount: + type: string + data: + type: array + items: + $ref: '#/components/schemas/matchmaking.v1.BotForexTrade' + totalCount: + type: string + matchmaking.v1.BotMoneyTrade: + type: object + properties: + orderId: + type: string + StockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + dealPrice: + type: string + closingPrice: + type: string + orderNumber: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + serviceCost: + type: string + earnestMoney: + type: string + orderMoney: + type: string + status: + type: string + createTime: + type: string + format: date-time + updateTime: + type: string + format: date-time + openTime: + type: string + format: date-time + closingTime: + type: string + format: date-time + closingCost: + type: string + faceValue: + type: string + overnightCost: + type: string + pryNum: + type: string + keepDecimal: + type: string + secondTime: + type: string + state: + type: string + matchmaking.v1.BotMoneyTradeData: + type: object + properties: + pageSize: + type: string + pageCount: + type: string + data: + type: array + items: + $ref: '#/components/schemas/matchmaking.v1.BotMoneyTrade' + totalCount: + type: string + matchmaking.v1.BotOrderBlockTrade: + type: object + properties: + orderId: + type: string + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + dealPrice: + type: string + closingPrice: + type: string + orderNumber: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + serviceCost: + type: string + marketMoney: + type: string + orderMoney: + type: string + status: + type: string + createTime: + type: string + format: date-time + updateTime: + type: string + format: date-time + openTime: + type: string + format: date-time + closingTime: + type: string + format: date-time + closingCost: + type: string + faceValue: + type: string + pryNum: + type: string + keepDecimal: + type: string + stockName: + type: string + type: + type: string + matchmaking.v1.BotOrderGbxTrade: + type: object + properties: + orderId: + type: string + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + dealPrice: + type: string + closingPrice: + type: string + orderNumber: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + serviceCost: + type: string + marketMoney: + type: string + orderMoney: + type: string + status: + type: string + createTime: + type: string + updateTime: + type: string + openTime: + type: string + closingTime: + type: string + closingCost: + type: string + faceValue: + type: string + pryNum: + type: string + keepDecimal: + type: string + stockName: + type: string + matchmaking.v1.BotOrderHkdTrade: + type: object + properties: + orderId: + type: string + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + dealPrice: + type: string + closingPrice: + type: string + orderNumber: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + serviceCost: + type: string + marketMoney: + type: string + orderMoney: + type: string + status: + type: string + createTime: + type: string + updateTime: + type: string + openTime: + type: string + closingTime: + type: string + closingCost: + type: string + faceValue: + type: string + pryNum: + type: string + keepDecimal: + type: string + stockName: + type: string + matchmaking.v1.BotSecondTrade: + type: object + properties: + orderId: + type: string + contractId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + dealPrice: + type: string + closingPrice: + type: string + orderNumber: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + serviceCost: + type: string + earnestMoney: + type: string + orderMoney: + type: string + status: + type: string + createTime: + type: string + format: date-time + updateTime: + type: string + format: date-time + openTime: + type: string + format: date-time + closingTime: + type: string + format: date-time + closingCost: + type: string + faceValue: + type: string + overnightCost: + type: string + pryNum: + type: string + keepDecimal: + type: string + secondTime: + type: string + state: + type: string + orderStatus: + type: string + orderValue: + type: string + matchmaking.v1.BotSecondTradeData: + type: object + properties: + pageSize: + type: string + pageCount: + type: string + data: + type: array + items: + $ref: '#/components/schemas/matchmaking.v1.BotSecondTrade' + totalCount: + type: string + matchmaking.v1.BotStockBlockTradeData: + type: object + properties: + pageSize: + type: string + pageCount: + type: string + data: + type: array + items: + $ref: '#/components/schemas/matchmaking.v1.BotOrderBlockTrade' + totalCount: + type: string + matchmaking.v1.BotStockBrlTrade: + type: object + properties: + orderId: + type: string + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + dealPrice: + type: string + closingPrice: + type: string + orderNumber: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + serviceCost: + type: string + marketMoney: + type: string + orderMoney: + type: string + status: + type: string + createTime: + type: string + updateTime: + type: string + openTime: + type: string + closingTime: + type: string + closingCost: + type: string + faceValue: + type: string + pryNum: + type: string + keepDecimal: + type: string + stockName: + type: string + matchmaking.v1.BotStockBrlTradeReply: + type: object + properties: + pageSize: + type: string + pageCount: + type: string + data: + type: array + items: + $ref: '#/components/schemas/matchmaking.v1.BotStockBrlTrade' + totalCount: + type: string + matchmaking.v1.BotStockEurTrade: + type: object + properties: + orderId: + type: string + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + dealPrice: + type: string + closingPrice: + type: string + orderNumber: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + serviceCost: + type: string + marketMoney: + type: string + orderMoney: + type: string + status: + type: string + createTime: + type: string + updateTime: + type: string + openTime: + type: string + closingTime: + type: string + closingCost: + type: string + faceValue: + type: string + pryNum: + type: string + keepDecimal: + type: string + stockName: + type: string + matchmaking.v1.BotStockEurTradeReply: + type: object + properties: + pageSize: + type: string + pageCount: + type: string + data: + type: array + items: + $ref: '#/components/schemas/matchmaking.v1.BotStockEurTrade' + totalCount: + type: string + matchmaking.v1.BotStockFurTrade: + type: object + properties: + orderId: + type: string + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + dealPrice: + type: string + closingPrice: + type: string + orderNumber: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + serviceCost: + type: string + marketMoney: + type: string + orderMoney: + type: string + status: + type: string + createTime: + type: string + updateTime: + type: string + openTime: + type: string + closingTime: + type: string + closingCost: + type: string + faceValue: + type: string + pryNum: + type: string + keepDecimal: + type: string + stockName: + type: string + matchmaking.v1.BotStockFurTradeReply: + type: object + properties: + pageSize: + type: string + pageCount: + type: string + data: + type: array + items: + $ref: '#/components/schemas/matchmaking.v1.BotStockFurTrade' + totalCount: + type: string + matchmaking.v1.BotStockGbxTradeData: + type: object + properties: + pageSize: + type: string + pageCount: + type: string + data: + type: array + items: + $ref: '#/components/schemas/matchmaking.v1.BotOrderGbxTrade' + totalCount: + type: string + matchmaking.v1.BotStockHkdTradeData: + type: object + properties: + pageSize: + type: string + pageCount: + type: string + data: + type: array + items: + $ref: '#/components/schemas/matchmaking.v1.BotOrderHkdTrade' + totalCount: + type: string + matchmaking.v1.BotStockIdnTrade: + type: object + properties: + orderId: + type: string + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + dealPrice: + type: string + closingPrice: + type: string + orderNumber: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + serviceCost: + type: string + marketMoney: + type: string + orderMoney: + type: string + status: + type: string + createTime: + type: string + updateTime: + type: string + openTime: + type: string + closingTime: + type: string + closingCost: + type: string + faceValue: + type: string + pryNum: + type: string + keepDecimal: + type: string + stockName: + type: string + matchmaking.v1.BotStockIdnTradeData: + type: object + properties: + pageSize: + type: string + pageCount: + type: string + data: + type: array + items: + $ref: '#/components/schemas/matchmaking.v1.BotStockIdnTrade' + totalCount: + type: string + matchmaking.v1.BotStockInrTrade: + type: object + properties: + orderId: + type: string + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + dealPrice: + type: string + closingPrice: + type: string + orderNumber: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + serviceCost: + type: string + marketMoney: + type: string + orderMoney: + type: string + status: + type: string + createTime: + type: string + updateTime: + type: string + openTime: + type: string + closingTime: + type: string + closingCost: + type: string + faceValue: + type: string + pryNum: + type: string + keepDecimal: + type: string + stockName: + type: string + matchmaking.v1.BotStockInrTradeData: + type: object + properties: + pageSize: + type: string + pageCount: + type: string + data: + type: array + items: + $ref: '#/components/schemas/matchmaking.v1.BotStockInrTrade' + totalCount: + type: string + matchmaking.v1.BotStockJpyTrade: + type: object + properties: + orderId: + type: string + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + dealPrice: + type: string + closingPrice: + type: string + orderNumber: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + serviceCost: + type: string + marketMoney: + type: string + orderMoney: + type: string + status: + type: string + createTime: + type: string + updateTime: + type: string + openTime: + type: string + closingTime: + type: string + closingCost: + type: string + faceValue: + type: string + pryNum: + type: string + keepDecimal: + type: string + stockName: + type: string + matchmaking.v1.BotStockJpyTradeReply: + type: object + properties: + pageSize: + type: string + pageCount: + type: string + data: + type: array + items: + $ref: '#/components/schemas/matchmaking.v1.BotStockJpyTrade' + totalCount: + type: string + matchmaking.v1.BotStockMysTrade: + type: object + properties: + orderId: + type: string + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + dealPrice: + type: string + closingPrice: + type: string + orderNumber: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + serviceCost: + type: string + marketMoney: + type: string + orderMoney: + type: string + status: + type: string + createTime: + type: string + updateTime: + type: string + openTime: + type: string + closingTime: + type: string + closingCost: + type: string + faceValue: + type: string + pryNum: + type: string + keepDecimal: + type: string + stockName: + type: string + numericCode: + type: string + matchmaking.v1.BotStockMysTradeData: + type: object + properties: + pageSize: + type: string + pageCount: + type: string + data: + type: array + items: + $ref: '#/components/schemas/matchmaking.v1.BotStockMysTrade' + totalCount: + type: string + matchmaking.v1.BotStockOptionInrTrade: + type: object + properties: + orderId: + type: string + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + dealPrice: + type: string + closingPrice: + type: string + orderNumber: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + serviceCost: + type: string + marketMoney: + type: string + orderMoney: + type: string + status: + type: string + createTime: + type: string + format: date-time + updateTime: + type: string + format: date-time + openTime: + type: string + format: date-time + closingTime: + type: string + format: date-time + closingCost: + type: string + faceValue: + type: string + pryNum: + type: string + keepDecimal: + type: string + stockName: + type: string + stopTime: + type: string + strikePrice: + type: string + tradingType: + type: string + stockCode: + type: string + multiplier: + type: string + costPrice: + type: string + ratio: + type: string + bid: + type: string + ask: + type: string + matchmaking.v1.BotStockOptionInrTradeData: + type: object + properties: + pageSize: + type: string + pageCount: + type: string + data: + type: array + items: + $ref: '#/components/schemas/matchmaking.v1.BotStockOptionInrTrade' + totalCount: + type: string + matchmaking.v1.BotStockSgdTrade: + type: object + properties: + orderId: + type: string + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + dealPrice: + type: string + closingPrice: + type: string + orderNumber: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + serviceCost: + type: string + marketMoney: + type: string + orderMoney: + type: string + status: + type: string + createTime: + type: string + updateTime: + type: string + openTime: + type: string + closingTime: + type: string + closingCost: + type: string + faceValue: + type: string + pryNum: + type: string + keepDecimal: + type: string + stockName: + type: string + matchmaking.v1.BotStockSgdTradeReply: + type: object + properties: + pageSize: + type: string + pageCount: + type: string + data: + type: array + items: + $ref: '#/components/schemas/matchmaking.v1.BotStockSgdTrade' + totalCount: + type: string + matchmaking.v1.BotStockThaTrade: + type: object + properties: + orderId: + type: string + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + dealPrice: + type: string + closingPrice: + type: string + orderNumber: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + serviceCost: + type: string + marketMoney: + type: string + orderMoney: + type: string + status: + type: string + createTime: + type: string + updateTime: + type: string + openTime: + type: string + closingTime: + type: string + closingCost: + type: string + faceValue: + type: string + pryNum: + type: string + keepDecimal: + type: string + stockName: + type: string + matchmaking.v1.BotStockThaTradeData: + type: object + properties: + pageSize: + type: string + pageCount: + type: string + data: + type: array + items: + $ref: '#/components/schemas/matchmaking.v1.BotStockThaTrade' + totalCount: + type: string + matchmaking.v1.BotUsOrderTrade: + type: object + properties: + orderId: + type: string + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + dealPrice: + type: string + closingPrice: + type: string + orderNumber: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + serviceCost: + type: string + marketMoney: + type: string + orderMoney: + type: string + status: + type: string + createTime: + type: string + updateTime: + type: string + openTime: + type: string + closingTime: + type: string + closingCost: + type: string + faceValue: + type: string + pryNum: + type: string + keepDecimal: + type: string + stockName: + type: string + matchmaking.v1.BotUsStockTradeData: + type: object + properties: + pageSize: + type: string + pageCount: + type: string + data: + type: array + items: + $ref: '#/components/schemas/matchmaking.v1.BotUsOrderTrade' + totalCount: + type: string + matchmaking.v1.BotUsersNullRequest: + type: object + properties: {} + matchmaking.v1.BotUsersReply: + type: object + properties: + code: + type: string + data: + type: string + message: + type: string + matchmaking.v1.BrlOrderReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.BrlOrderResult' + message: + type: string + matchmaking.v1.BrlOrderResult: + type: object + properties: + orderId: + type: string + matchmaking.v1.CancelBlockOrderRequest: + type: object + properties: + orderId: + type: string + type: + type: string + matchmaking.v1.CancelBrlOrderRequest: + type: object + properties: + orderId: + type: string + matchmaking.v1.CancelContractRequest: + type: object + properties: + orderId: + type: string + matchmaking.v1.CancelEurOrderRequest: + type: object + properties: + orderId: + type: string + matchmaking.v1.CancelForexRequest: + type: object + properties: + orderId: + type: string + matchmaking.v1.CancelFurOrderRequest: + type: object + properties: + orderId: + type: string + matchmaking.v1.CancelGbxOrderRequest: + type: object + properties: + orderId: + type: string + matchmaking.v1.CancelHkdOrderRequest: + type: object + properties: + orderId: + type: string + matchmaking.v1.CancelIdnOrderRequest: + type: object + properties: + orderId: + type: string + matchmaking.v1.CancelInrOrderRequest: + type: object + properties: + orderId: + type: string + matchmaking.v1.CancelJpyOrderRequest: + type: object + properties: + orderId: + type: string + matchmaking.v1.CancelMoneyRequest: + type: object + properties: + orderId: + type: string + matchmaking.v1.CancelMysOrderRequest: + type: object + properties: + orderId: + type: string + matchmaking.v1.CancelOptionInrOrderRequest: + type: object + properties: + orderId: + type: string + matchmaking.v1.CancelSgdOrderRequest: + type: object + properties: + orderId: + type: string + matchmaking.v1.CancelSpotsOrderRequest: + type: object + properties: + orderId: + type: string + matchmaking.v1.CancelThaOrderRequest: + type: object + properties: + orderId: + type: string + matchmaking.v1.CancelUsOrderRequest: + type: object + properties: + orderId: + type: string + matchmaking.v1.ContractReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.ContractResult' + message: + type: string + matchmaking.v1.ContractRequest: + type: object + properties: + contractId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + orderAmount: + type: string + orderNumber: + type: string + earnestMoney: + type: string + serviceCost: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + pryNum: + type: string + time: + type: string + matchmaking.v1.ContractResult: + type: object + properties: + orderId: + type: string + matchmaking.v1.EurOrderReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.EurOrderResult' + message: + type: string + matchmaking.v1.EurOrderResult: + type: object + properties: + orderId: + type: string + matchmaking.v1.ForexReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.ForexResult' + message: + type: string + matchmaking.v1.ForexRequest: + type: object + properties: + forexId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + orderAmount: + type: string + orderNumber: + type: string + earnestMoney: + type: string + serviceCost: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + pryNum: + type: string + time: + type: string + matchmaking.v1.ForexResult: + type: object + properties: + orderId: + type: string + matchmaking.v1.FurOrderReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.FurOrderResult' + message: + type: string + matchmaking.v1.FurOrderResult: + type: object + properties: + orderId: + type: string + matchmaking.v1.GetBotContractTradeReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.BotContractTradeData' + message: + type: string + matchmaking.v1.GetBotContractTradeRequest: + type: object + properties: + status: + type: string + pageSize: + type: string + pageCount: + type: string + state: + type: string + matchmaking.v1.GetBotDigitalTradeReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.BotDigitalTradeData' + message: + type: string + matchmaking.v1.GetBotDigitalTradeRequest: + type: object + properties: + status: + type: string + pageSize: + type: string + pageCount: + type: string + matchmaking.v1.GetBotForexTradeReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.BotForexTradeData' + message: + type: string + matchmaking.v1.GetBotForexTradeRequest: + type: object + properties: + status: + type: string + pageSize: + type: string + pageCount: + type: string + state: + type: string + matchmaking.v1.GetBotMoneyTradeReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.BotMoneyTradeData' + message: + type: string + matchmaking.v1.GetBotMoneyTradeRequest: + type: object + properties: + status: + type: string + pageSize: + type: string + pageCount: + type: string + state: + type: string + type: + type: string + matchmaking.v1.GetBotSecondTradeReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.BotSecondTradeData' + message: + type: string + matchmaking.v1.GetBotSecondTradeRequest: + type: object + properties: + status: + type: string + pageSize: + type: string + pageCount: + type: string + state: + type: string + matchmaking.v1.GetBotStockBlockTradeReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.BotStockBlockTradeData' + message: + type: string + matchmaking.v1.GetBotStockBlockTradeRequest: + type: object + properties: + status: + type: string + pageSize: + type: string + pageCount: + type: string + type: + type: string + matchmaking.v1.GetBotStockBrlTradeReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.BotStockBrlTradeReply' + message: + type: string + matchmaking.v1.GetBotStockEurTradeReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.BotStockEurTradeReply' + message: + type: string + matchmaking.v1.GetBotStockFurTradeReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.BotStockFurTradeReply' + message: + type: string + matchmaking.v1.GetBotStockGbxTradeReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.BotStockGbxTradeData' + message: + type: string + matchmaking.v1.GetBotStockGbxTradeRequest: + type: object + properties: + status: + type: string + pageSize: + type: string + pageCount: + type: string + matchmaking.v1.GetBotStockHkdTradeReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.BotStockHkdTradeData' + message: + type: string + matchmaking.v1.GetBotStockHkdTradeRequest: + type: object + properties: + status: + type: string + pageSize: + type: string + pageCount: + type: string + matchmaking.v1.GetBotStockIdnTradeReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.BotStockIdnTradeData' + message: + type: string + matchmaking.v1.GetBotStockInrTradeReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.BotStockInrTradeData' + message: + type: string + matchmaking.v1.GetBotStockJpyTradeReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.BotStockJpyTradeReply' + message: + type: string + matchmaking.v1.GetBotStockMysTradeReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.BotStockMysTradeData' + message: + type: string + matchmaking.v1.GetBotStockOptionInrTradeReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.BotStockOptionInrTradeData' + message: + type: string + matchmaking.v1.GetBotStockOptionInrTradeRequest: + type: object + properties: + status: + type: string + pageSize: + type: string + pageCount: + type: string + matchmaking.v1.GetBotStockSgdTradeReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.BotStockSgdTradeReply' + message: + type: string + matchmaking.v1.GetBotStockThaTradeReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.BotStockThaTradeData' + message: + type: string + matchmaking.v1.GetBrlBotStockTradeRequest: + type: object + properties: + status: + type: string + pageSize: + type: string + pageCount: + type: string + matchmaking.v1.GetEurBotStockTradeRequest: + type: object + properties: + status: + type: string + pageSize: + type: string + pageCount: + type: string + matchmaking.v1.GetFurBotStockTradeRequest: + type: object + properties: + status: + type: string + pageSize: + type: string + pageCount: + type: string + matchmaking.v1.GetIdnBotStockTradeRequest: + type: object + properties: + status: + type: string + pageSize: + type: string + pageCount: + type: string + matchmaking.v1.GetInrBotStockTradeRequest: + type: object + properties: + status: + type: string + pageSize: + type: string + pageCount: + type: string + matchmaking.v1.GetJpyBotStockTradeRequest: + type: object + properties: + status: + type: string + pageSize: + type: string + pageCount: + type: string + matchmaking.v1.GetMysBotStockTradeRequest: + type: object + properties: + status: + type: string + pageSize: + type: string + pageCount: + type: string + matchmaking.v1.GetSgdBotStockTradeRequest: + type: object + properties: + status: + type: string + pageSize: + type: string + pageCount: + type: string + matchmaking.v1.GetThaBotStockTradeRequest: + type: object + properties: + status: + type: string + pageSize: + type: string + pageCount: + type: string + matchmaking.v1.GetUsBotStockTradeReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.BotUsStockTradeData' + message: + type: string + matchmaking.v1.GetUsBotStockTradeRequest: + type: object + properties: + status: + type: string + pageSize: + type: string + pageCount: + type: string + matchmaking.v1.IdnOrderReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.IdnOrderResult' + message: + type: string + matchmaking.v1.IdnOrderResult: + type: object + properties: + orderId: + type: string + matchmaking.v1.InrOrderReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.InrOrderResult' + message: + type: string + matchmaking.v1.InrOrderResult: + type: object + properties: + orderId: + type: string + matchmaking.v1.JpyOrderReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.JpyOrderResult' + message: + type: string + matchmaking.v1.JpyOrderResult: + type: object + properties: + orderId: + type: string + matchmaking.v1.MoneyReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.MoneyResult' + message: + type: string + matchmaking.v1.MoneyRequest: + type: object + properties: + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + orderAmount: + type: string + orderNumber: + type: string + earnestMoney: + type: string + serviceCost: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + pryNum: + type: string + time: + type: string + type: + type: string + matchmaking.v1.MoneyResult: + type: object + properties: + orderId: + type: string + matchmaking.v1.MysOrderReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.ShareMysResult' + message: + type: string + matchmaking.v1.OptionInrOrderReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.OptionInrOrderResult' + message: + type: string + matchmaking.v1.OptionInrOrderRequest: + type: object + properties: + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + marketMoney: + type: string + orderNumber: + type: string + serviceCost: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + pryNum: + type: string + stopTime: + type: string + strikePrice: + type: string + tradingType: + type: string + stockCode: + type: string + multiplier: + type: string + ask: + type: string + bid: + type: string + matchmaking.v1.OptionInrOrderResult: + type: object + properties: + orderId: + type: string + matchmaking.v1.OrderBlockReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.OrderBlockResult' + message: + type: string + matchmaking.v1.OrderBlockRequest: + type: object + properties: + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + marketMoney: + type: string + orderNumber: + type: string + serviceCost: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + pryNum: + type: string + type: + type: string + matchmaking.v1.OrderBlockResult: + type: object + properties: + orderId: + type: string + matchmaking.v1.OrderGbxReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.OrderGbxResult' + message: + type: string + matchmaking.v1.OrderGbxRequest: + type: object + properties: + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + marketMoney: + type: string + orderNumber: + type: string + serviceCost: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + pryNum: + type: string + matchmaking.v1.OrderGbxResult: + type: object + properties: + orderId: + type: string + matchmaking.v1.OrderHkdReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.OrderHkdResult' + message: + type: string + matchmaking.v1.OrderHkdRequest: + type: object + properties: + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + marketMoney: + type: string + orderNumber: + type: string + serviceCost: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + pryNum: + type: string + matchmaking.v1.OrderHkdResult: + type: object + properties: + orderId: + type: string + matchmaking.v1.SecondOrderReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.SecondResult' + message: + type: string + matchmaking.v1.SecondOrderRequest: + type: object + properties: + contractId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + orderAmount: + type: string + orderNumber: + type: string + earnestMoney: + type: string + serviceCost: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + pryNum: + type: string + time: + type: string + matchmaking.v1.SecondResult: + type: object + properties: + orderId: + type: string + matchmaking.v1.SgdOrderReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.SgdOrderResult' + message: + type: string + matchmaking.v1.SgdOrderResult: + type: object + properties: + orderId: + type: string + matchmaking.v1.ShareBrlOrderRequest: + type: object + properties: + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + marketMoney: + type: string + orderNumber: + type: string + serviceCost: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + pryNum: + type: string + matchmaking.v1.ShareEurOrderRequest: + type: object + properties: + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + marketMoney: + type: string + orderNumber: + type: string + serviceCost: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + pryNum: + type: string + matchmaking.v1.ShareFurOrderRequest: + type: object + properties: + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + marketMoney: + type: string + orderNumber: + type: string + serviceCost: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + pryNum: + type: string + matchmaking.v1.ShareIdnOrderRequest: + type: object + properties: + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + marketMoney: + type: string + orderNumber: + type: string + serviceCost: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + pryNum: + type: string + matchmaking.v1.ShareInrOrderRequest: + type: object + properties: + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + marketMoney: + type: string + orderNumber: + type: string + serviceCost: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + pryNum: + type: string + matchmaking.v1.ShareJpyOrderRequest: + type: object + properties: + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + marketMoney: + type: string + orderNumber: + type: string + serviceCost: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + pryNum: + type: string + matchmaking.v1.ShareMysOrderRequest: + type: object + properties: + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + marketMoney: + type: string + orderNumber: + type: string + serviceCost: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + pryNum: + type: string + matchmaking.v1.ShareMysResult: + type: object + properties: + orderId: + type: string + matchmaking.v1.ShareNullRequest: + type: object + properties: {} + matchmaking.v1.SharePreReply: + type: object + properties: + code: + type: string + data: + type: string + message: + type: string + matchmaking.v1.SharePreRequest: + type: object + properties: + code: + type: string + id: + type: string + stock: + type: integer + format: int32 + matchmaking.v1.ShareSgdOrderRequest: + type: object + properties: + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + marketMoney: + type: string + orderNumber: + type: string + serviceCost: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + pryNum: + type: string + matchmaking.v1.ShareThaOrderRequest: + type: object + properties: + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + marketMoney: + type: string + orderNumber: + type: string + serviceCost: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + pryNum: + type: string + matchmaking.v1.ShareTradeStockIdRequest: + type: object + properties: + code: + type: string + codeOld: + type: string + stock: + type: string + matchmaking.v1.SpotsOrderReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.SpotsOrderResult' + message: + type: string + matchmaking.v1.SpotsOrderRequest: + type: object + properties: + digitalId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + dealPrice: + type: string + orderNumber: + type: string + orderMoney: + type: string + serviceCost: + type: string + matchmaking.v1.SpotsOrderResult: + type: object + properties: + orderId: + type: string + matchmaking.v1.ThaOrderReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.ThaOrderResult' + message: + type: string + matchmaking.v1.ThaOrderResult: + type: object + properties: + orderId: + type: string + matchmaking.v1.UpdateBlockOrderRequest: + type: object + properties: + orderId: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + type: + type: string + matchmaking.v1.UpdateBrlOrderRequest: + type: object + properties: + orderId: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + matchmaking.v1.UpdateContractRequest: + type: object + properties: + orderId: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + matchmaking.v1.UpdateEurOrderRequest: + type: object + properties: + orderId: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + matchmaking.v1.UpdateForexRequest: + type: object + properties: + orderId: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + matchmaking.v1.UpdateFurOrderRequest: + type: object + properties: + orderId: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + matchmaking.v1.UpdateGbxOrderRequest: + type: object + properties: + orderId: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + matchmaking.v1.UpdateHkdOrderRequest: + type: object + properties: + orderId: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + matchmaking.v1.UpdateIdnOrderRequest: + type: object + properties: + orderId: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + matchmaking.v1.UpdateInrOrderRequest: + type: object + properties: + orderId: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + matchmaking.v1.UpdateJpyOrderRequest: + type: object + properties: + orderId: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + matchmaking.v1.UpdateMoneyRequest: + type: object + properties: + orderId: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + matchmaking.v1.UpdateMysOrderRequest: + type: object + properties: + orderId: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + matchmaking.v1.UpdateOptionInrOrderRequest: + type: object + properties: + orderId: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + matchmaking.v1.UpdateSgdOrderRequest: + type: object + properties: + orderId: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + matchmaking.v1.UpdateThaOrderRequest: + type: object + properties: + orderId: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + matchmaking.v1.UpdateUsOrderRequest: + type: object + properties: + orderId: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + matchmaking.v1.UsOrderReply: + type: object + properties: + code: + type: string + data: + $ref: '#/components/schemas/matchmaking.v1.UsOrderResult' + message: + type: string + matchmaking.v1.UsOrderRequest: + type: object + properties: + stockId: + type: string + tradeType: + type: string + dealType: + type: string + limitPrice: + type: string + marketPrice: + type: string + marketMoney: + type: string + orderNumber: + type: string + serviceCost: + type: string + stopType: + type: string + stopLossPrice: + type: string + stopWinPrice: + type: string + pryNum: + type: string + matchmaking.v1.UsOrderResult: + type: object + properties: + orderId: + type: string +tags: + - name: Backend + - name: BlockTrade + - name: Contract + - name: Forex + - name: Money + - name: OptionInr + - name: Order + - name: Second + - name: ShareBrl + - name: ShareEur + - name: ShareFur + - name: ShareGbx + - name: ShareHkd + - name: ShareIdn + - name: ShareInr + - name: ShareJpy + - name: ShareMys + - name: ShareSgd + - name: ShareTha + - name: ShareUs + - name: Spots diff --git a/third_party/README.md b/third_party/README.md new file mode 100644 index 0000000..005faa2 --- /dev/null +++ b/third_party/README.md @@ -0,0 +1 @@ +# third_party diff --git a/third_party/errors/errors.proto b/third_party/errors/errors.proto new file mode 100644 index 0000000..0963d91 --- /dev/null +++ b/third_party/errors/errors.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +package errors; + +option go_package = "github.com/go-kratos/kratos/v2/errors;errors"; +option java_multiple_files = true; +option java_package = "com.github.kratos.errors"; +option objc_class_prefix = "KratosErrors"; + +import "google/protobuf/descriptor.proto"; + +extend google.protobuf.EnumOptions { + int32 default_code = 1108; +} + +extend google.protobuf.EnumValueOptions { + int32 code = 1109; +} \ No newline at end of file diff --git a/third_party/google/api/annotations.proto b/third_party/google/api/annotations.proto new file mode 100644 index 0000000..85c361b --- /dev/null +++ b/third_party/google/api/annotations.proto @@ -0,0 +1,31 @@ +// Copyright (c) 2015, Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +import "google/api/http.proto"; +import "google/protobuf/descriptor.proto"; + +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "AnnotationsProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + +extend google.protobuf.MethodOptions { + // See `HttpRule`. + HttpRule http = 72295728; +} diff --git a/third_party/google/api/client.proto b/third_party/google/api/client.proto new file mode 100644 index 0000000..d3d1ead --- /dev/null +++ b/third_party/google/api/client.proto @@ -0,0 +1,101 @@ +// Copyright 2019 Google LLC. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +import "google/protobuf/descriptor.proto"; + +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "ClientProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + + +extend google.protobuf.ServiceOptions { + // The hostname for this service. + // This should be specified with no prefix or protocol. + // + // Example: + // + // service Foo { + // option (google.api.default_host) = "foo.googleapi.com"; + // ... + // } + string default_host = 1049; + + // OAuth scopes needed for the client. + // + // Example: + // + // service Foo { + // option (google.api.oauth_scopes) = \ + // "https://www.googleapis.com/auth/cloud-platform"; + // ... + // } + // + // If there is more than one scope, use a comma-separated string: + // + // Example: + // + // service Foo { + // option (google.api.oauth_scopes) = \ + // "https://www.googleapis.com/auth/cloud-platform," + // "https://www.googleapis.com/auth/monitoring"; + // ... + // } + string oauth_scopes = 1050; +} + + +extend google.protobuf.MethodOptions { + // A definition of a client library method signature. + // + // In client libraries, each proto RPC corresponds to one or more methods + // which the end user is able to call, and calls the underlying RPC. + // Normally, this method receives a single argument (a struct or instance + // corresponding to the RPC request object). Defining this field will + // add one or more overloads providing flattened or simpler method signatures + // in some languages. + // + // The fields on the method signature are provided as a comma-separated + // string. + // + // For example, the proto RPC and annotation: + // + // rpc CreateSubscription(CreateSubscriptionRequest) + // returns (Subscription) { + // option (google.api.method_signature) = "name,topic"; + // } + // + // Would add the following Java overload (in addition to the method accepting + // the request object): + // + // public final Subscription createSubscription(String name, String topic) + // + // The following backwards-compatibility guidelines apply: + // + // * Adding this annotation to an unannotated method is backwards + // compatible. + // * Adding this annotation to a method which already has existing + // method signature annotations is backwards compatible if and only if + // the new method signature annotation is last in the sequence. + // * Modifying or removing an existing method signature annotation is + // a breaking change. + // * Re-ordering existing method signature annotations is a breaking + // change. + repeated string method_signature = 1051; +} \ No newline at end of file diff --git a/third_party/google/api/field_behavior.proto b/third_party/google/api/field_behavior.proto new file mode 100644 index 0000000..e9716a2 --- /dev/null +++ b/third_party/google/api/field_behavior.proto @@ -0,0 +1,80 @@ +// Copyright 2019 Google LLC. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +import "google/protobuf/descriptor.proto"; + +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "FieldBehaviorProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + + +// An indicator of the behavior of a given field (for example, that a field +// is required in requests, or given as output but ignored as input). +// This **does not** change the behavior in protocol buffers itself; it only +// denotes the behavior and may affect how API tooling handles the field. +// +// Note: This enum **may** receive new values in the future. +enum FieldBehavior { + // Conventional default for enums. Do not use this. + FIELD_BEHAVIOR_UNSPECIFIED = 0; + + // Specifically denotes a field as optional. + // While all fields in protocol buffers are optional, this may be specified + // for emphasis if appropriate. + OPTIONAL = 1; + + // Denotes a field as required. + // This indicates that the field **must** be provided as part of the request, + // and failure to do so will cause an error (usually `INVALID_ARGUMENT`). + REQUIRED = 2; + + // Denotes a field as output only. + // This indicates that the field is provided in responses, but including the + // field in a request does nothing (the server *must* ignore it and + // *must not* throw an error as a result of the field's presence). + OUTPUT_ONLY = 3; + + // Denotes a field as input only. + // This indicates that the field is provided in requests, and the + // corresponding field is not included in output. + INPUT_ONLY = 4; + + // Denotes a field as immutable. + // This indicates that the field may be set once in a request to create a + // resource, but may not be changed thereafter. + IMMUTABLE = 5; +} + + +extend google.protobuf.FieldOptions { + // A designation of a specific field behavior (required, output only, etc.) + // in protobuf messages. + // + // Examples: + // + // string name = 1 [(google.api.field_behavior) = REQUIRED]; + // State state = 1 [(google.api.field_behavior) = OUTPUT_ONLY]; + // google.protobuf.Duration ttl = 1 + // [(google.api.field_behavior) = INPUT_ONLY]; + // google.protobuf.Timestamp expire_time = 1 + // [(google.api.field_behavior) = OUTPUT_ONLY, + // (google.api.field_behavior) = IMMUTABLE]; + repeated FieldBehavior field_behavior = 1052; +} \ No newline at end of file diff --git a/third_party/google/api/http.proto b/third_party/google/api/http.proto new file mode 100644 index 0000000..69460cf --- /dev/null +++ b/third_party/google/api/http.proto @@ -0,0 +1,375 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +option cc_enable_arenas = true; +option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; +option java_multiple_files = true; +option java_outer_classname = "HttpProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + +// Defines the HTTP configuration for an API service. It contains a list of +// [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method +// to one or more HTTP REST API methods. +message Http { + // A list of HTTP configuration rules that apply to individual API methods. + // + // **NOTE:** All service configuration rules follow "last one wins" order. + repeated HttpRule rules = 1; + + // When set to true, URL path parameters will be fully URI-decoded except in + // cases of single segment matches in reserved expansion, where "%2F" will be + // left encoded. + // + // The default behavior is to not decode RFC 6570 reserved characters in multi + // segment matches. + bool fully_decode_reserved_expansion = 2; +} + +// # gRPC Transcoding +// +// gRPC Transcoding is a feature for mapping between a gRPC method and one or +// more HTTP REST endpoints. It allows developers to build a single API service +// that supports both gRPC APIs and REST APIs. Many systems, including [Google +// APIs](https://github.com/googleapis/googleapis), +// [Cloud Endpoints](https://cloud.google.com/endpoints), [gRPC +// Gateway](https://github.com/grpc-ecosystem/grpc-gateway), +// and [Envoy](https://github.com/envoyproxy/envoy) proxy support this feature +// and use it for large scale production services. +// +// `HttpRule` defines the schema of the gRPC/REST mapping. The mapping specifies +// how different portions of the gRPC request message are mapped to the URL +// path, URL query parameters, and HTTP request body. It also controls how the +// gRPC response message is mapped to the HTTP response body. `HttpRule` is +// typically specified as an `google.api.http` annotation on the gRPC method. +// +// Each mapping specifies a URL path template and an HTTP method. The path +// template may refer to one or more fields in the gRPC request message, as long +// as each field is a non-repeated field with a primitive (non-message) type. +// The path template controls how fields of the request message are mapped to +// the URL path. +// +// Example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get: "/v1/{name=messages/*}" +// }; +// } +// } +// message GetMessageRequest { +// string name = 1; // Mapped to URL path. +// } +// message Message { +// string text = 1; // The resource content. +// } +// +// This enables an HTTP REST to gRPC mapping as below: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456` | `GetMessage(name: "messages/123456")` +// +// Any fields in the request message which are not bound by the path template +// automatically become HTTP query parameters if there is no HTTP request body. +// For example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get:"/v1/messages/{message_id}" +// }; +// } +// } +// message GetMessageRequest { +// message SubMessage { +// string subfield = 1; +// } +// string message_id = 1; // Mapped to URL path. +// int64 revision = 2; // Mapped to URL query parameter `revision`. +// SubMessage sub = 3; // Mapped to URL query parameter `sub.subfield`. +// } +// +// This enables a HTTP JSON to RPC mapping as below: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456?revision=2&sub.subfield=foo` | +// `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: +// "foo"))` +// +// Note that fields which are mapped to URL query parameters must have a +// primitive type or a repeated primitive type or a non-repeated message type. +// In the case of a repeated type, the parameter can be repeated in the URL +// as `...?param=A¶m=B`. In the case of a message type, each field of the +// message is mapped to a separate parameter, such as +// `...?foo.a=A&foo.b=B&foo.c=C`. +// +// For HTTP methods that allow a request body, the `body` field +// specifies the mapping. Consider a REST update method on the +// message resource collection: +// +// service Messaging { +// rpc UpdateMessage(UpdateMessageRequest) returns (Message) { +// option (google.api.http) = { +// patch: "/v1/messages/{message_id}" +// body: "message" +// }; +// } +// } +// message UpdateMessageRequest { +// string message_id = 1; // mapped to the URL +// Message message = 2; // mapped to the body +// } +// +// The following HTTP JSON to RPC mapping is enabled, where the +// representation of the JSON in the request body is determined by +// protos JSON encoding: +// +// HTTP | gRPC +// -----|----- +// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +// "123456" message { text: "Hi!" })` +// +// The special name `*` can be used in the body mapping to define that +// every field not bound by the path template should be mapped to the +// request body. This enables the following alternative definition of +// the update method: +// +// service Messaging { +// rpc UpdateMessage(Message) returns (Message) { +// option (google.api.http) = { +// patch: "/v1/messages/{message_id}" +// body: "*" +// }; +// } +// } +// message Message { +// string message_id = 1; +// string text = 2; +// } +// +// +// The following HTTP JSON to RPC mapping is enabled: +// +// HTTP | gRPC +// -----|----- +// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +// "123456" text: "Hi!")` +// +// Note that when using `*` in the body mapping, it is not possible to +// have HTTP parameters, as all fields not bound by the path end in +// the body. This makes this option more rarely used in practice when +// defining REST APIs. The common usage of `*` is in custom methods +// which don't use the URL at all for transferring data. +// +// It is possible to define multiple HTTP methods for one RPC by using +// the `additional_bindings` option. Example: +// +// service Messaging { +// rpc GetMessage(GetMessageRequest) returns (Message) { +// option (google.api.http) = { +// get: "/v1/messages/{message_id}" +// additional_bindings { +// get: "/v1/users/{user_id}/messages/{message_id}" +// } +// }; +// } +// } +// message GetMessageRequest { +// string message_id = 1; +// string user_id = 2; +// } +// +// This enables the following two alternative HTTP JSON to RPC mappings: +// +// HTTP | gRPC +// -----|----- +// `GET /v1/messages/123456` | `GetMessage(message_id: "123456")` +// `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: +// "123456")` +// +// ## Rules for HTTP mapping +// +// 1. Leaf request fields (recursive expansion nested messages in the request +// message) are classified into three categories: +// - Fields referred by the path template. They are passed via the URL path. +// - Fields referred by the [HttpRule.body][google.api.HttpRule.body]. They are passed via the HTTP +// request body. +// - All other fields are passed via the URL query parameters, and the +// parameter name is the field path in the request message. A repeated +// field can be represented as multiple query parameters under the same +// name. +// 2. If [HttpRule.body][google.api.HttpRule.body] is "*", there is no URL query parameter, all fields +// are passed via URL path and HTTP request body. +// 3. If [HttpRule.body][google.api.HttpRule.body] is omitted, there is no HTTP request body, all +// fields are passed via URL path and URL query parameters. +// +// ### Path template syntax +// +// Template = "/" Segments [ Verb ] ; +// Segments = Segment { "/" Segment } ; +// Segment = "*" | "**" | LITERAL | Variable ; +// Variable = "{" FieldPath [ "=" Segments ] "}" ; +// FieldPath = IDENT { "." IDENT } ; +// Verb = ":" LITERAL ; +// +// The syntax `*` matches a single URL path segment. The syntax `**` matches +// zero or more URL path segments, which must be the last part of the URL path +// except the `Verb`. +// +// The syntax `Variable` matches part of the URL path as specified by its +// template. A variable template must not contain other variables. If a variable +// matches a single path segment, its template may be omitted, e.g. `{var}` +// is equivalent to `{var=*}`. +// +// The syntax `LITERAL` matches literal text in the URL path. If the `LITERAL` +// contains any reserved character, such characters should be percent-encoded +// before the matching. +// +// If a variable contains exactly one path segment, such as `"{var}"` or +// `"{var=*}"`, when such a variable is expanded into a URL path on the client +// side, all characters except `[-_.~0-9a-zA-Z]` are percent-encoded. The +// server side does the reverse decoding. Such variables show up in the +// [Discovery +// Document](https://developers.google.com/discovery/v1/reference/apis) as +// `{var}`. +// +// If a variable contains multiple path segments, such as `"{var=foo/*}"` +// or `"{var=**}"`, when such a variable is expanded into a URL path on the +// client side, all characters except `[-_.~/0-9a-zA-Z]` are percent-encoded. +// The server side does the reverse decoding, except "%2F" and "%2f" are left +// unchanged. Such variables show up in the +// [Discovery +// Document](https://developers.google.com/discovery/v1/reference/apis) as +// `{+var}`. +// +// ## Using gRPC API Service Configuration +// +// gRPC API Service Configuration (service config) is a configuration language +// for configuring a gRPC service to become a user-facing product. The +// service config is simply the YAML representation of the `google.api.Service` +// proto message. +// +// As an alternative to annotating your proto file, you can configure gRPC +// transcoding in your service config YAML files. You do this by specifying a +// `HttpRule` that maps the gRPC method to a REST endpoint, achieving the same +// effect as the proto annotation. This can be particularly useful if you +// have a proto that is reused in multiple services. Note that any transcoding +// specified in the service config will override any matching transcoding +// configuration in the proto. +// +// Example: +// +// http: +// rules: +// # Selects a gRPC method and applies HttpRule to it. +// - selector: example.v1.Messaging.GetMessage +// get: /v1/messages/{message_id}/{sub.subfield} +// +// ## Special notes +// +// When gRPC Transcoding is used to map a gRPC to JSON REST endpoints, the +// proto to JSON conversion must follow the [proto3 +// specification](https://developers.google.com/protocol-buffers/docs/proto3#json). +// +// While the single segment variable follows the semantics of +// [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2 Simple String +// Expansion, the multi segment variable **does not** follow RFC 6570 Section +// 3.2.3 Reserved Expansion. The reason is that the Reserved Expansion +// does not expand special characters like `?` and `#`, which would lead +// to invalid URLs. As the result, gRPC Transcoding uses a custom encoding +// for multi segment variables. +// +// The path variables **must not** refer to any repeated or mapped field, +// because client libraries are not capable of handling such variable expansion. +// +// The path variables **must not** capture the leading "/" character. The reason +// is that the most common use case "{var}" does not capture the leading "/" +// character. For consistency, all path variables must share the same behavior. +// +// Repeated message fields must not be mapped to URL query parameters, because +// no client library can support such complicated mapping. +// +// If an API needs to use a JSON array for request or response body, it can map +// the request or response body to a repeated field. However, some gRPC +// Transcoding implementations may not support this feature. +message HttpRule { + // Selects a method to which this rule applies. + // + // Refer to [selector][google.api.DocumentationRule.selector] for syntax details. + string selector = 1; + + // Determines the URL pattern is matched by this rules. This pattern can be + // used with any of the {get|put|post|delete|patch} methods. A custom method + // can be defined using the 'custom' field. + oneof pattern { + // Maps to HTTP GET. Used for listing and getting information about + // resources. + string get = 2; + + // Maps to HTTP PUT. Used for replacing a resource. + string put = 3; + + // Maps to HTTP POST. Used for creating a resource or performing an action. + string post = 4; + + // Maps to HTTP DELETE. Used for deleting a resource. + string delete = 5; + + // Maps to HTTP PATCH. Used for updating a resource. + string patch = 6; + + // The custom pattern is used for specifying an HTTP method that is not + // included in the `pattern` field, such as HEAD, or "*" to leave the + // HTTP method unspecified for this rule. The wild-card rule is useful + // for services that provide content to Web (HTML) clients. + CustomHttpPattern custom = 8; + } + + // The name of the request field whose value is mapped to the HTTP request + // body, or `*` for mapping all request fields not captured by the path + // pattern to the HTTP body, or omitted for not having any HTTP request body. + // + // NOTE: the referred field must be present at the top-level of the request + // message type. + string body = 7; + + // Optional. The name of the response field whose value is mapped to the HTTP + // response body. When omitted, the entire response message will be used + // as the HTTP response body. + // + // NOTE: The referred field must be present at the top-level of the response + // message type. + string response_body = 12; + + // Additional HTTP bindings for the selector. Nested bindings must + // not contain an `additional_bindings` field themselves (that is, + // the nesting may only be one level deep). + repeated HttpRule additional_bindings = 11; +} + +// A custom pattern is used for defining custom HTTP verb. +message CustomHttpPattern { + // The name of this custom HTTP verb. + string kind = 1; + + // The path matched by this custom verb. + string path = 2; +} diff --git a/third_party/google/api/httpbody.proto b/third_party/google/api/httpbody.proto new file mode 100644 index 0000000..1a5bb78 --- /dev/null +++ b/third_party/google/api/httpbody.proto @@ -0,0 +1,77 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.api; + +import "google/protobuf/any.proto"; + +option cc_enable_arenas = true; +option go_package = "google.golang.org/genproto/googleapis/api/httpbody;httpbody"; +option java_multiple_files = true; +option java_outer_classname = "HttpBodyProto"; +option java_package = "com.google.api"; +option objc_class_prefix = "GAPI"; + +// Message that represents an arbitrary HTTP body. It should only be used for +// payload formats that can't be represented as JSON, such as raw binary or +// an HTML page. +// +// +// This message can be used both in streaming and non-streaming API methods in +// the request as well as the response. +// +// It can be used as a top-level request field, which is convenient if one +// wants to extract parameters from either the URL or HTTP template into the +// request fields and also want access to the raw HTTP body. +// +// Example: +// +// message GetResourceRequest { +// // A unique request id. +// string request_id = 1; +// +// // The raw HTTP body is bound to this field. +// google.api.HttpBody http_body = 2; +// } +// +// service ResourceService { +// rpc GetResource(GetResourceRequest) returns (google.api.HttpBody); +// rpc UpdateResource(google.api.HttpBody) returns +// (google.protobuf.Empty); +// } +// +// Example with streaming methods: +// +// service CaldavService { +// rpc GetCalendar(stream google.api.HttpBody) +// returns (stream google.api.HttpBody); +// rpc UpdateCalendar(stream google.api.HttpBody) +// returns (stream google.api.HttpBody); +// } +// +// Use of this type only changes how the request and response bodies are +// handled, all other features will continue to work unchanged. +message HttpBody { + // The HTTP Content-Type header value specifying the content type of the body. + string content_type = 1; + + // The HTTP request/response body as raw binary. + bytes data = 2; + + // Application specific response metadata. Must be set in the first response + // for streaming APIs. + repeated google.protobuf.Any extensions = 3; +} diff --git a/third_party/google/protobuf/any.proto b/third_party/google/protobuf/any.proto new file mode 100644 index 0000000..e2c2042 --- /dev/null +++ b/third_party/google/protobuf/any.proto @@ -0,0 +1,158 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option go_package = "google.golang.org/protobuf/types/known/anypb"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "AnyProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; + +// `Any` contains an arbitrary serialized protocol buffer message along with a +// URL that describes the type of the serialized message. +// +// Protobuf library provides support to pack/unpack Any values in the form +// of utility functions or additional generated methods of the Any type. +// +// Example 1: Pack and unpack a message in C++. +// +// Foo foo = ...; +// Any any; +// any.PackFrom(foo); +// ... +// if (any.UnpackTo(&foo)) { +// ... +// } +// +// Example 2: Pack and unpack a message in Java. +// +// Foo foo = ...; +// Any any = Any.pack(foo); +// ... +// if (any.is(Foo.class)) { +// foo = any.unpack(Foo.class); +// } +// +// Example 3: Pack and unpack a message in Python. +// +// foo = Foo(...) +// any = Any() +// any.Pack(foo) +// ... +// if any.Is(Foo.DESCRIPTOR): +// any.Unpack(foo) +// ... +// +// Example 4: Pack and unpack a message in Go +// +// foo := &pb.Foo{...} +// any, err := anypb.New(foo) +// if err != nil { +// ... +// } +// ... +// foo := &pb.Foo{} +// if err := any.UnmarshalTo(foo); err != nil { +// ... +// } +// +// The pack methods provided by protobuf library will by default use +// 'type.googleapis.com/full.type.name' as the type URL and the unpack +// methods only use the fully qualified type name after the last '/' +// in the type URL, for example "foo.bar.com/x/y.z" will yield type +// name "y.z". +// +// +// JSON +// +// The JSON representation of an `Any` value uses the regular +// representation of the deserialized, embedded message, with an +// additional field `@type` which contains the type URL. Example: +// +// package google.profile; +// message Person { +// string first_name = 1; +// string last_name = 2; +// } +// +// { +// "@type": "type.googleapis.com/google.profile.Person", +// "firstName": , +// "lastName": +// } +// +// If the embedded message type is well-known and has a custom JSON +// representation, that representation will be embedded adding a field +// `value` which holds the custom JSON in addition to the `@type` +// field. Example (for message [google.protobuf.Duration][]): +// +// { +// "@type": "type.googleapis.com/google.protobuf.Duration", +// "value": "1.212s" +// } +// +message Any { + // A URL/resource name that uniquely identifies the type of the serialized + // protocol buffer message. This string must contain at least + // one "/" character. The last segment of the URL's path must represent + // the fully qualified name of the type (as in + // `path/google.protobuf.Duration`). The name should be in a canonical form + // (e.g., leading "." is not accepted). + // + // In practice, teams usually precompile into the binary all types that they + // expect it to use in the context of Any. However, for URLs which use the + // scheme `http`, `https`, or no scheme, one can optionally set up a type + // server that maps type URLs to message definitions as follows: + // + // * If no scheme is provided, `https` is assumed. + // * An HTTP GET on the URL must yield a [google.protobuf.Type][] + // value in binary format, or produce an error. + // * Applications are allowed to cache lookup results based on the + // URL, or have them precompiled into a binary to avoid any + // lookup. Therefore, binary compatibility needs to be preserved + // on changes to types. (Use versioned type names to manage + // breaking changes.) + // + // Note: this functionality is not currently available in the official + // protobuf release, and it is not used for type URLs beginning with + // type.googleapis.com. + // + // Schemes other than `http`, `https` (or the empty scheme) might be + // used with implementation specific semantics. + // + string type_url = 1; + + // Must be a valid serialized protocol buffer of the above specified type. + bytes value = 2; +} diff --git a/third_party/google/protobuf/api.proto b/third_party/google/protobuf/api.proto new file mode 100644 index 0000000..3d598fc --- /dev/null +++ b/third_party/google/protobuf/api.proto @@ -0,0 +1,208 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +import "google/protobuf/source_context.proto"; +import "google/protobuf/type.proto"; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "ApiProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; +option go_package = "google.golang.org/protobuf/types/known/apipb"; + +// Api is a light-weight descriptor for an API Interface. +// +// Interfaces are also described as "protocol buffer services" in some contexts, +// such as by the "service" keyword in a .proto file, but they are different +// from API Services, which represent a concrete implementation of an interface +// as opposed to simply a description of methods and bindings. They are also +// sometimes simply referred to as "APIs" in other contexts, such as the name of +// this message itself. See https://cloud.google.com/apis/design/glossary for +// detailed terminology. +message Api { + // The fully qualified name of this interface, including package name + // followed by the interface's simple name. + string name = 1; + + // The methods of this interface, in unspecified order. + repeated Method methods = 2; + + // Any metadata attached to the interface. + repeated Option options = 3; + + // A version string for this interface. If specified, must have the form + // `major-version.minor-version`, as in `1.10`. If the minor version is + // omitted, it defaults to zero. If the entire version field is empty, the + // major version is derived from the package name, as outlined below. If the + // field is not empty, the version in the package name will be verified to be + // consistent with what is provided here. + // + // The versioning schema uses [semantic + // versioning](http://semver.org) where the major version number + // indicates a breaking change and the minor version an additive, + // non-breaking change. Both version numbers are signals to users + // what to expect from different versions, and should be carefully + // chosen based on the product plan. + // + // The major version is also reflected in the package name of the + // interface, which must end in `v`, as in + // `google.feature.v1`. For major versions 0 and 1, the suffix can + // be omitted. Zero major versions must only be used for + // experimental, non-GA interfaces. + // + // + string version = 4; + + // Source context for the protocol buffer service represented by this + // message. + SourceContext source_context = 5; + + // Included interfaces. See [Mixin][]. + repeated Mixin mixins = 6; + + // The source syntax of the service. + Syntax syntax = 7; +} + +// Method represents a method of an API interface. +message Method { + // The simple name of this method. + string name = 1; + + // A URL of the input message type. + string request_type_url = 2; + + // If true, the request is streamed. + bool request_streaming = 3; + + // The URL of the output message type. + string response_type_url = 4; + + // If true, the response is streamed. + bool response_streaming = 5; + + // Any metadata attached to the method. + repeated Option options = 6; + + // The source syntax of this method. + Syntax syntax = 7; +} + +// Declares an API Interface to be included in this interface. The including +// interface must redeclare all the methods from the included interface, but +// documentation and options are inherited as follows: +// +// - If after comment and whitespace stripping, the documentation +// string of the redeclared method is empty, it will be inherited +// from the original method. +// +// - Each annotation belonging to the service config (http, +// visibility) which is not set in the redeclared method will be +// inherited. +// +// - If an http annotation is inherited, the path pattern will be +// modified as follows. Any version prefix will be replaced by the +// version of the including interface plus the [root][] path if +// specified. +// +// Example of a simple mixin: +// +// package google.acl.v1; +// service AccessControl { +// // Get the underlying ACL object. +// rpc GetAcl(GetAclRequest) returns (Acl) { +// option (google.api.http).get = "/v1/{resource=**}:getAcl"; +// } +// } +// +// package google.storage.v2; +// service Storage { +// rpc GetAcl(GetAclRequest) returns (Acl); +// +// // Get a data record. +// rpc GetData(GetDataRequest) returns (Data) { +// option (google.api.http).get = "/v2/{resource=**}"; +// } +// } +// +// Example of a mixin configuration: +// +// apis: +// - name: google.storage.v2.Storage +// mixins: +// - name: google.acl.v1.AccessControl +// +// The mixin construct implies that all methods in `AccessControl` are +// also declared with same name and request/response types in +// `Storage`. A documentation generator or annotation processor will +// see the effective `Storage.GetAcl` method after inheriting +// documentation and annotations as follows: +// +// service Storage { +// // Get the underlying ACL object. +// rpc GetAcl(GetAclRequest) returns (Acl) { +// option (google.api.http).get = "/v2/{resource=**}:getAcl"; +// } +// ... +// } +// +// Note how the version in the path pattern changed from `v1` to `v2`. +// +// If the `root` field in the mixin is specified, it should be a +// relative path under which inherited HTTP paths are placed. Example: +// +// apis: +// - name: google.storage.v2.Storage +// mixins: +// - name: google.acl.v1.AccessControl +// root: acls +// +// This implies the following inherited HTTP annotation: +// +// service Storage { +// // Get the underlying ACL object. +// rpc GetAcl(GetAclRequest) returns (Acl) { +// option (google.api.http).get = "/v2/acls/{resource=**}:getAcl"; +// } +// ... +// } +message Mixin { + // The fully qualified name of the interface which is included. + string name = 1; + + // If non-empty specifies a path under which inherited HTTP paths + // are rooted. + string root = 2; +} diff --git a/third_party/google/protobuf/compiler/plugin.proto b/third_party/google/protobuf/compiler/plugin.proto new file mode 100644 index 0000000..9242aac --- /dev/null +++ b/third_party/google/protobuf/compiler/plugin.proto @@ -0,0 +1,183 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// +// WARNING: The plugin interface is currently EXPERIMENTAL and is subject to +// change. +// +// protoc (aka the Protocol Compiler) can be extended via plugins. A plugin is +// just a program that reads a CodeGeneratorRequest from stdin and writes a +// CodeGeneratorResponse to stdout. +// +// Plugins written using C++ can use google/protobuf/compiler/plugin.h instead +// of dealing with the raw protocol defined here. +// +// A plugin executable needs only to be placed somewhere in the path. The +// plugin should be named "protoc-gen-$NAME", and will then be used when the +// flag "--${NAME}_out" is passed to protoc. + +syntax = "proto2"; + +package google.protobuf.compiler; +option java_package = "com.google.protobuf.compiler"; +option java_outer_classname = "PluginProtos"; + +option go_package = "google.golang.org/protobuf/types/pluginpb"; + +import "google/protobuf/descriptor.proto"; + +// The version number of protocol compiler. +message Version { + optional int32 major = 1; + optional int32 minor = 2; + optional int32 patch = 3; + // A suffix for alpha, beta or rc release, e.g., "alpha-1", "rc2". It should + // be empty for mainline stable releases. + optional string suffix = 4; +} + +// An encoded CodeGeneratorRequest is written to the plugin's stdin. +message CodeGeneratorRequest { + // The .proto files that were explicitly listed on the command-line. The + // code generator should generate code only for these files. Each file's + // descriptor will be included in proto_file, below. + repeated string file_to_generate = 1; + + // The generator parameter passed on the command-line. + optional string parameter = 2; + + // FileDescriptorProtos for all files in files_to_generate and everything + // they import. The files will appear in topological order, so each file + // appears before any file that imports it. + // + // protoc guarantees that all proto_files will be written after + // the fields above, even though this is not technically guaranteed by the + // protobuf wire format. This theoretically could allow a plugin to stream + // in the FileDescriptorProtos and handle them one by one rather than read + // the entire set into memory at once. However, as of this writing, this + // is not similarly optimized on protoc's end -- it will store all fields in + // memory at once before sending them to the plugin. + // + // Type names of fields and extensions in the FileDescriptorProto are always + // fully qualified. + repeated FileDescriptorProto proto_file = 15; + + // The version number of protocol compiler. + optional Version compiler_version = 3; + +} + +// The plugin writes an encoded CodeGeneratorResponse to stdout. +message CodeGeneratorResponse { + // Error message. If non-empty, code generation failed. The plugin process + // should exit with status code zero even if it reports an error in this way. + // + // This should be used to indicate errors in .proto files which prevent the + // code generator from generating correct code. Errors which indicate a + // problem in protoc itself -- such as the input CodeGeneratorRequest being + // unparseable -- should be reported by writing a message to stderr and + // exiting with a non-zero status code. + optional string error = 1; + + // A bitmask of supported features that the code generator supports. + // This is a bitwise "or" of values from the Feature enum. + optional uint64 supported_features = 2; + + // Sync with code_generator.h. + enum Feature { + FEATURE_NONE = 0; + FEATURE_PROTO3_OPTIONAL = 1; + } + + // Represents a single generated file. + message File { + // The file name, relative to the output directory. The name must not + // contain "." or ".." components and must be relative, not be absolute (so, + // the file cannot lie outside the output directory). "/" must be used as + // the path separator, not "\". + // + // If the name is omitted, the content will be appended to the previous + // file. This allows the generator to break large files into small chunks, + // and allows the generated text to be streamed back to protoc so that large + // files need not reside completely in memory at one time. Note that as of + // this writing protoc does not optimize for this -- it will read the entire + // CodeGeneratorResponse before writing files to disk. + optional string name = 1; + + // If non-empty, indicates that the named file should already exist, and the + // content here is to be inserted into that file at a defined insertion + // point. This feature allows a code generator to extend the output + // produced by another code generator. The original generator may provide + // insertion points by placing special annotations in the file that look + // like: + // @@protoc_insertion_point(NAME) + // The annotation can have arbitrary text before and after it on the line, + // which allows it to be placed in a comment. NAME should be replaced with + // an identifier naming the point -- this is what other generators will use + // as the insertion_point. Code inserted at this point will be placed + // immediately above the line containing the insertion point (thus multiple + // insertions to the same point will come out in the order they were added). + // The double-@ is intended to make it unlikely that the generated code + // could contain things that look like insertion points by accident. + // + // For example, the C++ code generator places the following line in the + // .pb.h files that it generates: + // // @@protoc_insertion_point(namespace_scope) + // This line appears within the scope of the file's package namespace, but + // outside of any particular class. Another plugin can then specify the + // insertion_point "namespace_scope" to generate additional classes or + // other declarations that should be placed in this scope. + // + // Note that if the line containing the insertion point begins with + // whitespace, the same whitespace will be added to every line of the + // inserted text. This is useful for languages like Python, where + // indentation matters. In these languages, the insertion point comment + // should be indented the same amount as any inserted code will need to be + // in order to work correctly in that context. + // + // The code generator that generates the initial file and the one which + // inserts into it must both run as part of a single invocation of protoc. + // Code generators are executed in the order in which they appear on the + // command line. + // + // If |insertion_point| is present, |name| must also be present. + optional string insertion_point = 2; + + // The file contents. + optional string content = 15; + + // Information describing the file content being inserted. If an insertion + // point is used, this information will be appropriately offset and inserted + // into the code generation metadata for the generated files. + optional GeneratedCodeInfo generated_code_info = 16; + } + repeated File file = 15; +} diff --git a/third_party/google/protobuf/descriptor.proto b/third_party/google/protobuf/descriptor.proto new file mode 100644 index 0000000..49ec653 --- /dev/null +++ b/third_party/google/protobuf/descriptor.proto @@ -0,0 +1,921 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// The messages in this file describe the definitions found in .proto files. +// A valid .proto file can be translated directly to a FileDescriptorProto +// without any other information (e.g. without reading its imports). + + +syntax = "proto2"; + +package google.protobuf; + +option go_package = "google.golang.org/protobuf/types/descriptorpb"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "DescriptorProtos"; +option csharp_namespace = "Google.Protobuf.Reflection"; +option objc_class_prefix = "GPB"; +option cc_enable_arenas = true; + +// descriptor.proto must be optimized for speed because reflection-based +// algorithms don't work during bootstrapping. +option optimize_for = SPEED; + +// The protocol compiler can output a FileDescriptorSet containing the .proto +// files it parses. +message FileDescriptorSet { + repeated FileDescriptorProto file = 1; +} + +// Describes a complete .proto file. +message FileDescriptorProto { + optional string name = 1; // file name, relative to root of source tree + optional string package = 2; // e.g. "foo", "foo.bar", etc. + + // Names of files imported by this file. + repeated string dependency = 3; + // Indexes of the public imported files in the dependency list above. + repeated int32 public_dependency = 10; + // Indexes of the weak imported files in the dependency list. + // For Google-internal migration only. Do not use. + repeated int32 weak_dependency = 11; + + // All top-level definitions in this file. + repeated DescriptorProto message_type = 4; + repeated EnumDescriptorProto enum_type = 5; + repeated ServiceDescriptorProto service = 6; + repeated FieldDescriptorProto extension = 7; + + optional FileOptions options = 8; + + // This field contains optional information about the original source code. + // You may safely remove this entire field without harming runtime + // functionality of the descriptors -- the information is needed only by + // development tools. + optional SourceCodeInfo source_code_info = 9; + + // The syntax of the proto file. + // The supported values are "proto2" and "proto3". + optional string syntax = 12; +} + +// Describes a message type. +message DescriptorProto { + optional string name = 1; + + repeated FieldDescriptorProto field = 2; + repeated FieldDescriptorProto extension = 6; + + repeated DescriptorProto nested_type = 3; + repeated EnumDescriptorProto enum_type = 4; + + message ExtensionRange { + optional int32 start = 1; // Inclusive. + optional int32 end = 2; // Exclusive. + + optional ExtensionRangeOptions options = 3; + } + repeated ExtensionRange extension_range = 5; + + repeated OneofDescriptorProto oneof_decl = 8; + + optional MessageOptions options = 7; + + // Range of reserved tag numbers. Reserved tag numbers may not be used by + // fields or extension ranges in the same message. Reserved ranges may + // not overlap. + message ReservedRange { + optional int32 start = 1; // Inclusive. + optional int32 end = 2; // Exclusive. + } + repeated ReservedRange reserved_range = 9; + // Reserved field names, which may not be used by fields in the same message. + // A given name may only be reserved once. + repeated string reserved_name = 10; +} + +message ExtensionRangeOptions { + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +// Describes a field within a message. +message FieldDescriptorProto { + enum Type { + // 0 is reserved for errors. + // Order is weird for historical reasons. + TYPE_DOUBLE = 1; + TYPE_FLOAT = 2; + // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if + // negative values are likely. + TYPE_INT64 = 3; + TYPE_UINT64 = 4; + // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if + // negative values are likely. + TYPE_INT32 = 5; + TYPE_FIXED64 = 6; + TYPE_FIXED32 = 7; + TYPE_BOOL = 8; + TYPE_STRING = 9; + // Tag-delimited aggregate. + // Group type is deprecated and not supported in proto3. However, Proto3 + // implementations should still be able to parse the group wire format and + // treat group fields as unknown fields. + TYPE_GROUP = 10; + TYPE_MESSAGE = 11; // Length-delimited aggregate. + + // New in version 2. + TYPE_BYTES = 12; + TYPE_UINT32 = 13; + TYPE_ENUM = 14; + TYPE_SFIXED32 = 15; + TYPE_SFIXED64 = 16; + TYPE_SINT32 = 17; // Uses ZigZag encoding. + TYPE_SINT64 = 18; // Uses ZigZag encoding. + } + + enum Label { + // 0 is reserved for errors + LABEL_OPTIONAL = 1; + LABEL_REQUIRED = 2; + LABEL_REPEATED = 3; + } + + optional string name = 1; + optional int32 number = 3; + optional Label label = 4; + + // If type_name is set, this need not be set. If both this and type_name + // are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP. + optional Type type = 5; + + // For message and enum types, this is the name of the type. If the name + // starts with a '.', it is fully-qualified. Otherwise, C++-like scoping + // rules are used to find the type (i.e. first the nested types within this + // message are searched, then within the parent, on up to the root + // namespace). + optional string type_name = 6; + + // For extensions, this is the name of the type being extended. It is + // resolved in the same manner as type_name. + optional string extendee = 2; + + // For numeric types, contains the original text representation of the value. + // For booleans, "true" or "false". + // For strings, contains the default text contents (not escaped in any way). + // For bytes, contains the C escaped value. All bytes >= 128 are escaped. + optional string default_value = 7; + + // If set, gives the index of a oneof in the containing type's oneof_decl + // list. This field is a member of that oneof. + optional int32 oneof_index = 9; + + // JSON name of this field. The value is set by protocol compiler. If the + // user has set a "json_name" option on this field, that option's value + // will be used. Otherwise, it's deduced from the field's name by converting + // it to camelCase. + optional string json_name = 10; + + optional FieldOptions options = 8; + + // If true, this is a proto3 "optional". When a proto3 field is optional, it + // tracks presence regardless of field type. + // + // When proto3_optional is true, this field must be belong to a oneof to + // signal to old proto3 clients that presence is tracked for this field. This + // oneof is known as a "synthetic" oneof, and this field must be its sole + // member (each proto3 optional field gets its own synthetic oneof). Synthetic + // oneofs exist in the descriptor only, and do not generate any API. Synthetic + // oneofs must be ordered after all "real" oneofs. + // + // For message fields, proto3_optional doesn't create any semantic change, + // since non-repeated message fields always track presence. However it still + // indicates the semantic detail of whether the user wrote "optional" or not. + // This can be useful for round-tripping the .proto file. For consistency we + // give message fields a synthetic oneof also, even though it is not required + // to track presence. This is especially important because the parser can't + // tell if a field is a message or an enum, so it must always create a + // synthetic oneof. + // + // Proto2 optional fields do not set this flag, because they already indicate + // optional with `LABEL_OPTIONAL`. + optional bool proto3_optional = 17; +} + +// Describes a oneof. +message OneofDescriptorProto { + optional string name = 1; + optional OneofOptions options = 2; +} + +// Describes an enum type. +message EnumDescriptorProto { + optional string name = 1; + + repeated EnumValueDescriptorProto value = 2; + + optional EnumOptions options = 3; + + // Range of reserved numeric values. Reserved values may not be used by + // entries in the same enum. Reserved ranges may not overlap. + // + // Note that this is distinct from DescriptorProto.ReservedRange in that it + // is inclusive such that it can appropriately represent the entire int32 + // domain. + message EnumReservedRange { + optional int32 start = 1; // Inclusive. + optional int32 end = 2; // Inclusive. + } + + // Range of reserved numeric values. Reserved numeric values may not be used + // by enum values in the same enum declaration. Reserved ranges may not + // overlap. + repeated EnumReservedRange reserved_range = 4; + + // Reserved enum value names, which may not be reused. A given name may only + // be reserved once. + repeated string reserved_name = 5; +} + +// Describes a value within an enum. +message EnumValueDescriptorProto { + optional string name = 1; + optional int32 number = 2; + + optional EnumValueOptions options = 3; +} + +// Describes a service. +message ServiceDescriptorProto { + optional string name = 1; + repeated MethodDescriptorProto method = 2; + + optional ServiceOptions options = 3; +} + +// Describes a method of a service. +message MethodDescriptorProto { + optional string name = 1; + + // Input and output type names. These are resolved in the same way as + // FieldDescriptorProto.type_name, but must refer to a message type. + optional string input_type = 2; + optional string output_type = 3; + + optional MethodOptions options = 4; + + // Identifies if client streams multiple client messages + optional bool client_streaming = 5 [default = false]; + // Identifies if server streams multiple server messages + optional bool server_streaming = 6 [default = false]; +} + + +// =================================================================== +// Options + +// Each of the definitions above may have "options" attached. These are +// just annotations which may cause code to be generated slightly differently +// or may contain hints for code that manipulates protocol messages. +// +// Clients may define custom options as extensions of the *Options messages. +// These extensions may not yet be known at parsing time, so the parser cannot +// store the values in them. Instead it stores them in a field in the *Options +// message called uninterpreted_option. This field must have the same name +// across all *Options messages. We then use this field to populate the +// extensions when we build a descriptor, at which point all protos have been +// parsed and so all extensions are known. +// +// Extension numbers for custom options may be chosen as follows: +// * For options which will only be used within a single application or +// organization, or for experimental options, use field numbers 50000 +// through 99999. It is up to you to ensure that you do not use the +// same number for multiple options. +// * For options which will be published and used publicly by multiple +// independent entities, e-mail protobuf-global-extension-registry@google.com +// to reserve extension numbers. Simply provide your project name (e.g. +// Objective-C plugin) and your project website (if available) -- there's no +// need to explain how you intend to use them. Usually you only need one +// extension number. You can declare multiple options with only one extension +// number by putting them in a sub-message. See the Custom Options section of +// the docs for examples: +// https://developers.google.com/protocol-buffers/docs/proto#options +// If this turns out to be popular, a web service will be set up +// to automatically assign option numbers. + +message FileOptions { + + // Sets the Java package where classes generated from this .proto will be + // placed. By default, the proto package is used, but this is often + // inappropriate because proto packages do not normally start with backwards + // domain names. + optional string java_package = 1; + + + // Controls the name of the wrapper Java class generated for the .proto file. + // That class will always contain the .proto file's getDescriptor() method as + // well as any top-level extensions defined in the .proto file. + // If java_multiple_files is disabled, then all the other classes from the + // .proto file will be nested inside the single wrapper outer class. + optional string java_outer_classname = 8; + + // If enabled, then the Java code generator will generate a separate .java + // file for each top-level message, enum, and service defined in the .proto + // file. Thus, these types will *not* be nested inside the wrapper class + // named by java_outer_classname. However, the wrapper class will still be + // generated to contain the file's getDescriptor() method as well as any + // top-level extensions defined in the file. + optional bool java_multiple_files = 10 [default = false]; + + // This option does nothing. + optional bool java_generate_equals_and_hash = 20 [deprecated=true]; + + // If set true, then the Java2 code generator will generate code that + // throws an exception whenever an attempt is made to assign a non-UTF-8 + // byte sequence to a string field. + // Message reflection will do the same. + // However, an extension field still accepts non-UTF-8 byte sequences. + // This option has no effect on when used with the lite runtime. + optional bool java_string_check_utf8 = 27 [default = false]; + + + // Generated classes can be optimized for speed or code size. + enum OptimizeMode { + SPEED = 1; // Generate complete code for parsing, serialization, + // etc. + CODE_SIZE = 2; // Use ReflectionOps to implement these methods. + LITE_RUNTIME = 3; // Generate code using MessageLite and the lite runtime. + } + optional OptimizeMode optimize_for = 9 [default = SPEED]; + + // Sets the Go package where structs generated from this .proto will be + // placed. If omitted, the Go package will be derived from the following: + // - The basename of the package import path, if provided. + // - Otherwise, the package statement in the .proto file, if present. + // - Otherwise, the basename of the .proto file, without extension. + optional string go_package = 11; + + + + + // Should generic services be generated in each language? "Generic" services + // are not specific to any particular RPC system. They are generated by the + // main code generators in each language (without additional plugins). + // Generic services were the only kind of service generation supported by + // early versions of google.protobuf. + // + // Generic services are now considered deprecated in favor of using plugins + // that generate code specific to your particular RPC system. Therefore, + // these default to false. Old code which depends on generic services should + // explicitly set them to true. + optional bool cc_generic_services = 16 [default = false]; + optional bool java_generic_services = 17 [default = false]; + optional bool py_generic_services = 18 [default = false]; + optional bool php_generic_services = 42 [default = false]; + + // Is this file deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for everything in the file, or it will be completely ignored; in the very + // least, this is a formalization for deprecating files. + optional bool deprecated = 23 [default = false]; + + // Enables the use of arenas for the proto messages in this file. This applies + // only to generated classes for C++. + optional bool cc_enable_arenas = 31 [default = true]; + + + // Sets the objective c class prefix which is prepended to all objective c + // generated classes from this .proto. There is no default. + optional string objc_class_prefix = 36; + + // Namespace for generated classes; defaults to the package. + optional string csharp_namespace = 37; + + // By default Swift generators will take the proto package and CamelCase it + // replacing '.' with underscore and use that to prefix the types/symbols + // defined. When this options is provided, they will use this value instead + // to prefix the types/symbols defined. + optional string swift_prefix = 39; + + // Sets the php class prefix which is prepended to all php generated classes + // from this .proto. Default is empty. + optional string php_class_prefix = 40; + + // Use this option to change the namespace of php generated classes. Default + // is empty. When this option is empty, the package name will be used for + // determining the namespace. + optional string php_namespace = 41; + + // Use this option to change the namespace of php generated metadata classes. + // Default is empty. When this option is empty, the proto file name will be + // used for determining the namespace. + optional string php_metadata_namespace = 44; + + // Use this option to change the package of ruby generated classes. Default + // is empty. When this option is not set, the package name will be used for + // determining the ruby package. + optional string ruby_package = 45; + + + // The parser stores options it doesn't recognize here. + // See the documentation for the "Options" section above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. + // See the documentation for the "Options" section above. + extensions 1000 to max; + + reserved 38; +} + +message MessageOptions { + // Set true to use the old proto1 MessageSet wire format for extensions. + // This is provided for backwards-compatibility with the MessageSet wire + // format. You should not use this for any other reason: It's less + // efficient, has fewer features, and is more complicated. + // + // The message must be defined exactly as follows: + // message Foo { + // option message_set_wire_format = true; + // extensions 4 to max; + // } + // Note that the message cannot have any defined fields; MessageSets only + // have extensions. + // + // All extensions of your type must be singular messages; e.g. they cannot + // be int32s, enums, or repeated messages. + // + // Because this is an option, the above two restrictions are not enforced by + // the protocol compiler. + optional bool message_set_wire_format = 1 [default = false]; + + // Disables the generation of the standard "descriptor()" accessor, which can + // conflict with a field of the same name. This is meant to make migration + // from proto1 easier; new code should avoid fields named "descriptor". + optional bool no_standard_descriptor_accessor = 2 [default = false]; + + // Is this message deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for the message, or it will be completely ignored; in the very least, + // this is a formalization for deprecating messages. + optional bool deprecated = 3 [default = false]; + + reserved 4, 5, 6; + + // Whether the message is an automatically generated map entry type for the + // maps field. + // + // For maps fields: + // map map_field = 1; + // The parsed descriptor looks like: + // message MapFieldEntry { + // option map_entry = true; + // optional KeyType key = 1; + // optional ValueType value = 2; + // } + // repeated MapFieldEntry map_field = 1; + // + // Implementations may choose not to generate the map_entry=true message, but + // use a native map in the target language to hold the keys and values. + // The reflection APIs in such implementations still need to work as + // if the field is a repeated message field. + // + // NOTE: Do not set the option in .proto files. Always use the maps syntax + // instead. The option should only be implicitly set by the proto compiler + // parser. + optional bool map_entry = 7; + + reserved 8; // javalite_serializable + reserved 9; // javanano_as_lite + + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message FieldOptions { + // The ctype option instructs the C++ code generator to use a different + // representation of the field than it normally would. See the specific + // options below. This option is not yet implemented in the open source + // release -- sorry, we'll try to include it in a future version! + optional CType ctype = 1 [default = STRING]; + enum CType { + // Default mode. + STRING = 0; + + CORD = 1; + + STRING_PIECE = 2; + } + // The packed option can be enabled for repeated primitive fields to enable + // a more efficient representation on the wire. Rather than repeatedly + // writing the tag and type for each element, the entire array is encoded as + // a single length-delimited blob. In proto3, only explicit setting it to + // false will avoid using packed encoding. + optional bool packed = 2; + + // The jstype option determines the JavaScript type used for values of the + // field. The option is permitted only for 64 bit integral and fixed types + // (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING + // is represented as JavaScript string, which avoids loss of precision that + // can happen when a large value is converted to a floating point JavaScript. + // Specifying JS_NUMBER for the jstype causes the generated JavaScript code to + // use the JavaScript "number" type. The behavior of the default option + // JS_NORMAL is implementation dependent. + // + // This option is an enum to permit additional types to be added, e.g. + // goog.math.Integer. + optional JSType jstype = 6 [default = JS_NORMAL]; + enum JSType { + // Use the default type. + JS_NORMAL = 0; + + // Use JavaScript strings. + JS_STRING = 1; + + // Use JavaScript numbers. + JS_NUMBER = 2; + } + + // Should this field be parsed lazily? Lazy applies only to message-type + // fields. It means that when the outer message is initially parsed, the + // inner message's contents will not be parsed but instead stored in encoded + // form. The inner message will actually be parsed when it is first accessed. + // + // This is only a hint. Implementations are free to choose whether to use + // eager or lazy parsing regardless of the value of this option. However, + // setting this option true suggests that the protocol author believes that + // using lazy parsing on this field is worth the additional bookkeeping + // overhead typically needed to implement it. + // + // This option does not affect the public interface of any generated code; + // all method signatures remain the same. Furthermore, thread-safety of the + // interface is not affected by this option; const methods remain safe to + // call from multiple threads concurrently, while non-const methods continue + // to require exclusive access. + // + // + // Note that implementations may choose not to check required fields within + // a lazy sub-message. That is, calling IsInitialized() on the outer message + // may return true even if the inner message has missing required fields. + // This is necessary because otherwise the inner message would have to be + // parsed in order to perform the check, defeating the purpose of lazy + // parsing. An implementation which chooses not to check required fields + // must be consistent about it. That is, for any particular sub-message, the + // implementation must either *always* check its required fields, or *never* + // check its required fields, regardless of whether or not the message has + // been parsed. + // + // As of 2021, lazy does no correctness checks on the byte stream during + // parsing. This may lead to crashes if and when an invalid byte stream is + // finally parsed upon access. + // + // TODO(b/211906113): Enable validation on lazy fields. + optional bool lazy = 5 [default = false]; + + // unverified_lazy does no correctness checks on the byte stream. This should + // only be used where lazy with verification is prohibitive for performance + // reasons. + optional bool unverified_lazy = 15 [default = false]; + + // Is this field deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for accessors, or it will be completely ignored; in the very least, this + // is a formalization for deprecating fields. + optional bool deprecated = 3 [default = false]; + + // For Google-internal migration only. Do not use. + optional bool weak = 10 [default = false]; + + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; + + reserved 4; // removed jtype +} + +message OneofOptions { + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message EnumOptions { + + // Set this option to true to allow mapping different tag names to the same + // value. + optional bool allow_alias = 2; + + // Is this enum deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for the enum, or it will be completely ignored; in the very least, this + // is a formalization for deprecating enums. + optional bool deprecated = 3 [default = false]; + + reserved 5; // javanano_as_lite + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message EnumValueOptions { + // Is this enum value deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for the enum value, or it will be completely ignored; in the very least, + // this is a formalization for deprecating enum values. + optional bool deprecated = 1 [default = false]; + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message ServiceOptions { + + // Note: Field numbers 1 through 32 are reserved for Google's internal RPC + // framework. We apologize for hoarding these numbers to ourselves, but + // we were already using them long before we decided to release Protocol + // Buffers. + + // Is this service deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for the service, or it will be completely ignored; in the very least, + // this is a formalization for deprecating services. + optional bool deprecated = 33 [default = false]; + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + +message MethodOptions { + + // Note: Field numbers 1 through 32 are reserved for Google's internal RPC + // framework. We apologize for hoarding these numbers to ourselves, but + // we were already using them long before we decided to release Protocol + // Buffers. + + // Is this method deprecated? + // Depending on the target platform, this can emit Deprecated annotations + // for the method, or it will be completely ignored; in the very least, + // this is a formalization for deprecating methods. + optional bool deprecated = 33 [default = false]; + + // Is this method side-effect-free (or safe in HTTP parlance), or idempotent, + // or neither? HTTP based RPC implementation may choose GET verb for safe + // methods, and PUT verb for idempotent methods instead of the default POST. + enum IdempotencyLevel { + IDEMPOTENCY_UNKNOWN = 0; + NO_SIDE_EFFECTS = 1; // implies idempotent + IDEMPOTENT = 2; // idempotent, but may have side effects + } + optional IdempotencyLevel idempotency_level = 34 + [default = IDEMPOTENCY_UNKNOWN]; + + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + + +// A message representing a option the parser does not recognize. This only +// appears in options protos created by the compiler::Parser class. +// DescriptorPool resolves these when building Descriptor objects. Therefore, +// options protos in descriptor objects (e.g. returned by Descriptor::options(), +// or produced by Descriptor::CopyTo()) will never have UninterpretedOptions +// in them. +message UninterpretedOption { + // The name of the uninterpreted option. Each string represents a segment in + // a dot-separated name. is_extension is true iff a segment represents an + // extension (denoted with parentheses in options specs in .proto files). + // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents + // "foo.(bar.baz).qux". + message NamePart { + required string name_part = 1; + required bool is_extension = 2; + } + repeated NamePart name = 2; + + // The value of the uninterpreted option, in whatever type the tokenizer + // identified it as during parsing. Exactly one of these should be set. + optional string identifier_value = 3; + optional uint64 positive_int_value = 4; + optional int64 negative_int_value = 5; + optional double double_value = 6; + optional bytes string_value = 7; + optional string aggregate_value = 8; +} + +// =================================================================== +// Optional source code info + +// Encapsulates information about the original source file from which a +// FileDescriptorProto was generated. +message SourceCodeInfo { + // A Location identifies a piece of source code in a .proto file which + // corresponds to a particular definition. This information is intended + // to be useful to IDEs, code indexers, documentation generators, and similar + // tools. + // + // For example, say we have a file like: + // message Foo { + // optional string foo = 1; + // } + // Let's look at just the field definition: + // optional string foo = 1; + // ^ ^^ ^^ ^ ^^^ + // a bc de f ghi + // We have the following locations: + // span path represents + // [a,i) [ 4, 0, 2, 0 ] The whole field definition. + // [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). + // [c,d) [ 4, 0, 2, 0, 5 ] The type (string). + // [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). + // [g,h) [ 4, 0, 2, 0, 3 ] The number (1). + // + // Notes: + // - A location may refer to a repeated field itself (i.e. not to any + // particular index within it). This is used whenever a set of elements are + // logically enclosed in a single code segment. For example, an entire + // extend block (possibly containing multiple extension definitions) will + // have an outer location whose path refers to the "extensions" repeated + // field without an index. + // - Multiple locations may have the same path. This happens when a single + // logical declaration is spread out across multiple places. The most + // obvious example is the "extend" block again -- there may be multiple + // extend blocks in the same scope, each of which will have the same path. + // - A location's span is not always a subset of its parent's span. For + // example, the "extendee" of an extension declaration appears at the + // beginning of the "extend" block and is shared by all extensions within + // the block. + // - Just because a location's span is a subset of some other location's span + // does not mean that it is a descendant. For example, a "group" defines + // both a type and a field in a single declaration. Thus, the locations + // corresponding to the type and field and their components will overlap. + // - Code which tries to interpret locations should probably be designed to + // ignore those that it doesn't understand, as more types of locations could + // be recorded in the future. + repeated Location location = 1; + message Location { + // Identifies which part of the FileDescriptorProto was defined at this + // location. + // + // Each element is a field number or an index. They form a path from + // the root FileDescriptorProto to the place where the definition occurs. + // For example, this path: + // [ 4, 3, 2, 7, 1 ] + // refers to: + // file.message_type(3) // 4, 3 + // .field(7) // 2, 7 + // .name() // 1 + // This is because FileDescriptorProto.message_type has field number 4: + // repeated DescriptorProto message_type = 4; + // and DescriptorProto.field has field number 2: + // repeated FieldDescriptorProto field = 2; + // and FieldDescriptorProto.name has field number 1: + // optional string name = 1; + // + // Thus, the above path gives the location of a field name. If we removed + // the last element: + // [ 4, 3, 2, 7 ] + // this path refers to the whole field declaration (from the beginning + // of the label to the terminating semicolon). + repeated int32 path = 1 [packed = true]; + + // Always has exactly three or four elements: start line, start column, + // end line (optional, otherwise assumed same as start line), end column. + // These are packed into a single field for efficiency. Note that line + // and column numbers are zero-based -- typically you will want to add + // 1 to each before displaying to a user. + repeated int32 span = 2 [packed = true]; + + // If this SourceCodeInfo represents a complete declaration, these are any + // comments appearing before and after the declaration which appear to be + // attached to the declaration. + // + // A series of line comments appearing on consecutive lines, with no other + // tokens appearing on those lines, will be treated as a single comment. + // + // leading_detached_comments will keep paragraphs of comments that appear + // before (but not connected to) the current element. Each paragraph, + // separated by empty lines, will be one comment element in the repeated + // field. + // + // Only the comment content is provided; comment markers (e.g. //) are + // stripped out. For block comments, leading whitespace and an asterisk + // will be stripped from the beginning of each line other than the first. + // Newlines are included in the output. + // + // Examples: + // + // optional int32 foo = 1; // Comment attached to foo. + // // Comment attached to bar. + // optional int32 bar = 2; + // + // optional string baz = 3; + // // Comment attached to baz. + // // Another line attached to baz. + // + // // Comment attached to qux. + // // + // // Another line attached to qux. + // optional double qux = 4; + // + // // Detached comment for corge. This is not leading or trailing comments + // // to qux or corge because there are blank lines separating it from + // // both. + // + // // Detached comment for corge paragraph 2. + // + // optional string corge = 5; + // /* Block comment attached + // * to corge. Leading asterisks + // * will be removed. */ + // /* Block comment attached to + // * grault. */ + // optional int32 grault = 6; + // + // // ignored detached comments. + optional string leading_comments = 3; + optional string trailing_comments = 4; + repeated string leading_detached_comments = 6; + } +} + +// Describes the relationship between generated code and its original source +// file. A GeneratedCodeInfo message is associated with only one generated +// source file, but may contain references to different source .proto files. +message GeneratedCodeInfo { + // An Annotation connects some span of text in generated code to an element + // of its generating .proto file. + repeated Annotation annotation = 1; + message Annotation { + // Identifies the element in the original source .proto file. This field + // is formatted the same as SourceCodeInfo.Location.path. + repeated int32 path = 1 [packed = true]; + + // Identifies the filesystem path to the original source .proto. + optional string source_file = 2; + + // Identifies the starting offset in bytes in the generated code + // that relates to the identified object. + optional int32 begin = 3; + + // Identifies the ending offset in bytes in the generated code that + // relates to the identified offset. The end offset should be one past + // the last relevant byte (so the length of the text = end - begin). + optional int32 end = 4; + } +} diff --git a/third_party/google/protobuf/duration.proto b/third_party/google/protobuf/duration.proto new file mode 100644 index 0000000..81c3e36 --- /dev/null +++ b/third_party/google/protobuf/duration.proto @@ -0,0 +1,116 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option cc_enable_arenas = true; +option go_package = "google.golang.org/protobuf/types/known/durationpb"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "DurationProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; + +// A Duration represents a signed, fixed-length span of time represented +// as a count of seconds and fractions of seconds at nanosecond +// resolution. It is independent of any calendar and concepts like "day" +// or "month". It is related to Timestamp in that the difference between +// two Timestamp values is a Duration and it can be added or subtracted +// from a Timestamp. Range is approximately +-10,000 years. +// +// # Examples +// +// Example 1: Compute Duration from two Timestamps in pseudo code. +// +// Timestamp start = ...; +// Timestamp end = ...; +// Duration duration = ...; +// +// duration.seconds = end.seconds - start.seconds; +// duration.nanos = end.nanos - start.nanos; +// +// if (duration.seconds < 0 && duration.nanos > 0) { +// duration.seconds += 1; +// duration.nanos -= 1000000000; +// } else if (duration.seconds > 0 && duration.nanos < 0) { +// duration.seconds -= 1; +// duration.nanos += 1000000000; +// } +// +// Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. +// +// Timestamp start = ...; +// Duration duration = ...; +// Timestamp end = ...; +// +// end.seconds = start.seconds + duration.seconds; +// end.nanos = start.nanos + duration.nanos; +// +// if (end.nanos < 0) { +// end.seconds -= 1; +// end.nanos += 1000000000; +// } else if (end.nanos >= 1000000000) { +// end.seconds += 1; +// end.nanos -= 1000000000; +// } +// +// Example 3: Compute Duration from datetime.timedelta in Python. +// +// td = datetime.timedelta(days=3, minutes=10) +// duration = Duration() +// duration.FromTimedelta(td) +// +// # JSON Mapping +// +// In JSON format, the Duration type is encoded as a string rather than an +// object, where the string ends in the suffix "s" (indicating seconds) and +// is preceded by the number of seconds, with nanoseconds expressed as +// fractional seconds. For example, 3 seconds with 0 nanoseconds should be +// encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should +// be expressed in JSON format as "3.000000001s", and 3 seconds and 1 +// microsecond should be expressed in JSON format as "3.000001s". +// +// +message Duration { + // Signed seconds of the span of time. Must be from -315,576,000,000 + // to +315,576,000,000 inclusive. Note: these bounds are computed from: + // 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years + int64 seconds = 1; + + // Signed fractions of a second at nanosecond resolution of the span + // of time. Durations less than one second are represented with a 0 + // `seconds` field and a positive or negative `nanos` field. For durations + // of one second or more, a non-zero value for the `nanos` field must be + // of the same sign as the `seconds` field. Must be from -999,999,999 + // to +999,999,999 inclusive. + int32 nanos = 2; +} diff --git a/third_party/google/protobuf/empty.proto b/third_party/google/protobuf/empty.proto new file mode 100644 index 0000000..5f992de --- /dev/null +++ b/third_party/google/protobuf/empty.proto @@ -0,0 +1,52 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option go_package = "google.golang.org/protobuf/types/known/emptypb"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "EmptyProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; +option cc_enable_arenas = true; + +// A generic empty message that you can re-use to avoid defining duplicated +// empty messages in your APIs. A typical example is to use it as the request +// or the response type of an API method. For instance: +// +// service Foo { +// rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); +// } +// +// The JSON representation for `Empty` is empty JSON object `{}`. +message Empty {} diff --git a/third_party/google/protobuf/field_mask.proto b/third_party/google/protobuf/field_mask.proto new file mode 100644 index 0000000..6b5104f --- /dev/null +++ b/third_party/google/protobuf/field_mask.proto @@ -0,0 +1,245 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "FieldMaskProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; +option go_package = "google.golang.org/protobuf/types/known/fieldmaskpb"; +option cc_enable_arenas = true; + +// `FieldMask` represents a set of symbolic field paths, for example: +// +// paths: "f.a" +// paths: "f.b.d" +// +// Here `f` represents a field in some root message, `a` and `b` +// fields in the message found in `f`, and `d` a field found in the +// message in `f.b`. +// +// Field masks are used to specify a subset of fields that should be +// returned by a get operation or modified by an update operation. +// Field masks also have a custom JSON encoding (see below). +// +// # Field Masks in Projections +// +// When used in the context of a projection, a response message or +// sub-message is filtered by the API to only contain those fields as +// specified in the mask. For example, if the mask in the previous +// example is applied to a response message as follows: +// +// f { +// a : 22 +// b { +// d : 1 +// x : 2 +// } +// y : 13 +// } +// z: 8 +// +// The result will not contain specific values for fields x,y and z +// (their value will be set to the default, and omitted in proto text +// output): +// +// +// f { +// a : 22 +// b { +// d : 1 +// } +// } +// +// A repeated field is not allowed except at the last position of a +// paths string. +// +// If a FieldMask object is not present in a get operation, the +// operation applies to all fields (as if a FieldMask of all fields +// had been specified). +// +// Note that a field mask does not necessarily apply to the +// top-level response message. In case of a REST get operation, the +// field mask applies directly to the response, but in case of a REST +// list operation, the mask instead applies to each individual message +// in the returned resource list. In case of a REST custom method, +// other definitions may be used. Where the mask applies will be +// clearly documented together with its declaration in the API. In +// any case, the effect on the returned resource/resources is required +// behavior for APIs. +// +// # Field Masks in Update Operations +// +// A field mask in update operations specifies which fields of the +// targeted resource are going to be updated. The API is required +// to only change the values of the fields as specified in the mask +// and leave the others untouched. If a resource is passed in to +// describe the updated values, the API ignores the values of all +// fields not covered by the mask. +// +// If a repeated field is specified for an update operation, new values will +// be appended to the existing repeated field in the target resource. Note that +// a repeated field is only allowed in the last position of a `paths` string. +// +// If a sub-message is specified in the last position of the field mask for an +// update operation, then new value will be merged into the existing sub-message +// in the target resource. +// +// For example, given the target message: +// +// f { +// b { +// d: 1 +// x: 2 +// } +// c: [1] +// } +// +// And an update message: +// +// f { +// b { +// d: 10 +// } +// c: [2] +// } +// +// then if the field mask is: +// +// paths: ["f.b", "f.c"] +// +// then the result will be: +// +// f { +// b { +// d: 10 +// x: 2 +// } +// c: [1, 2] +// } +// +// An implementation may provide options to override this default behavior for +// repeated and message fields. +// +// In order to reset a field's value to the default, the field must +// be in the mask and set to the default value in the provided resource. +// Hence, in order to reset all fields of a resource, provide a default +// instance of the resource and set all fields in the mask, or do +// not provide a mask as described below. +// +// If a field mask is not present on update, the operation applies to +// all fields (as if a field mask of all fields has been specified). +// Note that in the presence of schema evolution, this may mean that +// fields the client does not know and has therefore not filled into +// the request will be reset to their default. If this is unwanted +// behavior, a specific service may require a client to always specify +// a field mask, producing an error if not. +// +// As with get operations, the location of the resource which +// describes the updated values in the request message depends on the +// operation kind. In any case, the effect of the field mask is +// required to be honored by the API. +// +// ## Considerations for HTTP REST +// +// The HTTP kind of an update operation which uses a field mask must +// be set to PATCH instead of PUT in order to satisfy HTTP semantics +// (PUT must only be used for full updates). +// +// # JSON Encoding of Field Masks +// +// In JSON, a field mask is encoded as a single string where paths are +// separated by a comma. Fields name in each path are converted +// to/from lower-camel naming conventions. +// +// As an example, consider the following message declarations: +// +// message Profile { +// User user = 1; +// Photo photo = 2; +// } +// message User { +// string display_name = 1; +// string address = 2; +// } +// +// In proto a field mask for `Profile` may look as such: +// +// mask { +// paths: "user.display_name" +// paths: "photo" +// } +// +// In JSON, the same mask is represented as below: +// +// { +// mask: "user.displayName,photo" +// } +// +// # Field Masks and Oneof Fields +// +// Field masks treat fields in oneofs just as regular fields. Consider the +// following message: +// +// message SampleMessage { +// oneof test_oneof { +// string name = 4; +// SubMessage sub_message = 9; +// } +// } +// +// The field mask can be: +// +// mask { +// paths: "name" +// } +// +// Or: +// +// mask { +// paths: "sub_message" +// } +// +// Note that oneof type names ("test_oneof" in this case) cannot be used in +// paths. +// +// ## Field Mask Verification +// +// The implementation of any API method which has a FieldMask type field in the +// request should verify the included field paths, and return an +// `INVALID_ARGUMENT` error if any path is unmappable. +message FieldMask { + // The set of field mask paths. + repeated string paths = 1; +} diff --git a/third_party/google/protobuf/source_context.proto b/third_party/google/protobuf/source_context.proto new file mode 100644 index 0000000..06bfc43 --- /dev/null +++ b/third_party/google/protobuf/source_context.proto @@ -0,0 +1,48 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "SourceContextProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; +option go_package = "google.golang.org/protobuf/types/known/sourcecontextpb"; + +// `SourceContext` represents information about the source of a +// protobuf element, like the file in which it is defined. +message SourceContext { + // The path-qualified name of the .proto file that contained the associated + // protobuf element. For example: `"google/protobuf/source_context.proto"`. + string file_name = 1; +} diff --git a/third_party/google/protobuf/struct.proto b/third_party/google/protobuf/struct.proto new file mode 100644 index 0000000..0ac843c --- /dev/null +++ b/third_party/google/protobuf/struct.proto @@ -0,0 +1,95 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option cc_enable_arenas = true; +option go_package = "google.golang.org/protobuf/types/known/structpb"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "StructProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; + +// `Struct` represents a structured data value, consisting of fields +// which map to dynamically typed values. In some languages, `Struct` +// might be supported by a native representation. For example, in +// scripting languages like JS a struct is represented as an +// object. The details of that representation are described together +// with the proto support for the language. +// +// The JSON representation for `Struct` is JSON object. +message Struct { + // Unordered map of dynamically typed values. + map fields = 1; +} + +// `Value` represents a dynamically typed value which can be either +// null, a number, a string, a boolean, a recursive struct value, or a +// list of values. A producer of value is expected to set one of these +// variants. Absence of any variant indicates an error. +// +// The JSON representation for `Value` is JSON value. +message Value { + // The kind of value. + oneof kind { + // Represents a null value. + NullValue null_value = 1; + // Represents a double value. + double number_value = 2; + // Represents a string value. + string string_value = 3; + // Represents a boolean value. + bool bool_value = 4; + // Represents a structured value. + Struct struct_value = 5; + // Represents a repeated `Value`. + ListValue list_value = 6; + } +} + +// `NullValue` is a singleton enumeration to represent the null value for the +// `Value` type union. +// +// The JSON representation for `NullValue` is JSON `null`. +enum NullValue { + // Null value. + NULL_VALUE = 0; +} + +// `ListValue` is a wrapper around a repeated field of values. +// +// The JSON representation for `ListValue` is JSON array. +message ListValue { + // Repeated field of dynamically typed values. + repeated Value values = 1; +} diff --git a/third_party/google/protobuf/timestamp.proto b/third_party/google/protobuf/timestamp.proto new file mode 100644 index 0000000..3b2df6d --- /dev/null +++ b/third_party/google/protobuf/timestamp.proto @@ -0,0 +1,147 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option cc_enable_arenas = true; +option go_package = "google.golang.org/protobuf/types/known/timestamppb"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "TimestampProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; + +// A Timestamp represents a point in time independent of any time zone or local +// calendar, encoded as a count of seconds and fractions of seconds at +// nanosecond resolution. The count is relative to an epoch at UTC midnight on +// January 1, 1970, in the proleptic Gregorian calendar which extends the +// Gregorian calendar backwards to year one. +// +// All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap +// second table is needed for interpretation, using a [24-hour linear +// smear](https://developers.google.com/time/smear). +// +// The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By +// restricting to that range, we ensure that we can convert to and from [RFC +// 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings. +// +// # Examples +// +// Example 1: Compute Timestamp from POSIX `time()`. +// +// Timestamp timestamp; +// timestamp.set_seconds(time(NULL)); +// timestamp.set_nanos(0); +// +// Example 2: Compute Timestamp from POSIX `gettimeofday()`. +// +// struct timeval tv; +// gettimeofday(&tv, NULL); +// +// Timestamp timestamp; +// timestamp.set_seconds(tv.tv_sec); +// timestamp.set_nanos(tv.tv_usec * 1000); +// +// Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. +// +// FILETIME ft; +// GetSystemTimeAsFileTime(&ft); +// UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; +// +// // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z +// // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. +// Timestamp timestamp; +// timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); +// timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); +// +// Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. +// +// long millis = System.currentTimeMillis(); +// +// Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) +// .setNanos((int) ((millis % 1000) * 1000000)).build(); +// +// +// Example 5: Compute Timestamp from Java `Instant.now()`. +// +// Instant now = Instant.now(); +// +// Timestamp timestamp = +// Timestamp.newBuilder().setSeconds(now.getEpochSecond()) +// .setNanos(now.getNano()).build(); +// +// +// Example 6: Compute Timestamp from current time in Python. +// +// timestamp = Timestamp() +// timestamp.GetCurrentTime() +// +// # JSON Mapping +// +// In JSON format, the Timestamp type is encoded as a string in the +// [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the +// format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" +// where {year} is always expressed using four digits while {month}, {day}, +// {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional +// seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), +// are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone +// is required. A proto3 JSON serializer should always use UTC (as indicated by +// "Z") when printing the Timestamp type and a proto3 JSON parser should be +// able to accept both UTC and other timezones (as indicated by an offset). +// +// For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past +// 01:30 UTC on January 15, 2017. +// +// In JavaScript, one can convert a Date object to this format using the +// standard +// [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) +// method. In Python, a standard `datetime.datetime` object can be converted +// to this format using +// [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with +// the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use +// the Joda Time's [`ISODateTimeFormat.dateTime()`]( +// http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D +// ) to obtain a formatter capable of generating timestamps in this format. +// +// +message Timestamp { + // Represents seconds of UTC time since Unix epoch + // 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + // 9999-12-31T23:59:59Z inclusive. + int64 seconds = 1; + + // Non-negative fractions of a second at nanosecond resolution. Negative + // second values with fractions must still have non-negative nanos values + // that count forward in time. Must be from 0 to 999,999,999 + // inclusive. + int32 nanos = 2; +} diff --git a/third_party/google/protobuf/type.proto b/third_party/google/protobuf/type.proto new file mode 100644 index 0000000..d3f6a68 --- /dev/null +++ b/third_party/google/protobuf/type.proto @@ -0,0 +1,187 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +import "google/protobuf/any.proto"; +import "google/protobuf/source_context.proto"; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option cc_enable_arenas = true; +option java_package = "com.google.protobuf"; +option java_outer_classname = "TypeProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; +option go_package = "google.golang.org/protobuf/types/known/typepb"; + +// A protocol buffer message type. +message Type { + // The fully qualified message name. + string name = 1; + // The list of fields. + repeated Field fields = 2; + // The list of types appearing in `oneof` definitions in this type. + repeated string oneofs = 3; + // The protocol buffer options. + repeated Option options = 4; + // The source context. + SourceContext source_context = 5; + // The source syntax. + Syntax syntax = 6; +} + +// A single field of a message type. +message Field { + // Basic field types. + enum Kind { + // Field type unknown. + TYPE_UNKNOWN = 0; + // Field type double. + TYPE_DOUBLE = 1; + // Field type float. + TYPE_FLOAT = 2; + // Field type int64. + TYPE_INT64 = 3; + // Field type uint64. + TYPE_UINT64 = 4; + // Field type int32. + TYPE_INT32 = 5; + // Field type fixed64. + TYPE_FIXED64 = 6; + // Field type fixed32. + TYPE_FIXED32 = 7; + // Field type bool. + TYPE_BOOL = 8; + // Field type string. + TYPE_STRING = 9; + // Field type group. Proto2 syntax only, and deprecated. + TYPE_GROUP = 10; + // Field type message. + TYPE_MESSAGE = 11; + // Field type bytes. + TYPE_BYTES = 12; + // Field type uint32. + TYPE_UINT32 = 13; + // Field type enum. + TYPE_ENUM = 14; + // Field type sfixed32. + TYPE_SFIXED32 = 15; + // Field type sfixed64. + TYPE_SFIXED64 = 16; + // Field type sint32. + TYPE_SINT32 = 17; + // Field type sint64. + TYPE_SINT64 = 18; + } + + // Whether a field is optional, required, or repeated. + enum Cardinality { + // For fields with unknown cardinality. + CARDINALITY_UNKNOWN = 0; + // For optional fields. + CARDINALITY_OPTIONAL = 1; + // For required fields. Proto2 syntax only. + CARDINALITY_REQUIRED = 2; + // For repeated fields. + CARDINALITY_REPEATED = 3; + } + + // The field type. + Kind kind = 1; + // The field cardinality. + Cardinality cardinality = 2; + // The field number. + int32 number = 3; + // The field name. + string name = 4; + // The field type URL, without the scheme, for message or enumeration + // types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`. + string type_url = 6; + // The index of the field type in `Type.oneofs`, for message or enumeration + // types. The first type has index 1; zero means the type is not in the list. + int32 oneof_index = 7; + // Whether to use alternative packed wire representation. + bool packed = 8; + // The protocol buffer options. + repeated Option options = 9; + // The field JSON name. + string json_name = 10; + // The string value of the default value of this field. Proto2 syntax only. + string default_value = 11; +} + +// Enum type definition. +message Enum { + // Enum type name. + string name = 1; + // Enum value definitions. + repeated EnumValue enumvalue = 2; + // Protocol buffer options. + repeated Option options = 3; + // The source context. + SourceContext source_context = 4; + // The source syntax. + Syntax syntax = 5; +} + +// Enum value definition. +message EnumValue { + // Enum value name. + string name = 1; + // Enum value number. + int32 number = 2; + // Protocol buffer options. + repeated Option options = 3; +} + +// A protocol buffer option, which can be attached to a message, field, +// enumeration, etc. +message Option { + // The option's name. For protobuf built-in options (options defined in + // descriptor.proto), this is the short name. For example, `"map_entry"`. + // For custom options, it should be the fully-qualified name. For example, + // `"google.api.http"`. + string name = 1; + // The option's value packed in an Any message. If the value is a primitive, + // the corresponding wrapper type defined in google/protobuf/wrappers.proto + // should be used. If the value is an enum, it should be stored as an int32 + // value using the google.protobuf.Int32Value type. + Any value = 2; +} + +// The syntax in which a protocol buffer element is defined. +enum Syntax { + // Syntax `proto2`. + SYNTAX_PROTO2 = 0; + // Syntax `proto3`. + SYNTAX_PROTO3 = 1; +} diff --git a/third_party/google/protobuf/wrappers.proto b/third_party/google/protobuf/wrappers.proto new file mode 100644 index 0000000..d49dd53 --- /dev/null +++ b/third_party/google/protobuf/wrappers.proto @@ -0,0 +1,123 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Wrappers for primitive (non-message) types. These types are useful +// for embedding primitives in the `google.protobuf.Any` type and for places +// where we need to distinguish between the absence of a primitive +// typed field and its default value. +// +// These wrappers have no meaningful use within repeated fields as they lack +// the ability to detect presence on individual elements. +// These wrappers have no meaningful use within a map or a oneof since +// individual entries of a map or fields of a oneof can already detect presence. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option cc_enable_arenas = true; +option go_package = "google.golang.org/protobuf/types/known/wrapperspb"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "WrappersProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; + +// Wrapper message for `double`. +// +// The JSON representation for `DoubleValue` is JSON number. +message DoubleValue { + // The double value. + double value = 1; +} + +// Wrapper message for `float`. +// +// The JSON representation for `FloatValue` is JSON number. +message FloatValue { + // The float value. + float value = 1; +} + +// Wrapper message for `int64`. +// +// The JSON representation for `Int64Value` is JSON string. +message Int64Value { + // The int64 value. + int64 value = 1; +} + +// Wrapper message for `uint64`. +// +// The JSON representation for `UInt64Value` is JSON string. +message UInt64Value { + // The uint64 value. + uint64 value = 1; +} + +// Wrapper message for `int32`. +// +// The JSON representation for `Int32Value` is JSON number. +message Int32Value { + // The int32 value. + int32 value = 1; +} + +// Wrapper message for `uint32`. +// +// The JSON representation for `UInt32Value` is JSON number. +message UInt32Value { + // The uint32 value. + uint32 value = 1; +} + +// Wrapper message for `bool`. +// +// The JSON representation for `BoolValue` is JSON `true` and `false`. +message BoolValue { + // The bool value. + bool value = 1; +} + +// Wrapper message for `string`. +// +// The JSON representation for `StringValue` is JSON string. +message StringValue { + // The string value. + string value = 1; +} + +// Wrapper message for `bytes`. +// +// The JSON representation for `BytesValue` is JSON string. +message BytesValue { + // The bytes value. + bytes value = 1; +} diff --git a/third_party/openapi/v3/annotations.proto b/third_party/openapi/v3/annotations.proto new file mode 100644 index 0000000..54fe3aa --- /dev/null +++ b/third_party/openapi/v3/annotations.proto @@ -0,0 +1,60 @@ +// Copyright 2022 Google LLC. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package openapi.v3; + +import "openapi/v3/openapi.proto"; +import "google/protobuf/descriptor.proto"; + +// This option lets the proto compiler generate Java code inside the package +// name (see below) instead of inside an outer class. It creates a simpler +// developer experience by reducing one-level of name nesting and be +// consistent with most programming languages that don't support outer classes. +option java_multiple_files = true; + +// The Java outer classname should be the filename in UpperCamelCase. This +// class is only used to hold proto descriptor, so developers don't need to +// work with it directly. +option java_outer_classname = "AnnotationsProto"; + +// The Java package name must be proto package name with proper prefix. +option java_package = "org.openapi_v3"; + +// A reasonable prefix for the Objective-C symbols generated from the package. +// It should at a minimum be 3 characters long, all uppercase, and convention +// is to use an abbreviation of the package name. Something short, but +// hopefully unique enough to not conflict with things that may come along in +// the future. 'GPB' is reserved for the protocol buffer implementation itself. +option objc_class_prefix = "OAS"; + +// The Go package name. +option go_package = "github.com/google/gnostic/openapiv3;openapi_v3"; + +extend google.protobuf.FileOptions { + Document document = 1143; +} + +extend google.protobuf.MethodOptions { + Operation operation = 1143; +} + +extend google.protobuf.MessageOptions { + Schema schema = 1143; +} + +extend google.protobuf.FieldOptions { + Schema property = 1143; +} \ No newline at end of file diff --git a/third_party/openapi/v3/openapi.proto b/third_party/openapi/v3/openapi.proto new file mode 100644 index 0000000..7aede5e --- /dev/null +++ b/third_party/openapi/v3/openapi.proto @@ -0,0 +1,672 @@ +// Copyright 2020 Google LLC. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// THIS FILE IS AUTOMATICALLY GENERATED. + +syntax = "proto3"; + +package openapi.v3; + +import "google/protobuf/any.proto"; + +// This option lets the proto compiler generate Java code inside the package +// name (see below) instead of inside an outer class. It creates a simpler +// developer experience by reducing one-level of name nesting and be +// consistent with most programming languages that don't support outer classes. +option java_multiple_files = true; + +// The Java outer classname should be the filename in UpperCamelCase. This +// class is only used to hold proto descriptor, so developers don't need to +// work with it directly. +option java_outer_classname = "OpenAPIProto"; + +// The Java package name must be proto package name with proper prefix. +option java_package = "org.openapi_v3"; + +// A reasonable prefix for the Objective-C symbols generated from the package. +// It should at a minimum be 3 characters long, all uppercase, and convention +// is to use an abbreviation of the package name. Something short, but +// hopefully unique enough to not conflict with things that may come along in +// the future. 'GPB' is reserved for the protocol buffer implementation itself. +option objc_class_prefix = "OAS"; + +// The Go package name. +option go_package = "github.com/google/gnostic/openapiv3;openapi_v3"; + +message AdditionalPropertiesItem { + oneof oneof { + SchemaOrReference schema_or_reference = 1; + bool boolean = 2; + } +} + +message Any { + google.protobuf.Any value = 1; + string yaml = 2; +} + +message AnyOrExpression { + oneof oneof { + Any any = 1; + Expression expression = 2; + } +} + +// A map of possible out-of band callbacks related to the parent operation. Each value in the map is a Path Item Object that describes a set of requests that may be initiated by the API provider and the expected responses. The key value used to identify the callback object is an expression, evaluated at runtime, that identifies a URL to use for the callback operation. +message Callback { + repeated NamedPathItem path = 1; + repeated NamedAny specification_extension = 2; +} + +message CallbackOrReference { + oneof oneof { + Callback callback = 1; + Reference reference = 2; + } +} + +message CallbacksOrReferences { + repeated NamedCallbackOrReference additional_properties = 1; +} + +// Holds a set of reusable objects for different aspects of the OAS. All objects defined within the components object will have no effect on the API unless they are explicitly referenced from properties outside the components object. +message Components { + SchemasOrReferences schemas = 1; + ResponsesOrReferences responses = 2; + ParametersOrReferences parameters = 3; + ExamplesOrReferences examples = 4; + RequestBodiesOrReferences request_bodies = 5; + HeadersOrReferences headers = 6; + SecuritySchemesOrReferences security_schemes = 7; + LinksOrReferences links = 8; + CallbacksOrReferences callbacks = 9; + repeated NamedAny specification_extension = 10; +} + +// Contact information for the exposed API. +message Contact { + string name = 1; + string url = 2; + string email = 3; + repeated NamedAny specification_extension = 4; +} + +message DefaultType { + oneof oneof { + double number = 1; + bool boolean = 2; + string string = 3; + } +} + +// When request bodies or response payloads may be one of a number of different schemas, a `discriminator` object can be used to aid in serialization, deserialization, and validation. The discriminator is a specific object in a schema which is used to inform the consumer of the specification of an alternative schema based on the value associated with it. When using the discriminator, _inline_ schemas will not be considered. +message Discriminator { + string property_name = 1; + Strings mapping = 2; + repeated NamedAny specification_extension = 3; +} + +message Document { + string openapi = 1; + Info info = 2; + repeated Server servers = 3; + Paths paths = 4; + Components components = 5; + repeated SecurityRequirement security = 6; + repeated Tag tags = 7; + ExternalDocs external_docs = 8; + repeated NamedAny specification_extension = 9; +} + +// A single encoding definition applied to a single schema property. +message Encoding { + string content_type = 1; + HeadersOrReferences headers = 2; + string style = 3; + bool explode = 4; + bool allow_reserved = 5; + repeated NamedAny specification_extension = 6; +} + +message Encodings { + repeated NamedEncoding additional_properties = 1; +} + +message Example { + string summary = 1; + string description = 2; + Any value = 3; + string external_value = 4; + repeated NamedAny specification_extension = 5; +} + +message ExampleOrReference { + oneof oneof { + Example example = 1; + Reference reference = 2; + } +} + +message ExamplesOrReferences { + repeated NamedExampleOrReference additional_properties = 1; +} + +message Expression { + repeated NamedAny additional_properties = 1; +} + +// Allows referencing an external resource for extended documentation. +message ExternalDocs { + string description = 1; + string url = 2; + repeated NamedAny specification_extension = 3; +} + +// The Header Object follows the structure of the Parameter Object with the following changes: 1. `name` MUST NOT be specified, it is given in the corresponding `headers` map. 1. `in` MUST NOT be specified, it is implicitly in `header`. 1. All traits that are affected by the location MUST be applicable to a location of `header` (for example, `style`). +message Header { + string description = 1; + bool required = 2; + bool deprecated = 3; + bool allow_empty_value = 4; + string style = 5; + bool explode = 6; + bool allow_reserved = 7; + SchemaOrReference schema = 8; + Any example = 9; + ExamplesOrReferences examples = 10; + MediaTypes content = 11; + repeated NamedAny specification_extension = 12; +} + +message HeaderOrReference { + oneof oneof { + Header header = 1; + Reference reference = 2; + } +} + +message HeadersOrReferences { + repeated NamedHeaderOrReference additional_properties = 1; +} + +// The object provides metadata about the API. The metadata MAY be used by the clients if needed, and MAY be presented in editing or documentation generation tools for convenience. +message Info { + string title = 1; + string description = 2; + string terms_of_service = 3; + Contact contact = 4; + License license = 5; + string version = 6; + repeated NamedAny specification_extension = 7; + string summary = 8; +} + +message ItemsItem { + repeated SchemaOrReference schema_or_reference = 1; +} + +// License information for the exposed API. +message License { + string name = 1; + string url = 2; + repeated NamedAny specification_extension = 3; +} + +// The `Link object` represents a possible design-time link for a response. The presence of a link does not guarantee the caller's ability to successfully invoke it, rather it provides a known relationship and traversal mechanism between responses and other operations. Unlike _dynamic_ links (i.e. links provided **in** the response payload), the OAS linking mechanism does not require link information in the runtime response. For computing links, and providing instructions to execute them, a runtime expression is used for accessing values in an operation and using them as parameters while invoking the linked operation. +message Link { + string operation_ref = 1; + string operation_id = 2; + AnyOrExpression parameters = 3; + AnyOrExpression request_body = 4; + string description = 5; + Server server = 6; + repeated NamedAny specification_extension = 7; +} + +message LinkOrReference { + oneof oneof { + Link link = 1; + Reference reference = 2; + } +} + +message LinksOrReferences { + repeated NamedLinkOrReference additional_properties = 1; +} + +// Each Media Type Object provides schema and examples for the media type identified by its key. +message MediaType { + SchemaOrReference schema = 1; + Any example = 2; + ExamplesOrReferences examples = 3; + Encodings encoding = 4; + repeated NamedAny specification_extension = 5; +} + +message MediaTypes { + repeated NamedMediaType additional_properties = 1; +} + +// Automatically-generated message used to represent maps of Any as ordered (name,value) pairs. +message NamedAny { + // Map key + string name = 1; + // Mapped value + Any value = 2; +} + +// Automatically-generated message used to represent maps of CallbackOrReference as ordered (name,value) pairs. +message NamedCallbackOrReference { + // Map key + string name = 1; + // Mapped value + CallbackOrReference value = 2; +} + +// Automatically-generated message used to represent maps of Encoding as ordered (name,value) pairs. +message NamedEncoding { + // Map key + string name = 1; + // Mapped value + Encoding value = 2; +} + +// Automatically-generated message used to represent maps of ExampleOrReference as ordered (name,value) pairs. +message NamedExampleOrReference { + // Map key + string name = 1; + // Mapped value + ExampleOrReference value = 2; +} + +// Automatically-generated message used to represent maps of HeaderOrReference as ordered (name,value) pairs. +message NamedHeaderOrReference { + // Map key + string name = 1; + // Mapped value + HeaderOrReference value = 2; +} + +// Automatically-generated message used to represent maps of LinkOrReference as ordered (name,value) pairs. +message NamedLinkOrReference { + // Map key + string name = 1; + // Mapped value + LinkOrReference value = 2; +} + +// Automatically-generated message used to represent maps of MediaType as ordered (name,value) pairs. +message NamedMediaType { + // Map key + string name = 1; + // Mapped value + MediaType value = 2; +} + +// Automatically-generated message used to represent maps of ParameterOrReference as ordered (name,value) pairs. +message NamedParameterOrReference { + // Map key + string name = 1; + // Mapped value + ParameterOrReference value = 2; +} + +// Automatically-generated message used to represent maps of PathItem as ordered (name,value) pairs. +message NamedPathItem { + // Map key + string name = 1; + // Mapped value + PathItem value = 2; +} + +// Automatically-generated message used to represent maps of RequestBodyOrReference as ordered (name,value) pairs. +message NamedRequestBodyOrReference { + // Map key + string name = 1; + // Mapped value + RequestBodyOrReference value = 2; +} + +// Automatically-generated message used to represent maps of ResponseOrReference as ordered (name,value) pairs. +message NamedResponseOrReference { + // Map key + string name = 1; + // Mapped value + ResponseOrReference value = 2; +} + +// Automatically-generated message used to represent maps of SchemaOrReference as ordered (name,value) pairs. +message NamedSchemaOrReference { + // Map key + string name = 1; + // Mapped value + SchemaOrReference value = 2; +} + +// Automatically-generated message used to represent maps of SecuritySchemeOrReference as ordered (name,value) pairs. +message NamedSecuritySchemeOrReference { + // Map key + string name = 1; + // Mapped value + SecuritySchemeOrReference value = 2; +} + +// Automatically-generated message used to represent maps of ServerVariable as ordered (name,value) pairs. +message NamedServerVariable { + // Map key + string name = 1; + // Mapped value + ServerVariable value = 2; +} + +// Automatically-generated message used to represent maps of string as ordered (name,value) pairs. +message NamedString { + // Map key + string name = 1; + // Mapped value + string value = 2; +} + +// Automatically-generated message used to represent maps of StringArray as ordered (name,value) pairs. +message NamedStringArray { + // Map key + string name = 1; + // Mapped value + StringArray value = 2; +} + +// Configuration details for a supported OAuth Flow +message OauthFlow { + string authorization_url = 1; + string token_url = 2; + string refresh_url = 3; + Strings scopes = 4; + repeated NamedAny specification_extension = 5; +} + +// Allows configuration of the supported OAuth Flows. +message OauthFlows { + OauthFlow implicit = 1; + OauthFlow password = 2; + OauthFlow client_credentials = 3; + OauthFlow authorization_code = 4; + repeated NamedAny specification_extension = 5; +} + +message Object { + repeated NamedAny additional_properties = 1; +} + +// Describes a single API operation on a path. +message Operation { + repeated string tags = 1; + string summary = 2; + string description = 3; + ExternalDocs external_docs = 4; + string operation_id = 5; + repeated ParameterOrReference parameters = 6; + RequestBodyOrReference request_body = 7; + Responses responses = 8; + CallbacksOrReferences callbacks = 9; + bool deprecated = 10; + repeated SecurityRequirement security = 11; + repeated Server servers = 12; + repeated NamedAny specification_extension = 13; +} + +// Describes a single operation parameter. A unique parameter is defined by a combination of a name and location. +message Parameter { + string name = 1; + string in = 2; + string description = 3; + bool required = 4; + bool deprecated = 5; + bool allow_empty_value = 6; + string style = 7; + bool explode = 8; + bool allow_reserved = 9; + SchemaOrReference schema = 10; + Any example = 11; + ExamplesOrReferences examples = 12; + MediaTypes content = 13; + repeated NamedAny specification_extension = 14; +} + +message ParameterOrReference { + oneof oneof { + Parameter parameter = 1; + Reference reference = 2; + } +} + +message ParametersOrReferences { + repeated NamedParameterOrReference additional_properties = 1; +} + +// Describes the operations available on a single path. A Path Item MAY be empty, due to ACL constraints. The path itself is still exposed to the documentation viewer but they will not know which operations and parameters are available. +message PathItem { + string _ref = 1; + string summary = 2; + string description = 3; + Operation get = 4; + Operation put = 5; + Operation post = 6; + Operation delete = 7; + Operation options = 8; + Operation head = 9; + Operation patch = 10; + Operation trace = 11; + repeated Server servers = 12; + repeated ParameterOrReference parameters = 13; + repeated NamedAny specification_extension = 14; +} + +// Holds the relative paths to the individual endpoints and their operations. The path is appended to the URL from the `Server Object` in order to construct the full URL. The Paths MAY be empty, due to ACL constraints. +message Paths { + repeated NamedPathItem path = 1; + repeated NamedAny specification_extension = 2; +} + +message Properties { + repeated NamedSchemaOrReference additional_properties = 1; +} + +// A simple object to allow referencing other components in the specification, internally and externally. The Reference Object is defined by JSON Reference and follows the same structure, behavior and rules. For this specification, reference resolution is accomplished as defined by the JSON Reference specification and not by the JSON Schema specification. +message Reference { + string _ref = 1; + string summary = 2; + string description = 3; +} + +message RequestBodiesOrReferences { + repeated NamedRequestBodyOrReference additional_properties = 1; +} + +// Describes a single request body. +message RequestBody { + string description = 1; + MediaTypes content = 2; + bool required = 3; + repeated NamedAny specification_extension = 4; +} + +message RequestBodyOrReference { + oneof oneof { + RequestBody request_body = 1; + Reference reference = 2; + } +} + +// Describes a single response from an API Operation, including design-time, static `links` to operations based on the response. +message Response { + string description = 1; + HeadersOrReferences headers = 2; + MediaTypes content = 3; + LinksOrReferences links = 4; + repeated NamedAny specification_extension = 5; +} + +message ResponseOrReference { + oneof oneof { + Response response = 1; + Reference reference = 2; + } +} + +// A container for the expected responses of an operation. The container maps a HTTP response code to the expected response. The documentation is not necessarily expected to cover all possible HTTP response codes because they may not be known in advance. However, documentation is expected to cover a successful operation response and any known errors. The `default` MAY be used as a default response object for all HTTP codes that are not covered individually by the specification. The `Responses Object` MUST contain at least one response code, and it SHOULD be the response for a successful operation call. +message Responses { + ResponseOrReference default = 1; + repeated NamedResponseOrReference response_or_reference = 2; + repeated NamedAny specification_extension = 3; +} + +message ResponsesOrReferences { + repeated NamedResponseOrReference additional_properties = 1; +} + +// The Schema Object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. This object is an extended subset of the JSON Schema Specification Wright Draft 00. For more information about the properties, see JSON Schema Core and JSON Schema Validation. Unless stated otherwise, the property definitions follow the JSON Schema. +message Schema { + bool nullable = 1; + Discriminator discriminator = 2; + bool read_only = 3; + bool write_only = 4; + Xml xml = 5; + ExternalDocs external_docs = 6; + Any example = 7; + bool deprecated = 8; + string title = 9; + double multiple_of = 10; + double maximum = 11; + bool exclusive_maximum = 12; + double minimum = 13; + bool exclusive_minimum = 14; + int64 max_length = 15; + int64 min_length = 16; + string pattern = 17; + int64 max_items = 18; + int64 min_items = 19; + bool unique_items = 20; + int64 max_properties = 21; + int64 min_properties = 22; + repeated string required = 23; + repeated Any enum = 24; + string type = 25; + repeated SchemaOrReference all_of = 26; + repeated SchemaOrReference one_of = 27; + repeated SchemaOrReference any_of = 28; + Schema not = 29; + ItemsItem items = 30; + Properties properties = 31; + AdditionalPropertiesItem additional_properties = 32; + DefaultType default = 33; + string description = 34; + string format = 35; + repeated NamedAny specification_extension = 36; +} + +message SchemaOrReference { + oneof oneof { + Schema schema = 1; + Reference reference = 2; + } +} + +message SchemasOrReferences { + repeated NamedSchemaOrReference additional_properties = 1; +} + +// Lists the required security schemes to execute this operation. The name used for each property MUST correspond to a security scheme declared in the Security Schemes under the Components Object. Security Requirement Objects that contain multiple schemes require that all schemes MUST be satisfied for a request to be authorized. This enables support for scenarios where multiple query parameters or HTTP headers are required to convey security information. When a list of Security Requirement Objects is defined on the OpenAPI Object or Operation Object, only one of the Security Requirement Objects in the list needs to be satisfied to authorize the request. +message SecurityRequirement { + repeated NamedStringArray additional_properties = 1; +} + +// Defines a security scheme that can be used by the operations. Supported schemes are HTTP authentication, an API key (either as a header, a cookie parameter or as a query parameter), mutual TLS (use of a client certificate), OAuth2's common flows (implicit, password, application and access code) as defined in RFC6749, and OpenID Connect. Please note that currently (2019) the implicit flow is about to be deprecated OAuth 2.0 Security Best Current Practice. Recommended for most use case is Authorization Code Grant flow with PKCE. +message SecurityScheme { + string type = 1; + string description = 2; + string name = 3; + string in = 4; + string scheme = 5; + string bearer_format = 6; + OauthFlows flows = 7; + string open_id_connect_url = 8; + repeated NamedAny specification_extension = 9; +} + +message SecuritySchemeOrReference { + oneof oneof { + SecurityScheme security_scheme = 1; + Reference reference = 2; + } +} + +message SecuritySchemesOrReferences { + repeated NamedSecuritySchemeOrReference additional_properties = 1; +} + +// An object representing a Server. +message Server { + string url = 1; + string description = 2; + ServerVariables variables = 3; + repeated NamedAny specification_extension = 4; +} + +// An object representing a Server Variable for server URL template substitution. +message ServerVariable { + repeated string enum = 1; + string default = 2; + string description = 3; + repeated NamedAny specification_extension = 4; +} + +message ServerVariables { + repeated NamedServerVariable additional_properties = 1; +} + +// Any property starting with x- is valid. +message SpecificationExtension { + oneof oneof { + double number = 1; + bool boolean = 2; + string string = 3; + } +} + +message StringArray { + repeated string value = 1; +} + +message Strings { + repeated NamedString additional_properties = 1; +} + +// Adds metadata to a single tag that is used by the Operation Object. It is not mandatory to have a Tag Object per tag defined in the Operation Object instances. +message Tag { + string name = 1; + string description = 2; + ExternalDocs external_docs = 3; + repeated NamedAny specification_extension = 4; +} + +// A metadata object that allows for more fine-tuned XML model definitions. When using arrays, XML element names are *not* inferred (for singular/plural forms) and the `name` property SHOULD be used to add that information. See examples for expected behavior. +message Xml { + string name = 1; + string namespace = 2; + string prefix = 3; + bool attribute = 4; + bool wrapped = 5; + repeated NamedAny specification_extension = 6; +} + diff --git a/third_party/validate/README.md b/third_party/validate/README.md new file mode 100644 index 0000000..56698db --- /dev/null +++ b/third_party/validate/README.md @@ -0,0 +1,3 @@ +# protoc-gen-validate (PGV) + +* https://github.com/envoyproxy/protoc-gen-validate diff --git a/third_party/validate/validate.proto b/third_party/validate/validate.proto new file mode 100644 index 0000000..4195ecf --- /dev/null +++ b/third_party/validate/validate.proto @@ -0,0 +1,863 @@ +syntax = "proto2"; +package validate; + +option go_package = "github.com/envoyproxy/protoc-gen-validate/validate"; +option java_package = "io.envoyproxy.pgv.validate"; + +import "google/protobuf/descriptor.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/timestamp.proto"; + +// Validation rules applied at the message level +extend google.protobuf.MessageOptions { + // Disabled nullifies any validation rules for this message, including any + // message fields associated with it that do support validation. + optional bool disabled = 1071; + // Ignore skips generation of validation methods for this message. + optional bool ignored = 1072; +} + +// Validation rules applied at the oneof level +extend google.protobuf.OneofOptions { + // Required ensures that exactly one the field options in a oneof is set; + // validation fails if no fields in the oneof are set. + optional bool required = 1071; +} + +// Validation rules applied at the field level +extend google.protobuf.FieldOptions { + // Rules specify the validations to be performed on this field. By default, + // no validation is performed against a field. + optional FieldRules rules = 1071; +} + +// FieldRules encapsulates the rules for each type of field. Depending on the +// field, the correct set should be used to ensure proper validations. +message FieldRules { + optional MessageRules message = 17; + oneof type { + // Scalar Field Types + FloatRules float = 1; + DoubleRules double = 2; + Int32Rules int32 = 3; + Int64Rules int64 = 4; + UInt32Rules uint32 = 5; + UInt64Rules uint64 = 6; + SInt32Rules sint32 = 7; + SInt64Rules sint64 = 8; + Fixed32Rules fixed32 = 9; + Fixed64Rules fixed64 = 10; + SFixed32Rules sfixed32 = 11; + SFixed64Rules sfixed64 = 12; + BoolRules bool = 13; + StringRules string = 14; + BytesRules bytes = 15; + + // Complex Field Types + EnumRules enum = 16; + RepeatedRules repeated = 18; + MapRules map = 19; + + // Well-Known Field Types + AnyRules any = 20; + DurationRules duration = 21; + TimestampRules timestamp = 22; + } +} + +// FloatRules describes the constraints applied to `float` values +message FloatRules { + // Const specifies that this field must be exactly the specified value + optional float const = 1; + + // Lt specifies that this field must be less than the specified value, + // exclusive + optional float lt = 2; + + // Lte specifies that this field must be less than or equal to the + // specified value, inclusive + optional float lte = 3; + + // Gt specifies that this field must be greater than the specified value, + // exclusive. If the value of Gt is larger than a specified Lt or Lte, the + // range is reversed. + optional float gt = 4; + + // Gte specifies that this field must be greater than or equal to the + // specified value, inclusive. If the value of Gte is larger than a + // specified Lt or Lte, the range is reversed. + optional float gte = 5; + + // In specifies that this field must be equal to one of the specified + // values + repeated float in = 6; + + // NotIn specifies that this field cannot be equal to one of the specified + // values + repeated float not_in = 7; + + // IgnoreEmpty specifies that the validation rules of this field should be + // evaluated only if the field is not empty + optional bool ignore_empty = 8; +} + +// DoubleRules describes the constraints applied to `double` values +message DoubleRules { + // Const specifies that this field must be exactly the specified value + optional double const = 1; + + // Lt specifies that this field must be less than the specified value, + // exclusive + optional double lt = 2; + + // Lte specifies that this field must be less than or equal to the + // specified value, inclusive + optional double lte = 3; + + // Gt specifies that this field must be greater than the specified value, + // exclusive. If the value of Gt is larger than a specified Lt or Lte, the + // range is reversed. + optional double gt = 4; + + // Gte specifies that this field must be greater than or equal to the + // specified value, inclusive. If the value of Gte is larger than a + // specified Lt or Lte, the range is reversed. + optional double gte = 5; + + // In specifies that this field must be equal to one of the specified + // values + repeated double in = 6; + + // NotIn specifies that this field cannot be equal to one of the specified + // values + repeated double not_in = 7; + + // IgnoreEmpty specifies that the validation rules of this field should be + // evaluated only if the field is not empty + optional bool ignore_empty = 8; +} + +// Int32Rules describes the constraints applied to `int32` values +message Int32Rules { + // Const specifies that this field must be exactly the specified value + optional int32 const = 1; + + // Lt specifies that this field must be less than the specified value, + // exclusive + optional int32 lt = 2; + + // Lte specifies that this field must be less than or equal to the + // specified value, inclusive + optional int32 lte = 3; + + // Gt specifies that this field must be greater than the specified value, + // exclusive. If the value of Gt is larger than a specified Lt or Lte, the + // range is reversed. + optional int32 gt = 4; + + // Gte specifies that this field must be greater than or equal to the + // specified value, inclusive. If the value of Gte is larger than a + // specified Lt or Lte, the range is reversed. + optional int32 gte = 5; + + // In specifies that this field must be equal to one of the specified + // values + repeated int32 in = 6; + + // NotIn specifies that this field cannot be equal to one of the specified + // values + repeated int32 not_in = 7; + + // IgnoreEmpty specifies that the validation rules of this field should be + // evaluated only if the field is not empty + optional bool ignore_empty = 8; +} + +// Int64Rules describes the constraints applied to `int64` values +message Int64Rules { + // Const specifies that this field must be exactly the specified value + optional int64 const = 1; + + // Lt specifies that this field must be less than the specified value, + // exclusive + optional int64 lt = 2; + + // Lte specifies that this field must be less than or equal to the + // specified value, inclusive + optional int64 lte = 3; + + // Gt specifies that this field must be greater than the specified value, + // exclusive. If the value of Gt is larger than a specified Lt or Lte, the + // range is reversed. + optional int64 gt = 4; + + // Gte specifies that this field must be greater than or equal to the + // specified value, inclusive. If the value of Gte is larger than a + // specified Lt or Lte, the range is reversed. + optional int64 gte = 5; + + // In specifies that this field must be equal to one of the specified + // values + repeated int64 in = 6; + + // NotIn specifies that this field cannot be equal to one of the specified + // values + repeated int64 not_in = 7; + + // IgnoreEmpty specifies that the validation rules of this field should be + // evaluated only if the field is not empty + optional bool ignore_empty = 8; +} + +// UInt32Rules describes the constraints applied to `uint32` values +message UInt32Rules { + // Const specifies that this field must be exactly the specified value + optional uint32 const = 1; + + // Lt specifies that this field must be less than the specified value, + // exclusive + optional uint32 lt = 2; + + // Lte specifies that this field must be less than or equal to the + // specified value, inclusive + optional uint32 lte = 3; + + // Gt specifies that this field must be greater than the specified value, + // exclusive. If the value of Gt is larger than a specified Lt or Lte, the + // range is reversed. + optional uint32 gt = 4; + + // Gte specifies that this field must be greater than or equal to the + // specified value, inclusive. If the value of Gte is larger than a + // specified Lt or Lte, the range is reversed. + optional uint32 gte = 5; + + // In specifies that this field must be equal to one of the specified + // values + repeated uint32 in = 6; + + // NotIn specifies that this field cannot be equal to one of the specified + // values + repeated uint32 not_in = 7; + + // IgnoreEmpty specifies that the validation rules of this field should be + // evaluated only if the field is not empty + optional bool ignore_empty = 8; +} + +// UInt64Rules describes the constraints applied to `uint64` values +message UInt64Rules { + // Const specifies that this field must be exactly the specified value + optional uint64 const = 1; + + // Lt specifies that this field must be less than the specified value, + // exclusive + optional uint64 lt = 2; + + // Lte specifies that this field must be less than or equal to the + // specified value, inclusive + optional uint64 lte = 3; + + // Gt specifies that this field must be greater than the specified value, + // exclusive. If the value of Gt is larger than a specified Lt or Lte, the + // range is reversed. + optional uint64 gt = 4; + + // Gte specifies that this field must be greater than or equal to the + // specified value, inclusive. If the value of Gte is larger than a + // specified Lt or Lte, the range is reversed. + optional uint64 gte = 5; + + // In specifies that this field must be equal to one of the specified + // values + repeated uint64 in = 6; + + // NotIn specifies that this field cannot be equal to one of the specified + // values + repeated uint64 not_in = 7; + + // IgnoreEmpty specifies that the validation rules of this field should be + // evaluated only if the field is not empty + optional bool ignore_empty = 8; +} + +// SInt32Rules describes the constraints applied to `sint32` values +message SInt32Rules { + // Const specifies that this field must be exactly the specified value + optional sint32 const = 1; + + // Lt specifies that this field must be less than the specified value, + // exclusive + optional sint32 lt = 2; + + // Lte specifies that this field must be less than or equal to the + // specified value, inclusive + optional sint32 lte = 3; + + // Gt specifies that this field must be greater than the specified value, + // exclusive. If the value of Gt is larger than a specified Lt or Lte, the + // range is reversed. + optional sint32 gt = 4; + + // Gte specifies that this field must be greater than or equal to the + // specified value, inclusive. If the value of Gte is larger than a + // specified Lt or Lte, the range is reversed. + optional sint32 gte = 5; + + // In specifies that this field must be equal to one of the specified + // values + repeated sint32 in = 6; + + // NotIn specifies that this field cannot be equal to one of the specified + // values + repeated sint32 not_in = 7; + + // IgnoreEmpty specifies that the validation rules of this field should be + // evaluated only if the field is not empty + optional bool ignore_empty = 8; +} + +// SInt64Rules describes the constraints applied to `sint64` values +message SInt64Rules { + // Const specifies that this field must be exactly the specified value + optional sint64 const = 1; + + // Lt specifies that this field must be less than the specified value, + // exclusive + optional sint64 lt = 2; + + // Lte specifies that this field must be less than or equal to the + // specified value, inclusive + optional sint64 lte = 3; + + // Gt specifies that this field must be greater than the specified value, + // exclusive. If the value of Gt is larger than a specified Lt or Lte, the + // range is reversed. + optional sint64 gt = 4; + + // Gte specifies that this field must be greater than or equal to the + // specified value, inclusive. If the value of Gte is larger than a + // specified Lt or Lte, the range is reversed. + optional sint64 gte = 5; + + // In specifies that this field must be equal to one of the specified + // values + repeated sint64 in = 6; + + // NotIn specifies that this field cannot be equal to one of the specified + // values + repeated sint64 not_in = 7; + + // IgnoreEmpty specifies that the validation rules of this field should be + // evaluated only if the field is not empty + optional bool ignore_empty = 8; +} + +// Fixed32Rules describes the constraints applied to `fixed32` values +message Fixed32Rules { + // Const specifies that this field must be exactly the specified value + optional fixed32 const = 1; + + // Lt specifies that this field must be less than the specified value, + // exclusive + optional fixed32 lt = 2; + + // Lte specifies that this field must be less than or equal to the + // specified value, inclusive + optional fixed32 lte = 3; + + // Gt specifies that this field must be greater than the specified value, + // exclusive. If the value of Gt is larger than a specified Lt or Lte, the + // range is reversed. + optional fixed32 gt = 4; + + // Gte specifies that this field must be greater than or equal to the + // specified value, inclusive. If the value of Gte is larger than a + // specified Lt or Lte, the range is reversed. + optional fixed32 gte = 5; + + // In specifies that this field must be equal to one of the specified + // values + repeated fixed32 in = 6; + + // NotIn specifies that this field cannot be equal to one of the specified + // values + repeated fixed32 not_in = 7; + + // IgnoreEmpty specifies that the validation rules of this field should be + // evaluated only if the field is not empty + optional bool ignore_empty = 8; +} + +// Fixed64Rules describes the constraints applied to `fixed64` values +message Fixed64Rules { + // Const specifies that this field must be exactly the specified value + optional fixed64 const = 1; + + // Lt specifies that this field must be less than the specified value, + // exclusive + optional fixed64 lt = 2; + + // Lte specifies that this field must be less than or equal to the + // specified value, inclusive + optional fixed64 lte = 3; + + // Gt specifies that this field must be greater than the specified value, + // exclusive. If the value of Gt is larger than a specified Lt or Lte, the + // range is reversed. + optional fixed64 gt = 4; + + // Gte specifies that this field must be greater than or equal to the + // specified value, inclusive. If the value of Gte is larger than a + // specified Lt or Lte, the range is reversed. + optional fixed64 gte = 5; + + // In specifies that this field must be equal to one of the specified + // values + repeated fixed64 in = 6; + + // NotIn specifies that this field cannot be equal to one of the specified + // values + repeated fixed64 not_in = 7; + + // IgnoreEmpty specifies that the validation rules of this field should be + // evaluated only if the field is not empty + optional bool ignore_empty = 8; +} + +// SFixed32Rules describes the constraints applied to `sfixed32` values +message SFixed32Rules { + // Const specifies that this field must be exactly the specified value + optional sfixed32 const = 1; + + // Lt specifies that this field must be less than the specified value, + // exclusive + optional sfixed32 lt = 2; + + // Lte specifies that this field must be less than or equal to the + // specified value, inclusive + optional sfixed32 lte = 3; + + // Gt specifies that this field must be greater than the specified value, + // exclusive. If the value of Gt is larger than a specified Lt or Lte, the + // range is reversed. + optional sfixed32 gt = 4; + + // Gte specifies that this field must be greater than or equal to the + // specified value, inclusive. If the value of Gte is larger than a + // specified Lt or Lte, the range is reversed. + optional sfixed32 gte = 5; + + // In specifies that this field must be equal to one of the specified + // values + repeated sfixed32 in = 6; + + // NotIn specifies that this field cannot be equal to one of the specified + // values + repeated sfixed32 not_in = 7; + + // IgnoreEmpty specifies that the validation rules of this field should be + // evaluated only if the field is not empty + optional bool ignore_empty = 8; +} + +// SFixed64Rules describes the constraints applied to `sfixed64` values +message SFixed64Rules { + // Const specifies that this field must be exactly the specified value + optional sfixed64 const = 1; + + // Lt specifies that this field must be less than the specified value, + // exclusive + optional sfixed64 lt = 2; + + // Lte specifies that this field must be less than or equal to the + // specified value, inclusive + optional sfixed64 lte = 3; + + // Gt specifies that this field must be greater than the specified value, + // exclusive. If the value of Gt is larger than a specified Lt or Lte, the + // range is reversed. + optional sfixed64 gt = 4; + + // Gte specifies that this field must be greater than or equal to the + // specified value, inclusive. If the value of Gte is larger than a + // specified Lt or Lte, the range is reversed. + optional sfixed64 gte = 5; + + // In specifies that this field must be equal to one of the specified + // values + repeated sfixed64 in = 6; + + // NotIn specifies that this field cannot be equal to one of the specified + // values + repeated sfixed64 not_in = 7; + + // IgnoreEmpty specifies that the validation rules of this field should be + // evaluated only if the field is not empty + optional bool ignore_empty = 8; +} + +// BoolRules describes the constraints applied to `bool` values +message BoolRules { + // Const specifies that this field must be exactly the specified value + optional bool const = 1; +} + +// StringRules describe the constraints applied to `string` values +message StringRules { + // Const specifies that this field must be exactly the specified value + optional string const = 1; + + // Len specifies that this field must be the specified number of + // characters (Unicode code points). Note that the number of + // characters may differ from the number of bytes in the string. + optional uint64 len = 19; + + // MinLen specifies that this field must be the specified number of + // characters (Unicode code points) at a minimum. Note that the number of + // characters may differ from the number of bytes in the string. + optional uint64 min_len = 2; + + // MaxLen specifies that this field must be the specified number of + // characters (Unicode code points) at a maximum. Note that the number of + // characters may differ from the number of bytes in the string. + optional uint64 max_len = 3; + + // LenBytes specifies that this field must be the specified number of bytes + // at a minimum + optional uint64 len_bytes = 20; + + // MinBytes specifies that this field must be the specified number of bytes + // at a minimum + optional uint64 min_bytes = 4; + + // MaxBytes specifies that this field must be the specified number of bytes + // at a maximum + optional uint64 max_bytes = 5; + + // Pattern specifes that this field must match against the specified + // regular expression (RE2 syntax). The included expression should elide + // any delimiters. + optional string pattern = 6; + + // Prefix specifies that this field must have the specified substring at + // the beginning of the string. + optional string prefix = 7; + + // Suffix specifies that this field must have the specified substring at + // the end of the string. + optional string suffix = 8; + + // Contains specifies that this field must have the specified substring + // anywhere in the string. + optional string contains = 9; + + // NotContains specifies that this field cannot have the specified substring + // anywhere in the string. + optional string not_contains = 23; + + // In specifies that this field must be equal to one of the specified + // values + repeated string in = 10; + + // NotIn specifies that this field cannot be equal to one of the specified + // values + repeated string not_in = 11; + + // WellKnown rules provide advanced constraints against common string + // patterns + oneof well_known { + // Email specifies that the field must be a valid email address as + // defined by RFC 5322 + bool email = 12; + + // Hostname specifies that the field must be a valid hostname as + // defined by RFC 1034. This constraint does not support + // internationalized domain names (IDNs). + bool hostname = 13; + + // Ip specifies that the field must be a valid IP (v4 or v6) address. + // Valid IPv6 addresses should not include surrounding square brackets. + bool ip = 14; + + // Ipv4 specifies that the field must be a valid IPv4 address. + bool ipv4 = 15; + + // Ipv6 specifies that the field must be a valid IPv6 address. Valid + // IPv6 addresses should not include surrounding square brackets. + bool ipv6 = 16; + + // Uri specifies that the field must be a valid, absolute URI as defined + // by RFC 3986 + bool uri = 17; + + // UriRef specifies that the field must be a valid URI as defined by RFC + // 3986 and may be relative or absolute. + bool uri_ref = 18; + + // Address specifies that the field must be either a valid hostname as + // defined by RFC 1034 (which does not support internationalized domain + // names or IDNs), or it can be a valid IP (v4 or v6). + bool address = 21; + + // Uuid specifies that the field must be a valid UUID as defined by + // RFC 4122 + bool uuid = 22; + + // WellKnownRegex specifies a common well known pattern defined as a regex. + KnownRegex well_known_regex = 24; + } + + // This applies to regexes HTTP_HEADER_NAME and HTTP_HEADER_VALUE to enable + // strict header validation. + // By default, this is true, and HTTP header validations are RFC-compliant. + // Setting to false will enable a looser validations that only disallows + // \r\n\0 characters, which can be used to bypass header matching rules. + optional bool strict = 25 [default = true]; + + // IgnoreEmpty specifies that the validation rules of this field should be + // evaluated only if the field is not empty + optional bool ignore_empty = 26; +} + +// WellKnownRegex contain some well-known patterns. +enum KnownRegex { + UNKNOWN = 0; + + // HTTP header name as defined by RFC 7230. + HTTP_HEADER_NAME = 1; + + // HTTP header value as defined by RFC 7230. + HTTP_HEADER_VALUE = 2; +} + +// BytesRules describe the constraints applied to `bytes` values +message BytesRules { + // Const specifies that this field must be exactly the specified value + optional bytes const = 1; + + // Len specifies that this field must be the specified number of bytes + optional uint64 len = 13; + + // MinLen specifies that this field must be the specified number of bytes + // at a minimum + optional uint64 min_len = 2; + + // MaxLen specifies that this field must be the specified number of bytes + // at a maximum + optional uint64 max_len = 3; + + // Pattern specifes that this field must match against the specified + // regular expression (RE2 syntax). The included expression should elide + // any delimiters. + optional string pattern = 4; + + // Prefix specifies that this field must have the specified bytes at the + // beginning of the string. + optional bytes prefix = 5; + + // Suffix specifies that this field must have the specified bytes at the + // end of the string. + optional bytes suffix = 6; + + // Contains specifies that this field must have the specified bytes + // anywhere in the string. + optional bytes contains = 7; + + // In specifies that this field must be equal to one of the specified + // values + repeated bytes in = 8; + + // NotIn specifies that this field cannot be equal to one of the specified + // values + repeated bytes not_in = 9; + + // WellKnown rules provide advanced constraints against common byte + // patterns + oneof well_known { + // Ip specifies that the field must be a valid IP (v4 or v6) address in + // byte format + bool ip = 10; + + // Ipv4 specifies that the field must be a valid IPv4 address in byte + // format + bool ipv4 = 11; + + // Ipv6 specifies that the field must be a valid IPv6 address in byte + // format + bool ipv6 = 12; + } + + // IgnoreEmpty specifies that the validation rules of this field should be + // evaluated only if the field is not empty + optional bool ignore_empty = 14; +} + +// EnumRules describe the constraints applied to enum values +message EnumRules { + // Const specifies that this field must be exactly the specified value + optional int32 const = 1; + + // DefinedOnly specifies that this field must be only one of the defined + // values for this enum, failing on any undefined value. + optional bool defined_only = 2; + + // In specifies that this field must be equal to one of the specified + // values + repeated int32 in = 3; + + // NotIn specifies that this field cannot be equal to one of the specified + // values + repeated int32 not_in = 4; +} + +// MessageRules describe the constraints applied to embedded message values. +// For message-type fields, validation is performed recursively. +message MessageRules { + // Skip specifies that the validation rules of this field should not be + // evaluated + optional bool skip = 1; + + // Required specifies that this field must be set + optional bool required = 2; +} + +// RepeatedRules describe the constraints applied to `repeated` values +message RepeatedRules { + // MinItems specifies that this field must have the specified number of + // items at a minimum + optional uint64 min_items = 1; + + // MaxItems specifies that this field must have the specified number of + // items at a maximum + optional uint64 max_items = 2; + + // Unique specifies that all elements in this field must be unique. This + // contraint is only applicable to scalar and enum types (messages are not + // supported). + optional bool unique = 3; + + // Items specifies the contraints to be applied to each item in the field. + // Repeated message fields will still execute validation against each item + // unless skip is specified here. + optional FieldRules items = 4; + + // IgnoreEmpty specifies that the validation rules of this field should be + // evaluated only if the field is not empty + optional bool ignore_empty = 5; +} + +// MapRules describe the constraints applied to `map` values +message MapRules { + // MinPairs specifies that this field must have the specified number of + // KVs at a minimum + optional uint64 min_pairs = 1; + + // MaxPairs specifies that this field must have the specified number of + // KVs at a maximum + optional uint64 max_pairs = 2; + + // NoSparse specifies values in this field cannot be unset. This only + // applies to map's with message value types. + optional bool no_sparse = 3; + + // Keys specifies the constraints to be applied to each key in the field. + optional FieldRules keys = 4; + + // Values specifies the constraints to be applied to the value of each key + // in the field. Message values will still have their validations evaluated + // unless skip is specified here. + optional FieldRules values = 5; + + // IgnoreEmpty specifies that the validation rules of this field should be + // evaluated only if the field is not empty + optional bool ignore_empty = 6; +} + +// AnyRules describe constraints applied exclusively to the +// `google.protobuf.Any` well-known type +message AnyRules { + // Required specifies that this field must be set + optional bool required = 1; + + // In specifies that this field's `type_url` must be equal to one of the + // specified values. + repeated string in = 2; + + // NotIn specifies that this field's `type_url` must not be equal to any of + // the specified values. + repeated string not_in = 3; +} + +// DurationRules describe the constraints applied exclusively to the +// `google.protobuf.Duration` well-known type +message DurationRules { + // Required specifies that this field must be set + optional bool required = 1; + + // Const specifies that this field must be exactly the specified value + optional google.protobuf.Duration const = 2; + + // Lt specifies that this field must be less than the specified value, + // exclusive + optional google.protobuf.Duration lt = 3; + + // Lt specifies that this field must be less than the specified value, + // inclusive + optional google.protobuf.Duration lte = 4; + + // Gt specifies that this field must be greater than the specified value, + // exclusive + optional google.protobuf.Duration gt = 5; + + // Gte specifies that this field must be greater than the specified value, + // inclusive + optional google.protobuf.Duration gte = 6; + + // In specifies that this field must be equal to one of the specified + // values + repeated google.protobuf.Duration in = 7; + + // NotIn specifies that this field cannot be equal to one of the specified + // values + repeated google.protobuf.Duration not_in = 8; +} + +// TimestampRules describe the constraints applied exclusively to the +// `google.protobuf.Timestamp` well-known type +message TimestampRules { + // Required specifies that this field must be set + optional bool required = 1; + + // Const specifies that this field must be exactly the specified value + optional google.protobuf.Timestamp const = 2; + + // Lt specifies that this field must be less than the specified value, + // exclusive + optional google.protobuf.Timestamp lt = 3; + + // Lte specifies that this field must be less than the specified value, + // inclusive + optional google.protobuf.Timestamp lte = 4; + + // Gt specifies that this field must be greater than the specified value, + // exclusive + optional google.protobuf.Timestamp gt = 5; + + // Gte specifies that this field must be greater than the specified value, + // inclusive + optional google.protobuf.Timestamp gte = 6; + + // LtNow specifies that this must be less than the current time. LtNow + // can only be used with the Within rule. + optional bool lt_now = 7; + + // GtNow specifies that this must be greater than the current time. GtNow + // can only be used with the Within rule. + optional bool gt_now = 8; + + // Within specifies that this field must be within this duration of the + // current time. This constraint can be used alone or with the LtNow and + // GtNow rules. + optional google.protobuf.Duration within = 9; +}