Skip to content

Commit 5a72f14

Browse files
authored
Merge pull request #71 from c2s/master
Add margin trade
2 parents 93f4d67 + 3450d01 commit 5a72f14

File tree

3 files changed

+680
-1
lines changed

3 files changed

+680
-1
lines changed

src/Api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ abstract class Api
1616
/**
1717
* @var string SDK Version
1818
*/
19-
const VERSION = '1.1.11';
19+
const VERSION = '1.1.12';
2020

2121
/**
2222
* @var string

src/PrivateApi/Margin.php

Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,304 @@
1+
<?php
2+
3+
namespace KuCoin\SDK\PrivateApi;
4+
5+
6+
use KuCoin\SDK\Http\Request;
7+
use KuCoin\SDK\KuCoinApi;
8+
9+
10+
/**
11+
* Class Margin
12+
* @package KuCoin\SDK\PrivateApi
13+
* @see https://docs.kucoin.com/#margin-info
14+
*/
15+
class Margin extends KuCoinApi
16+
{
17+
/**
18+
* Get Mark Price.
19+
*
20+
* @param string $symbol Symbol
21+
* @return array
22+
* @throws \KuCoin\SDK\Exceptions\BusinessException
23+
* @throws \KuCoin\SDK\Exceptions\HttpException
24+
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
25+
*/
26+
public function getMarkPrice($symbol)
27+
{
28+
$response = $this->call(Request::METHOD_GET, sprintf('/api/v1/mark-price/%s/current', $symbol));
29+
return $response->getApiData();
30+
}
31+
32+
/**
33+
* Get Margin Configuration Info.
34+
*
35+
* @return mixed
36+
* @throws \KuCoin\SDK\Exceptions\BusinessException
37+
* @throws \KuCoin\SDK\Exceptions\HttpException
38+
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
39+
*/
40+
public function getConfig()
41+
{
42+
$response = $this->call(Request::METHOD_GET, '/api/v1/margin/config');
43+
return $response->getApiData();
44+
}
45+
46+
47+
/**
48+
* Get Margin Account
49+
*
50+
* @return mixed
51+
* @throws \KuCoin\SDK\Exceptions\BusinessException
52+
* @throws \KuCoin\SDK\Exceptions\HttpException
53+
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
54+
*/
55+
public function getAccount()
56+
{
57+
$response = $this->call(Request::METHOD_GET, '/api/v1/margin/account');
58+
return $response->getApiData();
59+
}
60+
61+
/**
62+
* Post Borrow Order.
63+
*
64+
* @param array $params
65+
* @return mixed
66+
* @throws \KuCoin\SDK\Exceptions\BusinessException
67+
* @throws \KuCoin\SDK\Exceptions\HttpException
68+
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
69+
*/
70+
public function borrow(array $params)
71+
{
72+
$response = $this->call(Request::METHOD_POST, '/api/v1/margin/borrow', $params);
73+
return $response->getApiData();
74+
}
75+
76+
/**
77+
* Get Borrow Order
78+
*
79+
* @param string $orderId
80+
* @return mixed
81+
* @throws \KuCoin\SDK\Exceptions\BusinessException
82+
* @throws \KuCoin\SDK\Exceptions\HttpException
83+
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
84+
*/
85+
public function getBorrow($orderId)
86+
{
87+
$response = $this->call(Request::METHOD_GET, '/api/v1/margin/borrow', compact('orderId'));
88+
return $response->getApiData();
89+
}
90+
91+
/**
92+
* Get Repay Record.
93+
*
94+
* @param string $currency Currency
95+
* @return mixed
96+
* @throws \KuCoin\SDK\Exceptions\BusinessException
97+
* @throws \KuCoin\SDK\Exceptions\HttpException
98+
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
99+
*/
100+
public function getOutstanding($currency)
101+
{
102+
$response = $this->call(Request::METHOD_GET, '/api/v1/margin/borrow/outstanding', compact('currency'));
103+
return $response->getApiData();
104+
}
105+
106+
/**
107+
* Get Repayment Record.
108+
*
109+
* @param string $currency Currency
110+
* @return mixed
111+
* @throws \KuCoin\SDK\Exceptions\BusinessException
112+
* @throws \KuCoin\SDK\Exceptions\HttpException
113+
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
114+
*/
115+
public function getRepayRecord($currency)
116+
{
117+
$response = $this->call(Request::METHOD_GET, '/api/v1/margin/borrow/repaid', compact('currency'));
118+
return $response->getApiData();
119+
}
120+
121+
/**
122+
* One-Click Repayment
123+
*
124+
* @param array $params Params
125+
* @return mixed
126+
* @throws \KuCoin\SDK\Exceptions\BusinessException
127+
* @throws \KuCoin\SDK\Exceptions\HttpException
128+
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
129+
*/
130+
public function repayAll(array $params)
131+
{
132+
$response = $this->call(Request::METHOD_POST, '/api/v1/margin/repay/all', $params);
133+
return $response->getApiData();
134+
}
135+
136+
/**
137+
* Repay a Single Order
138+
*
139+
* @param array $params Params
140+
* @return mixed
141+
* @throws \KuCoin\SDK\Exceptions\BusinessException
142+
* @throws \KuCoin\SDK\Exceptions\HttpException
143+
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
144+
*/
145+
public function repaySingle(array $params)
146+
{
147+
$response = $this->call(Request::METHOD_POST, '/api/v1/margin/repay/single', $params);
148+
return $response->getApiData();
149+
}
150+
151+
/**
152+
* Post Lend Order.
153+
*
154+
* @param array $params
155+
* @return mixed
156+
* @throws \KuCoin\SDK\Exceptions\BusinessException
157+
* @throws \KuCoin\SDK\Exceptions\HttpException
158+
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
159+
*/
160+
public function lend(array $params)
161+
{
162+
$response = $this->call(Request::METHOD_POST, '/api/v1/margin/lend', $params);
163+
return $response->getApiData();
164+
}
165+
166+
/**
167+
* Cancel Lend Order.
168+
*
169+
* @param string $orderId Lend order ID
170+
* @return mixed
171+
* @throws \KuCoin\SDK\Exceptions\BusinessException
172+
* @throws \KuCoin\SDK\Exceptions\HttpException
173+
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
174+
*/
175+
public function cancelLend($orderId)
176+
{
177+
$response = $this->call(Request::METHOD_DELETE, '/api/v1/margin/lend/' . $orderId);
178+
return $response->getApiData();
179+
}
180+
181+
/**
182+
* Set Auto-lend.
183+
*
184+
* @param array $params
185+
* @return mixed
186+
* @throws \KuCoin\SDK\Exceptions\BusinessException
187+
* @throws \KuCoin\SDK\Exceptions\HttpException
188+
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
189+
*/
190+
public function setAutoLend(array $params)
191+
{
192+
$response = $this->call(Request::METHOD_POST, '/api/v1/margin/toggle-auto-lend', $params);
193+
return $response->getApiData();
194+
}
195+
196+
/**
197+
* Get Active Order.
198+
*
199+
* @param array $params
200+
* @param array $pagination
201+
* @return mixed
202+
* @throws \KuCoin\SDK\Exceptions\BusinessException
203+
* @throws \KuCoin\SDK\Exceptions\HttpException
204+
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
205+
*/
206+
public function getLendActive(array $params, array $pagination = [])
207+
{
208+
$response = $this->call(Request::METHOD_GET, '/api/v1/margin/lend/active', $params + $pagination);
209+
return $response->getApiData();
210+
}
211+
212+
/**
213+
* Get Lent History.
214+
*
215+
* @param array $params
216+
* @param array $pagination
217+
* @return mixed
218+
* @throws \KuCoin\SDK\Exceptions\BusinessException
219+
* @throws \KuCoin\SDK\Exceptions\HttpException
220+
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
221+
*/
222+
public function getLendDone(array $params, array $pagination = [])
223+
{
224+
$response = $this->call(Request::METHOD_GET, '/api/v1/margin/lend/done', $params + $pagination);
225+
return $response->getApiData();
226+
}
227+
228+
/**
229+
* Get Active Lend Order List.
230+
*
231+
* @param array $params
232+
* @param array $pagination
233+
* @return mixed
234+
* @throws \KuCoin\SDK\Exceptions\BusinessException
235+
* @throws \KuCoin\SDK\Exceptions\HttpException
236+
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
237+
*/
238+
public function getUnsettled(array $params, array $pagination = [])
239+
{
240+
$response = $this->call(Request::METHOD_GET, '/api/v1/margin/lend/trade/unsettled', $params + $pagination);
241+
return $response->getApiData();
242+
}
243+
244+
/**
245+
* Get Settled Lend Order History
246+
*
247+
* @param array $params
248+
* @param array $pagination
249+
* @return mixed
250+
* @throws \KuCoin\SDK\Exceptions\BusinessException
251+
* @throws \KuCoin\SDK\Exceptions\HttpException
252+
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
253+
*/
254+
public function getSettled(array $params, array $pagination = [])
255+
{
256+
$response = $this->call(Request::METHOD_GET, '/api/v1/margin/lend/trade/settled', $params + $pagination);
257+
return $response->getApiData();
258+
}
259+
260+
/**
261+
* Get Account Lend Record
262+
*
263+
* @param string $currency
264+
* @return mixed
265+
* @throws \KuCoin\SDK\Exceptions\BusinessException
266+
* @throws \KuCoin\SDK\Exceptions\HttpException
267+
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
268+
*/
269+
public function getLendAssets($currency)
270+
{
271+
$response = $this->call(Request::METHOD_GET, '/api/v1/margin/lend/assets', compact('currency'));
272+
return $response->getApiData();
273+
}
274+
275+
/**
276+
* Lending Market Data.
277+
*
278+
* @param array $params
279+
* @return mixed
280+
* @throws \KuCoin\SDK\Exceptions\BusinessException
281+
* @throws \KuCoin\SDK\Exceptions\HttpException
282+
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
283+
*/
284+
public function getMarket(array $params)
285+
{
286+
$response = $this->call(Request::METHOD_GET, '/api/v1/margin/market', $params);
287+
return $response->getApiData();
288+
}
289+
290+
/**
291+
* Margin Trade Data
292+
*
293+
* @param string $currency
294+
* @return mixed
295+
* @throws \KuCoin\SDK\Exceptions\BusinessException
296+
* @throws \KuCoin\SDK\Exceptions\HttpException
297+
* @throws \KuCoin\SDK\Exceptions\InvalidApiUriException
298+
*/
299+
public function getTradeLast($currency)
300+
{
301+
$response = $this->call(Request::METHOD_GET, '/api/v1/margin/trade/last', compact('currency'));
302+
return $response->getApiData();
303+
}
304+
}

0 commit comments

Comments
 (0)