Skip to content

Commit 5490cd5

Browse files
authored
Merge pull request #13 from fugle-dev/feature/technical
feat: add REST endpoints for stock technical API
2 parents ad96e79 + e9a2f59 commit 5490cd5

File tree

3 files changed

+129
-2
lines changed

3 files changed

+129
-2
lines changed

fugle_marketdata/rest/stock/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from .intraday import Intraday
22
from .historical import Historical
33
from .snapshot import Snapshot
4+
from .technical import Technical
45

56

67
class RestStockClient:
@@ -19,3 +20,7 @@ def historical(self):
1920
@property
2021
def snapshot(self):
2122
return Snapshot(**self.config)
23+
24+
@property
25+
def technical(self):
26+
return Technical(**self.config)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from ..base_rest import BaseRest
2+
3+
class Technical(BaseRest):
4+
def sma(self, **params):
5+
symbol = params.pop('symbol')
6+
return self.request(f"technical/sma/{symbol}", **params)
7+
8+
def rsi(self, **params):
9+
symbol = params.pop('symbol')
10+
return self.request(f"technical/rsi/{symbol}", **params)
11+
12+
def kdj(self, **params):
13+
symbol = params.pop('symbol')
14+
return self.request(f"technical/kdj/{symbol}", **params)
15+
16+
def macd(self, **params):
17+
symbol = params.pop('symbol')
18+
return self.request(f"technical/macd/{symbol}", **params)
19+
20+
def bb(self, **params):
21+
symbol = params.pop('symbol')
22+
return self.request(f"technical/bb/{symbol}", **params)

tests/test_http_client.py

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def test_intraday_volumes_api_key(self, mocker, api_key_client):
323323
'https://api.fugle.tw/marketdata/v1.0/futopt/intraday/volumes/2330',
324324
headers={'X-API-KEY': 'api-key'}
325325
)
326-
326+
327327
class TestFutOptRestHistoricalClient:
328328
def test_futopt_historical(self, api_key_client):
329329
futopt = api_key_client.futopt
@@ -364,4 +364,104 @@ def test_historical_daily_bearer_token(self, bearer_client, mocker):
364364
mock_get.assert_called_once_with(
365365
'https://api.fugle.tw/marketdata/v1.0/futopt/historical/daily/2330',
366366
headers={'Authorization': 'Bearer bearer-token'}
367-
)
367+
)
368+
369+
370+
class TestStockRestTechnicalClient:
371+
def test_stock_technical(self, api_key_client):
372+
stock = api_key_client.stock
373+
assert hasattr(stock.technical, 'sma')
374+
assert hasattr(stock.technical, 'rsi')
375+
assert hasattr(stock.technical, 'kdj')
376+
assert hasattr(stock.technical, 'macd')
377+
assert hasattr(stock.technical, 'bb')
378+
379+
def test_technical_sma_api_key(self, mocker, api_key_client):
380+
stock = api_key_client.stock
381+
mock_get = mocker.patch('requests.get')
382+
stock.technical.sma(symbol='2330')
383+
mock_get.assert_called_once_with(
384+
'https://api.fugle.tw/marketdata/v1.0/stock/technical/sma/2330',
385+
headers={'X-API-KEY': 'api-key'}
386+
)
387+
388+
def test_technical_sma_bearer_token(self, mocker, bearer_client):
389+
stock = bearer_client.stock
390+
mock_get = mocker.patch('requests.get')
391+
stock.technical.sma(symbol='2330')
392+
mock_get.assert_called_once_with(
393+
'https://api.fugle.tw/marketdata/v1.0/stock/technical/sma/2330',
394+
headers={'Authorization': 'Bearer bearer-token'}
395+
)
396+
397+
def test_technical_rsi_api_key(self, mocker, api_key_client):
398+
stock = api_key_client.stock
399+
mock_get = mocker.patch('requests.get')
400+
stock.technical.rsi(symbol='2330')
401+
mock_get.assert_called_once_with(
402+
'https://api.fugle.tw/marketdata/v1.0/stock/technical/rsi/2330',
403+
headers={'X-API-KEY': 'api-key'}
404+
)
405+
406+
def test_technical_rsi_bearer_token(self, mocker, bearer_client):
407+
stock = bearer_client.stock
408+
mock_get = mocker.patch('requests.get')
409+
stock.technical.rsi(symbol='2330')
410+
mock_get.assert_called_once_with(
411+
'https://api.fugle.tw/marketdata/v1.0/stock/technical/rsi/2330',
412+
headers={'Authorization': 'Bearer bearer-token'}
413+
)
414+
415+
def test_technical_kdj_api_key(self, mocker, api_key_client):
416+
stock = api_key_client.stock
417+
mock_get = mocker.patch('requests.get')
418+
stock.technical.kdj(symbol='2330')
419+
mock_get.assert_called_once_with(
420+
'https://api.fugle.tw/marketdata/v1.0/stock/technical/kdj/2330',
421+
headers={'X-API-KEY': 'api-key'}
422+
)
423+
424+
def test_technical_kdj_bearer_token(self, mocker, bearer_client):
425+
stock = bearer_client.stock
426+
mock_get = mocker.patch('requests.get')
427+
stock.technical.kdj(symbol='2330')
428+
mock_get.assert_called_once_with(
429+
'https://api.fugle.tw/marketdata/v1.0/stock/technical/kdj/2330',
430+
headers={'Authorization': 'Bearer bearer-token'}
431+
)
432+
433+
def test_technical_macd_api_key(self, mocker, api_key_client):
434+
stock = api_key_client.stock
435+
mock_get = mocker.patch('requests.get')
436+
stock.technical.macd(symbol='2330')
437+
mock_get.assert_called_once_with(
438+
'https://api.fugle.tw/marketdata/v1.0/stock/technical/macd/2330',
439+
headers={'X-API-KEY': 'api-key'}
440+
)
441+
442+
def test_technical_macd_bearer_token(self, mocker, bearer_client):
443+
stock = bearer_client.stock
444+
mock_get = mocker.patch('requests.get')
445+
stock.technical.macd(symbol='2330')
446+
mock_get.assert_called_once_with(
447+
'https://api.fugle.tw/marketdata/v1.0/stock/technical/macd/2330',
448+
headers={'Authorization': 'Bearer bearer-token'}
449+
)
450+
451+
def test_technical_bb_api_key(self, mocker, api_key_client):
452+
stock = api_key_client.stock
453+
mock_get = mocker.patch('requests.get')
454+
stock.technical.bb(symbol='2330')
455+
mock_get.assert_called_once_with(
456+
'https://api.fugle.tw/marketdata/v1.0/stock/technical/bb/2330',
457+
headers={'X-API-KEY': 'api-key'}
458+
)
459+
460+
def test_technical_bb_bearer_token(self, mocker, bearer_client):
461+
stock = bearer_client.stock
462+
mock_get = mocker.patch('requests.get')
463+
stock.technical.bb(symbol='2330')
464+
mock_get.assert_called_once_with(
465+
'https://api.fugle.tw/marketdata/v1.0/stock/technical/bb/2330',
466+
headers={'Authorization': 'Bearer bearer-token'}
467+
)

0 commit comments

Comments
 (0)