/php/bitvavo.php

https://github.com/kroitor/ccxt · PHP · 1507 lines · 937 code · 37 blank · 533 comment · 79 complexity · 81d73c45efb07f563dfb39b1a5bc31b7 MD5 · raw file

Large files are truncated click here to view the full file

  1. <?php
  2. namespace ccxt;
  3. // PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
  4. // https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
  5. use Exception; // a common import
  6. use \ccxt\ExchangeError;
  7. use \ccxt\ArgumentsRequired;
  8. class bitvavo extends Exchange {
  9. public function describe() {
  10. return $this->deep_extend(parent::describe (), array(
  11. 'id' => 'bitvavo',
  12. 'name' => 'Bitvavo',
  13. 'countries' => array( 'NL' ), // Netherlands
  14. 'rateLimit' => 500,
  15. 'version' => 'v2',
  16. 'certified' => true,
  17. 'pro' => true,
  18. 'has' => array(
  19. 'CORS' => false,
  20. 'publicAPI' => true,
  21. 'privateAPI' => true,
  22. 'cancelAllOrders' => true,
  23. 'cancelOrder' => true,
  24. 'createOrder' => true,
  25. 'editOrder' => true,
  26. 'fetchBalance' => true,
  27. 'fetchCurrencies' => true,
  28. 'fetchDepositAddress' => true,
  29. 'fetchDeposits' => true,
  30. 'fetchMyTrades' => true,
  31. 'fetchOHLCV' => true,
  32. 'fetchOpenOrders' => true,
  33. 'fetchOrder' => true,
  34. 'fetchOrders' => true,
  35. 'fetchOrderBook' => true,
  36. 'fetchMarkets' => true,
  37. 'fetchTicker' => true,
  38. 'fetchTickers' => true,
  39. 'fetchTime' => true,
  40. 'fetchTrades' => true,
  41. 'fetchWithdrawals' => true,
  42. 'withdraw' => true,
  43. ),
  44. 'timeframes' => array(
  45. '1m' => '1m',
  46. '5m' => '5m',
  47. '15m' => '15m',
  48. '30m' => '30m',
  49. '1h' => '1h',
  50. '2h' => '2h',
  51. '4h' => '4h',
  52. '6h' => '6h',
  53. '8h' => '8h',
  54. '12h' => '12h',
  55. '1d' => '1d',
  56. ),
  57. 'urls' => array(
  58. 'logo' => 'https://user-images.githubusercontent.com/1294454/83165440-2f1cf200-a116-11ea-9046-a255d09fb2ed.jpg',
  59. 'api' => array(
  60. 'public' => 'https://api.bitvavo.com',
  61. 'private' => 'https://api.bitvavo.com',
  62. ),
  63. 'www' => 'https://bitvavo.com/',
  64. 'doc' => 'https://docs.bitvavo.com/',
  65. 'fees' => 'https://bitvavo.com/en/fees',
  66. 'referral' => 'https://bitvavo.com/?a=24F34952F7',
  67. ),
  68. 'api' => array(
  69. 'public' => array(
  70. 'get' => array(
  71. 'time',
  72. 'markets',
  73. 'assets',
  74. '{market}/book',
  75. '{market}/trades',
  76. '{market}/candles',
  77. 'ticker/price',
  78. 'ticker/book',
  79. 'ticker/24h',
  80. ),
  81. ),
  82. 'private' => array(
  83. 'get' => array(
  84. 'order',
  85. 'orders',
  86. 'ordersOpen',
  87. 'trades',
  88. 'balance',
  89. 'deposit',
  90. 'depositHistory',
  91. 'withdrawalHistory',
  92. ),
  93. 'post' => array(
  94. 'order',
  95. 'withdrawal',
  96. ),
  97. 'put' => array(
  98. 'order',
  99. ),
  100. 'delete' => array(
  101. 'order',
  102. 'orders',
  103. ),
  104. ),
  105. ),
  106. 'fees' => array(
  107. 'trading' => array(
  108. 'tierBased' => true,
  109. 'percentage' => true,
  110. 'taker' => 0.25 / 100,
  111. 'maker' => 0.20 / 100,
  112. 'tiers' => array(
  113. 'taker' => array(
  114. array( 0, 0.0025 ),
  115. array( 50000, 0.0024 ),
  116. array( 100000, 0.0022 ),
  117. array( 250000, 0.0020 ),
  118. array( 500000, 0.0018 ),
  119. array( 1000000, 0.0016 ),
  120. array( 2500000, 0.0014 ),
  121. array( 5000000, 0.0012 ),
  122. array( 10000000, 0.0010 ),
  123. ),
  124. 'maker' => array(
  125. array( 0, 0.0020 ),
  126. array( 50000, 0.0015 ),
  127. array( 100000, 0.0010 ),
  128. array( 250000, 0.0006 ),
  129. array( 500000, 0.0003 ),
  130. array( 1000000, 0.0001 ),
  131. array( 2500000, -0.0001 ),
  132. array( 5000000, -0.0003 ),
  133. array( 10000000, -0.0005 ),
  134. ),
  135. ),
  136. ),
  137. ),
  138. 'requiredCredentials' => array(
  139. 'apiKey' => true,
  140. 'secret' => true,
  141. ),
  142. 'exceptions' => array(
  143. 'exact' => array(
  144. '101' => '\\ccxt\\ExchangeError', // Unknown error. Operation may or may not have succeeded.
  145. '102' => '\\ccxt\\BadRequest', // Invalid JSON.
  146. '103' => '\\ccxt\\RateLimitExceeded', // You have been rate limited. Please observe the Bitvavo-Ratelimit-AllowAt header to see when you can send requests again. Failure to respect this limit will result in an IP ban. The default value is 1000 weighted requests per minute. Please contact support if you wish to increase this limit.
  147. '104' => '\\ccxt\\RateLimitExceeded', // You have been rate limited by the number of new orders. The default value is 100 new orders per second or 100.000 new orders per day. Please update existing orders instead of cancelling and creating orders. Please contact support if you wish to increase this limit.
  148. '105' => '\\ccxt\\PermissionDenied', // Your IP or API key has been banned for not respecting the rate limit. The ban expires at ${expiryInMs}.
  149. '107' => '\\ccxt\\ExchangeNotAvailable', // The matching engine is overloaded. Please wait 500ms and resubmit your order.
  150. '108' => '\\ccxt\\ExchangeNotAvailable', // The matching engine could not process your order in time. Please consider increasing the access window or resubmit your order.
  151. '109' => '\\ccxt\\ExchangeNotAvailable', // The matching engine did not respond in time. Operation may or may not have succeeded.
  152. '110' => '\\ccxt\\BadRequest', // Invalid endpoint. Please check url and HTTP method.
  153. '200' => '\\ccxt\\BadRequest', // ${param} url parameter is not supported. Please note that parameters are case-sensitive and use body parameters for PUT and POST requests.
  154. '201' => '\\ccxt\\BadRequest', // ${param} body parameter is not supported. Please note that parameters are case-sensitive and use url parameters for GET and DELETE requests.
  155. '202' => '\\ccxt\\BadRequest', // ${param} order parameter is not supported. Please note that certain parameters are only allowed for market or limit orders.
  156. '203' => '\\ccxt\\BadSymbol', // array("errorCode":203,"error":"symbol parameter is required.")
  157. '204' => '\\ccxt\\BadRequest', // ${param} parameter is not supported.
  158. '205' => '\\ccxt\\BadRequest', // ${param} parameter is invalid.
  159. '206' => '\\ccxt\\BadRequest', // Use either ${paramA} or ${paramB}. The usage of both parameters at the same time is not supported.
  160. '210' => '\\ccxt\\InvalidOrder', // Amount exceeds the maximum allowed amount (1000000000).
  161. '211' => '\\ccxt\\InvalidOrder', // Price exceeds the maximum allowed amount (100000000000).
  162. '212' => '\\ccxt\\InvalidOrder', // Amount is below the minimum allowed amount for this asset.
  163. '213' => '\\ccxt\\InvalidOrder', // Price is below the minimum allowed amount (0.000000000000001).
  164. '214' => '\\ccxt\\InvalidOrder', // Price is too detailed
  165. '215' => '\\ccxt\\InvalidOrder', // Price is too detailed. A maximum of 15 digits behind the decimal point are allowed.
  166. '216' => '\\ccxt\\InsufficientFunds', // array("errorCode":216,"error":"You do not have sufficient balance to complete this operation.")
  167. '217' => '\\ccxt\\InvalidOrder', // array("errorCode":217,"error":"Minimum order size in quote currency is 5 EUR or 0.001 BTC.")
  168. '230' => '\\ccxt\\ExchangeError', // The order is rejected by the matching engine.
  169. '231' => '\\ccxt\\ExchangeError', // The order is rejected by the matching engine. TimeInForce must be GTC when markets are paused.
  170. '232' => '\\ccxt\\BadRequest', // You must change at least one of amount, amountRemaining, price, timeInForce, selfTradePrevention or postOnly.
  171. '233' => '\\ccxt\\InvalidOrder', // array("errorCode":233,"error":"Order must be active (status new or partiallyFilled) to allow updating/cancelling.")
  172. '234' => '\\ccxt\\InvalidOrder', // Market orders cannot be updated.
  173. '235' => '\\ccxt\\ExchangeError', // You can only have 100 open orders on each book.
  174. '236' => '\\ccxt\\BadRequest', // You can only update amount or amountRemaining, not both.
  175. '240' => '\\ccxt\\OrderNotFound', // array("errorCode":240,"error":"No order found. Please be aware that simultaneously updating the same order may return this error.")
  176. '300' => '\\ccxt\\AuthenticationError', // Authentication is required for this endpoint.
  177. '301' => '\\ccxt\\AuthenticationError', // array("errorCode":301,"error":"API Key must be of length 64.")
  178. '302' => '\\ccxt\\AuthenticationError', // Timestamp is invalid. This must be a timestamp in ms. See Bitvavo-Access-Timestamp header or timestamp parameter for websocket.
  179. '303' => '\\ccxt\\AuthenticationError', // Window must be between 100 and 60000 ms.
  180. '304' => '\\ccxt\\AuthenticationError', // Request was not received within acceptable window (default 30s, or custom with Bitvavo-Access-Window header) of Bitvavo-Access-Timestamp header (or timestamp parameter for websocket).
  181. // '304' => '\\ccxt\\AuthenticationError', // Authentication is required for this endpoint.
  182. '305' => '\\ccxt\\AuthenticationError', // array("errorCode":305,"error":"No active API key found.")
  183. '306' => '\\ccxt\\AuthenticationError', // No active API key found. Please ensure that you have confirmed the API key by e-mail.
  184. '307' => '\\ccxt\\PermissionDenied', // This key does not allow access from this IP.
  185. '308' => '\\ccxt\\AuthenticationError', // array("errorCode":308,"error":"The signature length is invalid (HMAC-SHA256 should return a 64 length hexadecimal string).")
  186. '309' => '\\ccxt\\AuthenticationError', // array("errorCode":309,"error":"The signature is invalid.")
  187. '310' => '\\ccxt\\PermissionDenied', // This key does not allow trading actions.
  188. '311' => '\\ccxt\\PermissionDenied', // This key does not allow showing account information.
  189. '312' => '\\ccxt\\PermissionDenied', // This key does not allow withdrawal of funds.
  190. '315' => '\\ccxt\\BadRequest', // Websocket connections may not be used in a browser. Please use REST requests for $this->
  191. '317' => '\\ccxt\\AccountSuspended', // This account is locked. Please contact support.
  192. '400' => '\\ccxt\\ExchangeError', // Unknown error. Please contact support with a copy of your request.
  193. '401' => '\\ccxt\\ExchangeError', // Deposits for this asset are not available at this time.
  194. '402' => '\\ccxt\\PermissionDenied', // You need to verify your identitiy before you can deposit and withdraw digital assets.
  195. '403' => '\\ccxt\\PermissionDenied', // You need to verify your phone number before you can deposit and withdraw digital assets.
  196. '404' => '\\ccxt\\OnMaintenance', // Could not complete this operation, because our node cannot be reached. Possibly under maintenance.
  197. '405' => '\\ccxt\\ExchangeError', // You cannot withdraw digital assets during a cooldown period. This is the result of newly added bank accounts.
  198. '406' => '\\ccxt\\BadRequest', // array("errorCode":406,"error":"Your withdrawal is too small.")
  199. '407' => '\\ccxt\\ExchangeError', // Internal transfer is not possible.
  200. '408' => '\\ccxt\\InsufficientFunds', // array("errorCode":408,"error":"You do not have sufficient balance to complete this operation.")
  201. '409' => '\\ccxt\\InvalidAddress', // array("errorCode":409,"error":"This is not a verified bank account.")
  202. '410' => '\\ccxt\\ExchangeError', // Withdrawals for this asset are not available at this time.
  203. '411' => '\\ccxt\\BadRequest', // You can not transfer assets to yourself.
  204. '412' => '\\ccxt\\InvalidAddress', // array("errorCode":412,"error":"eth_address_invalid.")
  205. '413' => '\\ccxt\\InvalidAddress', // This address violates the whitelist.
  206. '414' => '\\ccxt\\ExchangeError', // You cannot withdraw assets within 2 minutes of logging in.
  207. ),
  208. 'broad' => array(
  209. 'start parameter is invalid' => '\\ccxt\\BadRequest', // array("errorCode":205,"error":"start parameter is invalid.")
  210. 'symbol parameter is invalid' => '\\ccxt\\BadSymbol', // array("errorCode":205,"error":"symbol parameter is invalid.")
  211. 'amount parameter is invalid' => '\\ccxt\\InvalidOrder', // array("errorCode":205,"error":"amount parameter is invalid.")
  212. 'orderId parameter is invalid' => '\\ccxt\\InvalidOrder', // array("errorCode":205,"error":"orderId parameter is invalid.")
  213. ),
  214. ),
  215. 'options' => array(
  216. 'BITVAVO-ACCESS-WINDOW' => 10000, // default 10 sec
  217. 'fetchCurrencies' => array(
  218. 'expires' => 1000, // 1 second
  219. ),
  220. ),
  221. 'commonCurrencies' => array(
  222. 'MIOTA' => 'IOTA', // https://github.com/ccxt/ccxt/issues/7487
  223. ),
  224. ));
  225. }
  226. public function fetch_time($params = array ()) {
  227. $response = $this->publicGetTime ($params);
  228. //
  229. // array( "time" => 1590379519148 )
  230. //
  231. return $this->safe_integer($response, 'time');
  232. }
  233. public function fetch_markets($params = array ()) {
  234. $response = $this->publicGetMarkets ($params);
  235. $currencies = $this->fetch_currencies_from_cache($params);
  236. $currenciesById = $this->index_by($currencies, 'symbol');
  237. //
  238. // array(
  239. // {
  240. // "$market":"ADA-BTC",
  241. // "$status":"trading", // "trading" "halted" "auction"
  242. // "$base":"ADA",
  243. // "$quote":"BTC",
  244. // "pricePrecision":5,
  245. // "minOrderInBaseAsset":"100",
  246. // "minOrderInQuoteAsset":"0.001",
  247. // "orderTypes" => array( "$market", "limit" )
  248. // }
  249. // )
  250. //
  251. $result = array();
  252. for ($i = 0; $i < count($response); $i++) {
  253. $market = $response[$i];
  254. $id = $this->safe_string($market, 'market');
  255. $baseId = $this->safe_string($market, 'base');
  256. $quoteId = $this->safe_string($market, 'quote');
  257. $base = $this->safe_currency_code($baseId);
  258. $quote = $this->safe_currency_code($quoteId);
  259. $symbol = $base . '/' . $quote;
  260. $status = $this->safe_string($market, 'status');
  261. $active = ($status === 'trading');
  262. $baseCurrency = $this->safe_value($currenciesById, $baseId);
  263. $amountPrecision = null;
  264. if ($baseCurrency !== null) {
  265. $amountPrecision = $this->safe_integer($baseCurrency, 'decimals', 8);
  266. }
  267. $precision = array(
  268. 'price' => $this->safe_integer($market, 'pricePrecision'),
  269. 'amount' => $amountPrecision,
  270. );
  271. $result[] = array(
  272. 'id' => $id,
  273. 'symbol' => $symbol,
  274. 'base' => $base,
  275. 'quote' => $quote,
  276. 'baseId' => $baseId,
  277. 'quoteId' => $quoteId,
  278. 'info' => $market,
  279. 'active' => $active,
  280. 'precision' => $precision,
  281. 'limits' => array(
  282. 'amount' => array(
  283. 'min' => $this->safe_float($market, 'minOrderInBaseAsset'),
  284. 'max' => null,
  285. ),
  286. 'price' => array(
  287. 'min' => null,
  288. 'max' => null,
  289. ),
  290. 'cost' => array(
  291. 'min' => $this->safe_float($market, 'minOrderInQuoteAsset'),
  292. 'max' => null,
  293. ),
  294. ),
  295. );
  296. }
  297. return $result;
  298. }
  299. public function fetch_currencies_from_cache($params = array ()) {
  300. // this method is $now redundant
  301. // currencies are $now fetched before markets
  302. $options = $this->safe_value($this->options, 'fetchCurrencies', array());
  303. $timestamp = $this->safe_integer($options, 'timestamp');
  304. $expires = $this->safe_integer($options, 'expires', 1000);
  305. $now = $this->milliseconds();
  306. if (($timestamp === null) || (($now - $timestamp) > $expires)) {
  307. $response = $this->publicGetAssets ($params);
  308. $this->options['fetchCurrencies'] = array_merge($options, array(
  309. 'response' => $response,
  310. 'timestamp' => $now,
  311. ));
  312. }
  313. return $this->safe_value($this->options['fetchCurrencies'], 'response');
  314. }
  315. public function fetch_currencies($params = array ()) {
  316. $response = $this->fetch_currencies_from_cache($params);
  317. //
  318. // array(
  319. // array(
  320. // "symbol":"ADA",
  321. // "$name":"Cardano",
  322. // "decimals":6,
  323. // "depositFee":"0",
  324. // "depositConfirmations":15,
  325. // "$depositStatus":"OK", // "OK", "MAINTENANCE", "DELISTED"
  326. // "withdrawalFee":"0.2",
  327. // "withdrawalMinAmount":"0.2",
  328. // "$withdrawalStatus":"OK", // "OK", "MAINTENANCE", "DELISTED"
  329. // "networks" => array( "Mainnet" ), // "ETH", "NEO", "ONT", "SEPA", "VET"
  330. // "message":"",
  331. // ),
  332. // )
  333. //
  334. $result = array();
  335. for ($i = 0; $i < count($response); $i++) {
  336. $currency = $response[$i];
  337. $id = $this->safe_string($currency, 'symbol');
  338. $code = $this->safe_currency_code($id);
  339. $depositStatus = $this->safe_value($currency, 'depositStatus');
  340. $deposit = ($depositStatus === 'OK');
  341. $withdrawalStatus = $this->safe_value($currency, 'withdrawalStatus');
  342. $withdrawal = ($withdrawalStatus === 'OK');
  343. $active = $deposit && $withdrawal;
  344. $name = $this->safe_string($currency, 'name');
  345. $precision = $this->safe_integer($currency, 'decimals', 8);
  346. $result[$code] = array(
  347. 'id' => $id,
  348. 'info' => $currency,
  349. 'code' => $code,
  350. 'name' => $name,
  351. 'active' => $active,
  352. 'fee' => $this->safe_float($currency, 'withdrawalFee'),
  353. 'precision' => $precision,
  354. 'limits' => array(
  355. 'amount' => array(
  356. 'min' => null,
  357. 'max' => null,
  358. ),
  359. 'price' => array(
  360. 'min' => null,
  361. 'max' => null,
  362. ),
  363. 'cost' => array(
  364. 'min' => null,
  365. 'max' => null,
  366. ),
  367. 'withdraw' => array(
  368. 'min' => $this->safe_float($currency, 'withdrawalMinAmount'),
  369. 'max' => null,
  370. ),
  371. ),
  372. );
  373. }
  374. return $result;
  375. }
  376. public function fetch_ticker($symbol, $params = array ()) {
  377. $this->load_markets();
  378. $market = $this->market($symbol);
  379. $request = array(
  380. 'market' => $market['id'],
  381. );
  382. $response = $this->publicGetTicker24h (array_merge($request, $params));
  383. //
  384. // {
  385. // "$market":"ETH-BTC",
  386. // "open":"0.022578",
  387. // "high":"0.023019",
  388. // "low":"0.022573",
  389. // "last":"0.023019",
  390. // "volume":"25.16366324",
  391. // "volumeQuote":"0.57333305",
  392. // "bid":"0.023039",
  393. // "bidSize":"0.53500578",
  394. // "ask":"0.023041",
  395. // "askSize":"0.47859202",
  396. // "timestamp":1590381666900
  397. // }
  398. //
  399. return $this->parse_ticker($response, $market);
  400. }
  401. public function parse_ticker($ticker, $market = null) {
  402. //
  403. // fetchTicker
  404. //
  405. // {
  406. // "$market":"ETH-BTC",
  407. // "$open":"0.022578",
  408. // "high":"0.023019",
  409. // "low":"0.022573",
  410. // "$last":"0.023019",
  411. // "volume":"25.16366324",
  412. // "volumeQuote":"0.57333305",
  413. // "bid":"0.023039",
  414. // "bidSize":"0.53500578",
  415. // "ask":"0.023041",
  416. // "askSize":"0.47859202",
  417. // "$timestamp":1590381666900
  418. // }
  419. //
  420. $marketId = $this->safe_string($ticker, 'market');
  421. $symbol = $this->safe_symbol($marketId, $market, '-');
  422. $timestamp = $this->safe_integer($ticker, 'timestamp');
  423. $last = $this->safe_float($ticker, 'last');
  424. $baseVolume = $this->safe_float($ticker, 'volume');
  425. $quoteVolume = $this->safe_float($ticker, 'volumeQuote');
  426. $vwap = $this->vwap($baseVolume, $quoteVolume);
  427. $change = null;
  428. $percentage = null;
  429. $average = null;
  430. $open = $this->safe_float($ticker, 'open');
  431. if (($open !== null) && ($last !== null)) {
  432. $change = $last - $open;
  433. if ($open > 0) {
  434. $percentage = $change / $open * 100;
  435. }
  436. $average = $this->sum($open, $last) / 2;
  437. }
  438. $result = array(
  439. 'symbol' => $symbol,
  440. 'timestamp' => $timestamp,
  441. 'datetime' => $this->iso8601($timestamp),
  442. 'high' => $this->safe_float($ticker, 'high'),
  443. 'low' => $this->safe_float($ticker, 'low'),
  444. 'bid' => $this->safe_float($ticker, 'bid'),
  445. 'bidVolume' => $this->safe_float($ticker, 'bidSize'),
  446. 'ask' => $this->safe_float($ticker, 'ask'),
  447. 'askVolume' => $this->safe_float($ticker, 'askSize'),
  448. 'vwap' => $vwap,
  449. 'open' => $open,
  450. 'close' => $last,
  451. 'last' => $last,
  452. 'previousClose' => null, // previous day close
  453. 'change' => $change,
  454. 'percentage' => $percentage,
  455. 'average' => $average,
  456. 'baseVolume' => $baseVolume,
  457. 'quoteVolume' => $quoteVolume,
  458. 'info' => $ticker,
  459. );
  460. return $result;
  461. }
  462. public function parse_tickers($tickers, $symbols = null) {
  463. $result = array();
  464. for ($i = 0; $i < count($tickers); $i++) {
  465. $result[] = $this->parse_ticker($tickers[$i]);
  466. }
  467. return $this->filter_by_array($result, 'symbol', $symbols);
  468. }
  469. public function fetch_tickers($symbols = null, $params = array ()) {
  470. $this->load_markets();
  471. $response = $this->publicGetTicker24h ($params);
  472. //
  473. // array(
  474. // {
  475. // "market":"ADA-BTC",
  476. // "open":"0.0000059595",
  477. // "high":"0.0000059765",
  478. // "low":"0.0000059595",
  479. // "last":"0.0000059765",
  480. // "volume":"2923.172",
  481. // "volumeQuote":"0.01743483",
  482. // "bid":"0.0000059515",
  483. // "bidSize":"1117.630919",
  484. // "ask":"0.0000059585",
  485. // "askSize":"809.999739",
  486. // "timestamp":1590382266324
  487. // }
  488. // )
  489. //
  490. return $this->parse_tickers($response, $symbols);
  491. }
  492. public function fetch_trades($symbol, $since = null, $limit = null, $params = array ()) {
  493. $this->load_markets();
  494. $market = $this->market($symbol);
  495. $request = array(
  496. 'market' => $market['id'],
  497. // 'limit' => 500, // default 500, max 1000
  498. // 'start' => $since,
  499. // 'end' => $this->milliseconds(),
  500. // 'tradeIdFrom' => '57b1159b-6bf5-4cde-9e2c-6bd6a5678baf',
  501. // 'tradeIdTo' => '57b1159b-6bf5-4cde-9e2c-6bd6a5678baf',
  502. );
  503. if ($limit !== null) {
  504. $request['limit'] = $limit;
  505. }
  506. if ($since !== null) {
  507. $request['start'] = $since;
  508. }
  509. $response = $this->publicGetMarketTrades (array_merge($request, $params));
  510. //
  511. // array(
  512. // {
  513. // "id":"94154c98-6e8b-4e33-92a8-74e33fc05650",
  514. // "timestamp":1590382761859,
  515. // "amount":"0.06026079",
  516. // "price":"8095.3",
  517. // "side":"buy"
  518. // }
  519. // )
  520. //
  521. return $this->parse_trades($response, $market, $since, $limit);
  522. }
  523. public function parse_trade($trade, $market = null) {
  524. //
  525. // fetchTrades (public)
  526. //
  527. // {
  528. // "$id":"94154c98-6e8b-4e33-92a8-74e33fc05650",
  529. // "$timestamp":1590382761859,
  530. // "$amount":"0.06026079",
  531. // "$price":"8095.3",
  532. // "$side":"buy"
  533. // }
  534. //
  535. // createOrder, fetchOpenOrders, fetchOrders, editOrder (private)
  536. //
  537. // {
  538. // "$id":"b0c86aa5-6ed3-4a2d-ba3a-be9a964220f4",
  539. // "$timestamp":1590505649245,
  540. // "$amount":"0.249825",
  541. // "$price":"183.49",
  542. // "$taker":true,
  543. // "$fee":"0.12038925",
  544. // "feeCurrency":"EUR",
  545. // "settled":true
  546. // }
  547. //
  548. // fetchMyTrades (private)
  549. //
  550. // {
  551. // "$id":"b0c86aa5-6ed3-4a2d-ba3a-be9a964220f4",
  552. // "$orderId":"af76d6ce-9f7c-4006-b715-bb5d430652d0",
  553. // "$timestamp":1590505649245,
  554. // "$market":"ETH-EUR",
  555. // "$side":"sell",
  556. // "$amount":"0.249825",
  557. // "$price":"183.49",
  558. // "$taker":true,
  559. // "$fee":"0.12038925",
  560. // "feeCurrency":"EUR",
  561. // "settled":true
  562. // }
  563. //
  564. // watchMyTrades (private)
  565. //
  566. // {
  567. // event => 'fill',
  568. // $timestamp => 1590964470132,
  569. // $market => 'ETH-EUR',
  570. // $orderId => '85d082e1-eda4-4209-9580-248281a29a9a',
  571. // fillId => '861d2da5-aa93-475c-8d9a-dce431bd4211',
  572. // $side => 'sell',
  573. // $amount => '0.1',
  574. // $price => '211.46',
  575. // $taker => true,
  576. // $fee => '0.056',
  577. // feeCurrency => 'EUR'
  578. // }
  579. //
  580. $price = $this->safe_float($trade, 'price');
  581. $amount = $this->safe_float($trade, 'amount');
  582. $cost = null;
  583. if (($price !== null) && ($amount !== null)) {
  584. $cost = $price * $amount;
  585. }
  586. $timestamp = $this->safe_integer($trade, 'timestamp');
  587. $side = $this->safe_string($trade, 'side');
  588. $id = $this->safe_string_2($trade, 'id', 'fillId');
  589. $marketId = $this->safe_integer($trade, 'market');
  590. $symbol = $this->safe_symbol($marketId, $market, '-');
  591. $taker = $this->safe_value($trade, 'taker');
  592. $takerOrMaker = null;
  593. if ($taker !== null) {
  594. $takerOrMaker = $taker ? 'taker' : 'maker';
  595. }
  596. $feeCost = $this->safe_float($trade, 'fee');
  597. $fee = null;
  598. if ($feeCost !== null) {
  599. $feeCurrencyId = $this->safe_string($trade, 'feeCurrency');
  600. $feeCurrencyCode = $this->safe_currency_code($feeCurrencyId);
  601. $fee = array(
  602. 'cost' => $feeCost,
  603. 'currency' => $feeCurrencyCode,
  604. );
  605. }
  606. $orderId = $this->safe_string($trade, 'orderId');
  607. return array(
  608. 'info' => $trade,
  609. 'id' => $id,
  610. 'symbol' => $symbol,
  611. 'timestamp' => $timestamp,
  612. 'datetime' => $this->iso8601($timestamp),
  613. 'order' => $orderId,
  614. 'type' => null,
  615. 'side' => $side,
  616. 'takerOrMaker' => $takerOrMaker,
  617. 'price' => $price,
  618. 'amount' => $amount,
  619. 'cost' => $cost,
  620. 'fee' => $fee,
  621. );
  622. }
  623. public function fetch_order_book($symbol, $limit = null, $params = array ()) {
  624. $this->load_markets();
  625. $request = array(
  626. 'market' => $this->market_id($symbol),
  627. );
  628. if ($limit !== null) {
  629. $request['depth'] = $limit;
  630. }
  631. $response = $this->publicGetMarketBook (array_merge($request, $params));
  632. //
  633. // {
  634. // "market":"BTC-EUR",
  635. // "nonce":35883831,
  636. // "bids":[
  637. // ["8097.4","0.6229099"],
  638. // ["8097.2","0.64151283"],
  639. // ["8097.1","0.24966294"],
  640. // ],
  641. // "asks":[
  642. // ["8097.5","1.36916911"],
  643. // ["8098.8","0.33462248"],
  644. // ["8099.3","1.12908646"],
  645. // ]
  646. // }
  647. //
  648. $orderbook = $this->parse_order_book($response);
  649. $orderbook['nonce'] = $this->safe_integer($response, 'nonce');
  650. return $orderbook;
  651. }
  652. public function parse_ohlcv($ohlcv, $market = null) {
  653. //
  654. // array(
  655. // 1590383700000,
  656. // "8088.5",
  657. // "8088.5",
  658. // "8088.5",
  659. // "8088.5",
  660. // "0.04788623"
  661. // )
  662. //
  663. return array(
  664. $this->safe_integer($ohlcv, 0),
  665. $this->safe_float($ohlcv, 1),
  666. $this->safe_float($ohlcv, 2),
  667. $this->safe_float($ohlcv, 3),
  668. $this->safe_float($ohlcv, 4),
  669. $this->safe_float($ohlcv, 5),
  670. );
  671. }
  672. public function fetch_ohlcv($symbol, $timeframe = '1m', $since = null, $limit = null, $params = array ()) {
  673. $this->load_markets();
  674. $market = $this->market($symbol);
  675. $request = array(
  676. 'market' => $market['id'],
  677. 'interval' => $this->timeframes[$timeframe],
  678. // 'limit' => 1440, // default 1440, max 1440
  679. // 'start' => $since,
  680. // 'end' => $this->milliseconds(),
  681. );
  682. if ($since !== null) {
  683. $request['start'] = $since;
  684. }
  685. if ($limit !== null) {
  686. $request['limit'] = $limit; // default 1440, max 1440
  687. }
  688. $response = $this->publicGetMarketCandles (array_merge($request, $params));
  689. //
  690. // [
  691. // [1590383700000,"8088.5","8088.5","8088.5","8088.5","0.04788623"],
  692. // [1590383580000,"8091.3","8091.5","8091.3","8091.5","0.04931221"],
  693. // [1590383520000,"8090.3","8092.7","8090.3","8092.5","0.04001286"],
  694. // ]
  695. //
  696. return $this->parse_ohlcvs($response, $market, $timeframe, $since, $limit);
  697. }
  698. public function fetch_balance($params = array ()) {
  699. $this->load_markets();
  700. $response = $this->privateGetBalance ($params);
  701. //
  702. // array(
  703. // {
  704. // "symbol" => "BTC",
  705. // "available" => "1.57593193",
  706. // "inOrder" => "0.74832374"
  707. // }
  708. // )
  709. //
  710. $result = array( 'info' => $response );
  711. for ($i = 0; $i < count($response); $i++) {
  712. $balance = $response[$i];
  713. $currencyId = $this->safe_string($balance, 'symbol');
  714. $code = $this->safe_currency_code($currencyId);
  715. $account = array(
  716. 'free' => $this->safe_float($balance, 'available'),
  717. 'used' => $this->safe_float($balance, 'inOrder'),
  718. );
  719. $result[$code] = $account;
  720. }
  721. return $this->parse_balance($result);
  722. }
  723. public function fetch_deposit_address($code, $params = array ()) {
  724. $this->load_markets();
  725. $currency = $this->currency($code);
  726. $request = array(
  727. 'symbol' => $currency['id'],
  728. );
  729. $response = $this->privateGetDeposit (array_merge($request, $params));
  730. //
  731. // {
  732. // "$address" => "0x449889e3234514c45d57f7c5a571feba0c7ad567",
  733. // "paymentId" => "10002653"
  734. // }
  735. //
  736. $address = $this->safe_string($response, 'address');
  737. $tag = $this->safe_string($response, 'paymentId');
  738. $this->check_address($address);
  739. return array(
  740. 'currency' => $code,
  741. 'address' => $address,
  742. 'tag' => $tag,
  743. 'info' => $response,
  744. );
  745. }
  746. public function create_order($symbol, $type, $side, $amount, $price = null, $params = array ()) {
  747. $this->load_markets();
  748. $market = $this->market($symbol);
  749. $request = array(
  750. 'market' => $market['id'],
  751. 'side' => $side,
  752. 'orderType' => $type,
  753. // 'amount' => $this->amount_to_precision($symbol, $amount),
  754. // 'price' => $this->price_to_precision($symbol, $price),
  755. // 'amountQuote' => $this->cost_to_precision($symbol, $cost),
  756. // 'timeInForce' => 'GTC', // "GTC" "IOC" "FOK"
  757. // 'selfTradePrevention' => "decrementAndCancel", // "decrementAndCancel" "cancelOldest" "cancelNewest" "cancelBoth"
  758. // 'postOnly' => false,
  759. // 'disableMarketProtection' => false, // don't cancel if the next fill $price is 10% worse than the best fill $price
  760. // 'responseRequired' => true, // false is faster
  761. );
  762. if ($type === 'market') {
  763. $cost = null;
  764. if ($price !== null) {
  765. $cost = $amount * $price;
  766. } else {
  767. $cost = $this->safe_float_2($params, 'cost', 'amountQuote');
  768. }
  769. if ($cost !== null) {
  770. $precision = $market['precision']['price'];
  771. $request['amountQuote'] = $this->decimal_to_precision($cost, TRUNCATE, $precision, $this->precisionMode);
  772. } else {
  773. $request['amount'] = $this->amount_to_precision($symbol, $amount);
  774. }
  775. $params = $this->omit($params, array( 'cost', 'amountQuote' ));
  776. } else if ($type === 'limit') {
  777. $request['price'] = $this->price_to_precision($symbol, $price);
  778. $request['amount'] = $this->amount_to_precision($symbol, $amount);
  779. }
  780. $response = $this->privatePostOrder (array_merge($request, $params));
  781. //
  782. // {
  783. // "orderId":"af76d6ce-9f7c-4006-b715-bb5d430652d0",
  784. // "$market":"ETH-EUR",
  785. // "created":1590505649241,
  786. // "updated":1590505649241,
  787. // "status":"filled",
  788. // "$side":"sell",
  789. // "orderType":"$market",
  790. // "$amount":"0.249825",
  791. // "amountRemaining":"0",
  792. // "onHold":"0",
  793. // "onHoldCurrency":"ETH",
  794. // "filledAmount":"0.249825",
  795. // "filledAmountQuote":"45.84038925",
  796. // "feePaid":"0.12038925",
  797. // "feeCurrency":"EUR",
  798. // "fills":array(
  799. // {
  800. // "id":"b0c86aa5-6ed3-4a2d-ba3a-be9a964220f4",
  801. // "timestamp":1590505649245,
  802. // "$amount":"0.249825",
  803. // "$price":"183.49",
  804. // "taker":true,
  805. // "fee":"0.12038925",
  806. // "feeCurrency":"EUR",
  807. // "settled":true
  808. // }
  809. // ),
  810. // "selfTradePrevention":"decrementAndCancel",
  811. // "visible":false,
  812. // "disableMarketProtection":false
  813. // }
  814. //
  815. return $this->parse_order($response, $market);
  816. }
  817. public function edit_order($id, $symbol, $type, $side, $amount = null, $price = null, $params = array ()) {
  818. $this->load_markets();
  819. $market = $this->market($symbol);
  820. $request = array();
  821. $amountRemaining = $this->safe_float($params, 'amountRemaining');
  822. $params = $this->omit($params, 'amountRemaining');
  823. if ($price !== null) {
  824. $request['price'] = $this->price_to_precision($symbol, $price);
  825. }
  826. if ($amount !== null) {
  827. $request['amount'] = $this->amount_to_precision($symbol, $amount);
  828. }
  829. if ($amountRemaining !== null) {
  830. $request['amountRemaining'] = $this->amount_to_precision($symbol, $amountRemaining);
  831. }
  832. $request = array_merge($request, $params);
  833. if ($request) {
  834. $request['orderId'] = $id;
  835. $request['market'] = $market['id'];
  836. $response = $this->privatePutOrder (array_merge($request, $params));
  837. return $this->parse_order($response, $market);
  838. } else {
  839. throw new ArgumentsRequired($this->id . ' editOrder requires an $amount argument, or a $price argument, or non-empty params');
  840. }
  841. }
  842. public function cancel_order($id, $symbol = null, $params = array ()) {
  843. if ($symbol === null) {
  844. throw new ArgumentsRequired($this->id . ' cancelOrder requires a $symbol argument');
  845. }
  846. $this->load_markets();
  847. $market = $this->market($symbol);
  848. $request = array(
  849. 'orderId' => $id,
  850. 'market' => $market['id'],
  851. );
  852. $response = $this->privateDeleteOrder (array_merge($request, $params));
  853. //
  854. // {
  855. // "orderId" => "2e7ce7fc-44e2-4d80-a4a7-d079c4750b61"
  856. // }
  857. //
  858. return $this->parse_order($response, $market);
  859. }
  860. public function cancel_all_orders($symbol = null, $params = array ()) {
  861. $this->load_markets();
  862. $request = array();
  863. $market = null;
  864. if ($symbol !== null) {
  865. $market = $this->market($symbol);
  866. $request['market'] = $market['id'];
  867. }
  868. $response = $this->privateDeleteOrders (array_merge($request, $params));
  869. //
  870. // array(
  871. // {
  872. // "orderId" => "1be6d0df-d5dc-4b53-a250-3376f3b393e6"
  873. // }
  874. // )
  875. //
  876. return $this->parse_orders($response, $market);
  877. }
  878. public function fetch_order($id, $symbol = null, $params = array ()) {
  879. if ($symbol === null) {
  880. throw new ArgumentsRequired($this->id . ' fetchOrder requires a $symbol argument');
  881. }
  882. $this->load_markets();
  883. $this->load_markets();
  884. $market = $this->market($symbol);
  885. $request = array(
  886. 'orderId' => $id,
  887. 'market' => $market['id'],
  888. );
  889. $response = $this->privateGetOrder (array_merge($request, $params));
  890. //
  891. // {
  892. // "orderId":"af76d6ce-9f7c-4006-b715-bb5d430652d0",
  893. // "$market":"ETH-EUR",
  894. // "created":1590505649241,
  895. // "updated":1590505649241,
  896. // "status":"filled",
  897. // "side":"sell",
  898. // "orderType":"$market",
  899. // "amount":"0.249825",
  900. // "amountRemaining":"0",
  901. // "onHold":"0",
  902. // "onHoldCurrency":"ETH",
  903. // "filledAmount":"0.249825",
  904. // "filledAmountQuote":"45.84038925",
  905. // "feePaid":"0.12038925",
  906. // "feeCurrency":"EUR",
  907. // "fills":array(
  908. // {
  909. // "$id":"b0c86aa5-6ed3-4a2d-ba3a-be9a964220f4",
  910. // "timestamp":1590505649245,
  911. // "amount":"0.249825",
  912. // "price":"183.49",
  913. // "taker":true,
  914. // "fee":"0.12038925",
  915. // "feeCurrency":"EUR",
  916. // "settled":true
  917. // }
  918. // ),
  919. // "selfTradePrevention":"decrementAndCancel",
  920. // "visible":false,
  921. // "disableMarketProtection":false
  922. // }
  923. //
  924. return $this->parse_order($response, $market);
  925. }
  926. public function fetch_orders($symbol = null, $since = null, $limit = null, $params = array ()) {
  927. if ($symbol === null) {
  928. throw new ArgumentsRequired($this->id . ' fetchOrders requires a $symbol argument');
  929. }
  930. $this->load_markets();
  931. $market = $this->market($symbol);
  932. $request = array(
  933. 'market' => $market['id'],
  934. // 'limit' => 500,
  935. // 'start' => $since,
  936. // 'end' => $this->milliseconds(),
  937. // 'orderIdFrom' => 'af76d6ce-9f7c-4006-b715-bb5d430652d0',
  938. // 'orderIdTo' => 'af76d6ce-9f7c-4006-b715-bb5d430652d0',
  939. );
  940. if ($since !== null) {
  941. $request['start'] = $since;
  942. }
  943. if ($limit !== null) {
  944. $request['limit'] = $limit; // default 500, max 1000
  945. }
  946. $response = $this->privateGetOrders (array_merge($request, $params));
  947. //
  948. // array(
  949. // {
  950. // "orderId":"af76d6ce-9f7c-4006-b715-bb5d430652d0",
  951. // "$market":"ETH-EUR",
  952. // "created":1590505649241,
  953. // "updated":1590505649241,
  954. // "status":"filled",
  955. // "side":"sell",
  956. // "orderType":"$market",
  957. // "amount":"0.249825",
  958. // "amountRemaining":"0",
  959. // "onHold":"0",
  960. // "onHoldCurrency":"ETH",
  961. // "filledAmount":"0.249825",
  962. // "filledAmountQuote":"45.84038925",
  963. // "feePaid":"0.12038925",
  964. // "feeCurrency":"EUR",
  965. // "fills":array(
  966. // {
  967. // "id":"b0c86aa5-6ed3-4a2d-ba3a-be9a964220f4",
  968. // "timestamp":1590505649245,
  969. // "amount":"0.249825",
  970. // "price":"183.49",
  971. // "taker":true,
  972. // "fee":"0.12038925",
  973. // "feeCurrency":"EUR",
  974. // "settled":true
  975. // }
  976. // ),
  977. // "selfTradePrevention":"decrementAndCancel",
  978. // "visible":false,
  979. // "disableMarketProtection":false
  980. // }
  981. // )
  982. //
  983. return $this->parse_orders($response, $market, $since, $limit);
  984. }
  985. public function fetch_open_orders($symbol = null, $since = null, $limit = null, $params = array ()) {
  986. $this->load_markets();
  987. $request = array(
  988. // 'market' => $market['id'],
  989. // 'limit' => 500,
  990. // 'start' => $since,
  991. // 'end' => $this->milliseconds(),
  992. // 'orderIdFrom' => 'af76d6ce-9f7c-4006-b715-bb5d430652d0',
  993. // 'orderIdTo' => 'af76d6ce-9f7c-4006-b715-bb5d430652d0',
  994. );
  995. $market = null;
  996. if ($symbol !== null) {
  997. $market = $this->market($symbol);
  998. $request['market'] = $market['id'];
  999. }
  1000. if ($since !== null) {
  1001. $request['start'] = $since;
  1002. }
  1003. if ($limit !== null) {
  1004. $request['limit'] = $limit; // default 500, max 1000
  1005. }
  1006. $response = $this->privateGetOrdersOpen (array_merge($request, $params));
  1007. //
  1008. // array(
  1009. // {
  1010. // "orderId":"af76d6ce-9f7c-4006-b715-bb5d430652d0",
  1011. // "$market":"ETH-EUR",
  1012. // "created":1590505649241,
  1013. // "updated":1590505649241,
  1014. // "status":"filled",
  1015. // "side":"sell",
  1016. // "orderType":"$market",
  1017. // "amount":"0.249825",
  1018. // "amountRemaining":"0",
  1019. // "onHold":"0",
  1020. // "onHoldCurrency":"ETH",
  1021. // "filledAmount":"0.249825",
  1022. // "filledAmountQuote":"45.84038925",
  1023. // "feePaid":"0.12038925",
  1024. // "feeCurrency":"EUR",
  1025. // "fills":array(
  1026. // {
  1027. // "id":"b0c86aa5-6ed3-4a2d-ba3a-be9a964220f4",
  1028. // "timestamp":1590505649245,
  1029. // "amount":"0.249825",
  1030. // "price":"183.49",
  1031. // "taker":true,
  1032. // "fee":"0.12038925",
  1033. // "feeCurrency":"EUR",
  1034. // "settled":true
  1035. // }
  1036. // ),
  1037. // "selfTradePrevention":"decrementAndCancel",
  1038. // "visible":false,
  1039. // "disableMarketProtection":false
  1040. // }
  1041. // )
  1042. //
  1043. return $this->parse_orders($response, $market, $since, $limit);
  1044. }
  1045. public function parse_order_status($status) {
  1046. $statuses = array(
  1047. 'new' => 'open',
  1048. 'canceled' => 'canceled',
  1049. 'canceledAuction' => 'canceled',
  1050. 'canceledSelfTradePrevention' => 'canceled',
  1051. 'canceledIOC' => 'canceled',
  1052. 'canceledFOK' => 'canceled',
  1053. 'canceledMarketProtection' => 'canceled',
  1054. 'canceledPostOnly' => 'canceled',
  1055. 'filled' => 'closed',
  1056. 'partiallyFilled' => 'open',
  1057. 'expired' => 'canceled',
  1058. 'rejected' => 'canceled',
  1059. );
  1060. return $this->safe_string($statuses, $status, $status);
  1061. }
  1062. public function parse_order($order, $market = null) {
  1063. //
  1064. // cancelOrder, cancelAllOrders
  1065. //
  1066. // {
  1067. // "orderId" => "2e7ce7fc-44e2-4d80-a4a7-d079c4750b61"
  1068. // }
  1069. //
  1070. // createOrder, fetchOrder, fetchOpenOrders, fetchOrders, editOrder
  1071. //
  1072. // {
  1073. // "orderId":"af76d6ce-9f7c-4006-b715-bb5d430652d0",
  1074. // "$market":"ETH-EUR",
  1075. // "created":1590505649241,
  1076. // "updated":1590505649241,
  1077. // "$status":"$filled",
  1078. // "$side":"sell",
  1079. // "orderType":"$market",
  1080. // "$amount":"0.249825",
  1081. // "amountRemaining":"0",
  1082. // "$price" => "183.49", // limit orders only
  1083. // "onHold":"0",
  1084. // "onHoldCurrency":"ETH",
  1085. // "filledAmount":"0.249825",
  1086. // "filledAmountQuote":"45.84038925",
  1087. // "feePaid":"0.12038925",
  1088. // "feeCurrency":"EUR",
  1089. // "fills":array(
  1090. // {
  1091. // "$id":"b0c86aa5-6ed3-4a2d-ba3a-be9a964220f4",
  1092. // "$timestamp":1590505649245,…