feat: redesign crypto market with synced favorites
This commit is contained in:
@@ -2,12 +2,59 @@
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\logic\CryptoLogic;
|
||||
use app\api\validate\CryptoValidate;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Log;
|
||||
|
||||
class CryptoController extends BaseApiController
|
||||
{
|
||||
public array $notNeedLogin = ['proxy'];
|
||||
public array $notNeedLogin = ['proxy', 'market'];
|
||||
|
||||
/**
|
||||
* 人民币加密行情与市场概览
|
||||
*/
|
||||
public function market()
|
||||
{
|
||||
try {
|
||||
return $this->data(CryptoLogic::market());
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('[CryptoMarket] controller failed: ' . $e->getMessage());
|
||||
return $this->fail('行情加载失败,请稍后重试');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前账号的加密自选列表
|
||||
*/
|
||||
public function favorites()
|
||||
{
|
||||
return $this->data(['symbols' => CryptoLogic::favorites($this->userId)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加入加密自选
|
||||
*/
|
||||
public function addFavorite()
|
||||
{
|
||||
$params = (new CryptoValidate())->post()->goCheck('favorite');
|
||||
if (!CryptoLogic::addFavorite($this->userId, (string) $params['symbol'])) {
|
||||
return $this->fail(CryptoLogic::getError());
|
||||
}
|
||||
return $this->success('已加入自选');
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消加密自选
|
||||
*/
|
||||
public function cancelFavorite()
|
||||
{
|
||||
$params = (new CryptoValidate())->post()->goCheck('favorite');
|
||||
if (!CryptoLogic::cancelFavorite($this->userId, (string) $params['symbol'])) {
|
||||
return $this->fail(CryptoLogic::getError());
|
||||
}
|
||||
return $this->success('已取消自选');
|
||||
}
|
||||
|
||||
/**
|
||||
* Binance API 代理(解决客户端直连被墙问题)
|
||||
|
||||
Reference in New Issue
Block a user