forked from 2boloto/ccxt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_trade.php
More file actions
73 lines (67 loc) · 4.09 KB
/
Copy pathtest_trade.php
File metadata and controls
73 lines (67 loc) · 4.09 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
<?php
namespace ccxt;
// ----------------------------------------------------------------------------
// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
// -----------------------------------------------------------------------------
function test_trade($exchange, $trade, $symbol, $now) {
assert ($trade);
$sampleTrade = array(
'info' => array( 'a' => 1, 'b' => 2, 'c' => 3 ), // the original decoded JSON as is
'id' => '12345-67890:09876/54321', // string $trade $id
'timestamp' => 1502962946216, // Unix $timestamp in milliseconds
'datetime' => '2017-08-17 12:42:48.000', // ISO8601 datetime with milliseconds
'symbol' => 'ETH/BTC', // $symbol
'order' => '12345-67890:09876/54321', // string order $id or null/None/null
'type' => 'limit', // order type, 'market', 'limit' or null/None/null
'side' => 'buy', // direction of the $trade, 'buy' or 'sell'
'takerOrMaker' => 'taker', // string, 'taker' or 'maker'
'price' => 0.06917684, // float price in quote currency
'amount' => 1.5, // amount of base currency
'cost' => 0.10376526, // total cost (including $fees), `price * amount`
);
$keys = is_array($sampleTrade) ? array_keys($sampleTrade) : array();
for ($i = 0; $i < count($keys); $i++) {
$key = $keys[$i];
assert (is_array($trade) && array_key_exists($key, $trade));
}
$fee = (is_array($trade) && array_key_exists('fee', $trade)) ? $trade['fee'] : null;
$fees = (is_array($trade) && array_key_exists('fees', $trade)) ? $trade['fees'] : null;
// logical XOR
if ($fee || $fees) {
assert (!($fee && $fees));
}
if ($fee) {
assert ((is_array($fee) && array_key_exists('cost', $fee)) && (is_array($fee) && array_key_exists('currency', $fee)));
}
if ($fees) {
assert (gettype($fees) === 'array' && count(array_filter(array_keys($fees), 'is_string')) == 0);
for ($i = 0; $i < count($fees); $i++) {
$fee = $fees[$i];
assert ((is_array($fee) && array_key_exists('cost', $fee)) && (is_array($fee) && array_key_exists('currency', $fee)));
}
}
$id = $trade['id'];
assert (($id === null) || (gettype($id) === 'string'));
$timestamp = $trade['timestamp'];
assert ((is_float($timestamp) || is_int($timestamp)) || $timestamp === null);
if ($timestamp) {
assert ($timestamp > 1230940800000); // 03 Jan 2009 - first block
assert ($timestamp < 2147483648000); // 19 Jan 2038 - int32 overflows
$adjustedNow = $now + 60000;
assert ($timestamp < $adjustedNow, 'trade.timestamp is greater than or equal to current time => $trade => ' . $exchange->iso8601 ($timestamp) . ' $now => ' . $exchange->iso8601 ($now));
}
assert ($trade['datetime'] === $exchange->iso8601 ($timestamp));
assert ($trade['symbol'] === $symbol, 'trade $symbol is not equal to requested $symbol => $trade => ' . $trade['symbol'] . ' requested => ' . $symbol);
assert ($trade['type'] === null || gettype($trade['type']) === 'string');
assert ($trade['side'] === null || $trade['side'] === 'buy' || $trade['side'] === 'sell', 'unexpected $trade side ' . $trade['side']);
assert ($trade['order'] === null || gettype($trade['order']) === 'string');
assert ((is_float($trade['price']) || is_int($trade['price'])), 'trade.price is not a number');
assert ($trade['price'] > 0);
assert ((is_float($trade['amount']) || is_int($trade['amount'])), 'trade.amount is not a number');
assert ($trade['amount'] >= 0);
assert ($trade['cost'] === null || (is_float($trade['cost']) || is_int($trade['cost'])), 'trade.cost is not a number');
assert ($trade['cost'] === null || $trade['cost'] >= 0);
$takerOrMaker = $trade['takerOrMaker'];
assert ($takerOrMaker === null || $takerOrMaker === 'taker' || $takerOrMaker === 'maker');
}