Skip to content

Commit a74279e

Browse files
author
Raunak Gupta
committed
Dev - added pagination in order fetch API.
1 parent d53210a commit a74279e

File tree

5 files changed

+88
-27
lines changed

5 files changed

+88
-27
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
'braces' => true,
1212
'cast_spaces' => true,
1313
'concat_space' => [
14-
'spacing' => 'none',
14+
'spacing' => 'one',
1515
],
1616
'declare_equal_normalize' => true,
1717
'elseif' => true,

README.md

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,59 @@
11
# WazirX Portfolio Tracker
22

3-
Free and open source solution to track your Wazirx Portfolio
3+
**Free and open source solution to track your Wazirx Portfolio.**
4+
5+
![wazirx rofit tracker thumbnail](screenshots/table-view.png "Sample Portfolio Overview")
6+
7+
Are you using WazirX for cryptocurrency trading? If yes, then you know that it only provides the list of crypto that you hold with quantity but did not tell you, that you are in a profit or lose or how your portfolio is doing overtime.
8+
So you can use this tool to get that details.
9+
10+
Oh, that's great but for this do I have to spin a server and install it?
11+
If you want you can do that but you can use [this link](), where I have already made it accessible for all the non-technical people.
12+
13+
### Features include:
14+
15+
Track all your crypto assets growth of WazirX exchange in one go. You can filter it or order/sort it based on profit, amount spend, etc.
16+
17+
Oh, that's great, but I think it is missing this thing, or if you can add this it will make much more sense.
18+
Sure, please let me know [here](https://github.com/finallyRaunak/wazirx-portfolio-tracker/discussions/new) so that I can review and see how it can be incorporated.
19+
20+
### Why this?
21+
22+
It is a simple tool to take a quick snap of your portfolio.
23+
24+
# Demo
25+
26+
- You can see a live preview from [here]()
27+
- You can also check this [screenshot](screenshots/full-page-view.png)
428

529
# Installation
630

7-
- Download the the zip
31+
- Download the zip
832
- Extract the zip
9-
- From cli cd to the extracted dir
33+
- From CLI cd to the extracted dir
1034
- run composer install
1135
- Update the `BASE_URL` in `src/constants.php` file.
36+
- Now Navigate to your site (_which you have defined in `BASE_URL`_) and see the report.
1237

1338
# Donate
1439

40+
Like it? considering donating a few dollars (even 1 USDT) keeps us motivated to build such a tool that can ease up your crypto journey.
41+
You can donate to the below given address.
42+
1543
| Currency | Network | Address |
1644
|----------|---------|----------------------------------------------|
17-
| BUSD | BEP20 | `0x4Fabb145d64652a948d72533023f6E7A623C7C53` |
18-
| USDT | BEP20 | |
19-
| USDT | TRC20 | |
45+
| ETH | BEP20 | `0x162AB205bb9fac0e423F31C7e5E974E649E5980c` |
46+
| BUSD | BEP20 | `0x162AB205bb9fac0e423F31C7e5E974E649E5980c` |
47+
| USDT | ERC20 | `0x162AB205bb9fac0e423F31C7e5E974E649E5980c` |
48+
| USDT | BEP20 | `0x162AB205bb9fac0e423F31C7e5E974E649E5980c` |
49+
| USDT | TRC20 | `TQVWzF8iXmYSwNmAkBNfKMpv9YwRjSWXtq` |
2050

2151

2252
# Disclaimer
53+
2354
- This is an unofficial WazirX Portfolio Tracker which enhances the wallet user experience. The brand and copyright of the word "WazirX" belong to WazirX (https://wazirx.com).
24-
- I do not recommend that any cryptocurrency should be bought, sold, or held by you. Do conduct your own due diligence and consult your financial advisor before making any investment decisions.
55+
- I do not recommend that any cryptocurrency should be bought, sold, or held by you. Do conduct your due diligence and consult your financial advisor before making any investment decisions.
56+
57+
# License
58+
59+
wazirx-portfolio-tracker is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

src/BalanceSheet.php

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
class BalanceSheet
99
{
10+
private $orderArr;
11+
1012
public function index()
1113
{
1214
$this->render_view('wrx', [
@@ -75,8 +77,8 @@ public function getMarketPrice(array $cryptoList, array $tradingPair): array
7577
if ($crypto == 'wrx' && $base == 'wrx') {
7678
continue;
7779
}
78-
$location = array_search($crypto.$base, array_column($tickers, 'symbol'));
79-
$price[$crypto.'/'.$base]['current_price'] = $tickers[$location]['bidPrice'];
80+
$location = array_search($crypto . $base, array_column($tickers, 'symbol'));
81+
$price[$crypto . '/' . $base]['current_price'] = $tickers[$location]['bidPrice'];
8082
}
8183
}
8284

@@ -112,10 +114,14 @@ private function pullOrders($wrx, string $crypto, array $tradingPair)
112114
{
113115
$price = [];
114116
foreach ($tradingPair as $base) {
115-
if (!$wrx->isValidTradingPair($crypto.$base)) {
117+
$this->orderArr = [];
118+
119+
if (!$wrx->isValidTradingPair($crypto . $base)) {
116120
continue;
117121
}
118-
$orders = $wrx->getOrders($crypto.$base);
122+
123+
$orders = $this->getSequentialOrders($wrx, $crypto . $base, 0);
124+
119125
$qty = $invest = 0;
120126
if (empty($orders) || (!empty($orders['code']) && ($orders['code'] == 1999))) {
121127
continue;
@@ -141,11 +147,11 @@ private function pullOrders($wrx, string $crypto, array $tradingPair)
141147
if (empty($qty)) {
142148
continue;
143149
}
144-
$price[$crypto.'/'.$base] = [
150+
$price[$crypto . '/' . $base] = [
145151
'dca' => $invest / $qty,
146152
'qty' => $qty,
147153
];
148-
$price[$crypto.'/'.$base]['investment'] = $price[$crypto.'/'.$base]['dca'] * $price[$crypto.'/'.$base]['qty'];
154+
$price[$crypto . '/' . $base]['investment'] = $price[$crypto . '/' . $base]['dca'] * $price[$crypto . '/' . $base]['qty'];
149155
}
150156

151157
return $price;
@@ -216,6 +222,23 @@ public function jsonToTable(array $invests, float $usableBalance): void
216222
public function render_view(string $view, array $data = []): void
217223
{
218224
extract($data);
219-
require 'views/'.$view.'.php';
225+
require 'views/' . $view . '.php';
226+
}
227+
228+
private function getSequentialOrders($wrx, string $symbol, int $fromOrderID)
229+
{
230+
$orders = $wrx->getOrders($symbol, ($fromOrderID + 1));
231+
if (empty($orders) || (!empty($orders['code']) && ($orders['code'] == 1999))) {
232+
return $this->orderArr;
233+
}
234+
235+
$this->orderArr = array_merge($this->orderArr, $orders);
236+
if (count($orders) == 1000) {
237+
$this->orderArr = array_merge($this->orderArr, $orders);
238+
$fromOrderID = $orders[count($orders) - 1]['id'];
239+
$this->getSequentialOrders($wrx, $symbol, $fromOrderID);
240+
}
241+
242+
return $this->orderArr;
220243
}
221244
}

src/Wrx.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ final class Wrx
5050
protected function __construct(string $apiKey = null, string $apiSecret = null)
5151
{
5252
CacheManager::setDefaultConfig(new ConfigurationOption([
53-
'path' => __DIR__.DIRECTORY_SEPARATOR.'cache',
53+
'path' => __DIR__ . DIRECTORY_SEPARATOR . 'cache',
5454
'defaultChmod' => 0755,
5555
'itemDetailedDate' => true,
5656
]));
@@ -98,7 +98,7 @@ public static function getInstance(string $apiKey = null, string $apiSecret = nu
9898
*/
9999
public function getFunds(): array
100100
{
101-
$cacheKey = md5($this->apiKey).'-funds';
101+
$cacheKey = md5($this->apiKey) . '-funds';
102102

103103
$this->fields = [
104104
'timestamp' => round(microtime(true) * 1000),
@@ -108,7 +108,7 @@ public function getFunds(): array
108108
$this->fields['signature'] = hash_hmac('sha256', http_build_query($this->fields), $this->apiSecret);
109109

110110
$this->headers = [
111-
'X-Api-Key: '.$this->apiKey,
111+
'X-Api-Key: ' . $this->apiKey,
112112
'Content-Type: application/x-www-form-urlencoded',
113113
];
114114

@@ -129,7 +129,7 @@ public function getFunds(): array
129129
*/
130130
private function removeDust(string $cacheKey): array
131131
{
132-
$cachedStr = $this->cacheAdapter->getItem($cacheKey.'-actual');
132+
$cachedStr = $this->cacheAdapter->getItem($cacheKey . '-actual');
133133

134134
if ($cachedStr->isHit()) {
135135
return $cachedStr->get();
@@ -165,7 +165,7 @@ private function removeDust(string $cacheKey): array
165165
*/
166166
public function ticker(string $symbol): array
167167
{
168-
$cacheKey = 'ticker-'.$symbol;
168+
$cacheKey = 'ticker-' . $symbol;
169169
$this->fields = [
170170
'symbol' => $symbol,
171171
];
@@ -198,27 +198,30 @@ public function tickers(): array
198198
* Method to return all the orders of a specific trading pair like BTCINR, BTTCUSDT, etc., from WazirX.
199199
*
200200
* @param string $symbol
201+
* @param int $orderId
202+
*
201203
* @return array
202204
* @throws PhpfastcacheInvalidArgumentException
203205
* @throws PhpfastcacheLogicException
204206
* @throws \Psr\Cache\InvalidArgumentException
205207
*/
206-
public function getOrders(string $symbol): array
208+
public function getOrders(string $symbol, int $orderId = 0): array
207209
{
208-
$cacheKey = md5($this->apiKey).'-'.$symbol.'-order';
210+
$cacheKey = md5($this->apiKey) . '-' . $symbol . '-order-' . $orderId;
209211

210212
$this->fields = [
211213
'symbol' => $symbol,
212214
'timestamp' => round(microtime(true) * 1000),
213215
'recvWindow' => 60000,
214216
'limit' => 1000,
217+
'orderId' => $orderId,
215218
];
216219
$encodedPayload = hash_hmac('sha256', http_build_query($this->fields), $this->apiSecret);
217220

218221
$this->fields['signature'] = $encodedPayload;
219222

220223
$this->headers = [
221-
'X-Api-Key: '.$this->apiKey,
224+
'X-Api-Key: ' . $this->apiKey,
222225
'Content-Type: application/x-www-form-urlencoded',
223226
];
224227

@@ -247,7 +250,7 @@ private function request(string $path, string $cacheKey, int $duration = 10): ar
247250
}
248251
sleep(2);
249252
$ch = curl_init();
250-
curl_setopt($ch, CURLOPT_URL, $this->apiURL.$path);
253+
curl_setopt($ch, CURLOPT_URL, $this->apiURL . $path);
251254
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
252255
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
253256
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

src/utility.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function pr($param = [], $continue = true, string $label = null)
1313
return null;
1414
}
1515
if (!empty($label)) {
16-
echo '<p>-- '.$label.' --</p>';
16+
echo '<p>-- ' . $label . ' --</p>';
1717
}
1818

1919
echo '<pre>';
@@ -58,7 +58,7 @@ function getHeaders($respHeaders): array
5858
*/
5959
function getSiteURL(string $uri = '/'): string
6060
{
61-
return rtrim(BASE_URL, '/').'/'.ltrim($uri, '/');
61+
return rtrim(BASE_URL, '/') . '/' . ltrim($uri, '/');
6262
}
6363

6464
/**
@@ -68,7 +68,7 @@ function getSiteURL(string $uri = '/'): string
6868
*/
6969
function getAssetURI(string $uri): string
7070
{
71-
return rtrim(getSiteURL(), '/').'/src/views/'.ltrim($uri, '/');
71+
return rtrim(getSiteURL(), '/') . '/src/views/' . ltrim($uri, '/');
7272
}
7373

7474
/**

0 commit comments

Comments
 (0)