-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtests.py
98 lines (75 loc) · 2.76 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import os
import unittest
from oplab import Client
c = Client()
c.login(os.environ['USER'], os.environ['PASSWORD'])
# getting orders
class TestOrderMethods(unittest.TestCase):
def test_get_portfolio_orders(self):
"""
Portfolio orders should return an array
"""
orders = c.domain.get_portfolio_orders(14915)
self.assertIsInstance(orders, list)
class TestHistoricalDataMethods(unittest.TestCase):
def test_get_historical_data(self):
"""
Should return last 252 days of historical data
"""
data = c.domain.get_historical_data('PETR4', 252)
self.assertEqual(len(data['data']), 252)
class TestOrderMethods(unittest.TestCase):
def test_create_order(self):
"""
Should return a newly created order with the same symbol
"""
created_order = c.domain.create_order(
{'symbol': 'PETR4', 'price': 20, 'amount': 100, 'direction': 'buy', 'order_type': 'test', 'status': 'executed'}, 14915)
self.assertEqual(created_order['symbol'], 'PETR4')
class TestPortfoliosMethods(unittest.TestCase):
def test_get_portfolios(self):
"""
Should return an array of portfolios
"""
portfolios = c.domain.get_portfolios()
self.assertIsInstance(portfolios, list)
def test_get_portfolio(self):
"""
Should return a portfolio
"""
portfolios = c.domain.get_portfolios()
portfolio_id = portfolios[0]['id']
portfolio = c.domain.get_portfolio(portfolio_id)
print(portfolio)
self.assertIsInstance(portfolio, dict)
class TestMarketEndpoints(unittest.TestCase):
def test_base_url(self):
"""
Should return https://api.oplab.com.br/v3/market
as default market url.
"""
self.assertEqual(c.market.url(), 'https://api.oplab.com.br/v3/market')
def test_historical_options(self):
options = c.market.historical_options('PETZ3')
self.assertIsInstance(
options, list)
class TestDomainEndpoints(unittest.TestCase):
def test_base_url(self):
"""
Should return https://api.oplab.com.br/v3/domain
as default domain url.
"""
self.assertEqual(c.domain.url(), 'https://api.oplab.com.br/v3/domain')
def test_get_portfolio_orders(self):
portfolio = c.domain.get_portfolios()[-1]
self.assertIsInstance(
c.domain.get_portfolio_orders(portfolio['id']), list)
class TestQuantEndpoints(unittest.TestCase):
def test_base_url(self):
"""
Should return https://api.oplab.com.br/v3/quant
as default domain url.
"""
self.assertEqual(c.quant.url(), 'https://api.oplab.com.br/v3/quant')
if __name__ == '__main__':
unittest.main()