Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
token
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wallet
token
Commits
75649d9a
Commit
75649d9a
authored
Dec 19, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into feature/optimize
parents
15074f33
2a80c274
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
107 additions
and
10 deletions
+107
-10
MarketController.php
api/controllers/MarketController.php
+6
-4
FactoryService.php
common/service/exchange/factory/FactoryService.php
+1
-1
ZhaobiBuilder.php
common/service/exchange/factory/ZhaobiBuilder.php
+100
-5
No files found.
api/controllers/MarketController.php
View file @
75649d9a
...
...
@@ -10,15 +10,17 @@ class MarketController extends BaseController
{
public
function
actionDetail
()
{
$symbol
=
Yii
::
$app
->
request
->
get
(
'symbol'
,
''
);
if
(
false
==
$symbol
)
{
$currency
=
Yii
::
$app
->
request
->
post
(
'currency'
,
''
);
$base_currency
=
Yii
::
$app
->
request
->
post
(
'base_currency'
,
''
);
$exchange
=
Yii
::
$app
->
request
->
post
(
"exchange"
,
'Zhaobi'
);
if
(
false
==
$currency
||
false
==
$base_currency
)
{
$msg
=
'invalid symbol'
;
$code
=
-
1
;
goto
doEnd
;
}
$builder
=
ExchangeBuilderFactory
::
create
(
'Zhaobi'
);
$result
=
$builder
->
getDetail
(
$symbol
);
if
(
-
1
==
$result
[
'code'
]){
$result
=
$builder
->
getDetail
(
strtoupper
(
$currency
),
strtoupper
(
$base_currency
)
);
if
(
-
1
==
$result
[
'code'
])
{
$msg
=
'invalid symbol'
;
$code
=
-
1
;
goto
doEnd
;
...
...
common/service/exchange/factory/FactoryService.php
View file @
75649d9a
...
...
@@ -13,7 +13,7 @@ use linslin\yii2\curl\Curl;
abstract
class
FactoryService
{
protected
$code
=
-
1
;
protected
$basic_coin
=
[
'ETH'
,
'BTC'
,
'USDT'
,
'BTY'
,
'CNYT'
];
protected
$basic_coin
=
[
'ETH'
,
'BTC'
,
'USDT'
,
'BTY'
,
'CNYT'
,
'CCNY'
];
protected
$basic_price
=
[];
protected
$redis
;
...
...
common/service/exchange/factory/ZhaobiBuilder.php
View file @
75649d9a
...
...
@@ -167,14 +167,109 @@ class ZhaobiBuilder extends FactoryService
return
[
'code'
=>
$this
->
code
,
'notice'
=>
$data
];
}
public
function
getDetail
(
$symbol
)
/*
* @params $currency 交易货币
* @params $base_currency 基础货币
*/
public
function
getDetail
(
$currency
,
$base_currency
)
{
list
(
$low
,
$high
,
$close
,
$open
,
$vol
)
=
$this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$symbol
),
'low'
,
'high'
,
'last'
,
'open'
,
'vol'
);
if
(
empty
(
$low
)
&&
empty
(
$high
)
&&
empty
(
$close
)
&&
empty
(
$open
)
&&
empty
(
$vol
))
{
return
[
'code'
=>
$this
->
code
,
'ticker'
=>
[]];
$code
=
0
;
$ticker
=
[];
$symbol
=
$currency
.
$base_currency
;
list
(
$low
,
$high
,
$close
,
$open
)
=
$this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$symbol
),
'low'
,
'high'
,
'last'
,
'open'
);
if
(
empty
(
$low
)
&&
empty
(
$high
)
&&
empty
(
$close
)
&&
empty
(
$open
))
{
if
(
$this
->
basic_coin
[
2
]
==
$currency
)
{
//交易货币为USDT
$symbol
=
$base_currency
.
$this
->
basic_coin
[
2
];
list
(
$low
,
$high
,
$close
,
$open
)
=
$this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$symbol
),
'low'
,
'high'
,
'last'
,
'open'
);
if
(
!
empty
(
$low
)
&&
!
empty
(
$high
)
&&
!
empty
(
$close
)
&&
!
empty
(
$open
))
{
$low
=
number_format
(
1
/
$low
,
6
,
'.'
,
''
);
$high
=
number_format
(
1
/
$high
,
6
,
'.'
,
''
);
$open
=
number_format
(
1
/
$open
,
6
,
'.'
,
''
);
$close
=
number_format
(
1
/
$close
,
6
,
'.'
,
''
);
$ticker
=
[
'low'
=>
$low
,
'high'
=>
$high
,
'open'
=>
$open
,
'close'
=>
$close
];
goto
doEnd
;
}
}
if
(
$this
->
basic_coin
[
5
]
==
$base_currency
)
{
//基础货币为CCNY
$symbol_currency
=
$currency
.
$this
->
basic_coin
[
2
];
$symbol_base_currency
=
$this
->
basic_coin
[
2
]
.
$base_currency
;
list
(
$low_currency
,
$high_currency
,
$close_currency
,
$open_currency
)
=
$this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$symbol_currency
),
'low'
,
'high'
,
'last'
,
'open'
);
if
(
empty
(
$low_currency
)
&&
empty
(
$high_currency
)
&&
empty
(
$close_currency
)
&&
empty
(
$open_currency
))
{
$code
=
$this
->
code
;
goto
doEnd
;
}
list
(
$low_base_currency
,
$high_base_currency
,
$close_base_currency
,
$open_base_currency
)
=
$this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$symbol_base_currency
),
'low'
,
'high'
,
'last'
,
'open'
);
if
(
empty
(
$low_base_currency
)
&&
empty
(
$high_base_currency
)
&&
empty
(
$close_base_currency
)
&&
empty
(
$open_base_currency
))
{
$code
=
$this
->
code
;
goto
doEnd
;
}
$low
=
number_format
(
$low_currency
*
$low_base_currency
,
6
,
'.'
,
''
);
$high
=
number_format
(
$high_currency
*
$high_base_currency
,
6
,
'.'
,
''
);
$close
=
number_format
(
$close_currency
*
$close_base_currency
,
6
,
'.'
,
''
);
$open
=
number_format
(
$open_currency
*
$open_base_currency
,
6
,
'.'
,
''
);
$ticker
=
[
'low'
=>
$low
,
'high'
=>
$high
,
'open'
=>
$open
,
'close'
=>
$close
];
goto
doEnd
;
}
if
(
$this
->
basic_coin
[
5
]
==
$currency
)
{
//交易货币为CCNY
$symbol_currency
=
$base_currency
.
$this
->
basic_coin
[
2
];
$symbol_base_currency
=
$this
->
basic_coin
[
2
]
.
$currency
;
if
(
$currency
.
$base_currency
==
'CCNYUSDT'
)
{
list
(
$low
,
$high
,
$close
,
$open
)
=
$this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$base_currency
.
$currency
),
'low'
,
'high'
,
'last'
,
'open'
);
if
(
empty
(
$low
)
&&
empty
(
$high
)
&&
empty
(
$close
)
&&
empty
(
$open
))
{
$code
=
$this
->
code
;
goto
doEnd
;
}
$low
=
number_format
(
1
/
$low
,
6
,
'.'
,
''
);
$high
=
number_format
(
1
/
$high
,
6
,
'.'
,
''
);
$close
=
number_format
(
1
/
$close
,
6
,
'.'
,
''
);
$open
=
number_format
(
1
/
$open
,
6
,
'.'
,
''
);
$ticker
=
[
'low'
=>
$low
,
'high'
=>
$high
,
'open'
=>
$open
,
'close'
=>
$close
];
goto
doEnd
;
}
list
(
$low_currency
,
$high_currency
,
$close_currency
,
$open_currency
)
=
$this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$symbol_currency
),
'low'
,
'high'
,
'last'
,
'open'
);
if
(
empty
(
$low_currency
)
&&
empty
(
$high_currency
)
&&
empty
(
$close_currency
)
&&
empty
(
$open_currency
))
{
$code
=
$this
->
code
;
goto
doEnd
;
}
list
(
$low_base_currency
,
$high_base_currency
,
$close_base_currency
,
$open_base_currency
)
=
$this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$symbol_base_currency
),
'low'
,
'high'
,
'last'
,
'open'
);
if
(
empty
(
$low_base_currency
)
&&
empty
(
$high_base_currency
)
&&
empty
(
$close_base_currency
)
&&
empty
(
$open_base_currency
))
{
$code
=
$this
->
code
;
goto
doEnd
;
}
$low
=
number_format
(
1
/
$low_currency
*
$low_base_currency
,
6
,
'.'
,
''
);
$high
=
number_format
(
1
/
$high_currency
*
$high_base_currency
,
6
,
'.'
,
''
);
$close
=
number_format
(
1
/
$close_currency
*
$close_base_currency
,
6
,
'.'
,
''
);
$open
=
number_format
(
1
/
$open_currency
*
$open_base_currency
,
6
,
'.'
,
''
);
$ticker
=
[
'low'
=>
$low
,
'high'
=>
$high
,
'open'
=>
$open
,
'close'
=>
$close
];
goto
doEnd
;
}
doEnd
:
return
[
'code'
=>
$code
,
'ticker'
=>
$ticker
];
}
$ticker
=
[
'vol'
=>
$vol
,
'low'
=>
$low
,
'open'
=>
$open
,
'high'
=>
$high
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment