美文网首页
虚拟交易所系统2.0

虚拟交易所系统2.0

作者: 9995857 | 来源:发表于2017-06-01 12:13 被阅读0次

    数据库

    1. 用户表

    tbl_user

    字段 类型 默认值 说明
    uuid varchar(36) 主键
    name varchar(100) 用户名
    password varchar(100) MD5密码
    exchangerate double(6,2) 0 交易手续费
    createtime varchar(32) 创建时间
    status int(3) 0 当前状态 0:正常 2:异常

    2. 余额表

    tbl_balance

    字段 类型 默认值 说明
    uuid varchar(36) 主键
    userid varchar(36) 用户ID
    balance double(11,3) 0 账户余额
    lastupdatetime varchar(32) 最后更新时间

    3. 充值表

    tbl_recharge

    字段 类型 默认值 说明
    uuid varchar(36) 主键
    userid varchar(36) 用户ID
    amount double(11,3) 0 充值金额
    createtime varchar(32) 创建时间
    remark varchar(255) 说明

    3. 持仓表

    tbl_holdstock

    字段 类型 默认值 说明
    uuid varchar(36) 主键
    userid varchar(36) 用户ID
    stockcode varchar(6) 股票代码
    count int(11) 0 持仓数量
    lastupdatetime varchar(32) 最后更新时间
    useridstockcode varchar(50) 标识 userid_stockcode

    4. 交易记录表 每日一张表

    tbl_exchangehistoryYYYYMMDD

    字段 类型 默认值 说明
    uuid varchar(36) 主键
    commandid varchar(36) 命令ID
    userid varchar(36) 用户ID
    stockcode varchar(6) 股票代码
    type varchar(20) 类型 buy:买入 sell:卖出
    price double(7,3) 0 交易价格
    count int(11) 0 交易数量
    exchangeamount double(11,3) 0 交易税金额
    stockamount double(11,3) 0 股票金额
    totalamount double(11,3) 0 交易总金额
    holdstockbefore int(11) 0 交易前持仓
    holdstockafter int(11) 0 交易后持仓
    balancebefore double(11,3) 0 交易前余额
    balanceafter double(11,3) 0 交易后余额
    createtime varchar(32) 创建时间

    接口

    Servlet

    1. 创建用户

    /servlet/createuser

    Request:
    {
            "name":"15901197623",         //用户名 手机号  中文英文
            "password":"12345678",        //密码 6~20位 任意
            "exchangerate":"2.5"          //交易费率
    }
    Response:
    {
            "statusCode":"000000",
            "result":{
                "uuid":"qwertyuioasdfghjkzxcvbnm",
                "name":"15901197623",
                "password":"12345678",
                "exchangerate":"2.5",
                "createtime":"2017-07-02 14:34:33",
                "status":"0"
             }
    }
    

    2. 检查用户名密码

    /servlet/checkuser

    Request:
    {
            "name":"15901197623",                            //用户名 手机号  中文英文
            "password":"tyuiotrthfkghjhkfhgjhkjtyui",        //密码 可以是明文也可以密文
    }
    Response:
    {
            "statusCode":"000000",
            "result":{
                "uuid":"qwertyuioasdfghjkzxcvbnm",
                "name":"15901197623",
                "password":"12345678",
                "exchangerate":"2.5",
                "createtime":"2017-07-02 14:34:33",
                "status":"0"
             }
    }
    

    3. 检查密码

    /servlet/checkpassword

    Request:
    {
            "userid":"qwertyuioasdfghjkzxcvbnm",          //用户ID
            "password":"12345678"                         //密码 可以是明文也可以密文
    }
    Response:
    {
            "statusCode":"000000",
            "result":"ok"
    }
    

    4. 获得用户数据

    /servlet/getuserdata

    Request:
    /servlet/getuserdata?userid=qwertyuioasdfghjkzxcvbnm
    Response:
    {
            "statusCode":"000000",
            "result":{
                "userid":"qwertyuioasdfghjkzxcvbnm",
                "name":"15901197623",
                "exchangerate":"2.5",
                "balance":"45000",
                "stockdata":[
                     {
                         "uuid":"fdaserqrewrqewrdgqeterqwe",
                         "userid":"qwertyuioasdfghjkzxcvbnm",
                         "stockcode":"601988",
                         "count":"2000",
                         "lastupdatetime":"2017-07-12 12:33:33",
                         "useridstockcode":"qwertyuioasdfghjkzxcvbnm_601988"
                      },
                      ……
                 ]
             }
    }
    

    5. 获得持仓数据

    /servlet/getbalanceholdstock

    Request:
    {
            "userid":"qwertyuioasdfghjkzxcvbnm",          //用户ID
            "stockcode":"601988"                         //股票代码
    }
    Response:
    {
            "statusCode":"000000",
            "result":{
                "userid":"qwertyuioasdfghjkzxcvbnm",
                "stockcode":"601988",
                "balance":"45000",
                "holdcount":"2000"
            }
    }
    

    6. 获得股票数据

    /servlet/getstockdata

    Request:
    /servlet/getstockdata?stockcode=601988
    }
    Response:
    {
            "statusCode":"000000",
            "result":{
                "gid":"sh601009",               /*股票编号*/
                "increPer": "9.91",             /*涨跌百分比*/
                "increase": "43.99",            /*涨跌额*/
                "name":"南京银行",              /*股票名称*/
                "todayStartPri":"8.26",         /*今日开盘价*/
                "yestodEndPri":"8.26",          /*昨日收盘价*/
                "nowPri":"8.37",                /*当前价格*/
                "todayMax":"8.55",              /*今日最高价*/
                "todayMin":"8.25",              /*今日最低价*/
                "competitivePri":"8.37",        /*竞买价*/
                "reservePri":"8.38",            /*竞卖价*/
                "traNumber":"34501453",         /*成交量*/
                "traAmount":"290889560",        /*成交金额*/
                "buyOne":"10870",               /*买一*/
                "buyOnePri":"8.37",             /*买一报价*/
                "buyTwo":"177241",              /*买二*/
                "buyTwoPri":"8.36",             /*买二报价*/
                "buyThree":"92600",             /*买三*/
                "buyThreePri":"8.35",           /*买三报价*/
                "buyFour":"87200"               /*买四*/
                "buyFourPri":"8.34",            /*买四报价*/
                "buyFive":"113700",             /*买五*/
                "buyFivePri":"8.42",            /*买五报价*/
                "sellOne":"47556",              /*卖一*/
                "sellOnePri":"8.38",            /*卖一报价*/
                "sellTwo":"103057",             /*卖二*/
                "sellTwoPri":"8.39",            /*卖二报价*/
                "sellThree":"186689",           /*卖三*/
                "sellThreePri":"8.40",          /*卖三报价*/
                "sellFour":"49000",             /*卖四*/
                "sellFourPri":"8.41",           /*卖四报价*/        
                "sellFive":"214535",            /*卖五*/
                "sellFivePri":"15.21",          /*卖五报价*/
                "date":"2012-12-11",            /*日期*/
                "time":"15:03:06",              /*时间*/
            }
    }
    

    7. 充值

    /servlet/rechargebalance

    Request:
    {
            "userid":"qwertyuioasdfghjkzxcvbnm",          //用户ID
            "password":"12345678",                        //密码 6~20位 任意
            "amount":"1002.5"                                //充值金额
    }
    Response:
    {
            "statusCode":"000000",
            "result":{
                "uuid":"fdas6fdsa6f5dsa5f536adsf3ad5ads",
                "userid":"qwertyuioasdfghjkzxcvbnm",
                "balance":"46002.5",
                "lastupdatetime":"2017-06-11 12:34:33"
            }
    }
    

    8. 提现

    /servlet/withdrawbalance

    Request:
    {
            "userid":"qwertyuioasdfghjkzxcvbnm",          //用户ID
            "password":"12345678",                        //密码 6~20位 任意
            "amount":"2.5"                                //提现金额
    }
    Response:
    {
            "statusCode":"000000",
            "result":{
                "uuid":"fuytrurtyurtyurtsfgfdsyurtyuyetrytr",
                "userid":"qwertyuioasdfghjkzxcvbnm",
                "balance":"46000",
                "lastupdatetime":"2017-06-11 12:38:33"
            }
    }
    

    9. 买入股票

    /servlet/buystock

    Request:
    {
            "userid":"qwertyuioasdfghjkzxcvbnm",          //用户ID
            "password":"12345678",                        //密码 6~20位
            "stockcode":"601988",                         //股票代码
            "count":"1000"                                //买入数量
            "execute":"true",                             //是否真实执行
    }
    Response:
    {
            "statusCode":"000000",
            "result":{
                "uuid":"dafadsfdagvcthtrygdsfgsdg",
                "commandid":"",
                "userid":"qwertyuioasdfghjkzxcvbnm",
                "stockcode":"601988",
                "type":"buy",
                "price":"7.12",
                "count":"1000",
                "holdstockbefore":"0",
                "holdstockafter":"1000",
                "balancebefore":"46000",
                "balanceafter":"38862.2",
                "exchangeamount":"17.8",
                "stockamount":"7120",
                "totalamount":"7137.8",
                "createtime":"2017-06-13 14:28:31"
            }
    }
    

    10. 买出股票

    /servlet/sellstock

    Request:
    {
            "userid":"qwertyuioasdfghjkzxcvbnm",          //用户ID
            "password":"12345678",                        //密码 6~20位
            "stockcode":"601988",                         //股票代码
            "count":"1000"                                //买入数量
            "execute":"true",                             //是否真实执行
    }
    Response:
    {
            "statusCode":"000000",
            "result":{
                "uuid":"kljhvcbyujewvdcjhwofiuldvklc",
                "commandid":"",
                "userid":"qwertyuioasdfghjkzxcvbnm",
                "stockcode":"601988",
                "type":"sell",
                "price":"7.12",
                "count":"1000",
                "holdstockbefore":"0",
                "holdstockafter":"1000",
                "balancebefore":"38862.2",
                "balanceafter":"45964.4",
                "exchangeamount":"17.8",
                "stockamount":"7120",
                "totalamount":"7102.2",
                "createtime":"2017-06-13 15:18:32"
            }
    }
    

    11. 批量操作命令

    /servlet/batchcommand

    Request:
    {
            "12321df43refd45refd4":{
                    "type":"balance",
                    "userid":"qwertyuioasdfghjkzxcvbnm", 
                    "password":"12345678",
             },
             "oi89vfadsnq4irdadaf78":{
                    "type":"holdstock",
                    "userid":"qwertyuioasdfghjkzxcvbnm",
                    "password":"12345678",
                    "stockcode":"601988"
             },
             "54786fdasfas6d8f57fa":{
                    "type":"balance&holdstock",
                    "userid":"qwertyuioasdfghjkzxcvbnm",
                    "password":"12345678",
                    "stockcode":"601988"
             },
             "dfaoiusfads68afsdljfdas":{
                    "type":"buy",
                    "commandid":"fdfidsapo68fsadhifads",
                    "userid":"qwertyuioasdfghjkzxcvbnm", 
                    "stockcode":"601988"
                    "count":"1000"
             },
             "7a89f0ds576fadsfasd987":{
                    "type":"sell",
                    "commandid":"dfasiuy687sfdadfasdfasd",
                    "userid":"qwertyuioasdfgffhjkzxcvbnm", 
                    "password":"12345678",
                    "stockcode":"601988"
                    "count":"1000"
             }
    }
    Response:
    {
            "statusCode":"000000",
            "result":{
                "12321df43refd45refd4":{
                    "userid":"qwertyuioasdfghjkzxcvbnm", 
                    "balance":"45964.4"
                },
                "oi89vfadsnq4irdadaf78":{
                    "userid":"qwertyuioasddfghjkzxcvbnm",
                    "stockcode":"601988"
                    "holdcount":"1000"
                },
                "54786fdasfas6d8f57fa":{
                    "userid":"qwertyuioasdfghjkzxcvbnm",
                    "stockcode":"601988"
                    "holdcount":"1000",
                    "balance":"45964.4"
               },
               "dfaoiusfads68afsdljfdas":{
                    "userid":"qwertyuioasdfghdjkzxcvbnm", 
                    "stockcode":"601988"
                    "count":"1000"
               },
               "7a89f0ds576fadsfasd987":{
                    "userid":"qwertyuioasdfdghjkzxcvbnm",
                    "stockcode":"601988"
                    "count":"1000"
             }
        }
    }
    

    Cache存储结构

    |名称|说明|结构|
    |:--|:--:|
    |cachekey_user|用户集合|Map<userid,UserMap>|
    |cachekey_user_name|用户名集合|Map<username,UserMap>|
    |cachekey_balance|余额集合|Map<balanceid,BalanceMap>|
    |cachekey_balance_userid|用户余额集合|Map<userid,BalanceMap>|
    |cachekey_holdstock|持仓集合|Map<holdstockid,HoldstockMap|
    |cachekey_holdstock_userid|用户持仓集合|Map< userid,HoldstockMapList>|

    数据库存储算法

    配置文件

    配置项 默认值 说明
    STOCK_DATA_BASEURL 获得股票大盘数据接口
    COMMAND_FILE_ROOT 数据库更新文件夹根目录位置

    文件夹

    task 为命令任务文件夹 有三种命令 ,分别在三个文件夹中

    1. 创建交易记录 create_exchange 每秒钟一个文件. 追写
    2. 更改用户余额 update_balance 每个用户一个文件 新写
    3. 修改用户股票持仓 update_holdstock 每个用户每只股票一个文件 新写 每次都覆盖之前的记录

    update_balance update_holdstock 分别为线程,做了容器ConcurrentHashMap<userid,command>. 每次有新的数据,将覆盖之前的数据

    database 为准备入库文件夹 里面每10秒一个文件夹
    2017091610452.cmd
    2017091610453.cmd
    在每个10秒的文件夹中,分别有如下文件

    1. new.db 等待入库文件 这个文件是将最近10秒的文件内容,一并写入到此文件中
    2. process.db 正在入库文件

    process.db仅仅是new.db在执行阶段的替身rename

    history 为入库归档文件夹 每小时一个文件夹
    2017091610.cmd 这里只有create_exchange命令需要存储

    文件夹示例

    [-]/CacheFile/TradeCommand
        [-]task
             [-]create_exchange.cmd   #每秒一个文件
                 [-]20170916104523.cmd    
                 [-]20170916104524.cmd
                 [-]20170916104525.cmd
                 [-]20170916104526.cmd
             [-]update_holdstock.cmd   #每用户一个文件
                 [-]fdardashj23hh324jlk324ghj.cmd
                 [-]sdaffad89s7fdjash32u4342j.cmd
                 [-]fda9fds9a8h2i4342ifjdu342j.cmd
             [-]update_balance.cmd   #每用户每只股票一个文件
                 [-]fdardashj23hh324jlk324ghj_601988.cmd
                 [-]sdaffad89s7fdjash32u4342j_601988.cmd
                 [-]sdaffad89s7fdjash32u4342j_601931.cmd
                 [-]sdaffad89s7fdjash32u4342j_602483.cmd
                 [-]fda9fds9a8h2i4342ifjdu342j_601988.cmd
        [-]database
                 [-]create_exchange.cmd   #每10秒一个文件
                      [-]2017091610452.cmd
                 [-]update_holdstock.cmd  #每10秒一个文件
                      [-]2017091610452.cmd
                 [-]update_balance.cmd  #每10秒一个文件
                      [-]2017091610452.cmd
        [-]history
                 [-]2017091610.cmd   #每小时一个文件  这里只有交易记录  
    

    相关文章

      网友评论

          本文标题:虚拟交易所系统2.0

          本文链接:https://www.haomeiwen.com/subject/vqunxxtx.html