-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_utils.py
More file actions
139 lines (124 loc) · 5.6 KB
/
test_utils.py
File metadata and controls
139 lines (124 loc) · 5.6 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import time
import unittest
from tests.shared_test_setup import UnitTestBase
from tkpysdk import get_order_history, \
create_position, \
get_position_details, \
get_erc20_balance, \
get_order_book, \
create_order, remove_liquidity_and_burn
class UnitTestPositions(UnitTestBase):
def test_get_order_history(self):
order_history = get_order_history(api_key=self.API_KEY,
api_secret=self.API_SECRET,
network=self.NETWORK,
query={
'walletAddress': self.WALLET_ADDRESS
})
print(order_history)
self.assertIsNotNone(order_history)
def test_create_position(self):
post_body = {
'traderAddress': self.TRADER_ADDRESS,
'walletAddress': self.WALLET_ADDRESS,
'token0': self.TOKEN0,
'token1': self.TOKEN1,
'amount0Desired': 0.001,
'amount1Desired': 0,
'priceLower': '0.705',
'priceUpper': '0.95',
'fee': 3000,
'gasPrice': self.GAS_PRICE,
'estimateGasOnly': True, # set estimateGasOnly = False to actually send transactions on chain
}
position = create_position(api_key=self.API_KEY,
api_secret=self.API_SECRET,
network=self.NETWORK,
post_body=post_body)
print(position)
self.assertIsNotNone(position)
def test_get_position_details(self):
position_details = get_position_details(wallet_address=self.WALLET_ADDRESS,
network=self.NETWORK,
api_key=self.API_KEY,
api_secret=self.API_SECRET)
print(position_details)
self.assertIsNotNone(position_details)
def test_remove_liquidity_and_burn(self):
"""
Expected to be failed
@return:
"""
print(f'self.apikey: {self.API_KEY}')
post_body = {
'traderAddress': self.TRADER_ADDRESS,
'walletAddress': self.WALLET_ADDRESS,
'positionId': 2884,
'gasPrice': self.GAS_PRICE,
'estimateGasOnly': False, # set estimateGasOnly = False to actually send transactions on chain
}
result = remove_liquidity_and_burn(api_key=self.API_KEY,
api_secret=self.API_SECRET,
network=self.NETWORK,
post_body=post_body)
print(result)
self.assertEqual('Returned error: execution reverted: Invalid token ID', result)
class UnitTestQuote(UnitTestBase):
def test_get_erc20_balance(self):
result = get_erc20_balance(network=self.NETWORK,
query={
'walletAddress': self.WALLET_ADDRESS,
'erc20TokenAddress': self.TOKEN0,
},
api_secret=self.API_SECRET,
api_key=self.API_KEY)
print(result)
self.assertIsNotNone(result)
def test_get_order_book(self):
result = get_order_book(network=self.NETWORK,
query={
'symbol': 'CELO/cUSD',
'side': 'bid',
'amountUSD': 100,
},
api_secret=self.API_SECRET,
api_key=self.API_KEY)
self.order_book = result
print(f'result: {result}')
self.assertIsNotNone(result)
class UnitTestSwap(UnitTestBase):
def test_create_order(self):
order_book = get_order_book(network=self.NETWORK,
query={
'symbol': 'CELO/cUSD',
'side': 'bid',
'amountUSD': 100,
},
api_secret=self.API_SECRET,
api_key=self.API_KEY)
ask_price = order_book['bids'][0][0]
allowed_slippage = 0.001 # Replace with the actual value
wallet_address = self.WALLET_ADDRESS # Replace with the actual value
amount_in = 200 # Replace with the actual value
trader_address = self.TRADER_ADDRESS # Replace with the actual value
post_body = {
'routeHashes': [order_book['bids'][0][2]],
'expireTimestamp': int(time.time() + 12),
'walletAddress': wallet_address,
'amountIn': amount_in,
'amountOutMin': (amount_in / ask_price) * (1 - allowed_slippage),
'strategyId': 1,
'strategyType': 2,
'traderAddress': trader_address,
'newClientOrderId': f"test-{int(time.time())}",
'dynamicGasPrice': False,
'estimateGasOnly': True # set estimateGasOnly = False to actually send transactions on chain
}
result = create_order(api_key=self.API_KEY,
api_secret=self.API_SECRET,
network=self.NETWORK,
post_body=post_body)
print(result)
self.assertIsNotNone(result)
if __name__ == '__main__':
unittest.main()